Community
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.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Make a new body on a face of a first made Body

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
641 Views, 4 Replies

Make a new body on a face of a first made Body

A below picture is a sample.
I made a body from a surface using Revolve at first(the gray one).
And I want to make a new body(the red one) on the endFace or other faces.
But I don't know the way to make the red body using python API automatically.
How do I write that?

sample_draw.png

 

Here's my code to draw the first body. I was able to get the endFace from it, but I didn't know what to do after that....

 

import adsk.core, adsk.fusion, math, traceback

def run(context):
    ui = None
    try: 
        app = adsk.core.Application.get()
        ui = app.userInterface

        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        design = app.activeProduct

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Create a new sketch on the xy plane.
        sketches = rootComp.sketches;
        xyPlane = rootComp.xYConstructionPlane;
        sketch = sketches.add(xyPlane)

        # Draw a circle.
        circles = sketch.sketchCurves.sketchCircles
        circle1 = circles.addByCenterRadius(adsk.core.Point3D.create(10, 0, 0), 2)
        
        # Draw a line to use as the axis of revolution.
        lines = sketch.sketchCurves.sketchLines
        axisLine = lines.addByTwoPoints(adsk.core.Point3D.create(0, -10, 0), adsk.core.Point3D.create(0, 10, 0))
        axisLine2 = lines.addByTwoPoints(adsk.core.Point3D.create(15, -10, 0), adsk.core.Point3D.create(15, 10, 0))

        # Get the profile defined by the circle.
        prof = sketch.profiles.item(0)

        # Create an revolution input to be able to define the input needed for a revolution
        # while specifying the profile and that a new component is to be created
        revolves = rootComp.features.revolveFeatures
        revInput = revolves.createInput(prof, axisLine, adsk.fusion.FeatureOperations.NewComponentFeatureOperation)

        # Define that the extent is an angle of pi to get half of a torus.
        angle = adsk.core.ValueInput.createByReal(math.pi)
        revInput.setAngleExtent(False, angle)

        # Create the extrusion.
        ext = revolves.add(revInput)
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

Tags (2)
4 REPLIES 4
Message 2 of 5
kandennti
in reply to: Anonymous

Hi miki.

 

I did it like this.

・・・
        ext = revolves.add(revInput)

        # Get endFace
        endFace :adsk.fusion.BRepFace = ext.endFaces.item(0)

        # Create sketch
        comp = endFace.body.parentComponent
        sketch2 = comp.sketches.add(endFace)
        lines2 = sketch2.sketchCurves.sketchLines

        pnt3D = adsk.core.Point3D
        axisLine3 = lines2.addByTwoPoints(pnt3D.create(15, -10, 0), pnt3D.create(15, 10, 0))

        # Create revolve
        prof2 = sketch2.profiles.item(0)
        revolves2 = comp.features.revolveFeatures
        newBody = adsk.fusion.FeatureOperations.NewBodyFeatureOperation
        revInput2 = revolves2.createInput(prof2, axisLine3, newBody)
        angle2 = adsk.core.ValueInput.createByReal(math.pi * 0.75)
        revInput2.setAngleExtent(False, angle2)
        ext2 = revolves2.add(revInput2)

・・・

 

I learned too.

 

 

 

Message 3 of 5
Anonymous
in reply to: kandennti

kanndenti, thank you for your reply!

I changed 

        endFace :adsk.fusion.BRepFace = ext.endFaces.item(0)

to 

        endFace = ext.endFaces.item(0)

and I was able to make it!

Message 4 of 5
kandennti
in reply to: Anonymous

今気が付きましたが、日本語でよかったのですね。

 

形状的に、スイープで作成した方が楽なような気がしましたが・・・。

Message 5 of 5
Anonymous
in reply to: kandennti

私も日本人の方だなと思っていたのですが、一応英語の方のフォーラムだったので😅

添付の図はサンプルから適当に持ってきたものだったのですが、

Revolveに限らずExtrudeなどで作ったボディの面から新しくボディを作る方法がわからなかったので助かりました。

ありがとうございます!

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

Post to forums  

Autodesk Design & Make Report