Message 1 of 1
Occurrence.replace() does not work on unresolved components
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to make a script that fixes a large number of unresolved components in Python, but when I use Occurrence.replace() on the unresolved occurrence an error is thrown. Right clicking and using the replace button on both the timeline and the part in browser works correctly. When I use the code on unresolved component it works correctly. The error and my code is reproduced below. Any help would be greatly appreceated!
Checking test part
Searching for match for: test part ... found!
Traceback (most recent call last):
File "<string>", line 24, in <module>
File "<string>", line 16, in replaceOccurrence
File "C:\Program Files/Autodesk/webdeploy/production/10477bbe50cc169c7bd2cee9059bc7c9d0b71ec0/Api/Python/packages\adsk\fusion.py", line 46223, in replace
return _fusion.Occurrence_replace(self, newFile, replaceAll)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: 2 : InternalValidationError : Xl::Utils::findObjectPath(this, objPath)app = adsk.core.Application.get()
folder = None
for project in app.data.dataProjects:
if project.name == "Parts":
folder = project.rootFolder
break
def replaceOccurrence(occurrence):
name = occurrence.name
print("Searching for match for: " + name + " ... ", end = "")
for item in folder.dataFiles:
if item.name == name:
print("found!")
occurrence.replace(item, False)
product = app.activeProduct
for item in product.timeline:
occurrence = item.entity
if isinstance(occurrence, adsk.fusion.Occurrence):
print("Checking " + occurrence.name)
if item.healthState == 2:
replaceOccurrence(occurrence)