sketch returns another sketch instead of referencePlane

sketch returns another sketch instead of referencePlane

metd01567
Advocate Advocate
827 Views
5 Replies
Message 1 of 6

sketch returns another sketch instead of referencePlane

metd01567
Advocate
Advocate

I'm trying to get the normal to a sketch, via the reference plane's geometry.  But for the "Slots" sketch in the attached example, the referencePlane is a "Sketch" object.  If I redefine the Slots sketch plane to the root XY plane, I get a "ConstructionPlane" as expected.

 

Here's the offending code:

 

import adsk.core, adsk.fusion, traceback


def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        comp = design.rootComponent

        refSketch = comp.sketches.itemByName("Slots")

        ui.messageBox("sketch plane is a: " + refSketch.referencePlane.classType())

        rotAxis = refSketch.referencePlane.geometry.normal

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Accepted solutions (2)
828 Views
5 Replies
Replies (5)
Message 2 of 6

goyals
Autodesk
Autodesk
Accepted solution

To create a sketch, we can use another sketch as referencePlane for it. If you query referencePlane again on returned sketch, you will get the construction plane of it.



Shyam Goyal
Sr. Software Dev. Manager
0 Likes
Message 3 of 6

metd01567
Advocate
Advocate

I added:

 

 

        
        ui.messageBox("sketch's sketch plane is a: " + refSketch.referencePlane.referencePlane.classType())

but that returned "Profile".

 

 

0 Likes
Message 4 of 6

metd01567
Advocate
Advocate

Of course, a sketch's reference plane can be a profile too.  Over time I've become more careful about sketch interdependencies, but this started as one of my first projects.  I don't doubt that I had a sketch referencing a sketch which then referenced a profile (which then belonged in a sketch).

 

So now I'd like to change my question to: "how can a script reliably determine a sketch's normal?".  Technically you've solved my original problem, should I start a new topic or do we keep going here?

 

 

This points to a common problem in the API documentation. In general when a property or method returns multiple types, we've got to rely on the Description text to psych out the possibilities.   The Description for Sketch.referencePlane: says "construction plane or planar face the sketch is associated to".  I figured out ConstructionPlane, but what are all possible types of "planar face"?

 

Even if I had a complete list of referencePlane types, the ones I know of don't have a common method or property to determine the normal.  The code to sift through them would be messy.  And brittle, API changes could break it.  Should I request adding a "normal" property to Sketch, completing the "xDirection" and "yDirection"?  In theory I should be able to derive normal from x/y direction using the right hand rule.  But I'd have to pull out my textbooks to do it. 

0 Likes
Message 5 of 6

BrianEkins
Mentor
Mentor
Accepted solution
The easiest way is to get it directly from the sketch. Unfortunately it's not directly exposed but using other information that is exposed it's easy to compute. Something like:

normal = sk.xDirection.crossProduct(sk.yDirection)
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 6 of 6

metd01567
Advocate
Advocate

Thanks. I did a general search for "cross product" but of course it's found by "crossproduct".   I wasn't expecting it  in Vector3D, but it makes sense.  You caught me just in time, before I tried to cook something up myself.

 

I changed my rotational axis assignment to:

    rotAxis = rotSketch.xDirection.crossProduct(rotSketch.yDirection)

and that did the trick.

0 Likes