Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

How to find the world coordinants of a point

Anonymous

How to find the world coordinants of a point

Anonymous
Not applicable

Hello, I want to translate an occurrence object to match its origin to another point (sketch or construction point) but I don't know how to find the world co-ordinates of the point.

 

Any sample code? Many thanks

0 Likes
Reply
Accepted solutions (1)
1,722 Views
3 Replies
Replies (3)

ekinsb
Alumni
Alumni
Accepted solution

There are three different objects that represent a point; construction point, sketch point, and a vertex on a surface or solid model.

 

The ConstructionPoint object has a "geometry" property that returns a Point3D object which is a wrapper for the coordinates of a point.

The BRepVertex object also has a "geometry" property that returns a Point3D object.

 

The SketchPoint object also has a "geometry" property but in this case the coordinate returned is not what you want.  A sketch point is defined in sketch space, not model space, and the coordinate returned by the "geometry" property is in sketch space.  However, the SketchPoint object has a worldGeometry property which returns a Point3D object in world space.

 

Below is some code that demonstrates repositioning a selected occurrence to a selected point.

 

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

        # Have the occurrence selected.
        occSel = ui.selectEntity('Select an occurrence', 'Occurrences')
        occ = adsk.fusion.Occurrence.cast(occSel.entity)
        if not occ:
            ui.messageBox('An occurrence must be selected.')

        # Have the point selected.            
        pointSel = ui.selectEntity('Select a point', 'Vertices, SketchPoints, ConstructionPoints')
        pnt = pointSel.entity
        if not pnt:
            ui.messageBox('A point must be selected.')    
        
        # Get the point geometry.
        coord = adsk.core.Point3D.cast(None)
        if type(pnt) is adsk.fusion.ConstructionPoint or type(pnt) is adsk.fusion.BRepVertex:
            coord = pnt.geometry
        elif type(pnt) is adsk.fusion.SketchPoint:
            coord = pnt.worldGeometry
            
        # Reposition the occurrence.
        occMatrix = occ.transform
        occMatrix.translation = coord.asVector()
        
        occ.transform = occMatrix
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes

Anonymous
Not applicable

Thanks for the help.

Follow-up question: How do I translate an occurrence so that its origin will match to an arbitrary point on a Fitted Spline curve?

In other words, I need to find/compute at run time any point's worldGeometry on a spline curve.

Given the spline curve is parametrically defined, there must be a mathematical way to do this. But I am not smart enough to find the solution yet.

Any help much appreciated!

1 Like

marcinszydlowski.1984
Enthusiast
Enthusiast

Hello. This is probably outdated but for those who still search a solution there's simple way to calculate this.

You only need to transform point by matrix of sketch which this point belongs to:

 

# Definition of point in sketch space (2D, but Z coordinate can be also set)
samplePoint = adsk.core.Point3D.create(-2, 3, 1)

# Find its world coordinates
transformedPoint = samplePoint.copy()
transformedPoint.transformBy(sampleSketch.transform)

 

0 Likes