• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Autodesk Inventor Customization

    Reply
    Distinguished Contributor
    Posts: 350
    Registered: ‎07-12-2007

    Merge Points

    112 Views, 7 Replies
    01-24-2013 03:04 PM

    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.
    Please use plain text.
    Valued Contributor
    thomaskennedy
    Posts: 101
    Registered: ‎09-27-2010

    Re: Merge Points

    01-25-2013 01:13 AM 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

    Please use plain text.
    Distinguished Contributor
    Posts: 350
    Registered: ‎07-12-2007

    Re: Merge Points

    01-29-2013 05:10 PM 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.
    Please use plain text.
    Valued Contributor
    thomaskennedy
    Posts: 101
    Registered: ‎09-27-2010

    Re: Merge Points

    01-30-2013 02:51 AM 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?

    Please use plain text.
    Distinguished Contributor
    Posts: 350
    Registered: ‎07-12-2007

    Re: Merge Points

    01-30-2013 06:32 PM 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.
    Please use plain text.
    Distinguished Contributor
    Posts: 350
    Registered: ‎07-12-2007

    Re: Merge Points

    02-03-2013 03:25 PM 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.
    Please use plain text.
    Valued Contributor
    cean_au
    Posts: 100
    Registered: ‎07-11-2011

    Re: Merge Points

    02-03-2013 08:05 PM in reply to: robmatthews

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

     

    cean

    Please use plain text.
    ADN Support Specialist
    Posts: 183
    Registered: ‎08-14-2012

    Re: Merge Points

    02-05-2013 01:40 PM 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

    Please use plain text.