I'm trying to insert a new area from selected areas in a drawing . In the attached script, I add all the points of the selected areas to the "newPointSet" variable and create a new Geom. The current output is far from the desired output. What do I need to do?
Attachments: Current output.png Desired output.png input.png InsertGeom.txt
Add the branches and the points in index order.
For Each doesn't ensure any particular order, so use an indexed For for these cases.
Dim newGeom, newPointSet
Dim geom, branch, point
Dim i, j
For Each geom in geomSet
For i = 0 To geom.BranchSet.Count - 1
Set branch = geom.BranchSet.Item(i)
For j = 0 To branch.PointSet.Count - 1
Set point = branch.PointSet.Item(j)
Next ' j
Next ' i
Next ' geom
It's fine to use For Each for the geoms, since there order doesn't matter (unless it does!).
Many thanks. I tried the code above but I'm getting the same result
I think you are expecting too much of Manifold here. You are taking the points from each branch and combining them into one branch, but you are expecting Manifold to understand that what you intend is to generate a perimeter from these points by joining the shapes. Manifold is doing exactly what you ask: it is creating an area with one branch of points. It creates the first set of 5 points, then it crosses over to the other area and creates the next set of points, and then it crosses back to close the geometry.
Your algorithm will only work (i.e., do what you intend) on very simple geometries where your points also happen to be arranged in order around the perimeter of the new area to be formed. In the more common, general case it will not work. For complex geometries, it will never work.
What is it that you are trying to do? Fill in the empty space between two areas? I am not even sure how you would describe this problem algorithmically.
How about select the two elements, and then use the transform toolbar to create a convex hull.
Don't know if that works for all your shapes of course...
sorry for the late reply. convex hull works works for me.