Can I call a rule, then return to the previous one and continue it? Or call a cga within a cga?

1514
7
10-16-2014 08:23 AM
LR
by
Regular Contributor

For example like this, to produce a red 10m tall block. The script is very simplified, just to show the general idea.. I can't just pack the function into Lot.

Lot -->

ColorScript

extrude(10)

ColorScript -->

color(1,0,0)

Also is it somehow possible to call another cga within a cga file? For example, I have one function (coloring) I need to execute on every building and that function doesn't change. It's also rather big and gets in the way because I can't collapse it. Another case would be the roof construction parts, or texturing parts. So what I basically want to do is something like

Lot -->

extrude (10)

ColorScript.cga

is that possible somehow?

0 Kudos
7 Replies
ChrisWilkins
Regular Contributor

Add this line to your first CGA rule:

import ColorScript: "rules/ColorScript.cga" #(Or whatever the path to the imported cga file is)

Then your code will work as in your second example:

Lot --> 

extrude (10

ColorScript.colorMe

This sends the extruded mass into a rule called "colorMe" in your rule ColorScript.cga.

This importing can go more than one level deep.

0 Kudos
LR
by
Regular Contributor

Thanks!

However there's one problem, I can't get the loading to work dynamically. What I'm trying to do is create a base script that calls other scripts based on their gid for each building. It works manually, but when I try to create the path with variables, it doesn't (mismatched token). The same method works for textures, though.

I figured if this works, I could use the same method to "switch back" from the second script to the first..

version "2014.0"

attr gid = 0

attr gidpath = "rules/"+gid+".cga"

import gid_switch: "rules/628071.cga"  //works, gid of shape

import gid_switch2 : gidpath // doesn't work

import gid_switch2 : "rules/"+gid+".cga" // doesn't work

//test for constructed path for textures, works

attr path = "images/"+gid+"/"

attr end = ".jpg"

Lot -->

  texture(path+"chickens"+end)

  alignScopeToGeometry(zUp, 0, world.lowest)

  setupProjection(0, scope.xy, 0.3, 0.3)

  projectUV(0)

gid_switch.Lot //just a color command

0 Kudos
ChrisWilkins
Regular Contributor

This can't be done this way... No dynamic CGA importing. 

0 Kudos
MatthiasBuehler
Regular Contributor

This is the only way of getting 'back' to the first rule:

rule1.cga:

------------

import rule2: "rule2.cga"

Shape -->

    rule2.DoExtrude

rule2.Mass -->

    color(1,0,0)

rule2.cga:

------------

DoExtrude -->

    extrude(10)

    Mass // notice this is an UNUSED RULE with a yellow warning

-----------------------------------------------------------------------------------------

this should result in a red extruded shape.

ok ?

Matthias Buehler

Head of 3D Technologies

twitter: @MattB3D

--------------------------------

Garsdale Design Limited

matthias.buehler@garsdaledesign.co.uk

www.garsdaledesign.co.uk

0 Kudos
ChrisWilkins
Regular Contributor

Matt, he'd like to build the string for the name of the imported CGA file dynamically... see his 2nd question.

0 Kudos
LR
by
Regular Contributor

Yep, otherwise it wouldn't be very useful in my situation. So could it be done in another way? With Python maybe?

Even something like this would be ok, creating the list wouldn't be too hard with Excel:

ThisDoesntWork-->

case gid == 628071: import gid_switch: "rules/628071.cga"

case gid == 628072: import gid_switch: "rules/628072.cga"

case gid == 999: color(0,1,0)

else: color (1,0,1)

0 Kudos
MatthiasBuehler
Regular Contributor

Hi ..

no, there's no other syntax in CGA to do this.

sorry.

I wished for this also a loooong time.

e.g.

attr number = 1

Shape -->

    eval("Rule" + str(number))

Rule1 -->

    Continue.

Matthias Buehler

Head of 3D Technologies

twitter: @MattB3D

--------------------------------

Garsdale Design Limited

matthias.buehler@garsdaledesign.co.uk

www.garsdaledesign.co.uk

0 Kudos