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: 

Lines created on a sketch on a new plane don't appear on the plane

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dahousecat
418 Views, 2 Replies

Lines created on a sketch on a new plane don't appear on the plane

I'm just learning Fusion 360's API and writing one of my first scripts.

 

In my script I created a new sketch on the zx plane and added 3 points to this sketch in 3d space.

 

It then creates a new plane using the 3 points and adds a new sketch on the new plane.

 

It then draws 3 lines on the new sketch.

 

When I run the script and then make "My New Plane" visible I expect to see the 3 lines align with plane, however they are perpendicular to the plane.

 

Here is my code:

 

 

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 on the xz construction plane
        sketches = rootComp.sketches
        sketch = sketches.add(rootComp.xZConstructionPlane)
      
        # Create 3 points
        position1 = adsk.core.Point3D.create(0, 0, 0)   
        point1 = sketch.sketchPoints.add(position1)
        
        position2 = adsk.core.Point3D.create(0, 1, 2)
        point2 = sketch.sketchPoints.add(position2)
        
        position3 = adsk.core.Point3D.create(0, -1, 2)
        point3 = sketch.sketchPoints.add(position3)
        
        # Create construction plane input
        planeInput = rootComp.constructionPlanes.createInput()
    
        # Add construction plane by three points
        planeInput.setByThreePoints(point1, point2, point3)
        newPlane = rootComp.constructionPlanes.add(planeInput)
        newPlane.name = 'My New Plane'
        
        # Create new sketch on new plane
        newSketch = sketches.add(newPlane)  
        newSketch.name = 'My New Sketch'
        
        # Draw 3 lines on new sketch
        newLine1 = newSketch.sketchCurves.sketchLines.addByTwoPoints(position1, position2)
        newLine2 = newSketch.sketchCurves.sketchLines.addByTwoPoints(position2, position3)
        newLine3 = newSketch.sketchCurves.sketchLines.addByTwoPoints(position3, position1)
        

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

 

What am I doing wrong?

 

Can anyone explain why newLine1, newLine2 and newLine3 are not on newPlane?

Or what I need to do differently to make sure they do appear on newPlane?

2 REPLIES 2
Message 2 of 3
JesusFreke
in reply to: dahousecat

When you're adding points to a sketch, you specify the points in the coordinate space of the sketch. Since you are using the x-z plane, the x sketch coordinate is mapped to the x world coordinate, and the y sketch coordinate is mapped to the z sketch coordinate.

 

Basically, any time you use a non-zero "Z" value in the context of the sketch coordinate space, the result will be out of the plane of the sketch.

 

Here's what I think you want:

 

position1 = adsk.core.Point3D.create(0, 0, 0)
point1 = sketch.sketchPoints.add(position1)

position2 = adsk.core.Point3D.create(1, 2, 0)
point2 = sketch.sketchPoints.add(position2)

position3 = adsk.core.Point3D.create(-1, 2, 0)
point3 = sketch.sketchPoints.add(position3)

 

Although, strangely when you add a sketch to the xZ plane, it seems to get flipped so that the positive y sketch direction is the negative z world direction. So you may want to flip your "y" coordinates:

 

position1 = adsk.core.Point3D.create(0, 0, 0)
point1 = sketch.sketchPoints.add(position1)

position2 = adsk.core.Point3D.create(1, -2, 0)
point2 = sketch.sketchPoints.add(position2)

position3 = adsk.core.Point3D.create(-1, -2, 0)
point3 = sketch.sketchPoints.add(position3)

 

 

 

Message 3 of 3
kdrector
in reply to: JesusFreke

Doesn't the proposed solution simply change the orientation of the construction plane to match his points?
 
Is that what dahousecat really wants?  I doubt it since the solution doesn't directly tell him how to generally produce points on his construction plane.  I think the proper solution would be to explain how to do that.
 
 
If you want an example, draw the lines on the construction plane with these points keeping the z value zero.
 
position1 = adsk.core.Point3D.create(0, 0, 0)
        point1 = sketch.sketchPoints.add(position1)
        
        position2 = adsk.core.Point3D.create(0, 1, 2)
        position2a = adsk.core.Point3D.create(1,2,0)
        point2 = sketch.sketchPoints.add(position2)
        
        position3 = adsk.core.Point3D.create(0, -1, 2)
        position3a = adsk.core.Point3D.create(-1,2,0)
        point3 = sketch.sketchPoints.add(position3)
 
But if I'm wrong, let me know.

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