Selected entity question
-
Short question.
Is:Sketchup.active_model.active_entities[0]
the selected entity?
-
No, these are the entities in the open group or component instance.
You want:
Sketchup.active_model.selection[0]
Class: Sketchup::Selection
A set of the currently selected entities.
SketchUp Ruby API Documentation (ruby.sketchup.com)
-
Thanks. That was what I suspected.
Now I need to find a way to do what I want to do from the selection.
A side question. What about getting the selected material?
Sketchup.active_model.materials[0] won’t do it then either I guess? -
That would be Sketchup.active_model.materials.current
-
That method gives you the current 'active' material in the model.
But... if you want to get a material from the currently selected entity, then you use:mat = Sketchup.active_model.selection[0].material
However, you might be better off filtering the selection, until you get an entity of the kind you want... e.g.
face = Sketchup.active_model.selection.grep(Sketchup;;Face)[0] mat = nil mat = face.material if face
Where the first face in the selection returns its material, or nil...
-
Thanks, I read in a older post somewhere, and I think it was by Thomthom, that there was a bug that could Bugsplat SU when using materials.current if there wasn't any materials in SU. Do you know if that still is an issue or if it has been fixed?
-
Why do you need to get the
model.materials.current
?
You could pre-set it usingmodel.materials.current = a_material
Having previously seta_material = model.materials["A_Name"]
You haven't really explained the full context......
-
They are just for two small snippets that I will need some advise from Thomasz (Thea settings) to make them properly.
I'm just preparing for when he will have some time to look into it...
Advertisement