I have been wondering if there is a way to make python update an attribute from a report in CE. I have declared a start value to an attribute, which is used throughout the script, I then want to change this attribute to a number that is reported when the whole script has run, and instead of doing this for a 100 startshapes it would be easier to run a script.
You might be able to do this using an extra Python export script similar to what was suggested as Option 2 in this post (but adding an extra step to retrieve the reported value):
1) Create an export python script. Right click on the scripts folder -> New -> Python Module -> Select Module:Export (Reporting) and choose a name (e.g. export_script.py).
2) In the finishModel() function, add code to retrieve the reported value, set the attribute value, and set the attribute source to USER.
r = model.getReports()['myReport'] # read value of report (need to report value in cga code) ce.setAttribute(shape, '/ce/rule/height', r) # can set attr val like this ce.setAttributeSource(shape, '/ce/rule/height', 'USER') # set source of attr val to user since we changed it and also so we can access it in the other python script that calls this one
3) In your first python script, add code (lines 4-7 below) to call the export script.
# get list of selected shapes shapeList = ce.getObjectsFrom(ce.selection, ce.isShape) # run export script to set attributes to reported values expSettings = ScriptExportModelSettings() expSettings.setScript("export_script.py") ce.export(shapeList, expSettings) for shape in shapeList: # print rule attribute print(ce.getAttributeSource(shape, '/ce/rule/height')) print(ce.getAttribute(shape, '/ce/rule/height'))