Rectangle on non-parallel plane

Rectangle on non-parallel plane

brad.bylls
Collaborator Collaborator
351 Views
11 Replies
Message 1 of 12

Rectangle on non-parallel plane

brad.bylls
Collaborator
Collaborator

How do you draw a rectangle on a plane that is not parallel to one of the origin planes using API?

The center of the rectangle is at one of the end points of the line, and the long side of the rectangle is parallel to the line.

Screenshot 2025-07-31 154636.png

Brad Bylls
0 Likes
352 Views
11 Replies
Replies (11)
Message 2 of 12

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

One way is to draw the rectangle on a sketch on YZplane or XZplane and then making a projection of its lines over a sketch over the tilted plane.

 

Does it make sense for you?

 

0 Likes
Message 3 of 12

BrianEkins
Mentor
Mentor

Is the line in a sketch that was created on the face you want the rectangle on?

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 4 of 12

brad.bylls
Collaborator
Collaborator
I don't think that would work because the dimensions would not be correct.
Brad Bylls
0 Likes
Message 5 of 12

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

Ok, understood.

 

I'd suggest two more options:

 

1) To draw the rectangle on a new XY-based sketch, and then apply a transformation (rotation and displacement) to it.

This transformation have same rotations as the sketch when you draw the line; and a displacement from rectangle center point to one of the line's end-points.

 

2) Keep a copy of the transformation matrix of the current sketch (where you have the line), calculate an inverse transformation of its matrix, which will translate the sketch to a XY-Based sketch; then you can draw the rectangle with dimensions; and finally apply the already kept transformation matrix to set it back where it was at the beginning.

 

Does any of this options make sense for you?

 

Regards,

Jorge Jaramillo

 

 

0 Likes
Message 6 of 12

brad.bylls
Collaborator
Collaborator
I'm sorry Jorge but I have no idea what you are talking about.
It all sounds Greek to me.

Brad
Brad Bylls
0 Likes
Message 7 of 12

BrianEkins
Mentor
Mentor

I'm not 100% what you need, but here is a script that prompts you to select a sketch point. It expects that point to be the end of a line. It then creates a rectangle in the sketch the line is in that is centered on the selected point and oriented parallel to the line. The size of the rectangle is hard-coded in the script.

"""This file acts as the main module for this script."""

import traceback
import adsk.core
import adsk.fusion

# Initialize the global variables for the Application and UserInterface objects.
app = adsk.core.Application.get()
ui  = app.userInterface


def run(_context: str):
    """This function is called by Fusion when the script is run."""

    try:
        # define the width and height of the rectangle
        length = 4
        width = 2

        # Have the sketch point selected.
        try:
            sel = ui.selectEntity('Select the sketch point.', adsk.core.SelectionFilters.SketchPoints)
        except:
            return
        
        skPnt: adsk.fusion.SketchPoint = sel.entity

        # Check if there's a single line connected to the point.
        if skPnt.connectedEntities.count != 1:
            ui.messageBox('A single line should connect to the selected point.')
            return
        
        if skPnt.connectedEntities[0].objectType != adsk.fusion.SketchLine.classType():
            ui.messageBox('A single line should connect to the selected point.')
            return

        skLine: adsk.fusion.SketchLine = skPnt.connectedEntities[0]

        # Get the direction of the line by going from the select poing to the other.
        # The line direction will be the length direction of the rectangle.
        if skPnt == skLine.startSketchPoint:
            lengthDir = skLine.startSketchPoint.geometry.vectorTo(skLine.endSketchPoint.geometry)
        else:
            lengthDir = skLine.endSketchPoint.geometry.vectorTo(skLine.startSketchPoint.geometry)
        lengthDir.normalize()

        # Calculate the width direction so it is 90 to the length direction.
        widthDir = adsk.core.Vector3D.create(0, 0, 1).crossProduct(lengthDir)
        widthDir.normalize()

        # Calculate the offset of the corner of the rectangle so the selected
        # point will be at the center of the rectangle.
        lengthDir.scaleBy(-length / 2)
        widthDir.scaleBy(-width / 2)
        pntOne = skPnt.geometry
        pntOne.translateBy(lengthDir)
        pntOne.translateBy(widthDir)

        # Calculate the other two points. A negative value is use when scaling
        # because it was scaled with a negative value when getting the first
        # point and this results in a positive scale.
        pntTwo = pntOne.copy()
        lengthDir.normalize()
        lengthDir.scaleBy(-length)
        pntTwo.translateBy(lengthDir)

        pntThree = pntTwo.copy()
        widthDir.normalize()
        widthDir.scaleBy(-width)
        pntThree.translateBy(widthDir)        

        # Create the rectangle.
        sk = skLine.parentSketch
        skLines = sk.sketchCurves.sketchLines
        skLines.addThreePointRectangle(pntOne, pntTwo, pntThree)
    except:  #pylint:disable=bare-except
        # Write the error message to the TEXT COMMANDS window.
        app.log(f'Failed:\n{traceback.format_exc()}')
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 8 of 12

brad.bylls
Collaborator
Collaborator

@BrianEkins, the rectangle sketch plane is perpendicular to the plane that has the line sketch and parallel to the line.

The line would actually be where the two planes intersect.

I am creating a die spring.

The path for the spring and the guide path are created in the sketch with the line on the selected plane.

Hopefully the picture will help explain what I am trying to do.

If you need the entire script of what I have, I will gladly pass it along.

Screenshot 2025-08-04 114741.png

Brad Bylls
0 Likes
Message 9 of 12

BrianEkins
Mentor
Mentor

Sorry, but it's still not clear to me what the geometry is. Maybe post a model with the results you're trying to create by manually creating it.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 10 of 12

brad.bylls
Collaborator
Collaborator

Attached is a step model of two springs.

The red spring is correct. The rectangle is perpendicular to the centerline of the spring, and parallel to the plane it is on.

The plane the red spring is on is parallel to the X-Z plane.

The blue spring is the problem.

The plane it is on is not parallel to any origin plane.

The rectangle is not perpendicular to the spring centerline or parallel to the plane the spring is on.

Brad Bylls
0 Likes
Message 11 of 12

BrianEkins
Mentor
Mentor

Sorry that it's taken me a while to get back to this. I'm still struggling to understand the geometry. It isn't easy to see the orientation of the geometry in a 2D picture. Maybe forget about the spring for now and focus on the initial input. You have a plane and a line. I don't know if the line lies on the plane or is perpendicular to the plane. From the STEP model I can now see what it means for a spring to be "on" a plane. I think what would help is to show the input the user provides to your program. And then go step-by-step through what you need to create to build the spring. Because the model is a STEP file I can't see the modeling operations or the sketches you created.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 12 of 12

brad.bylls
Collaborator
Collaborator

@BrianEkins I think at this point since it is quite confusing, if you send me your email address I will add you to the Entitlement list and you can down load the app from the app store.

If you search 'Springs' you will find Mold Tech Mold/Die Springs.

This app is not protected so you can see how it operates and access the code.

I hope that will help and thanks for your help.

 

Brad

Brad Bylls
0 Likes