Set Rule Attribute in Export Script

762
7
03-08-2013 04:20 AM
HD1
by
New Contributor
Hi, im trying to use a rule-attribute to enable and disable the report() calls during shape generation so that I dont waste time amd memory creating report data that i only need during export.

If I manually set the attribute to true before exporting it works, trying to set it in the Python script however, fails.

I have a main.cga which imports my report.cga.

The report.cga declares an attribute and the rule that does the reporting is a selection rule:
attr bEnableExportReport = false
ReportData --> case bEnableExportReport == true: Report() else : NIL


In my export script I set the attribute to True in the "initModel" using '/ce/rule/report.bEnableExportReport' (before model is generated), but even though the attribute does get set to True (i am using ce.getAttribute() to make sure ), the script and rule behaves as if the attribute is still False - therefore no report-data.

I have tried setting the attributeScope to 'RULE' before setting the value to true to make sure its using the rule-scope attribute.

I have also tried setting the other attribute '/ce/rule/bEnableExportReport' - is this the Shape's version ? [ why are there two attributes on the shape for the same attr ? ]

Is there a "flush-attributes" command I should call to make the attributes get relfected to the shape/rules?
Tags (3)
0 Kudos
7 Replies
MatthiasBuehler1
Frequent Contributor
Hi !


Usually you need to do 2 things in Python to set the value, as you want it :

1] set the rule source of the attr
2] set the attr value

Your issue - I guess - is that you don't set the rule source correctly. If you set the source to 'RULE', you set it to the default value which is initialized in the CGA rule. You don't want that. You want to set it to 'USER' since YOU are setting the value.


This should work.

Let me know..

Matt
0 Kudos
HD1
by
New Contributor
Hi, ive been playing around with the scope and attributes etc but it still doesnt quite work.

So far I am calling this  :

def initModel(exportContextUUID, shapeUUID):

    shape = Shape(shapeUUID)
    ce.setAttributeSource(shape, "/ce/rule/instanceReporting.bEnableExportData", 'USER')
    ce.setAttribute(shape, "/ce/rule/instanceReporting.bEnableExportData", True )  

    ctx = ScriptExportModelSettings(exportContextUUID)


It causes the Inspector UI to update the attribute as expected, but during the Model-Generation, the Rule doesn't use the new value. Only after the script has finished and I manually re-generate the model, does the rule use the new value and create the report information.

PS: Ive also treid using "/ce/user/" instead of "/ce/rule/" for the "setAttribute()" call but it seems not to make any difference

Thanks, H
0 Kudos
MatthiasBuehler1
Frequent Contributor
Hi ..


Just before I go and test this myself :

A few notes, just want to make sure you're aware of this.

- If you run the script based exporter itself, nothing is exported, thus no models are exported
- The script based exporter is accompanying a standard exporter, such as e.g. the FBX export, where you actually export geometry.
- To do so, export with a standard file format ( e.g. obj, fbx, .. ) and in the MISC tab, select your script.

Thus, can it be that it may work, but you just don't see the updates because you don't write geometry ?

Seems you're a coding PRO, so just want to make sure. 😮
0 Kudos
HD1
by
New Contributor
Hi,
I am using the python-based export, without exporting models to FBX etc, to extract reported info (as in Tutorial #12).
I don't need the exported meshes, but I do need the Rule to run and create the geometry/reports so that the script can read the reports to write out to a custom text-file.

The script is generating models, because I experimented by calling ce.generateModels in initModel(), just in case, and it went into an infinite loop 🙂 (unsurprisingly) - which might need a safety-guard as I had to force-close CityEngine in task-manager.

Running the export script in a model-export and selecting the script in the "misc" section didnt fix it.

And yeah, I am a programmer by trade 🙂

I mean I can just leave the reporting in all the time, it isnt a critical problem, but the reports clutter the UI and obviously wastes memory and time when generating models - especially if we start using this on whole cities. Having the script toggle the attribute to do the reporting would be far nicer.

Thanks, H.
0 Kudos
MatthiasBuehler1
Frequent Contributor
Hi ..

ok.

maybe if you have the time, it'd be better that you create a tiny CE project to post here which I can directly use to reproduce the issue. Then we directly can talk about the issue and have both the data.

I can certainly track something down, but it may be faster if you provide a minimal reproduction dataset.

let me know..

m.
0 Kudos
HD1
by
New Contributor
Hi, Here is a test-project.

The script ought to print out a success or failure message based on the report() which is done in the Rule based on testing the bDoReports attribute.

Testing procedure:
1) Select Shape
2) Press Ctrl-E to export models on selected shape.
3) Select Script-Based-Export and export using "myExport.py".
4) Check Python Console-Output for message.

Thanks, H.
0 Kudos
AndreasUlmer
Esri Contributor
Hi H,

modifying data within the export callbacks is tricky, or to put it frank, not working reliably. Reason is that the exporter runs in a different thread, and the shape references you get in the callbacks are not reliable references to the shapes in the scene's data structure.

For your case I suggest to do the required modifications in a "preflight" method before the exporter is started.

#1 set shape attributes
#2 start the export process (scripted-export)
#3 (restore shape attributes)

Your script with these modifications is attached.
(Note: Run this script directly via Python -> Run script (or f9), instead of starting the exporter)
Does this help you further?

best
Andreas
0 Kudos