Getting Point Location after Transform

Getting Point Location after Transform

jss.mlls
Contributor Contributor
1,453 Views
8 Replies
Message 1 of 9

Getting Point Location after Transform

jss.mlls
Contributor
Contributor

Hello,

 

I have a Point3D object that has been added to a sketch of a component. I translate the component using the following:

 

transform = occ.transform2
transform.translation = adsk.core.Vector3D.create(transX, transY, transZ)
occ.transform2 = transform
design.snapshots.add()

 

Where occ holds the occurrence of the component containing the sketch with the Point3D object. 

 

After this transform, I can see in the GUI that the transform of the component and the point is successful, however looking at the point's data, it still reads its original location pre-transform.

 

Is there a way I can look at the Point3D object and see its new location after the transform?

 

Thanks

Jesse

0 Likes
Accepted solutions (1)
1,454 Views
8 Replies
Replies (8)
Message 2 of 9

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

How are you getting the coordinates of the sketch point?  With sketchpoint.geometry?

With sketchPoint.worldGeometry instead of sketchPoint.geometry you will get the new position in the world space, which get updated after make the transformation.

 

I hope this could help you.

 

Regards,

Jorge Jaramillo

 

 

Message 3 of 9

kandennti
Mentor
Mentor
Accepted solution

Hi @jss.mlls -San.

 

I am guessing since it is not publicly available, but I think it is probably a problem with getting the coordinate values of a point.
For example, here is a sample of obtaining the coordinates from a sketch point in the state shown in the image.

1.png

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion

def run(context):
    ui: core.UserInterface = None
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        transX = 1.0
        transY = 2.0
        transZ = 3.0
        occ: fusion.Occurrence = root.occurrences[0]

        transform: core.Matrix3D = occ.transform2
        transform.translation = core.Vector3D.create(transX, transY, transZ)
        occ.transform2 = transform
        des.snapshots.add()

        # nativeObject
        skt: fusion.Sketch = occ.component.sketches[0]
        targetSktPoint: fusion.SketchPoint = skt.sketchPoints[-1]

        app.log("***")
        app.log(f"{targetSktPoint.worldGeometry.asArray()}")
        app.log(f"Has assemblyContext: {True if skt.assemblyContext else False}")

        # proxy
        proxySkt: fusion.Sketch = skt.createForAssemblyContext(occ)
        targetProxySktPoint: fusion.SketchPoint = proxySkt.sketchPoints[-1]

        app.log("***")
        app.log(f"{targetProxySktPoint.worldGeometry.asArray()}")
        app.log(f"Has assemblyContext: {True if proxySkt.assemblyContext else False}")

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

 

As an example of the result, you will get output like this.

 ***
 (1.0, 2.0, 0.0)
 Has assemblyContext: False
 ***
 (2.0, 4.0, 3.0)
 Has assemblyContext: True

The first coordinate value output is a nativeObject. The next output is a proxy.
You need to understand the description (Proxies) here in the documentation.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-88A4DB43-CFDD-4CFF-B124-7EE67915A07A 

 

In the example above, the sketch point was obtained programmatically, but the point selected using ui.selectEntity is always a proxy.

 

Also, the above example was a sketch point, but it would be more confusing for a ConstructionPoint.
If you are interested, please see here.

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/deep-occurrence-issues/td-p/12026471 

0 Likes
Message 4 of 9

jss.mlls
Contributor
Contributor

Hi wtallerderadera,

 

Thanks for the reply. I have tried worldGeometry and the location remains the same before and after the transform. I also tried adding 

 

adsk.doEvents()

 

to see if it was some kind of catchup thing. It is interesting, I can go into the GUI after the transform operation, and the sketch point is indeed updated to the new location, along with the rest of the component:

 

jssmlls_0-1689000475573.png

 

But querying the location before:

ptPreTrans = pickandplaceCircle.centerSketchPoint.worldGeometry

 

 

and after:

ptPostTrans = pickandplaceCircle.centerSketchPoint.worldGeometry

 

show the same location:

(7.332056714285714, 0.75, -8.9918575),(7.332056714285714, 0.75, -8.9918575)

 

 

0 Likes
Message 5 of 9

jss.mlls
Contributor
Contributor

Hi kandennti,

 

Thanks for the reply, let me dig into your message and I will get back to you.

 

Thanks

Jesse

0 Likes
Message 6 of 9

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

After playing a lit bit with an example, my findings are the following:

1. The sketch point's world geometry is different than its regular geometry if the sketch plane is set to other than the XY plane of its component.

2. To get sketch point' real world geometry you have to transform its world geometry by the matrix of its component.

 

Here is the code I used:

 

def point_coords_on_tx():
    transX = 2
    transY = 3
    transZ = 4
    occ: adsk.fusion.Occurrence = root.occurrences.item(0)
    design = des

    sk: adsk.fusion.Sketch = occ.component.sketches.item(0)
    sk_p: adsk.fusion.SketchPoint = sk.sketchPoints.item(1)
    app.log(f'Before: {sk_p.geometry.asArray()=} {sk_p.worldGeometry.asArray()=}')
    app.log(f'        {sk.transform.asArray()=}')
    app.log(f'        {occ.transform2.asArray()=}')

    transform = occ.transform2
    transform.translation = adsk.core.Vector3D.create(transX, transY, transZ)
    occ.transform2 = transform
    design.snapshots.add()

    app.log(f'After : {sk_p.geometry.asArray()=} {sk_p.worldGeometry.asArray()=}')
    app.log(f'        {sk.transform.asArray()=}')
    app.log(f'        {occ.transform2.asArray()=}')

    wg: adsk.core.Point3D = sk_p.worldGeometry.copy()
    im: adsk.core.Matrix3D = occ.transform2.copy()
    wg.transformBy(im)
    app.log(f'End   : {wg.asArray()=}')

 

 

To test it I just create a component, a plane 10 mm above Z, a sketch on it and a point inside this sketch:

wtallerdemadera_0-1689047039263.png

The results are:

1. Sketch point was placed in (1,2,0)

2. Sketch was place on a plane 10mm above Z-axis

3. The world geometry of the sketch point indicates that placement under sketch placement

4. The component was moved to +10mm on X, +20 on Y and +30 on Z

After running the code:

5. The component was placed on (20,30,40)

6. As a result, the point get moved to (30,50,50)

7. The real world geometry of the sketch point is printed, using it's component matrix to transform its location.

 

I hope this could help.

 

Regards,

Jorge Jaramillo

 

Message 7 of 9

jss.mlls
Contributor
Contributor

Thanks @kandennti and @Jorge_Jaramillo  for your responses. If I utilize the proxy version of the sketch I can indeed get the updated location of the point after the transform. @Jorge_Jaramillo  I was not able to try your second method but it looks promising. Thanks all.

Message 8 of 9

garrygoldberg1
Contributor
Contributor

Building a fintech app requires careful planning, development, and consideration of various factors. Here's a step-by-step guide to help you understand the process: how to build a fintech app

  1. Define Your Goals and Target Audience: Start by clearly defining the purpose of your fintech app and identifying your target audience. Determine what specific financial services or features your app will provide.

0 Likes
Message 9 of 9

MichaelT_123
Advisor
Advisor

Hi FFellows,

 

There is a useful property of a sketch object which alleviates the hurdles of finding a required sketch point position in the design's model space:

returnValue = sketch_proxy.sketchToModelSpace(sketchCoordinate)

 

Regards

MichaelT

 

 

MichaelT