Point3D.create makes z coordinate negative before placing point

Point3D.create makes z coordinate negative before placing point

Anonymous
961 Views
6 Replies
Message 1 of 7

Point3D.create makes z coordinate negative before placing point

Anonymous
Not applicable

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.

0 Likes
Accepted solutions (1)
962 Views
6 Replies
Replies (6)
Message 2 of 7

MichaelT_123
Advisor
Advisor

Hi Mr. DaHouseCat,

 

... just have started fusiventure...?

Consider changing 'Z' to 'Y'.

 

Regards

MichaelT

 

PS. Nice smile though :).

 

MichaelT
0 Likes
Message 3 of 7

JesusFreke
Advocate
Advocate

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.

0 Likes
Message 4 of 7

JesusFreke
Advocate
Advocate
Accepted solution

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 🙂

 

 

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

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

0 Likes
Message 6 of 7

candice.pimenta9E4XT
Participant
Participant
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 ?
0 Likes
Message 7 of 7

kandennti
Mentor
Mentor

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()))

 

0 Likes