Hello all,
Year 0 Newbie here. I’m trying to write a simple script that would output the surface area of each types of materials in each component in the model.
I’m not totally new to coding but I come from an excel-vba kind of background and am pretty lost in how Ruby API works. I’ve done about 3 day’s worth of research and while I can do simple things like create faces and copy things, I don’t know how to extract information from an existing model.
Not exactly asking for a full handout code here, but if I can get some sample code or a few relevant lines thrown my way that’s related to what I’m trying to do I’d be really grateful.
A general idea of my code is:
Define the all the entities in my model with
model = Sketchup.active_model entities = model.entities
And then I’d need to loop through each entity (I’m assuming an entity is a unique component), assigning it to a key in a dictionary.
While I’m referring to each entity, I will start another for each loop through all the faces to create a nested dictionary of existing faces in each component. Then I want to sum up the total surface area for each material within the component. And write that as the value for each material.
Like a
for i in total_faces
material_dictionary = [:colour01] = sum_colour01 + facei_colour01
export = {:component_name => material_dictionary{}}
Then finally export this all to a csv.
In the end this should give me the material surface area breakdown for every component in the model. Fredo6’s extension have the two halves that I want (material break down, and outlines component paths) but I can’t exactly open it up to see the code.
So to break it down:
how does one loop through each individual component (preferrably through individual instances as well)?
how does one get a list of faces, and loop through them?
how does one export a dictionary to csv?
Any help is welcome, thank you!