Edit group by ruby-code instead of a right mouse click
-
Hi!
Is it possible to edit a group by ruby-code instead of a right mouse click in contextmenu.
Thanks...
Andreas
-
Open a Group of Component - no.
-
To 'edit' a group use
group.entities
You add-to or erase-from the set, or transform some of its entities etc - just as you would any other entities set... i.e. likemodel.entities
etc... and the changes occur inside the groupYou could simulate the 'edit group' command - set a shortcut e.g. '
Shift+Ctrl+Alt+G
' to the 'edit group' menu item and then use 'win32ole.so
' to run the key-stroke(s) to make that group active and then edit its entities to make your selection and then close the group usingclose_active
... BUT it's pretty convoluted and would be PC dependent AND why do it? -
I would like to make a cutout in a wall (group) to insert a door or window.
Andreas
-
@andreas said:
I would like to make a cutout in a wall (group) to insert a door or window.
Andreas
That is definitely possible. The group has an Entities collection.
Add a Rectangle to the groups Entities. Pushpull its face to the opposite side of the wall. Delete the face.
-
You work directly with the Group's entities, just like you would the model's entities. Having an editing context is a useful concept for people when modeling, but is not necessary when editing geometry using the Ruby API.
This sample shows how you might get to a Group's entities.
all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup;;Group} my_group = all_groups.select{|g| g.name == "My Group"} my_entities = group.entities my_entities.add_face(...)
-
When you add geometry it goes into an
entities
collection.
You have:-
model.entities
= everything that's placed in the model
group.entities
= everything that's placed in the group
definition.entities
= everything that's placed in the component's definition
there is also
model.active_entities
= everything that is placed in the current context - so this could be equal to themodel.entities
, OR if the user starts your tool whilst he is editing a group it would become thegroup.entities
automatically.
Example - this code snippet adds a new [empty] group into the model, then it adds a line 1" tall into that group, it then adds a second [empty] group inside the first group and adds a line 10" long at the first line's end but in that new group.model=Sketchup.active_model group1=model.entities.add_group() group1.entities.add_line([0,0,0],[0,0,1]) group2=group1.entities.add_group() group2.entities.add_line([0,0,1],[10,0,1])
Run it [copy/paste the into a file in Plugins and use
load"file.txt"
in the Ruby Console] and see the results...
Hopefully this is helpful... -
@jim said:
You work directly with the Group's entities, just like you would the model's entities. Having an editing context is a useful concept for people when modeling, but is not necessary when editing geometry using the Ruby API.
This sample shows how you might get to a Group's entities.
> all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup;;Group} > my_group = all_groups.select{|g| g.name == "My Group"} > my_entities = group.entities > my_entities.add_face(...) >
my_entities = group.entities don´t works.
I think it must be:
my_entities = my_group.entities
but that don´t works too.Can someone help me?
Thanks
Andreas -
You first get a reference to the required group, then one to its entities, and then do stuff in that entities collection...
To see if each step is working addputs my_group
etc after it's defined it should then print up the group-id in the ruby console or 'nil'!
It should bemy_group
in your code if you want to work inside that group.
Do you have a group with that specific name ?
Obviously the.add_face(...)
needs expanding so the...
is a list of at least three coplanar points!!
It WILL work...
Why not test it using my method that adds a new group tomodel.active_entities
with
my_group=model.active_entities.add_group()
NOW you are sure to havemy_group
... now add the face tomy_group.entities
-
@tig said:
You first get a reference to the required group, then one to its entities, and then do stuff in that entities collection...
To see if each step is working addputs my_group
etc after it's defined it should then print up the group-id in the ruby console or 'nil'!
It should bemy_group
in your code if you want to work inside that group.
Do you have a group with that specific name ?
Obviously the.add_face(...)
needs expanding so the...
is a list of at least three coplanar points!!
It WILL work...
Why not test it using my method that adds a new group tomodel.active_entities
with
my_group=model.active_entities.add_group()
NOW you are sure to havemy_group
... now add the face tomy_group.entities
Hello TIG,
I need access to an existing group to add a face. I would like to make a cutout in a wall (existing group) to insert a door or window.
Andreas
-
I only suggested the making a new group method so that you might understand how it works in a test...
Did you try my 'puts' methods to report if you are actually getting the 'group' etc using your methods ?
Assuming you corrected the group >> my_group it should work IF the names match... -
@tig said:
...Assuming you corrected the group >> my_group it should work IF the names match...
It does not work.
all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup;;Group} my_group = all_groups.select{|g| g.name == "G1"} my_entities = my_group.entities
The result is:
all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup::Group}
finds several groups
=> [#Sketchup::Group:0x80db350, #Sketchup::Group:0x80db320, #Sketchup::Group:0x80db2f0, #Sketchup::Group:0x80e6768]my_group = all_groups.select{|g| g.name == "G1"}
picks one of the groups
=> [#Sketchup::Group:0x80e6768]my_entities = my_group.entities
gives the following error
NoMethodError: (eval):1:inget_binding': undefined method
entities' for [#Sketchup::Group:0x80e6768:Array]I don`t understand that!!!
Is there anybody who can explain it to me?
-
all_groups.select{|g| g.name == "G1"}
returns an array with a group - not just the group itself.Since this line is suppose to filter out a single group we assume there will be only one item in the array and therefore extract the first item in the array.
my_group = all_groups.select{|g| g.name == "G1"}.first
So the whole lot would be:
all_groups = Sketchup.active_model.entities.find_all{|e| e.class == Sketchup;;Group} my_group = all_groups.select{|g| g.name == "G1"}.first my_entities = my_group.entities
-
@thomthom said:
my_group = all_groups.select{|g| g.name == "G1"}.first
Thanks - that´s exactly what I need!!!
- 5 years later
-
@tig said:
You could simulate the 'edit group' command - set a shortcut e.g. '
Shift+Ctrl+Alt+G
' to the 'edit group' menu item and then use 'win32ole.so
' to run the key-stroke(s) to make that group active..I'd like to dig up this old thread because I'm looking for a way (a tool started by a keypress) to drill down many nested groups up to the group with the face I picked, and have that group opened to start pushpulling / modifying etc.
Normally I use the outliner to get to the right group but sometimes it's not clear and I have to double click a few times on the target face to drill down the hierarchy. I'd like to skip that double clicking by firing a tool and just pick the face.
I tried making this into a small tool. With the pickhelper I can select the picked face but the group itself isn't opened.
I also tried TIG's suggestion above in a tool but I can't find the 'edit group' command in the shortcuts so can't bind it to a keypress.
Any suggestions??
edit: turns out the shortcut list is generated dynamically. If I select a group and then open the shortcut preferences, I do get the option to assign a key.
-
To set up a shortcut that is context-sensitive you must be in that selection-context.
So to shortcut 'Edit Group' you first need to select a group to get that possibility in the context-menu and you must then open SketchUp's Preferences > Shortcuts and filter for 'Group'... - then set up the shortcut on that tool's command... then of course you'll need to mimic some key-presses etc in some third party code executed by Ruby - all as outlined earlier [PC only]...PS: This 'context' issue when making shortcuts applies to many selection-sensitive commands - like Reverse and Orient, which both need a face to be selected before they appear in the context-menu list...
Advertisement