Subtract the selection of edges
-
OK
Here's one way to reduce a selection to include just its
faces
...model = Sketchup.active_model ss = model.selection faces = ss.grep(Sketchup;;Face) ss.clear ss.add(faces)
To explain...
You make a reference to the model.
You make a reference to the model's selection.
You grep the model's selection to collect just its faces.
You clear the model's selection.
You add the faces to the model's selection.Now your preselected entities only include '
faces
'...I guess this is where you need to be ?
-
Yes it's exactly that TIG.
I thank you very much! -
I just realized that there is a problem!
My ultimate goal is to write a code that explodes a component and then selects all the faces.
To explode a component I use this method:
Sketchup.send_action 21111
To select faces, I use your TIG method.
All works well if I use these codes in 2 steps.
If I want to combine the 2 codes in the same method, nothing works!
Sketchup.send_action 21111 model = Sketchup.active_model ss = model.selection faces = ss.grep(Sketchup;;Face) ss.clear ss.add(faces)
Do you know what for and how to get around the problem?
Thank you
-
I wouldn't rely on send_action, the numerical ones only apply on PCs anyway.
How about this.model = Sketchup.active_model ss = model.selection compo = ss.grep(Sketchup;;ComponentInstance)[0] if compo exs = compo.explode # array of all entities resulting from the explode. faces = exs.grep(Sketchup;;Face) ss.clear ss.add(faces) else #no compo selected UI.messagebox("You must preselect a component-instance !") end
To explain...
You make a reference to the model, then its selection.
You grep the selection and take the first 'hit' on a component-instance
Unless there is a preselected instance you get an error message.
If there is a 'compo
' it is exploded [and the results collected], and the selection changes to include only the faces in that.
If you want to process the exploded faces further there's no need to 'select' them, because 'faces' is already an array list of them - so for example, to make them all 'Red' you could omit thess.add(faces)
and instead addfaces.each{|f| f.material = 'Red' }
??? -
I tried this code and it still does not work:
array = [] mod = Sketchup.active_model sel = mod.selection sel.grep(Sketchup;;ComponentInstance).each do |s| s.definition.entities.grep(Sketchup;;Face).each do |f| array << f end s.explode end sel.add(array) p array
The "Entity Info" window indicates that faces are selected, while on the SketchUp scene nothing is selected.
It's too strange for me!
Thanks for your help.
Manuel
-
In your example, posted before my last one, the code will fail because when you explode the instance any reference to the definition's own faces will be lost - but the explode itself returns an array of the new faces that have resulted from the explode...
-
Thank you TIG, your method works perfectly.
@tig said:
In your example, posted before my last one, the code will fail because when you explode the instance any reference to the definition's own faces will be lost - but the explode itself returns an array of the new faces that have resulted from the explode...
I understand! Your code is a perfect example of how to recover faces after the explode method.
@tig said:
I wouldn't rely on send_action, the numerical ones only apply on PCs anyway.
I did not know! This can then cause problems in other methods that I have written.
How will you "copy / paste in place" a component being selected without using "send_action"?I do not know how to do otherwise than this method:
Sketchup.send_action CMD_COPY Sketchup.send_action 21939
Thanks for your help.
-
http://ruby.sketchup.com/Sketchup.html#send_action-class_method
List the common 'strings' and also the PC only send_actions.However, some are 'missing'...
These are still undocumented - some might be obsolete too...
copy:
cut:
editDelete:
getCurrentView:
getModels:
newDocument:
openDocument:
paste: [BUT there's NOT a pasteInPlace: ! To do that you must somehow replicate the selected entities and add them to the current context, applying a suitable transformation etc]
placeModel:
printDocument:
saveDocument:
select3dTextTool:
selectionZoomExt:
shareModel:
uploadComponent:
viewShowGuides:These are also broken on MAC - or at least they were...
getModels:
getPhotoTexture:
shareModel:
uploadComponent: -
@tig said:
http://ruby.sketchup.com/Sketchup.html# ... ass_method
List the common 'strings' and also the PC only send_actions.Yes I saw indeed!
Before coming to post my questions I did some research and I found all the "send_actions" in this TOPIC.
To avoid problems, I prefer not to use "send_actions".
How can you copy the faces and edges of a component and paste in place them on the outside of the component ?
Code is very complicated for me to write without the "send_actions".
Thank you
Manuel
-
This isn't a method, but an outline of a process...
You have a component-instance.
From that instance you can get the component-definition.
You can then add a new instance of that into the same entities-context as the original instance, using a copy of the original's transformation.
Now you can process that new instance.For example, you can explode it get a reference to everything, then erase everything that's not an edge - e.g. faces, text, dims, and nested groups and instances.
Now you have the edges.If you'd like a group containing just those edges...
Once you have the component-definition, you first add a new empty group into the same entities-context.
You can now make a reference to the group.entities context and then add the new instance into that new context, explode and trim the array of entities, to finally leave only the desired edges inside the group.
Now you have the required edges inside your group.
[Remember that you can rename that container group etc as desired]
Advertisement