We were using this script to clean up the model tree when importing some STP files. After updating to 2024 seems mergeFinalLevel is no longer in use… how can I replace this script? Can someone point me in the right direction?
#--------------------------------------------------------
# Corrects issues with nested Part Occurrences and missing
# part descriptions / names
#--------------------------------------------------------
selected = scene.getSelectedOccurrences()
if len(selected) != 1:
print("ERROR: Please select a single Part Occurrence!")
else:
print("Program running, please wait a while...")
scene.mergeFinalLevel(selected, 2, True)
algo.createInstancesBySimilarity(selected, 1.000000, 1.000000, True, False, False)
#Corrects names of all Part Occurences
selectedParts = scene.getSelectedOccurrences()
emptyOccurrences = scene.findByProperty('Name', '', selectedParts)
for idx,part in enumerate(emptyOccurrences):
parent = scene.getParent(part)
core.setProperty(part, "Name", core.getProperty(parent, "Name")+".0"+str(idx))
print ("Process Completed!")
The function ‘mergeFinalLevel’ is still there but has been renamed ‘mergePartOccurrencesByFinalAssemblies’. A lot changes happened in the API with the 2024 version, please have a look at the Changelog here!
I had a go at rebuilding the script looking at the changelog, but I am facing two bugs:
Incompatibility between merge hidden parts mode set to `Merge Separately` and collapse to parent set to `True`. Hidden parts were destroyed.
[2025/02/03 2:15:03] function missing required argument 'UVPositionprecision' (pos 7)
This is how the script is looking now. What am I missing? what should I set the UVPositionprecision to?
#--------------------------------------------------------
# Corrects issues with nested Part Occurrences and missing
# part descriptions / names
# Updated for Pixyz 2024
#--------------------------------------------------------
selected = scene.getSelectedOccurrences()
if len(selected) != 1:
print("ERROR: Please select a single Part Occurrence!")
else:
print("Program running, please wait a while...")
scene.mergePartOccurrencesByFinalAssemblies(selected, 2, True)
algo.convertSimilarPartOccurrencesToInstances(selected, 1.000000, 1.000000, True, False, False)
#Corrects names of all Part Occurences
selectedParts = scene.getSelectedOccurrences()
emptyOccurrences = scene.findOccurrencesByProperty('Name', '', selectedParts)
for idx, part in enumerate(emptyOccurrences):
parent = scene.getParent(part)
core.setProperty(part, "Name", core.getProperty(parent, "Name")+".0"+str(idx))
print("Corrected name for " + Name)
print ("Process Completed!")
The first issue is related to the parameter you specifyed for mergePartOccurrencesByFinalAssemblies.
You asked to merge the hidden parts separetly AND to collapse everything to the parent. Unfortunatly this two mode are not compatible. Beceause having the hidden parts merged separatly would mean they will not be colapsed to the parent.
To solve this, either change the parameter to scene.mergePartOccurrencesByFinalAssemblies(selected, scene.MergeHiddenPartsMode.Destroy, True) or scene.mergePartOccurrencesByFinalAssemblies(selected, scene.MergeHiddenPartsMode.MakeVisible, True)
For the second issue, it seems algo.convertSimilarPartOccurrencesToInstances doesn’t match the expected function prototype. Check the new one here: Class Algo.
This function has been completly removed because there is no need for this anymore. Before we had to stop code execution manually then check when this stop was asked to then chain with the next command.
Now it’s done automatically, the script execution will interrupt whenever it can. There is no need to check if there is a interruptionRequested anymore.