BIM-Tools / SketchUp-IFC-Manager

IFC data manager and exporter for SketchUp.
GNU General Public License v3.0
59 stars 20 forks source link

How to write IFC info to a skp file by SketchUp Ruby #9

Closed cloud1980 closed 5 years ago

cloud1980 commented 5 years ago

I want to generate the su model by ruby and save the ifc information at the same time.

That’s my code:

1. create a group by l, b, h and transform group to component

l = 5000 b = 600 h = 800 model = Sketchup.active_model entities = model.active_entities status = entities.clear! #clear the entities!!! group = entities.add_group pts = pts[0] = [0, 0, 0] pts[1] = [l, 0, 0] pts[2] = [l, b, 0] pts[3] = [0, b, 0] face = group.entities.add_face(pts) status = face.pushpull(h) componentinstance = group.to_component

My question is: How to save my User-defined properties? For example, how to save the IfcBeam’s l, b ,h attributes.

Thanks.

janbrouwer commented 5 years ago

At the moment there are two supported methods for writing properties.

  1. Add AttributeDictionaries under the "IFC 2x3" dictionary. So they are part of the IFC data. Like when you import an IFC containing additional property sets.
  2. Add AttributeDictionaries under the "dynamicattributes" dictionary. To create parametric components (Only user-visible parameters starting with "CPset" are exported). Like: https://3dwarehouse.sketchup.com/model/cf631169-453a-4f23-9a07-e1be52dfee38/ProvisionForVoid-Rectangle-IFC2X3

I hope this helps you on the way!

cloud1980 commented 5 years ago

Thanks a lot.

cloud1980 commented 5 years ago

It’s so kind of you! And I have more questions when I try to write ruby code to realize it.

I think there is a dictionary named “'IFC 2x3”, and the “IFC 2x3” dictionary has a dictionary named “BaseQuantities”. Then the “BaseQuantities” dictionary has the dictionary named “Width”, “Depth”, “Height”. Each of “Width”, “Depth”, “Height” has the key named “Value”.

  1. Is my understanding correct?

  2. For I can’t find any threads about it in the SketchUp Ruby API documents, can you teach me more about how to realize the nested dictionary in ruby?

For example, I creat “Width”, “Depth”, “Height” dictionary in the lowest level. How to nest them inside the “BaseQuantities” dictionary and “IFC 2x3” dictionary.

status = componentinstance.set_attribute "Width", "Value", b.to_s status = componentinstance.set_attribute "Depth", "Value", l.to_s status = componentinstance.set_attribute "Height", "Value", h.to_s