## importing.cga attr function(parameter) = parameter*someCalculation import importedcga: "rules/imported.cga" (function) import importedcga2: "rules/imported2.cga" (function) Rule --> case someCondition == True: importedcga.importedRule case someOtherCondition == True: importedcga2.importedRule else: NIL ## imported.cga attr parameter = 0 #empty attribute (to be set within this cga's rule). attr function = 0 #empty attribute (overwritten by the import statement in importing.cga) importedRule --> set(parameter, geometry.area) report("metric", function(parameter))
## importing.cga import importedcga: "rules/imported.cga" #(function) import importedcga2: "rules/imported2.cga" #(function) Rule --> case someCondition == True: importedcga.importedRule case someOtherCondition == True: importedcga2.importedRule else: NIL ## imported.cga import masterFunction: "rules/masterFunction.cga" #(function) attr parameter = 0 #empty attribute (to be set within this cga's rule). importedRule --> set(parameter, geometry.area) report("metric", masterFunction.function(parameter)) ## masterFunction.cga - All imported.cga files import this file. attr function(parameter) = parameter*someCalculation
import b : "b.cga" import c : "c.cga" A --> b.B b.Mass --> c.ReportBottom
B --> extrude(world.y, 10) Mass # note that Mass must remain an 'undefined rule', so you'll not be able to avoid the yellow warning.
ReportBottom --> report("BottomArea", geometry.area(bottom) )
Hi guys ..
Yes, this works.
Just usually, I don't import a master rule into an other 'god rule'. 🙂
I try to pass down all values needed from the master rule down to the slave rules, if somehow possible.
What's also not so beautiful is if each slave rule itself imports e.g. a 'general reporting' rule, you will see instances of that rule in the Inspector ( each selectable ), which is visually confusing.
Thus, note the structure in the following example .. I guess it gives the best overall import structures :
code in cga file the master file "a.cga", which is assigned to the shape, with Start Rule A :import b : "b.cga" import c : "c.cga" A --> b.B b.Mass --> c.ReportBottom
code in cga file "b.cga" :B --> extrude(world.y, 10) Mass # note that Mass must remain an 'undefined rule', so you'll not be able to avoid the yellow warning.
code in cga file "c.cga" :ReportBottom --> report("BottomArea", geometry.area(bottom) )
As you see in those 3 rule files, all content is 'distributed' from the master file 'a' to 'b' and then taken back to a to be sent to 'c' for reporting.
That way, you can create rules, which e.g. creates all Masses alone, all Roofs alone, all Facades alone and distribute all via the master rule file, then cycle it back.
This is advanced shit, boys !
I try to pass down all values needed from the master rule down to the slave rules, if somehow possible.
############### #master.cga import as1: "C:\filepath\attributeStorage1.cga" import as2: "C:\filepath\attributeStorage2.cga" import mr1: C:\filepath\massingRules1.cga import mr2: C:\filepath\massingRules.cga attr master_height = 0 #empty startRule --> [INDENT]case someLogic: [/INDENT] [INDENT][INDENT]set(master_height, as1.stored_height) as1.startRule[/INDENT][/INDENT] [INDENT]case someOtherLogic:[/INDENT] [INDENT][INDENT]set(master_height, as2.stored_height) as2.startRule[/INDENT][/INDENT] [INDENT]else: doNothing. [/INDENT] as1.as(type) --> as(type) as2.as(type) --> as(type) as(type) --> [INDENT]case type == "type1": mr1.startRule case type == "type2": mr2.startRule else: doNothing.[/INDENT] ############### #attributeStorage1.cga attr stored_height = 10 attr type = "" #empty startRule --> [INDENT]case someLogic: set(type, "type1") as(type) case someOtherLogic: set(type, "type2") as(type) else: doNothing. [/INDENT] ############### #attributeStorage2.cga attr stored_height = 20 attr type = "" #empty startRule --> [INDENT]case someLogic: set(type, "type1") as(type) case someOtherLogic: set(type, "type2") as(type) else: doNothing. [/INDENT] ############### #massingRules1.cga attr master_height = 0 empty #overwritten when imported by master.cga (?) startRule --> [INDENT]extrude(master_height) Massing.[/INDENT] ############### #massingRules2.cga attr master_height = 0 empty #overwritten when imported by master.cga (?) startRule--> [INDENT]extrude(master_height * 0.5) Massing.[/INDENT]