Select to view content in your preferred language

How to create file name by variable

549
1
05-30-2023 06:55 PM
trungta
New Contributor

Hi everyone, I'm creating my first ruler file with City engine, and I'm wondering how to create a path to Texture files with the filename controlled by 1 or more variables? Please see attached image file. Thanks everyone!Screenshot 2023-05-31 084720.png

 
Tags (3)
0 Kudos
1 Reply
JonasObertuefer
Esri Contributor

Hi @trungta,

Cool that you're digging into CGA 🙂

You got two errors in your code snippet:

  1. Attributes are global and need to be declared outside of rules,  usually they are put at the top of the file.
  2. If you want to mix strings with variables you need a plus sign between the string and the variable. There is an example in the following cga reference page: https://doc.arcgis.com/en/cityengine/latest/cga/cga-asset-texture-search.htm

After you change this there won't be any errors:

 

attr HH = rint(scope.sy/5)
attr WW = rint(scope.sx/5)

Floor_facade -->
	setupProjection(0, scope.xy, scope.sx, scope.sy)
	texture("/ESRI.lib/assets/Facades/International/Upperfloors/u_f0" + HH + "_t0" + WW + "*.jpg")
	projectUV(0)

 

However there are some more things to consider:

  • Attributes are only evaluated once at the start of the generation. So scope.sy and scope.sx will always return the same value for the initial shape you assigned the rule. If you want to calculate using the scope of the current shape in the shape tree you need to
    • directly  calculate between the strings instead of HH/WW or
    • define the calculation as a function or
    • do the calculation as a local variable
  • your texture() operation as currently written will often not find a texture. You would need to either:
    • copy them into a seperate project and rename them or
    • adjust your asset search string/ your calculation

Hope this helps and happy coding!

Cheers
Jonas

0 Kudos