Select to view content in your preferred language

Mass insert 3D model at preference point

1253
5
Jump to solution
10-09-2012 01:37 AM
Thu_GiangDang
Emerging Contributor
I have a layer of points, each with an unique ID. I have a file which maps the point ID to the building model's file name. What I want to do now is to write a rule file which takes the ID and produce the file name, then use i(file name) to insert the model at the points.

My questions are:
- is there any way to implement a hash function in cga grammar?
- is there any looping mechanism in cga?
- if it is impossible to achieve what I want using rule file, what are the other options I have?

I am new to City Engine, so please pardon my lack of knowledge. Thanks for your time.
0 Kudos
1 Solution

Accepted Solutions
MatthiasBuehler1
Deactivated User
loading those attributes from a text file is possible with Python scripting, by parsing the file, reading the value, then setting the value as either object attribute or as a user set value.

[ Python scripting is available in CityEngine Advanced, not Basic. ]

ok ?

View solution in original post

0 Kudos
5 Replies
MatthiasBuehler1
Deactivated User
Hi !


The 'loop' you mention is done automatically by running a rule 'on all shapes', by using 1 rule on multiple shapes.

As you may have noticed, each attributed GIS point ('point feature') is converted to a tiny little shape.

Now if you have an ID for each building - which comes in as an Object Attr - you can use this ID string in a function to point CGA to the correct file.

Check Tutorial 3 !
http://video.arcgis.com/watch/1769/tutorial-3-map-control

e.g. like this. change to attr and asset names to your specific names.

[the code may contain errors. I did not check it.]


assetFinder(ID) =
    case ID == "abcd" : "assets/building_abcd.dae"
    case ID == "efgh" : "assets/building_edgh.dae"
    ..
    else: "builtin:cube"

attr BuildingID = "" # Point to Object Attribute with the actual ID info.

Lot -->
    alignScopeToAxes()
    s(0,0,0)
    i(assetFinder(BuildingID))
    center(xz)
    Building.

0 Kudos
MatthiasBuehler1
Deactivated User
Btw. you could of course also directly create an attribute which describes the asset path to the building as a string in your GIS application. Then you don't have to make the mapping function in CityEngine.


Let me know how it works.

Matt
0 Kudos
Thu_GiangDang
Emerging Contributor
Hi,

Thank you for your solution. For now what I did was I manually assigned the different start rule for different points and use the case-else grammar to get the correct file path, but your method is way better.

However, the full point feature class is quite big (around 500), and the mapping information is store elsewhere (I'm trying to export it into an excel file or a text file). If there is anyway of reading the value directly from the file and do mapping it would be better in term of effort and also better for maintenance, if later on the data is updated or more models are added in.

Thanks again for your time!
0 Kudos
MatthiasBuehler1
Deactivated User
loading those attributes from a text file is possible with Python scripting, by parsing the file, reading the value, then setting the value as either object attribute or as a user set value.

[ Python scripting is available in CityEngine Advanced, not Basic. ]

ok ?
0 Kudos
Thu_GiangDang
Emerging Contributor
Thanks for your answer!
0 Kudos