Selected entity question

Selected entity question

Postby Pixero » Wed May 15, 2019 9:29 am

Short question.
Is:
Code: Select all
Sketchup.active_model.active_entities[0]

the selected entity?
0
User avatar
Pixero 
 

Re: Selected entity question

Postby jiminy-billy-bob » Wed May 15, 2019 8:26 pm

0
User avatar
jiminy-billy-bob 
PluginStore Author
PluginStore Author
 

Re: Selected entity question

Postby Pixero » Wed May 15, 2019 10:02 pm

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?
0
User avatar
Pixero 
 

Re: Selected entity question

Postby jiminy-billy-bob » Sat May 18, 2019 10:23 pm

0
User avatar
jiminy-billy-bob 
PluginStore Author
PluginStore Author
 

Re: Selected entity question

Postby TIG » Sun May 19, 2019 6:28 pm

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:
Code: Select all
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.
Code: Select all
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...
1
TIG
User avatar
TIG 
Global Moderator
 

Re: Selected entity question

Postby Pixero » Sun May 19, 2019 7:30 pm

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?
0
User avatar
Pixero 
 

Re: Selected entity question

Postby TIG » Sun May 19, 2019 7:45 pm

Why do you need to get the model.materials.current ?
You could pre-set it using model.materials.current = a_material
Having previously set a_material = model.materials["A_Name"]

You haven't really explained the full context......
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Selected entity question

Postby Pixero » Sun May 19, 2019 7:54 pm

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...
0
User avatar
Pixero 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 3 guests

Visit our sponsors: