Autodesk Inventor Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Merge Points
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Why does this code fragment not work? (Within an active part sketch, with some sketched geometry.)
I'm just trying to close the loops to have valid extrusion profiles.
Please help.
Dim iCounter As Integer
Dim icounter2 As Integer
Dim oSPoint1 As SketchPoint
Dim oSPoint2 As SketchPoint
Dim xVal1 As Double
Dim xVal2 As Double
Dim yVal1 As Double
Dim yVal2 As Double
For iCounter = 1 To oSketch.SketchPoints.Count
For icounter2 = 2 To oSketch.SketchPoints.Count
If iCounter <> icounter2 Then
xVal1 = oSketch.SketchPoints(iCounter).Geometry.X
xVal2 = oSketch.SketchPoints(icounter2).Geometry.X
yVal1 = oSketch.SketchPoints(iCounter).Geometry.Y
yVal2 = oSketch.SketchPoints(icounter2).Geometry.Y
If xVal1 = xVal2 Then
If yVal1 = yVal2 Then
Set oSPoint1 = oSketch.SketchPoints(iCounter)
Set oSPoint2 = oSketch.SketchPoints(icounter2)
oSPoint1.Merge (oSPoint2)
End If
End If
End If
Next
Next
This is my signature, not part of my post.
Re: Merge Points
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I had a similar problem after I imported an autocad file into a sketch.
Here's the code I'm using :
Dim StartCounter As Integer Dim PointItemMaster As SketchPoint Dim PointItemClient As SketchPoint For Each PointItemMaster In oSketch.SketchPoints StartCounter = 0 For Each PointItemClient In oSketch.SketchPoints If Round(PointItemClient.Geometry.x,4) = Round(PointItemMaster.Geometry.x,4) And Round(PointItemClient.Geometry.y,4) = Round(PointItemMaster.Geometry.y,4) Then StartCounter = StartCounter + 1 If StartCounter = 2 Then PointItemMaster.Merge(PointItemClient) StartCounter = 0 Exit For End If End If Next PointItemClient Next PointItemMaster
I had to round the sketchpoints X/Y to 4 decimal places for it to work, when I dumped the co-ordinates out I found some were 0.000000000000001mm out - 4 decimal places was accurate enough for me.
Hope this helps!
Tom
Re: Merge Points
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for that Thomas; however it seems that I'm getting the same error: Run-time error 438: Object doesn't support this property or method. And your sample seems to be doing essentially the same as mine.
I thought it might be a problem with the version: we're using 2010, but i fired up 2012 and it's the same.
I didn't acutally mention that I'm running this from Excel; I have included as references Autodesk Inventor Compatibility Host 1.0; Autodesk Inventor Object Library and Autodesk Inventor's Apprentice Object Library.
Is there anything else I might have missed?
This is my signature, not part of my post.
Re: Merge Points
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hmm OK so your issue isn't with the Merge() method failing because of tolerances.
At what line does your code fail?
Re: Merge Points
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
It fails at the PointItemMaster.Merge(PointItemClient) (or the equivalent in my code).
This is my signature, not part of my post.
Re: Merge Points
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I got the points to become coincident by starting one entity from the endpoint of the previous entity, rather than from the Transient Geometry point2d that they share, to wit:
Call oSketchBlockDef.SketchArcs.AddByCenterStartEndPoin
Call oSketchBlockDef.SketchArcs.AddByCenterStartEndPoin
Call oSketchBlockDef.SketchLines.AddByTwoPoints(oSketch
Call oSketchBlockDef.SketchLines.AddByTwoPoints(oSketch
I drew the two end arcs, and then they two connecting lines; I could equally have stepped my way round the keyway.)
This closed the loop.
Thanks for your help.
This is my signature, not part of my post.
Re: Merge Points
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I was thinking not merging but adding coincident constraints between the two points.
cean
Re: Merge Points
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
cean_au,
You have to use Merge method to replace two sketch points by one point. This is the Sketch API requirement.
If you create coincident constraint between the ends of two lines, endpoints are merged in the background automatically. You may easily verify his fact checking SketchPoints.Count property before and after coincident operation.

Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network
