Select to view content in your preferred language

Update an attribute from a report

1099
4
09-11-2017 06:06 AM
KristianMortensen1
Regular Contributor

Hello

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. 

Kind regards 

Kristian 

0 Kudos
4 Replies
LR
by
Frequent Contributor

Export the report and read the values.

0 Kudos
KristianMortensen1
Regular Contributor

So there is no way to do it without having to export the report out of CE?

0 Kudos
LR
by
Frequent Contributor

AFAIK no, unless there was some change in the last version. It's annoying but since you're automating it anyway, it shouldn't be a big problem.

0 Kudos
CherylLau
Esri Regular Contributor

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):

https://community.esri.com/thread/172315#comment-587903 

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'][0]        # 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'))
0 Kudos