how to select intersection area (profile) of 2 circles using API

how to select intersection area (profile) of 2 circles using API

liminma8458
Collaborator Collaborator
982 Views
2 Replies
Message 1 of 3

how to select intersection area (profile) of 2 circles using API

liminma8458
Collaborator
Collaborator

Hi,

 

I want to create an extrusion from the intersection area (the central profile) of 2 circles as in attached picture. how can I identify and select this profile using API.

 

Thank you very much!

 

Limin

 

Untitled.png

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes
Accepted solutions (1)
983 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni
Accepted solution

Here's some VBA code that demonstrates one approach.  The first thing to notice is that the intersection is not available as part of the profile unless you add intersection points between the two circles.  Otherwise only the two whole circles are available.  Once the points are added, then there are three paths within the profile and it's a matter of figuring out how the path you want is different than the other two and looking for it.  The code below is using the sweep angle of the arcs to find the smaller path.

 

Public Sub CircleIntersectSample()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    Dim partDef As PartComponentDefinition
    Set partDef = partDoc.ComponentDefinition
    
    Dim sketch As PlanarSketch
    Set sketch = partDef.sketches.Add(partDef.WorkPlanes.Item(3), False)
    
    Dim tg As TransientGeometry
    Set tg = ThisApplication.TransientGeometry
    
    ' Draw the two circles.
    Dim circ1 As SketchCircle
    Set circ1 = sketch.SketchCircles.AddByCenterRadius(tg.CreatePoint2d(6, 0), 8)
    Dim circ2 As SketchCircle
    Set circ2 = sketch.SketchCircles.AddByCenterRadius(tg.CreatePoint2d(-5, 0), 7)
    
    ' Temporarily ground the circles so they don't move as the intersections are added.
    Dim ground1 As GroundConstraint
    Set ground1 = sketch.GeometricConstraints.AddGround(circ1)
    Dim ground2 As GroundConstraint
    Set ground2 = sketch.GeometricConstraints.AddGround(circ2)
    
    
    ' Add intersection points so the intersections are considered in the profile creation.
    Dim skPnt As SketchPoint
    Set skPnt = sketch.SketchPoints.Add(tg.CreatePoint2d(0, 4))
    Call sketch.GeometricConstraints.AddCoincident(skPnt, circ1)
    Call sketch.GeometricConstraints.AddCoincident(skPnt, circ2)
    
    Set skPnt = sketch.SketchPoints.Add(tg.CreatePoint2d(0, -4))
    Call sketch.GeometricConstraints.AddCoincident(skPnt, circ1)
    Call sketch.GeometricConstraints.AddCoincident(skPnt, circ2)
    
    ' Delete the grounds.
    ground1.Delete
    ground2.Delete
    
    Dim prof As Profile
    Set prof = sketch.Profiles.AddForSolid()
    
    ' Find the union piece of the two circles by looking
    ' for a path that contains two arcs whose sweep is less
    ' than 180 degrees.
    Dim pi As Double
    pi = Atn(1) * 4
    Dim path As ProfilePath
    For Each path In prof
        Dim arc1 As Arc2d
        Set arc1 = path.Item(1).curve
        If arc1.SweepAngle < pi Then
            Dim arc2 As Arc2d
            Set arc2 = path.Item(2).curve
            If arc2.SweepAngle < pi Then
                path.AddsMaterial = True
            Else
                path.AddsMaterial = False
            End If
        Else
            path.AddsMaterial = False
        End If
    Next
    
    Dim extDef As ExtrudeDefinition
    Set extDef = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(prof, kNewBodyOperation)
    Call extDef.SetDistanceExtent(5, kPositiveExtentDirection)
    Dim ext As ExtrudeFeature
    Set ext = partDef.Features.ExtrudeFeatures.Add(extDef)
End Sub

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

liminma8458
Collaborator
Collaborator

Brian,

 

It works great and really what I want! Thank you very much!

 

Limin

Thanks
Limin
Inventor pro 2023 64 bit update 5.3; Windows 11 pro 64 bit version 24H2; Office 2013 64 bit

Download iCable in App Store to Create Cables Easily

0 Likes