Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to select the faces after combining BRep bodies to use revolve feature.

Message 1 of 1
245 Views, 0 Replies

How to select the faces after combining BRep bodies to use revolve feature.

I have got into a new problem with this. I would really appreciate it if you could help to.

1) I am combining the bodies so that  I can use the revolve feature. But after combining two bodies I am not being able to select the face that I want to revolve. In the user interface, I can select the face and revolve it to starting face of the next body. However, with the script, I am not being able to select the end face of the 1st body to revolve. 



# I have attached the 2 Brep bodies made and combined with script. The blue line is sketeched to make axis line for revolve. Using UI i can select the faces but with script I could not slect the face of body to revolev.


Could you please look into the code and help me to figure out how to solve this issue. I would really appreciate your help. 


Screen Shot 2020-03-01 at 8.26.58 PM.pngScreen Shot 2020-03-01 at 8.26.29 PM.pngScreen Shot 2020-03-01 at 8.27.48 PM.png


#Fusion360API Python script
import adsk.core, adsk.fusion, traceback
import time

def run(context):
    ui = None
        # data file path
        path = '/Users/rizal/Desktop/20mm_cubeCoordinates.txt'

        app = adsk.core.Application.get()
        ui  = app.userInterface
        # new document
        # app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des = adsk.fusion.Design.cast(app.activeProduct)

        # direct design
        des.designType = adsk.fusion.DesignTypes.DirectDesignType

        # time
        startTime = time.time()

        # read file
        data = readData(path)

        # point3D
        pnt3D = adsk.core.Point3D
        pnts = [pnt3D.create(x, y, z) for (x, y, z) in data]

        # create cylinder
        radius =0.035
        cylinders = initCylinders(pnts, radius)

        # add bodies
        root = des.rootComponent
        bodies = root.bRepBodies

        # for i in range(bodies.count-1):

        [bodies.add(cyl) for cyl in cylinders]

        #Sketching lines to make axis for revolve 
        sketches = root.sketches
        xyPlane = root.xYConstructionPlane
        sketch = sketches.add(xyPlane)

        lines = sketch.sketchCurves.sketchLines
        axisline = lines.addByTwoPoints(

        #Collection object to store bodies for combine operation
        coll = adsk.core.ObjectCollection.create()

        combine = root.features.combineFeatures
        combineInput = combine.createInput(bodies.item(0),coll)
        body = combine.add(combineInput)

        # face1 = body.faces[2]
        # face2 = body.faces[3]
        # revolves = root.features.revolveFeatures
        # revInput = revolves.createInput(face1,axisline,adsk.fusion.FeatureOperations.JoinFeatureOperation)
        # revInput.setOneSideToExtent(face2)

        # ext = revolves.add(revInput)
        # # for i in range(bodies.count-1):

        # fin
        des.designType = adsk.fusion.DesignTypes.ParametricDesignType
        msg = '-- Done --\nBodyCount : {}\nTime : {}'.format(
            len(cylinders),time.time() - startTime)

        if ui:

def initCylinders(
    pnts :list,
    radius :float
    ) -> list:

    tmpMgr = adsk.fusion.TemporaryBRepManager.get()
    cyls = []
    for idx in range(2):
        # creating vector to orient epllipse along the path
        vec = adsk.core.Vector3D.create(pnts[idx].x,pnts[idx].y,pnts[idx].z)

        #creating elliptical cylinder with major radius 0.02 and minor radius 0.01 and direction of vector 
        cyl = tmpMgr.createEllipticalCylinderOrCone(
            pnts[idx],0.02, 0.01, pnts[idx + 1], 0.02, vec)

        if cyl:
    return cyls

def readData(
    path :str
    ) -> list:

    with open(path, 'r', buffering = -1, encoding = 'utf-8-sig') as f:
        lst = f.readlines()
    data = [s.replace('\n', '').split(',') for s in lst]

    app  :adsk.core.Application = adsk.core.Application.get()
    des  :adsk.fusion.Design = app.activeProduct
    um = des.unitsManager
    conv = um.convert(1, um.defaultLengthUnits, um.internalUnits)

    return [(float(x) * conv, float(y) * conv, float(z) * conv) for (x,y,z) in data]




Tags (2)

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

Post to forums  

Technology Administrators