Deep Occurrence Issues
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
Here are the coordinate values from the origin of the root component for all points.
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.
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.