- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm pretty new to the API, and only barely understand proxies, so I'm hoping that there is a simple solution that I've overlooked. When I am dealing with occurrences that are direct children of the root component, I have no issues with setting their transform2 properties directly, or with adding new component copies via the Occurrences.addNewComponentCopy method.
However, when I am dealing with occurrences that are nested within other occurrences (that is, not direct children of the root component), I begin to encounter issues with transform2. I believe I have figured out how to make this work using a proxy occurrence when setting transform2 directly, but I get the same transform error when using addNewComponentCopy in a nested occurrence, and I don't see a way around this.
I've created a minimal script that demonstrates the problem:
import adsk.core, adsk.fusion, traceback, math
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
###
# setting up parent and child occurrences / components
###
rootComponent = app.activeProduct.rootComponent
parentOccurrence = rootComponent.occurrences.addNewComponent(adsk.core.Matrix3D.create())
parentComponent = parentOccurrence.component
childOccurrence = parentComponent.occurrences.addNewComponent(adsk.core.Matrix3D.create())
###
# here's the demonstration part
###
# setting transform works
childOccurrence.transform = adsk.core.Matrix3D.create()
# setting transform2 fails with
# "RuntimeError: 3 : transform overrides can only be set on Occurrence proxy from root component"
childOccurrence.transform2 = adsk.core.Matrix3D.create()
# setting transform2 won't work unless I create a proxy occurrence
# this works, but I'm not sure it's completely correct
childOccurrenceProxy = childOccurrence.createForAssemblyContext(parentOccurrence)
childOccurrenceProxy.transform2 = adsk.core.Matrix3D.create()
# however, using addNewComponentCopy fails with the same error as
# setting transform2 without a proxy
childOccurrenceCopy = parentComponent.occurrences.addNewComponentCopy(
childOccurrenceProxy.component,
adsk.core.Matrix3D.create())
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
The error I get (if you comment out the first naive attempt to set transform2) is this:
Does anyone have any insight about how to work around this problem?
Thanks,
Brent
Solved! Go to Solution.