SPB
March 8, 2016, 5:06pm
1
Dear Specialists,
I have a model that was imported from .ifc. (out of Allplan). There are a lot of classified components, but not all components are useful for me…
because of that I want to hide those components that does not have the ifc attribute “Allplan Attributes”
I tried this, its not really that what I tried to acchieve with my above explaned issue:
modell = Sketchup.active_model
entities = modell.active_entities
sel = modell.selection
sel.each {|entity|
if entity.is_a? (Sketchup::ComponentInstance)
path =[“IFC 2x3”, “IfcBuildingElementProxy”, “Allplan Attributes”] #not right
val = entity.definition.get_classification_value(path)#not right
if val.to_s = “Allplan Attributes” #not right
UI.messagebox.val#not right
end
#entity .
#end
end
}
Here one element without the Allplan Attributes: I whant to hide all of them
Here one element with the Allplan Attributes: I whant them to be still visible
hoping for help
SPB
1 Like
you need to use == when comparing items, but it may need more than just that…
I’ve got a cleanup ruby for ifc imports these snippets may help you work things out…
these are a couple of my ‘test’ scripts that helped me decide what to use in the final version…
this is the code that remove the ‘extra’ coplanar edges…
t1 = Time.now
##---------------------------------------------------------------------------------------
# Clear ifc Edges if not visable?
model = Sketchup.active_model
defs = model.definitions
ifc_comps =[]
defs.each{|d|
next if d.image?
next if d.group?
ins=[]
d.instances.each{|i|ins << i.name}
ifc_comps << d.instances unless ins.empty?
}
edges = []
count = 0
ifc_comps.each{|c| edges << [c[0].definition.entities.grep(Sketchup::Edge).find_all{|e| e.valid? &&
e.hidden? &&
e.faces.length == 2 &&
e.faces[0].normal.dot(e.faces[1].normal)>0.9999999999999 }] }
model.start_operation("Clear ifc Edges")
edges.flatten!.each{|e| count+=1
e.parent.entities.erase_entities(e) rescue next
Sketchup::set_status_text((" #{count} of #{edges.length}" ),SB_PROMPT)
# break if count == 10
}
model.commit_operation
puts Time.now - t1
then hides all the ‘Space’ components on their own Layer…
##---------------------------------------------------------------------------------------
# space
t1 = Time.now
model = Sketchup.active_model
defs = model.definitions
layers = model.layers
space_layer = layers.add("IfcSpace")
space_layer.visible = false
space_layer.page_behavior = LAYER_HIDDEN_BY_DEFAULT | LAYER_IS_HIDDEN_ON_NEW_PAGES
spaces =[]
defs.each{|d|
next if d.image?
next if d.group?
ins=[]
d.instances.each{|i|ins << i.name if i.name =~ /IfcSpace/
d.layer = "IfcSpace" if i.name =~ /IfcSpace/
}
spaces << d.instances unless ins.empty?
}
draw_elements = []
spaces.flatten!.each{|s| draw_elements << [s.definition.entities.find_all{|e| e if e.valid?}]
}
model.start_operation("Hidden Spaces")
count = 0
draw_elements.flatten!.each{|e| count+=1
next if e.class == Sketchup::ComponentInstance
e.hidden = true
Sketchup::set_status_text((" #{count} of #{draw_elements.length}" ),SB_PROMPT)
#break if count == 10
}
model.commit_operation
puts Time.now - t1
##---------------------------------------------------------------------------------------
then I work through doing stuff like adding material colors…
puts Time.now - t1
##---------------------------------------------------------------------------------------
# floors
model = Sketchup.active_model
defs = model.definitions
floors =[]
defs.each{|d|
next if d.image?
next if d.group?
ins=[]
d.instances.each{|i|ins << i.name if i.name =~ /IfcSlab/}
floors << d.instances unless ins.empty?
}
faces = {}
tally = 0
floors.map{|e| tally += 1; faces[e[0].name.concat(tally)] = e[0].definition.entities.grep( Sketchup::Face)}
flr_tile = model.materials.add('flr_white_tile')
flr_tile.color = Sketchup::Color.new(255, 255, 255, 255)
flr_tile.alpha = 1.0
flr_wood = model.materials.add('flr_shiny_wood')
flr_wood.color = Sketchup::Color.new(117, 70, 15, 255)
flr_wood.alpha = 1.0
flr_slab = model.materials.add('flr_matte_slab')
flr_slab.color = Sketchup::Color.new(125, 125, 125, 0)
flr_slab.alpha = 1.0
count = 0
floor_faces = 0
faces.values.map{|v| floor_faces += v.length}
model.start_operation("Paint floors")
faces.each_pair{|k,v|
v.each{|f|
count+=1
Sketchup::set_status_text(("Painting #{count} faces of #{floor_faces} floor faces" ),SB_PROMPT)
next unless f.valid?
if k.include? 'Wood'
f.material = flr_wood
elsif k.include? 'Ceramic'
f.material = flr_tile
else
f.material = flr_slab
end
f.back_material = f.material
}
}
model.commit_operation
##---------------------------------------------------------------------------------------
puts Time.now - t1
##---------------------------------------------------------------------------------------
if you post a ifc file I could have a look at what you might need to filter…
john
Can you export one of the components as a standalone SKP file, and post it here ?