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: 

Point3D.create makes z coordinate negative before placing point

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
dahousecat
526 Views, 6 Replies

Point3D.create makes z coordinate negative before placing point

I've made a very simple script to place a point at 1, 1, 1.

 

When I run it I see a point has been created at 1, 1, -1.

 

Why is the z axis been made negative?

 

import adsk.core, adsk.fusion, traceback

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

        design = adsk.fusion.Design.cast(app.activeProduct)

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

        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xZConstructionPlane)

        # Create point       
        testPosition1 = adsk.core.Point3D.create(1, 1, 1)
        testPoint1 = sketch.sketchPoints.add(testPosition1)
        
        # Test values
        print('x: ' + str(testPoint1.worldGeometry.x))
        print('y: ' + str(testPoint1.worldGeometry.y))
        print('z: ' + str(testPoint1.worldGeometry.z))    
        
        # Outputs
        # x: 1.0
        # y: 1.0
        # z: -1.0
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

The Fusion 36o UI also reports the point is at Z -1.

6 REPLIES 6
Message 2 of 7
MichaelT_123
in reply to: dahousecat

Hi Mr. DaHouseCat,

 

... just have started fusiventure...?

Consider changing 'Z' to 'Y'.

 

Regards

MichaelT

 

PS. Nice smile though :).

 

MichaelT
Message 3 of 7
JesusFreke
in reply to: dahousecat

Hmm, yeah. It looks like the sketch's axis has been flipped. rootComp.xZConstructionPlane.geometry.uDirection is (0, 0, 1), but sketch.yDirection is (0, 0, -1).

 

I find that... surprising. If you specify a ConstructionPlane as the basis for a sketch, I would expect the sketch to have the same axis as the reference plane.

Message 4 of 7
JesusFreke
in reply to: JesusFreke

I suspect it's a consequence of the default "y-up" view, which I always found... strange. I always use z-up, which makes much more sense to me. But anyway, if you have y-up enabled, and position the viewport so that +x is to the right, then +z is down. So when you add a sketch like this, "up" (positive y) in the sketch is in the -z direction.

 

I can confirm that if you have z-up enabled, adding a sketch to the xY plane has the coordinate space you would expect 🙂

 

 

 

Message 5 of 7
dahousecat
in reply to: JesusFreke

Thanks, and I agree - very strange that Z up is not the default!

Message 6 of 7

Hi, how did you solve this ?
I'm creating a 3D point to 1,1,1 and it appears at 1,1,-1. And the UI also states the z coordinate is negative. I also have sketch.yDirection.z = -1
I have Z-up preference set, so what should I do now ?
Message 7 of 7

Hi @candice.pimenta9E4XT .

 

By using the Sketch.modelToSketchSpace method, you should be able to create a point at the desired location.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-dfec5579-3ee5-432b-80d9-50710515bd71 

 

import adsk.core, adsk.fusion, traceback

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

        design = adsk.fusion.Design.cast(app.activeProduct)

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

        # Create sketch
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xZConstructionPlane)

        # Create point       
        testPosition1 = adsk.core.Point3D.create(1, 1, 1)
        testPoint1 = sketch.sketchPoints.add(testPosition1)
        
        # Test values 
        app.log(f'{testPoint1.worldGeometry.asArray()}')

        # use modelToSketchSpace
        modelToSketchPoint = sketch.modelToSketchSpace(testPosition1)
        testPoint2 = sketch.sketchPoints.add(modelToSketchPoint)
        app.log(f'modelToSketchSpace:{testPoint2.worldGeometry.asArray()}')
        
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report