Closing open groups via Ruby?
-
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