Which direction is positive z in the API?

Which direction is positive z in the API?

siliconlad
Contributor Contributor
400 Views
1 Reply
Message 1 of 2

Which direction is positive z in the API?

siliconlad
Contributor
Contributor

I have the following script which creates, a circular sketch, 2 sketch points and 2 sketch lines (as below).

 

image.png

 

The code for this is shown below (based on the Construction Plane API sample)

 

 

import adsk.core, adsk.fusion, traceback

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

        # Create a document.
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)

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

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

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

        # Create sketch circle
        sketchCircles = sketch.sketchCurves.sketchCircles
        centerPoint = adsk.core.Point3D.create(0, 0, 0)
        sketchCircles.addByCenterRadius(centerPoint, 5.0)

        # Create sketch line
        sketchLines = sketch.sketchCurves.sketchLines
        startPoint = adsk.core.Point3D.create(5, 5, 0)
        endPoint = adsk.core.Point3D.create(5, 10, 0)
        sketchLineOne = sketchLines.addByTwoPoints(startPoint, endPoint)
        endPointTwo = adsk.core.Point3D.create(10, 5, 0)
        sketchLineTwo = sketchLines.addByTwoPoints(startPoint, endPointTwo)

        # Create two sketch points
        sketchPoints = sketch.sketchPoints
        positionOne = adsk.core.Point3D.create(0, 5.0, 0)
        sketchPointOne = sketchPoints.add(positionOne)
        positionTwo = adsk.core.Point3D.create(5.0, 0, 0)
        sketchPointTwo = sketchPoints.add(positionTwo)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

  

`startPoint` which is created with coordinates (5, 5, 0) is placed in position (5, 0, -5) according to my axis in the top right corner. Given that the sketch is on the xZConstructionPlane I would be able to understand how specifying (5, 5, 0) ends up as (5, 0, 5), but I cannot understand how (5, 5, 0) maps to (5, 0, -5)??

0 Likes
Accepted solutions (1)
401 Views
1 Reply
Reply (1)
Message 2 of 2

john.kirchner
Autodesk
Autodesk
Accepted solution

You can get information about the orientation of sketches in the API a few different ways. For example you can get the xDirection and yDirection from the sketch object. Here's a sketch created on the xZConstructionPlane

 

 

sketch.xDirection #(1.0, 0.0, 0.0)
sketch.yDirection #(0.0, 0.0, -1.0)

 

 

I've added the asArray() output next to each line. So the sketch positive X aligns to world/design positive X, sketch positive Y aligns to world/design negative Z.

This aligns with what is seen in the UI as well if you open up the sketch and look at the labelled axis

johnkirchner_0-1704915665455.png

 



One last thing to note is that Fusion uses right handed coordinate systems.