Closing open groups via Ruby?
-
Hi All,
First post here. I'm wondering if there is a way to close any open groups when a tool is activated.
I'm working on a texturing tool that operates outside of groups. You simply select the face you want, then select another face in the model and the texture is copied to that face and aligned properly (using plane intersection).
The whole impetus for this is that I mainly work in Sketchup to map for Source games. When exporting to Source VMF format, a valid solid has to be a group of faces that makes a convex shape. So for the most part, you will be dealing with groups. So not being able to align textures across groups is a pretty big pain (as soon as you open a group, the other group's textures are replaced by a material color).
So I was thinking it would be more polished if the tool could automatically (or at least optionally) be able to back out of all the open groups when you activate the tool.
An example video of the tool in use can be found here.
http://www.youtube.com/watch?v=hb63D7Cmt50Any ideas would be appreciated. Thanks!
-
EDIT: I was way off....apparently there is a way to close groups! Sorry 'bout that,
[deleted rubbish and misleading comments]... you could check if the user is inside a group when the script is activated and pop up an error saying that must not be in group edit mode and then exit the script so they can get out of group edit mode.
That way they would be forced into only being able to use the script outside of all groups.
Chris
-
Use a test like
until model.active_entities==model.entities model.close_active end
this will close active group or component edits, including any nesting, back to the base model entities...
You can't 'open' them BUT you can 'close' them.
-
@tig said:
Use a test like
until model.active_entities==model.entities > model.close_active > end
this will close active group or component edits, including any nesting, back to the base model entities...
You can't 'open' them BUT you can 'close' them.
Beware of this method!
Normally when you close group in SU it adds the action to the Undo stack. But this method doesn't do this. So when you close the group and then decide to undo a few steps you'll get corrupted geometry as it offsets the modified geometry. -
Thank you for the replies. Given the issues involved, I think I'll either let them back out on their own, or at most go with a UI message.
On a related subject, I've found something I never noticed before regarding groups. It seems that if you copy a group, it acts like a component until you modify it through one of the default tools.
Example, I have a group containing an arch, I copy that group to another location. My tool (which adds the face under the cursor to a selection for visual feedback), will highlight that face in all instances as if it were a component. Though if I go to one of the instances and say... position the texture, it only affects the open group as expected.
So I'm guessing that Sketchup does something similar to copy on write as far as groups. So what's the best way for me to do the same?
I'm guessing depreciated or not, Group.make_unique is probably the way to go. So I'm guessing I'll have to walk up the entities to find the groups's Sketchup::ComponentDefinition, and if the instance's are greater than 1, make each unique, and the call pickhelper again to get the possible "new" face.
Is there a better way to do this?
Am I better off using an observer for this? (I've not used them before) and just make each group unique as they are created?
Thanks!
-
Well, Group.make_unique doesn't cut it. I get a warning that it's depreciated, but still the same behavior. I suppose I could make new groups and copy the entities over, delete the originals and insert them, but it seems like there should be an easier way. Obviously, at least internally, Sketchup has a way to do this.
-
If you use group.make_unique on every copy you make they should each become 'individual' - there is still the misleading 'deprecated' error message that is plain 'wrong'!
Are you using 'copy' and transforming the 'copy' or 'add_instance()' ?? -
@tig said:
If you use group.make_unique on every copy you make they should each become 'individual' - there is still the misleading 'deprecated' error message that is plain 'wrong'!
Are you using 'copy' and transforming the 'copy' or 'add_instance()' ??What I tried to do was something like this..
I call it on the face returned by picked_face
def GroupUniqueAsNeeded(ent) while (ent.respond_to?('parent') ) if ((ent.is_a? Sketchup;;ComponentDefinition)) if ent.group? if ent.instances.length > 0 ent.instances.each do |e| e.make_unique end return 1 end # else component end end ent = ent.parent end end
If it returns one, I redo the pick, getting (theoretically) the correct face. But in practice, sometimes when I assign a material to the face, it's still painting that face in all copies.
Perhaps I'm getting caught in this parent bug
http://forums.sketchucation.com/viewtopic.php?f=180&t=31318&p=275894#p275894 -
Not sure about your code - I don't have time to test it tonight...
Here's a one-liner method to ensure that ALL groups in the model are unique [as they ought to be!] BEFORE you start doing anything
Sketchup.active_model.definitions.each{|d| d.instances[1..-1].each{|i| i.make_unique} if d.group? and d.instances[1]}
-
@tig said:
@tig said:
Not sure about your code - I don't have time to test it tonight...
Here's a one-liner method to ensure that ALL groups in the model are unique [as they ought to be!] BEFORE you start doing anything
Sketchup.active_model.definitions.each{|d| d.instances[1..-1].each{|i| i.make_unique} if d.group? and d.instances[1]}
Thank you sir! That did the trick.
-
Has this bug been squashed?
@thomthom said:
@tig said:
Use a test like
until model.active_entities==model.entities > > model.close_active > > end
this will close active group or component edits, including any nesting, back to the base model entities...
You can't 'open' them BUT you can 'close' them.
Beware of this method!
Normally when you close group in SU it adds the action to the Undo stack. But this method doesn't do this. So when you close the group and then decide to undo a few steps you'll get corrupted geometry as it offsets the modified geometry. -
In SU2014, yes. We found a few more methods with this same issue, like Definitionlist.load*
Changelog got full details.Sent from my LT25i using Tapatalk
-
@thomthom said:
In SU2014, yes.
What would be the best way to write this for Sketchup 8 or 2013?
(google translator) -
You can try this:
until model.active_entities==model.entities tname = model.active_path.last.typename ### model.start_operation("Close #{tname} Edit") # model.close_active() # model.commit_operation() ### end
-
@dacastror said:
@thomthom said:
In SU2014, yes.
What would be the best way to write this for Sketchup 8 or 2013?
(google translator)In SU8 and SU2013 and older that method is bugged. No known workaround I'm afraid.
Advertisement