Newbie Ruby Question
-
Hello,
I am completely new to Ruby and not sure if this is the best place to ask the following beginners question. In the Sketchup API reference there is the following example:#------------------------------------------------------------------------
depth = 100
width = 100
model = Sketchup.active_model
entities = model.active_entities
pts = []
pts[0] = [0, 0, 0]
pts[1] = [width, 0, 0]
pts[2] = [width, depth, 0]
pts[3] = [0, depth, 0]Add the face to the entities in the model
face = entities.add_face pts
I just happen to know that the second and third entities in the
entities objects are edges.
entity1 = entities[1]
entity2 = entities[2]
edges = entity1.all_connected
if (edges)
UI.messagebox edges.to_s
else
UI.messagebox "Failure"
end
#-----------------------------------------------------------------------------When I type entities[0].class in the console the response is Sketchup::ComponentInstance
What exactly is going on? I thought I only created 4 edges and one face but there is also a ComponentInstance defined. What exactly is a ComponentInstance and why is it defined? as there is no Component present. How does Sketchup iterate through the entities array?
So :
entities[0].class Sketchup::ComponentInstance
entities[1].class Sketchup::Edge
entities[2].class Sketchup::Edge
entities[3].class Sketchup::Edge
entities[4].class Sketchup::Edge
entities[5].class Sketchup::Face -
The code in itself doesn't create a component. Are you sure the SketchUp starter figure isn't in the scene as well?
Components and definitions in short (and this description is flawed):
A component definition is an 'object' that's stored in the internal library (example: the geometry and materials for 1 tree). You can have a definition in your file without it being visible in your model.A component instance is a visible 'copy' of the definition in your model. Using components is a good thing if you want to have several copies of the same element (like a forest). For every copy, SketchUp only uses a reference to the definition and only a few unique data entries for every copy (like position, scale, rotation etc). This keeps your sketchup file small and, if you want to refine every tree, you only have to change 1 to change them all.
For more information on components, read in the API about component definition and component instance:
http://www.sketchup.com/intl/en/developer/docs/ourdoc/componentdefinition
http://www.sketchup.com/intl/en/developer/docs/ourdoc/componentinstance -
@unknownuser said:
He bedankt Kaas!, helemaal gelijk ik had Lisanne niet verwijderd!
Kaas=Cheese in Dutch
In English: "Thanks Cheese"
I did not remove Lisanne which is a component.....just silly
Groet
Michiel -
Delete any placed components and use:
Model Info > Statistics > Purge Unused...
Then the first definition in the empty model is your own...***In your case you are actually looking for newly added geometry...
It is best to add a group [group = model.active_entities.add_group()
] and then add the new geometry into that - then all of that newly added geometry is ingroup.entities
, rather thanmodel.active_entities
- avoiding your issue altogether.***If you ever need it use:
model.definitions[-1]
references the last added definition...
So whatever you have just added is now properly referenced. -
Thanks for that!
That brings me to something else I have been struggling with today.If I have loaded a component into my model and want to pushpull a face with ruby, how would I do that?
I find enough information on this when its loose geometry but not when it is in a group or component. -
To find the face in its 'context' you need to use
definition.instance[0].entities
orgroup.entities
rather thanmodel.active_entities
,
ormodel.entities
Advertisement