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.
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
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!
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?
It fails at the PointItemMaster.Merge(PointItemClient) (or the equivalent in my code).
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:
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.
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.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.