Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a Python script for exporting images of components. If a parent component has a child component and bodies, I'm trying to get an image of just the parent's bodies. The child components should be hidden.
There's an attached sample file and the code is below. The parent component has a cube body. The child component has a cylinder body. The parent image should be of only the cube. However, I can't get the viewport to show the cube and hide the cylinder. Thanks in advance!
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
viewPort = app.activeViewport
ui = app.userInterface
activeProduct = app.activeProduct
design = adsk.fusion.Design.cast(activeProduct)
rootFolder = None
folderDialog = ui.createFolderDialog()
folderDialog.title = "Selcect a folder for images"
dialogResult = folderDialog.showDialog()
if dialogResult == adsk.core.DialogResults.DialogOK:
rootFolder = folderDialog.folder + "\\"
else:
return
for occurrence in design.rootComponent.allOccurrences:
if occurrence.bRepBodies.count > 0 and occurrence.childOccurrences.count > 0:
for childOccurrence in occurrence.childOccurrences:
# childOccurrence.isVisible = False # doesn't work, isVisible is readonly
hideIt = True # stuck here
imageFileName = occurrence.component.partNumber + ".png"
occurrence.activate()
occurrence.isIsolated = True
viewPort.fit()
viewPort.saveAsImageFile(rootFolder + imageFileName, 100, 100)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.