Redefine attribute in imported script

1440
3
11-22-2013 10:21 AM
Tom-PierreFrappé-Sénéclauze
New Contributor II
Hi, I have three sequential CGA scripts I would like to keep in separate files for simplicity.
The second one uses "set" to define an attribute (BldgTypeCu) orginally defined in the main script, and then this attribute is used by the last script to set the color of the building.

In theory, should work: however, I get an error message: 'No such attribute:  BldgTypeCu in second script' (in essence). If I take the first call to the attribute out of the first script and leave it only in the second, it works, but then the third script does not seem to be able to access it.

How do I fix this error?

Here are the three scripts:
the first:
version "2012.1"

attr ActualUseC = "" 
attr BldgHeight = 0
attr BldgTypeCu = ""
attr Neighbourh = ""
attr ZoningCode = "" 
attr NumberOfSt = "" 
## to color by # of units
#attr Colorby = "NumberOfSt"
## OR to color by biulding use type
attr Colorby = "BldgTypeCu"


import bd1: "BuildingbyType.cga"(BldgTypeCu) #BldgTypeCu in parenthesis to allow imported script to over-ride attribute value in importing script
#import cr1 : "ColorRule.cga"

@StartRule
Footprint --> 
case Neighbourh == "James Bay" || Neighbourh == "": 
 Building
else:
 print("the neighborhood is: "+Neighbourh)
 Building
 color("#f0f0f0")

Building -->
 bd1.Building





The second:
/**
 * File:    BuildingbyType.cga
 * Created: 22 Nov 2013 19:02:58 GMT
 * Author:  tfrappe
 */

version "2012.1"
attr ActualUseC = "" 
attr ZoningCode = "" 
attr BldgTypeCu = ""
import cr1 : "ColorRule.cga"

Building -->
## SFD
case  ActualUseC == "000" || ActualUseC == "002" ||ActualUseC == "020" || ActualUseC == "032" || ActualUseC == "033"|| ActualUseC == "034"|| ActualUseC == "035"|| ActualUseC == "036" || ActualUseC =="041" || ActualUseC == "239":
  set(BldgTypeCu,"SFD") 
  extrude(rand(6,8))
  ColorRule
 
## LMFD
case ActualUseC == "029" || ActualUseC == "030" || ActualUseC == "039" || ActualUseC == "042" || ActualUseC == "047" || ActualUseC == "049" || ActualUseC == "050" || ActualUseC == "051" || ActualUseC == "052" || ActualUseC == "053" || ActualUseC == "057" || ActualUseC == "058" || ActualUseC == "237" || ActualUseC == "287"|| ActualUseC == "285" || ActualUseC == "286" :
 set(BldgTypeCu,"LMFD") 
 extrude(rand(9,12))
 ColorRule 

else:
 set(BldgTypeCu,"OTHER") 
 print("the actual use code is : "+ActualUseC)
 extrude(25)
 ColorRule 
 


ColorRule -->
 cr1.Color



The third:
/**
 * File:    ColorRule.cga
 * Created: 22 Nov 2013 18:54:39 GMT
 * Author:  tfrappe
 */

version "2012.1"
attr Colorby = ""
attr BldgTypeCu =""
attr NumberOfSt = "" 


Color-->
case Colorby == "BldgTypeCu":
  case BldgTypeCu == "SFD": color("#FFEBAF")
  case BldgTypeCu == "SFD2": color("##F4C362")
  case BldgTypeCu == "LMFD": color("#F4C362")
  case BldgTypeCu == "HMFD": color("#FFAA00")
  case BldgTypeCu == "COMM": color("#FF7F7F")
  case BldgTypeCu == "IND": color("#704489")
  case BldgTypeCu == "INST": color("#6788CA")
  case BldgTypeCu == "MU": color("#FF7F7F")  #SAME AS COMMERCIAL FOR NOW
  case BldgTypeCu == "CMTY": color("#AB0066")
  else: color("#00ffff")
 
 else: color("#0000ff")
Tags (2)
0 Kudos
3 Replies
MatthiasBuehler1
Frequent Contributor II
case Colorby == "BldgTypeCu":



okay ?

matt.
0 Kudos
Tom-PierreFrappé-Sénéclauze
New Contributor II
Sorry Matt, don't understand your reply.

For simplicity, I've cut some of the script in ColorRule.cga ; there are a couple ways in which I want to color the models, one is by building type (which is stored in the attribute BldgTypeCu), the other is by number of strata (stored in attribute NumberOfSt). The attribute Colorby is the toggle I use to switch between one and the other by feeding it the name of the field I want to color by (though I am not using this other than in the 'case' structure, so could have named the two cases whatever; note that the case "colorby == "NumberOfSt":" has been cut from the example above to simplify the script).

Not sure if that helps to clarify the scripts. If you can tell me more about your suggestion above (if still relevant after I explained this), it might help...

thanks!
Tom
0 Kudos
MatthiasBuehler1
Frequent Contributor II
Hi,


What I wanted to say is there's the most obvious error in your code:

attr BldgTypeCu =""


the attribute BldgTypeCu is of the type 'string', an empty string.

In
case Colorby == "BldgTypeCu": 


you are comparing Colorby with a string of the value 'BldgTypeCu' (the word itself), not the actual value of the attribute 'BldgTypeCu'.

You need to remove the quote signs. :)

Sorry for the confusion .. :rolleyes:

ok ?

m.
0 Kudos