Skip to content

03: Selecting and visualizing

jakob-beetz edited this page Dec 21, 2016 · 2 revisions

#Selecting and visualizing When you loaded a model into the viewer, the model is being displayed in the central window pane. There are a number of ways to interact between the graphic display ('the viewer') and the script.

For this purpose, the variables viewer and selection are available by default.

selection - retrieving the user selection

The last object that was selected by the users (either by clicking on a 3D representation or using the tree views to the left) is available in the selection variable:

product = selection
print (selection.GlobalId)

Note that GlobalId is available for all objects that have a 3D or 2D representations, since only sub-classes of IfcProduct can have a IfcProductRepresentation. Since IfcProduct in turn is a subclass of IfcRoot, the instance must have a GlobalId

get_selection_set() - retrieving multiple selections

When more then one object is selected in the viewer, the list of all IfcProducts can be retrieved using the get_selection_set() function of the viewer object:

products = viewer.get_selection_set(model)
for product in products:
    print(product.GlobalId)

set_color() - Coloring results

In order to get a visual feedback of the the objects manipulated by the script you can use a convenience function to color your results:

products = viewer.get_selection_set(model)
for product in products:
    viewer.set_color(product, 0.8,0,0)

This colors all currently selected objects red

toggle_visibility() - hiding/unhiding objects

You can switch the visibility of objects by:

products = model.by_type("IfcWall")
for product in products:
    viewer.toggle_visibility(product,True)  

This hides all wall objects in the model. To switch them on again, replace True by False

Setting

Clone this wiki locally