Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Merge Points

7 REPLIES 7
Reply
Message 1 of 8
robmatthews
1076 Views, 7 Replies

Merge Points

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.
7 REPLIES 7
Message 2 of 8
thomaskennedy
in reply to: robmatthews

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

Message 3 of 8
robmatthews
in reply to: thomaskennedy

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.
Message 4 of 8
thomaskennedy
in reply to: robmatthews

Hmm OK so your issue isn't with the Merge() method failing because of tolerances.

 

At what line does your code fail?

Message 5 of 8
robmatthews
in reply to: thomaskennedy

It fails at the PointItemMaster.Merge(PointItemClient) (or the equivalent in my code).

=============================================
This is my signature, not part of my post.
Message 6 of 8
robmatthews
in reply to: robmatthews

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.AddByCenterStartEndPoint(Coords(7), Coords(3), Coords(6), True)
        Call oSketchBlockDef.SketchArcs.AddByCenterStartEndPoint(Coords(8), Coords(4), Coords(5), False)
        Call oSketchBlockDef.SketchLines.AddByTwoPoints(oSketchBlockDef.SketchArcs(1).StartSketchPoint, oSketchBlockDef.SketchArcs(2).EndSketchPoint)
        Call oSketchBlockDef.SketchLines.AddByTwoPoints(oSketchBlockDef.SketchArcs(2).StartSketchPoint, oSketchBlockDef.SketchArcs(1).EndSketchPoint)

 

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.
Message 7 of 8
cean_au
in reply to: robmatthews

I was thinking not merging but adding coincident constraints between the two points.

 

cean

Message 8 of 8
Vladimir.Ananyev
in reply to: cean_au

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report