- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi there.
This is a question that was recently asked in the Japanese forum.
I answered it, but it seemed very complicated to me.
First, create an occurrence (Part_A:1) in the root component.
Then, we will move and rotate the created occurrence.
The attached file looks like this, although I made a sketch to check it later.
The goal is to create a new occurrence in Part_A with the origin at the position moved X+100mm.
I thought I could create a new one by doing the following process, since it uses the component.occurrences of Part_A.
# Fusion360API Python script
import traceback
import adsk.fusion
import adsk.core
def run(context):
ui: adsk.core.UserInterface = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
des: adsk.fusion.Design = app.activeProduct
root: adsk.fusion.Component = des.rootComponent
# get Occurrence Part_A:1
occPartA: adsk.fusion.Occurrence = root.occurrences[0]
# Origin for the new Occurrence
newOri: adsk.core.Point3D = adsk.core.Point3D.create(10,0,0)
# Create Matrix
mat: adsk.core.Matrix3D = adsk.core.Matrix3D.create()
mat.setWithCoordinateSystem(
newOri,
adsk.core.Vector3D.create(1,0,0),
adsk.core.Vector3D.create(0,1,0),
adsk.core.Vector3D.create(0,0,1)
)
# Create Occurrence
comp: adsk.fusion.Component = occPartA.component
occs: adsk.fusion.Occurrences = comp.occurrences
newOcc: adsk.fusion.Occurrence = occs.addNewComponent(mat)
# Light on Origin
newOcc.component.isOriginFolderLightBulbOn = True
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
When you actually run the script, the occurrence is created in a different position than expected.
This is what it looks like from the Top orientation.
The orientation of the XYZ axis is the same as that of Part_A, but the position of the origin is clearly created with the orientation of the root component.
I can't tell if this is a bug or a specification, but it seems to be making it very difficult to understand.
Is this really the right way to handle it?
In case you're wondering, here's a sample to help you get to the goal of this.
def run(context):
ui: adsk.core.UserInterface = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
des: adsk.fusion.Design = app.activeProduct
root: adsk.fusion.Component = des.rootComponent
# get Occurrence Part_A:1
occPartA: adsk.fusion.Occurrence = root.occurrences[0]
# Origin for the new Occurrence
newOri: adsk.core.Point3D = adsk.core.Point3D.create(10,0,0)
# *** Adding ***
# Get only the orientation of Occurrence.transform
matPartA: adsk.core.Matrix3D = occPartA.transform
matPartA.translation = adsk.core.Vector3D.create(0,0,0)
# Align with the orientation of part_A
newOri.transformBy(matPartA)
# ******
# Create Matrix
mat: adsk.core.Matrix3D = adsk.core.Matrix3D.create()
mat.setWithCoordinateSystem(
newOri,
adsk.core.Vector3D.create(1,0,0),
adsk.core.Vector3D.create(0,1,0),
adsk.core.Vector3D.create(0,0,1)
)
# Create Occurrence
comp: adsk.fusion.Component = occPartA.component
occs: adsk.fusion.Occurrences = comp.occurrences
newOcc: adsk.fusion.Occurrence = occs.addNewComponent(mat)
# Light on Origin
newOcc.component.isOriginFolderLightBulbOn = True
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
However, if the process is to be performed at a deeper occurrence, additional calculations are required.
Solved! Go to Solution.