AddCoincident constraint for multiple sketch entities

AddCoincident constraint for multiple sketch entities

Anonymous
Not applicable
848 Views
1 Reply
Message 1 of 2

AddCoincident constraint for multiple sketch entities

Anonymous
Not applicable

Hi,

 

I have created multiple sketch entities like line, arc, circle etc. using the Inventor API's. Now I want to add the coincident constraint between start point of line, start point of arc and center point of circle.

 

I have added coincident constraint through UI(Please see attached snap). The same I want to add using Inventor API's.

 

Please tell me which API I should use to add the coincident constraint for such multiple entities.

 

Thanks in advance!

0 Likes
Accepted solutions (1)
849 Views
1 Reply
Reply (1)
Message 2 of 2

ekinsb
Alumni
Alumni
Accepted solution

It's a little confusing what you need to do.  In this case you have to be aware of what's happening internally within Inventor when you add the coincident constraint.  It's not actually adding a new constraint but is changing the entities so that they share a single sketch point.

 

The code below demonstrates two different approaches to get the same result.  One is to create the initial sketch entities entirely independent of each other and then connect that points after.  The code does this below to connect the two lines to the circle center by using the Merge method on the SketchPoint object.  The second approach, and the one I prefer is to create then connected.  The code below demonsrates this when it's creating the arc.  Instead of defining the start point of the arc using X,Y coordinates it provides the center sketch point of the circle.  This does two things.  First it defines the position and it will also create the line such that it's uses that sketch point as it's starting point.

 

Public Sub SketchConstraints()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    
    Dim sketch As PlanarSketch
    Set sketch = partDoc.ComponentDefinition.Sketches.Add( _
                 partDoc.ComponentDefinition.WorkPlanes.Item(3))
    
    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry
    
    Dim line1 As SketchLine
    Dim line2 As SketchLine
    Dim circ As SketchCircle
    Dim arc As SketchArc
    
    Set circ = sketch.SketchCircles.AddByCenterRadius( _
                                           tg.CreatePoint2d(0, 0), 5)
    
    Set line1 = sketch.SketchLines.AddByTwoPoints( _
                                           tg.CreatePoint2d(1, 1), _
                                           tg.CreatePoint2d(6, 6))
    Set line2 = sketch.SketchLines.AddByTwoPoints( _
                                           tg.CreatePoint2d(-1, 1), _
                                           tg.CreatePoint2d(-6, 6))
    
    Set arc = sketch.SketchArcs.AddByThreePoints( _
                                           circ.CenterSketchPoint, _
                                           tg.CreatePoint2d(1, -3), _
                                           tg.CreatePoint2d(4, -4))
                                                  
    Call circ.CenterSketchPoint.Merge(line1.StartSketchPoint)
    Call circ.CenterSketchPoint.Merge(line2.StartSketchPoint)
    
    sketch.Solve
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog