Select to view content in your preferred language

Conditional Import Statements for Rules

1325
2
Jump to solution
08-12-2017 12:53 PM
DavidWasserman
Frequent Contributor

Hi All, 

I have a hypothetical question about importing outside rules. Is it possible to set up conditional imports? I know in python it is very easy to do something like this: 

  try:
            import pandas as pd
 except:
            # Pandas is shipped with ArcGIS Pro and ArcGIS 10.4 and higher.  The previous logic should hopefully prevent users from ever hitting this error.
            arcpy.AddError("This BetterBusBuffers tool requires the python library pandas, but the tool was unable to import the library.")
‍‍‍‍‍

I was curious if something similar is possible in CGA. In my earliest attempts, I start with a simple import statement:

import Street_Text : "Street_Text.cga"‍

Then, I figured, because the text for import is just text, I can just replace it with a const. 

const conditional_text_import= case fileExists("Street_Text.cga"): "Street_Text.cga" else:  "/ESRI.lib/rules/General/Text.cga" 
‍import Street_Text : conditional_text_import‍‍

This however returns an error. I have since tried doing the import statements within rules and other variations (I did not think they would work but I thought I would try). Is this simply not possible in CityEngine? Any alternatives? 

My goal is to essentially make a rule not being in the folder not be catastrophic to the rules function. It is a small thing, and there are other options, but I just want to keep a rules user experience a little easier. I think I am especially concerned when the functionality being added is not critical to many people's use cases.  

Relevant docs: 

import 

Using CE 2017. Any thoughts appreciated. 

CWilkins-esristaff to your knowledge is this possible? 

David Wasserman, AICP
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Unless something changed in CE 2017 that I'm not aware of, conditional imports are not possible in CGA.

View solution in original post

2 Replies
by Anonymous User
Not applicable

Unless something changed in CE 2017 that I'm not aware of, conditional imports are not possible in CGA.

DavidWasserman
Frequent Contributor

Thanks! I just wanted to check from a Jedi master if I was missing something. 

David Wasserman, AICP
0 Kudos