Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

error trying to revolve using a construction plane's axis

metd01567
Advocate

error trying to revolve using a construction plane's axis

metd01567
Advocate
Advocate

 

I'm trying to revolve the rectangle in the "SlotProfile" sketch to create a cylinder.  That works in the user interface. I'm able to select one of the two halves, use the vertical axis of the sketch, and revolve 360 degrees to get a cylinder. (edit - looking back I actually selected the model's z axis.  I'll look into that further)   But the following extracted code gets an error on the last line: "RuntimeError: 3 : fail to get the ObjectPath of the axis".  I tried the vDirection and normal of the referencePlane (not expecting them to work), and got the same error.  I'm not really sure what the error is saying.

 

    selectedSketchEntity = sketchSelectionInput.selection(0).entity
    selectedSketch = adsk.fusion.Sketch.cast(selectedSketchEntity)
        revolveFeats = feats.revolveFeatures
        revolveInput = revolveFeats.createInput(refProfiles[0], selectedSketch.referencePlane.geometry.vDirection , adsk.fusion.FeatureOperations.JoinFeatureOperation)
        revFeat = revolveFeats.add(revolveInput)

The documentation for createInput says the axis parameter is of type Base, so maybe there are multiple types supported.  The description says: "The axis can be a sketch line, construction axis, or linear edge".Since createInput accepted the axis parameter, so the type may be correct.

 

I want to revolve around the vertical axis of the sketch. I thought the sketch's "uDirection" would do that for me. (edit - the sketch's referencePlane is a ConstructionPlane object, I assumed the uDirection of the plane would qualify as a "construction axis")

 

 

0 Likes
Reply
Accepted solutions (1)
753 Views
5 Replies
Replies (5)

goyals
Autodesk
Autodesk

revolveFeatures.createInput does not take vector 3D as input. You need to pass a constructionAxis, edge or sketch line. May be you can try by creating a constructionAxis using two planes, one in which your profile is lying and second a plane perpendicular to it.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes

metd01567
Advocate
Advocate

Thanks.  I assumed the sketch's referencePlane, which is a ConstructionPlane, would have ConstructionAxes defined.  I guess that's not the case?

 

 

I will always have a SketchLine that's coincident with the sketch's z axis.  It's not obvious to me how to get the original SketchLine from a ProfileCurve, so I could grind through all the SketchLines in the "SlotProfile" sketch.  Is there an easier way to find that line within the sketch?

 

Worst case I could create a construction axis from a transient InfiniteLine3D based on the sketch's origin and uDirection vector.

0 Likes

goyals
Autodesk
Autodesk
Accepted solution

You can create  construction axis from a transient InfiniteLine3D based on the sketch's origin and uDirection vector only in DirectModelling mode so getting the sketch line is only solution.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes

metd01567
Advocate
Advocate

That seemed easy enough, but I expected the sketch's curves to be defined relative to the sketch's reference plane; or maybe absolute.   That's not the case, I'm missing something basic.

 

Here's what I got for the SketchLine start/end points.  I think the last line is the one I want, but it's upside down and aligned to the Y axis:

>>> 
start x/y/z: -0.159/0.832/0.000, end x/y/z: -0.159/0.000/0.000
start x/y/z: 0.159/0.835/0.000, end x/y/z: -0.159/0.832/0.000
start x/y/z: -0.159/0.000/0.000, end x/y/z: 0.159/-0.000/0.000
start x/y/z: 0.159/-0.000/0.000, end x/y/z: 0.159/0.835/0.000
start x/y/z: 0.000/0.000/0.000, end x/y/z: 0.000/0.833/0.000

That's from this code, it hits the "no axis" case and returns:

import adsk.core, adsk.fusion

def run(context):

    app = adsk.core.Application.get()
    ui = app.userInterface
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    comp = design.rootComponent

    selectedSketch = comp.sketches.itemByName("SlotProfile")

    ######################
    revAxis = None
    print ("")
    for thisCurve in selectedSketch.sketchCurves.sketchLines:
        start = thisCurve.geometry.startPoint
        end = thisCurve.geometry.endPoint
        print("start x/y/z: {:.3f}/{:.3f}/{:.3f}, end x/y/z: {:.3f}/{:.3f}/{:.3f}".format(start.x, start.y, start.z, end.x, end.y, end.z), flush=True)
        if (abs(start.x) < 0.001 and abs(start.y) < 0.001 and abs(end.x) < 0.001 and abs(end.y) < 0.001):
            revAxis = thisCurve
            break
    if not revAxis:
        ui.messageBox("no axis")
        return False
    else:
        ui.messageBox("axis found")
        return True

 

0 Likes

metd01567
Advocate
Advocate

Based on the prints, I looked for x and z close to zero vs x and y.  The code below got me the cylinder that I want.

 

I'm left with a few dangling questions: To use this generally, how do I anticipate the coordinates returned by the SketchLine geometry, knowing the sketch's reference plane?  I hacked in a "number reasonably close to zero" comparison, what's the best practice for doing that in Fusion 360 API scripting? 

 

Also I'd appreciate knowing if there's a better way to search for the SketchLine.

 

import adsk.core, adsk.fusion

def run(context):

    app = adsk.core.Application.get()
    ui = app.userInterface
    product = app.activeProduct
    design = adsk.fusion.Design.cast(product)
    comp = design.rootComponent

    selectedSketch = comp.sketches.itemByName("SlotProfile")

    ######################
    revAxis = None
    print ("")
    for thisCurve in selectedSketch.sketchCurves.sketchLines:
        start = thisCurve.geometry.startPoint
        end = thisCurve.geometry.endPoint
        print("start x/y/z: {:.3f}/{:.3f}/{:.3f}, end x/y/z: {:.3f}/{:.3f}/{:.3f}".format(start.x, start.y, start.z, end.x, end.y, end.z), flush=True)
        if (abs(start.x) < 0.001 and abs(start.z) < 0.001 and abs(end.x) < 0.001 and abs(end.z) < 0.001):
            revAxis = thisCurve
            break
    if not revAxis:
        ui.messageBox("no axis")
        return False
    else:
        ui.messageBox("axis found")

        revolveInput = comp.features.revolveFeatures.createInput(selectedSketch.profiles[0], revAxis , adsk.fusion.FeatureOperations.JoinFeatureOperation)
        revolveInput.setAngleExtent(False, adsk.core.ValueInput.createByString("360 deg"))
        revFeat = comp.features.revolveFeatures.add(revolveInput)

1 Like