Deep Occurrence Issues

Deep Occurrence Issues

kandennti
Mentor Mentor
482 Views
2 Replies
Message 1 of 3

Deep Occurrence Issues

kandennti
Mentor
Mentor

As far as I know, there are three types of points represented in GUI: BRepVertex, SketchPoint, and ConstructionPoint.
When creating scripts, I think there are cases where I need the user to specify a point and need its position from the origin of the root component.

 

The attached data is as follows.

  • Create an occurrence (Component1:1) in the root component and another occurrence (Component2:1).
  • The origin of any occurrence has a different position from the origin of the root component.
  • In the last occurrence (Component2:1), there is a point such that BRepVertex, SketchPoint and ConstructionPoint have the same position. (light blue)

1.png

 

 

Here are the coordinate values from the origin of the root component for all points.

1.png

 

The following script has been created
When a point is selected, the result is output, including the coordinate values from the origin of the root component of the text command window.

# Fusion360API Python script

import traceback
import adsk
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
        ver: str = app.version

        msg: str = "Select Point / ESC = Cancel"
        selFilter: str = "Vertices,SketchPoints,ConstructionPoints"

        while True:
            sel: core.Selection = selectEnt(msg, selFilter)
            if not sel:
                return

            entity = sel.entity

            point: core.Point3D = None
            if entity.objectType == fusion.BRepVertex.classType():
                point = entity.geometry
            elif entity.objectType == fusion.SketchPoint.classType():
                point = entity.worldGeometry
            elif entity.objectType == fusion.ConstructionPoint.classType():
                point = entity.geometry
            else:
                return

            infos = [
                f"****Fusion Ver{ver}",
                f"classType: {entity.classType()}",
                f"Proxy?Native?: {get_proxy_type(entity)}",
                f"geometry.asArray: {get_format_values(point)}"
            ]

            app.log("\n".join(infos))

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


def get_format_values(point: core.Point3D) -> list[str]:
    app: core.Application = core.Application.get()
    unitsMgr: core.UnitsManager = app.activeProduct.unitsManager

    return [unitsMgr.formatInternalValue(v) for v in point.asArray()]


def get_proxy_type(entity) -> str:
    app: core.Application = core.Application.get()
    root: fusion.Component = app.activeProduct.rootComponent

    comp: fusion.Component = get_parent_component(entity)

    if root == comp:
        return "Native(Root)"

    native = entity.nativeObject
    if native:
        return "Proxy"
    else:
        return "Native"


def get_parent_component(entity) -> fusion.Component:
    if entity.objectType == fusion.BRepVertex.classType():
        return entity.body.parentComponent
    elif entity.objectType == fusion.SketchPoint.classType():
        return entity.parentSketch.parentComponent
    elif entity.objectType == fusion.ConstructionPoint.classType():
        return entity.component
    else:
        return None


def selectEnt(
    msg: str,
    filterStr: str
) -> core.Selection:

    try:
        app: core.Application = core.Application.get()
        ui: core.UserInterface = app.userInterface
        sel = ui.selectEntity(msg, filterStr)
        return sel
    except:
        return None

 

Here is the result when you select any point while using show/hide.

 ****Fusion Ver2.0.16265
classType: adsk::fusion::BRepVertex
Proxy?Native?: Proxy
geometry.asArray: ['20.00 mm', '30.00 mm', '30.00 mm']
 ****Fusion Ver2.0.16265
classType: adsk::fusion::SketchPoint
Proxy?Native?: Proxy
geometry.asArray: ['20.00 mm', '30.00 mm', '30.00 mm']
 ****Fusion Ver2.0.16265
classType: adsk::fusion::ConstructionPoint
Proxy?Native?: Proxy
geometry.asArray: ['10.00 mm', '20.00 mm', '20.00 mm']

Only ConstructionPoint does not give the desired result.

 

The reason is that the Point3D returned by the Proxy's ConstructionPoint.component property is the result of one occurrents above.
This is the cause of the lack of uniformity and very confusing compared to other elements.

 

A simple way to find the coordinates from the origin of the root component in ConstructionPoint is this way.

・・・
            elif entity.objectType == fusion.ConstructionPoint.classType():
                point = entity.geometry
                occ: fusion.Occurrence = entity.assemblyContext
                if occ:
                    mat: core.Matrix3D = occ.transform  # transform2 NG
                    point.transformBy(mat)
・・・

It works without error in Ver 2.0.16265, but the Occurrence.transform method is obsolete.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-7fb9ea55-5c24-4c27-b1c4-2e92f42774f7 

IntelliSense is already not working.

1.png

 

As I mentioned somewhere before, the Occurrence.transform method should not be deprecated.
I haven't looked into it, but ConstructionPlane and ConstructionAxis may have the same problem.

483 Views
2 Replies
Replies (2)
Message 2 of 3

kandennti
Mentor
Mentor

If we must do away with the Occurrence.transform method, we will have to do it this way.

 

・・・
            elif entity.objectType == fusion.ConstructionPoint.classType():
                point = entity.geometry
                occ: fusion.Occurrence = entity.assemblyContext
                if occ:
                    mat: core.Matrix3D = occ.transform2
                    nativeConstructionPoint = entity.nativeObject
                    point = nativeConstructionPoint.geometry
                    point.transformBy(mat)
・・・

 

It is still confusing that the ConstructionPoint proxy is not consistent with other objects.

Even getting the coordinates of the origin of the occurrents is confusing.

0 Likes
Message 3 of 3

MichaelT_123
Advisor
Advisor

Hi Kandennti-San,

 

 As far as I understand the intricacy of the F360 model .... ConstructionEntities are 'anchored' in their respective components, and as such, their geometries are related to the contexts of the component's occurrences.  

I haven't checked it explicitly, but this implies that constructionEntity.geometry for two differently positioned occurrences of the same component should result in non-equal outcomes.

In order to find their mode space position, their residence occurrence transforms must be taken into account.

 

Regards

MichaelT

MichaelT