Entities relationship - Sketchup Ruby SDK
-
@dan rathbun said:
Well then unless the "boxes" have been grouped or made into a component... then they are nothing but primitives that happen to share vertices.
Hi Dan,
Thanks for the advisory.
As you can see, I am new to Sketchup's workflow and best practices.
If I understand correctly, it is reasonable to expect some group/component from proper Sketchup usage.
Regards
-
@nicholas_yue said:
If I understand correctly, it is reasonable to expect some group/component from proper Sketchup usage.
Well.. yes, if the user wants to treat the collection as an entity,.. give it name so it can be found, or have that name when it's exported,... make it easy to move, or scale the "group".... and have the faces in the group inherit a color and/or material en masse (by assigning them to the group in one step. Otherwise you have to assign them to each individual face.)
-
@nicholas_yue said:
@dan rathbun said:
Did You group the boxes, and then give each group a name ??
No, I didn't
I am working on an exporter and need to deal with scenes as is rather than require the plugin user to change their work flow.
Normal workflow would be to group or make components out of objects. In which case you can get the name.
group.name
andcomponentinstance.name
,componentinstance.definition.name
. -
If you simply can't group/component the boxes' geometry [which would be a logical step when making them!]... BUT they are separated by 'gaps' then if you take a face or an edge you can use
.all_connected
- to get an array of all faces and edges connected to the face or edge. So if you know that there are just two separate sets of geometry in the same context that will be connected to each other, then make a list of all entities - say...
ents=Sketchup.active_model.entities
- then take
box1=ents[-1].all_connected
- to list all edges/faces connected to the last entity in the model... then
box2=[] ents.each{|e| if not e.all_connected.include?(box1[0]) box2=e.all_connected break end }
- Now
box1
andbox2
are arrays of the two 'separate' sets of geometry. If you just want just the boxes' faces then filer the arrays fore.class==Sketchup::Face
etc...
Note that this will fail IF there's any other geometry or objects in the SKP...
- then take
-
@tig said:
ents=Sketchup.active_model.entities
- then take
box1=ents[-1].all_connected
- to list all edges/faces connected to the last entity in the model... then
box2=[] ents.each{|e| if not e.all_connected.include?(box1[0]) box2=e.all_connected break end }
I tried but it get's really slow with very large scene.
I am after a more direct way to find out
(1) How many objects are in the model
(2) For each object, what are the faces, edges, vertexI am doing this to write out the information as a text output so I can render it in Renderman.
Is there an easier approach for folks writing exporter for SketchUp, I had a look at some of the example exporter and they don't look straight forward.
- then take
-
@nicholas_yue said:
(1) How many objects are in the model
If you mean "objects" as in groups or components, that is easy. Use
model.definitions
to access that. But if you mean "objects" as in clusters of connected meshes which isn't connected, then TIG's way is the only way to do it. -
@nicholas_yue said:
I am after a more direct way to find out
(1) How many objects are in the modelSketchup.active_model.entities.count
also:
model.number_faces -
@dan rathbun said:
@nicholas_yue said:
I am after a more direct way to find out
(1) How many objects are in the modelSketchup.active_model.entities.count
That only returns the number of entities in the root context, entities inside groups and components are not counted.
-
Yep.. and doesn't account for other kinds of things that would likely be exported, like: Layers, Materials, Colors, Scenes, Styles, AttributeDictionary etc.
Basically all the collection counts need to be summed, together with model.entities and definitions.each.entities, but it may be possible to use
ObjectSpace.each_object
to get raw numbers, rather than iterating the model DOM... but only ONE model must be open, or the numbers are worthless. -
Thanks for all the suggestions, pointers and tips.
I am making progress exporting both raw entities and entities within components instances (including the transformation)
It's not complete yet (some instance are place wrongly) but I should be able to figure the rest out (might be group handling etc)
Thank you once again.
Advertisement