导出墙体顶点时重复端点及坐标异常问题求助
Hey Daniel, let's dig into why all your walls are spitting out identical vertex sets—this is a common pitfall when working with BIM/3D component geometry, so we'll fix this step by step.
First, let's unpack the two issues you mentioned:
92 endpoints from edge retrieval: This almost certainly means you're pulling edges from all nested components attached to the wall (like trim, embedded fixtures, or even opening boundaries) instead of just the wall's core solid geometry. BIM tools often bundle these sub-elements under the parent wall object, so you need to filter for only the primary solid.
28 identical vertices from face/mesh extraction: The culprit here is usually one of two things:
- You're reusing the same cached geometry object across all walls (instead of fetching each wall's unique instance geometry)
- You're pulling local coordinates from the wall's family template, not converting them to the project's global/world coordinate system
Step-by-Step Fixes
Let's walk through actionable checks and fixes:
Ensure you're fetching per-wall instance geometry
Don't define your geometry options or pull the geometric element outside of your wall loop. For example, if you're using an API like Revit, your loop should look something like this (pseudocode):// Correct approach: Fetch geometry INSIDE the wall loop foreach (Wall wall in allWalls) { GeometryOptions geomOpts = new GeometryOptions(); geomOpts.ComputeReferences = true; geomOpts.DetailLevel = ViewDetailLevel.Fine; // Get full geometry GeometryElement geomElem = wall.get_Geometry(geomOpts); // Process geomElem for this specific wall... }If you pull
geomElemonce before the loop, you'll just reuse the first wall's geometry for every subsequent one.Convert local coordinates to world space
Most BIM components store their geometry in a local family coordinate system. To get real-world positions, you need to apply the wall's transformation matrix to each vertex. Using the same Revit example:foreach (Solid solid in geomElem.OfType<Solid>()) { foreach (Face face in solid.Faces) { Mesh mesh = face.Triangulate(); foreach (XYZ localVertex in mesh.Vertices) { // Convert local vertex to world coordinates XYZ worldVertex = wall.Transform.OfPoint(localVertex); // Add worldVertex to your wall's vertex set } } }Without this transformation, every wall based on the same family will have identical local coordinates—even if they're in different positions in the project.
Filter for core wall geometry
Exclude non-solid elements (like wires, edges from openings, or nested sub-components) by checking the geometry type. Only processSolidobjects that belong to the wall's core (you can also check theMaterialIdto confirm it's the wall's structural material if needed).Validate vertex uniqueness per wall
After extracting transformed vertices, add a quick check to log the first few coordinates for each wall. If they're still identical, double-check that your loop is actually iterating over distinct wall instances (not a single repeated object) and that the transformation matrix is unique per wall.
Quick Reality Check
If your walls are based on the same family, their local vertex counts (28 in your case) will match—but their world coordinates should differ based on where each wall is placed. The key fix here is almost always the coordinate transformation step paired with fetching instance-specific geometry.
内容的提问来源于stack exchange,提问作者Daniel Ignjat

