Get intersection points between sketch entities

Get intersection points between sketch entities

ebunn3
Advocate Advocate
434 Views
1 Reply
Message 1 of 2

Get intersection points between sketch entities

ebunn3
Advocate
Advocate

 

Hi,

 

Another newbie question:  I'm trying to get the intersection points between intersecting geometries in a sketch.  I am trying to use SketchLine.intersections Method (line 59 in the attached code).  It crashes on that line of code.  Can someone explain what I am doing wrong.  Thanks again.

 

Eric

ebunn3_1-1628522102525.png

 

 

 

 

 

#Author-Bunn
#Description-

increment = .1

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        radius1 = 2
        radius2 = 0.156

        #get the application
        app = adsk.core.Application.get()
        ui  = app.userInterface
        design = app.activeProduct

        # #get the root component
        # rootComp = design.rootComponent
        #Cast the root component (casting versus setting will get access to more intellisense)
        rootComp = adsk.fusion.Component.cast(design.rootComponent)

        #create a new sketch on the xy plane
        sketches = rootComp.sketches
        Plane = rootComp.yZConstructionPlane
        sketch = sketches.add(Plane)
        sketch.name = 'YZ Plane'

        #get the id of the cushion body
        prodBody = adsk.core.ObjectCollection.create()
        prodBody = rootComp.bRepBodies.itemByName('Pump')

        # Get sketch points
        projCrv = sketch.project(prodBody)
        sketchCurves = sketch.sketchCurves
        


        BB = sketch.boundingBox
        minBB = BB.minPoint
        maxBB = BB.maxPoint
        
        minBB = sketch.modelToSketchSpace(minBB)
        minX = minBB.x
        minY = minBB.y
        minZ = minBB.z

        maxBB = sketch.modelToSketchSpace(maxBB)
        maxX = maxBB.x
        maxY = maxBB.y
        maxZ = maxBB.z
        

        #Create Base Line on Sketch
        lines = sketch.sketchCurves.sketchLines
        line1 = lines.addByTwoPoints(adsk.core.Point3D.create(maxZ-increment , minY , 0), adsk.core.Point3D.create(maxZ-increment , maxY ,0))

        intersections = line1.intersections(sketchCurves)


        i= increment
        while i <= maxZ:
            retval = line1.intersectWithCurve()
            i += increment


    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

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

kandennti
Mentor
Mentor
Accepted solution

Hi @ebunn3 .

 

The parameter of the intersections method needs to be an ObjectCollection.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-423d7df9-2247-4e4d-b37b-3ef9f4d24b06 

 

・・・
        #Create Base Line on Sketch
        lines = sketch.sketchCurves.sketchLines
        line1 = lines.addByTwoPoints(adsk.core.Point3D.create(maxZ-increment , minY , 0), adsk.core.Point3D.create(maxZ-increment , maxY ,0))

        # intersections = line1.intersections(sketchCurves)
        crvs: adsk.core.ObjectCollection = adsk.core.ObjectCollection.create()
        [crvs.add(c) for c in  sketchCurves]
        intersections = line1.intersections(crvs)

・・・

 

0 Likes