I was wondering if theres a way to have the definition information (entity info) automatically added to IFC dynamic options. for example. if i have component type IFCbeam. i would like the name (ifclabel : …) to be the same as my component definition.
Unfortunately it is not possible to link the IFC parameters, such as IfcLabel, to the Component Attributes. But you can automate this with a Ruby script.
No problem, here is a small part of the script that I use for automatically assigning IFC data to component definitions.
Ruby script
### IFC PARAMETER FILL ### ------------------------------------------------------
mod = Sketchup.active_model # Open model
defs = mod.definitions # All definitions in model
# Check if IFC classifications are loaded in model
if mod.classifications['IFC 2x3']
# Update all classified definitions in model
defs.each do |definition|
classify_type = definition.get_attribute 'AppliedSchemaTypes', 'IFC 2x3'
if classify_type
# Overwrite the IFC label name with the definition name
path = ['IFC 2x3', classify_type.to_s, 'Name', 'IfcLabel']
definition.set_classification_value(path, definition.name)
end
end
UI.messagebox("Update completed")
end
To Do
Copy the Ruby script.
Open de Ruby Console in SketchUp.
Window menu → Ruby Console
Paste the Ruby script into the Ruby Console and press the Enter key.
When the script is executed, each IFC 2x3 classified component definition will have the IfcLabel parameter provided with the component definition name.
is it possible to create a button that executes this ruby console coding automatically aswell?
and is there a place where i can check these codes to add maybe more data?
i’ve tried to add something but i keep on getting error messages.
the goal is to add the material name to objecttype in ifc.
IFC PARAMETER FILL ### ------------------------------------------------------
mod = Sketchup.active_model # Open model
defs = mod.definitions # All definitions in model
Check if IFC classifications are loaded in model
if mod.classifications[‘IFC 2x3’]
Update all classified definitions in model
defs.each do |definition|
classify_type = definition.get_attribute 'AppliedSchemaTypes', 'IFC 2x3'
if classify_type
# Overwrite the IFC label name with the definition name
path = ['IFC 2x3', classify_type.to_s, 'Name', 'IfcLabel']
definition.set_classification_value(path,
definition.name)
end
if classify_type
path = [‘IFC 2x3’, classify_type.to_s, ‘objecttype’, ‘IfcLabel’]
definition.set_classification_value(path, material=name)
Just a few things in advance.
It is important that you post the Ruby code correctly on this forum so that it is readable.
If you want to do more with Ruby scripting in SketchUp or perhaps extension development, it is important to learn how to program with Ruby. Here are a number of useful links that give you more information
The SketchUp Developers website explains more about how to get started with the Ruby API.
Now coming back to your questions.
You can package this script as an extension so that you can “start” it using a button in the toolbar.
And you can also enter other parameters automatically, but then you have to change the path.
See here the documentation from the Ruby API regarding the assignment of classification values.
In addition, I see a number of errors in the code.
I expect you will want to read the material of the component? In that case you have to read the material from the component instance of the definition. Multiple instances of a definition can each contain a different material.
And you must also pay close attention to how you describe the values in the path. This is case sensitive!
In this case you read the material name from the first component instance of the relevant definition.
The ObjectType IfcLabel will now contain this value.
what i have done now is inputted the line you suggested but i get this error message now.
I only need 2 definitions in my IFC parameter fill. name and material name.
code failed with an error: NoMethodError: undefined method `display_name' for nil:NilClass
```ruby
## IFC PARAMETER FILL ### ------------------------------------------------------
mod = Sketchup.active_model # Open model
defs = mod.definitions # All definitions in model
# Check if IFC classifications are loaded in model
if mod.classifications['IFC 2x3']
# Update all classified definitions in model
defs.each do |definition|
classify_type = definition.get_attribute 'AppliedSchemaTypes', 'IFC 2x3'
if classify_type
# Overwrite the IFC label name with the definition name
path = ['IFC 2x3', classify_type.to_s, 'ObjectType', 'IfcLabel']
definition.set_classification_value(path, definition.instances[0].material.display_name.to_s)
end
end
UI.messagebox("Update completed")
end
So you have to find out whether the instance of the definition contains a material.
If not, I will leave in this case, the variable inst_mat contains an empty string.
# Get the material from the first instance of the definition
# Or get a empty string ""
inst_mat = definition.instances[0].material.nil? ? "" : definition.instances[0].material.display_name
# Overwrite the IFC label ObjectType with the first definition instance material
path = ['IFC 2x3', classify_type.to_s, 'ObjectType', 'IfcLabel']
definition.set_classification_value(path, inst_mat)
You can combine the snippits of the Name and ObjectType in the IF statement.
Dear,
I use materials add a collor or texture to my component. Some of these materials i have made myself. and named aswell. but i never use the instance entry box in entity info.
so what i would like the ruby to do is go check each component for which material is linked to it and use the name as saved in the material library.
if thats impossible its no big deal for me to input the material manually in the in textbox.
i keep getting an error code when importing your lines. I tried a few different ways but always same error
Code failed with an error: NoMethodError: undefined method `material' for nil:NilClass
```ruby
### IFC PARAMETER FILL ### ------------------------------------------------------
mod = Sketchup.active_model # Open model
defs = mod.definitions # All definitions in model
# Check if IFC classifications are loaded in model
if mod.classifications['IFC 2x3']
# Update all classified definitions in model
defs.each do |definition|
classify_type = definition.get_attribute 'AppliedSchemaTypes', 'IFC 2x3'
if classify_type
# Overwrite the IFC label name with the definition name
inst_mat = definition.instances[0].material.nil? ? "niet bepaald" : definition.instances[0].material.display_name
path = ['IFC 2x3', classify_type.to_s, 'ObjectType', 'IfcLabel']
definition.set_classification_value(path, inst_mat)
end
end
defs.each do |definition|
classify_type = definition.get_attribute 'AppliedSchemaTypes', 'IFC 2x3'
if classify_type
path = ['IFC 2x3', classify_type.to_s, 'Name', 'IfcLabel']
definition.set_classification_value(path, definition.name)
end
end
UI.messagebox("Update completed")
end
sorry if i do stupid things.
The component definition contains / defines the content of a SketchUp component. Components are a collection of entities that can be applied and reused multiple times in a model. When a component is applied, it is an instance that refers to the component definition.
Restart SketchUp and run the code below.
This should work.
Ruby Code
### IFC PARAMETER FILL ### ------------------------------------------------------
mod = Sketchup.active_model # Open model
defs = mod.definitions # All definitions in model
# Check if IFC classifications are loaded in model
if mod.classifications['IFC 2x3']
# Update all classified definitions in model
defs.each do |definition|
classify_type = definition.get_attribute 'AppliedSchemaTypes', 'IFC 2x3'
if classify_type
# Overwrite the IFC label name with the definition name
path = ['IFC 2x3', classify_type.to_s, 'Name', 'IfcLabel']
definition.set_classification_value(path, definition.name)
# Get the material from the first instance of the definition
# Or get a empty string ""
inst_mat = definition.instances[0].material.nil? ? "niet bepaald" : definition.instances[0].material.display_name
# Overwrite the IFC label ObjectType with the first definition instance material
path = ['IFC 2x3', classify_type.to_s, 'ObjectType', 'IfcLabel']
definition.set_classification_value(path, inst_mat)
end
end
UI.messagebox("Update completed")
end
thanks again for your effort. its much appreciated.
i got it working in an almost empty file but for some reason it wont work in an existing drawing file.
what could be the isseu here. the fact not everything is a component?
or other possible reason i cant recall for the moment.
The script ran through the entire definitions list, and assumed that there was an instance of each definition in the 3D model. If there are definitions in the model, but no instances, the script will crash.
To Do
Make sure you purge the project first (Purge Unused).
IFC PARAMETER FILL ### ------------------------------------------------------
mod = Sketchup.active_model # Open model
defs = mod.definitions # All definitions in model
Check if IFC classifications are loaded in model
if mod.classifications[‘IFC 2x3’]
Update all classified definitions in model
defs.each do |definition|
classify_type = definition.get_attribute 'AppliedSchemaTypes', 'IFC 2x3'
if classify_type
# Overwrite the IFC label name with the definition name
path = ['IFC 2x3', classify_type.to_s, 'Name', 'IfcLabel']
definition.set_classification_value(path, definition.name)
# Get the material from the first instance of the definition
# Or get a empty string ""
inst_mat = definition.instances[0].material.nil? ? "niet bepaald" : definition.instances[0].material.display_name
# Overwrite the IFC label ObjectType with the first definition instance material
path = ['IFC 2x3', classify_type.to_s, 'ObjectType', 'IfcLabel']
definition.set_classification_value(path, inst_mat)
end
end
UI.messagebox("Update completed")
end
He doesn’t take my definition of my component into IFClabel. This only happens with new drawings.
:3: warning: encountered \r in middle of line, treated as a mere space
:5: warning: encountered \r in middle of line, treated as a mere space
:6: warning: encountered \r in middle of line, treated as a mere space
:8: warning: encountered \r in middle of line, treated as a mere space
:9: warning: encountered \r in middle of line, treated as a mere space
:10: warning: encountered \r in middle of line, treated as a mere space
:12: warning: encountered \r in middle of line, treated as a mere space
:13: warning: encountered \r in middle of line, treated as a mere space
:14: warning: encountered \r in middle of line, treated as a mere space
:17: warning: encountered \r in middle of line, treated as a mere space
:18: warning: encountered \r in middle of line, treated as a mere space
:20: warning: encountered \r in middle of line, treated as a mere space
:21: warning: encountered \r in middle of line, treated as a mere space
:22: warning: encountered \r in middle of line, treated as a mere space
:23: warning: encountered \r in middle of line, treated as a mere space
:24: warning: encountered \r in middle of line, treated as a mere space
:25: warning: encountered \r in middle of line, treated as a mere space
Error: #
:17:in `block in '
:8:in `each'
:8:in `'
SketchUp:in `eval'