Add_group() method bug ? Need help !
-
Hi all,
I'm currently writing a script that creates/edits a lot of groups.
When I create a new group, I often get a message "Undefined method 'entities' for ComponentInstance", as if the new empty group is handled first like a component instance by SU. So of course there's no 'entities' method for such an object.
Sometimes the bug pops up, sometimes not, but when it appears, it is always when no argument is givent to 'add_group'.
So I decided to overwrite the default 'add_group' method like this:class Sketchup;;Entities alias_method ;add_group_su, ;add_group def add_group(*args) g=self.add_group_su(*args) while g.class!=Sketchup;;Group g.erase! if args[0] g=self.add_group_su(*args) else g=self.add_group_su end end return g end end
It gives very good results (empty groups are created as expected), but guess what ? I'm now getting other error messages like:
@unknownuser said:
Error: #<TypeError: reference to deleted Entity>
C:/PROGRA~1/Google/GOOGLE~4/Plugins/.../Entities.rb:10:in `add_group_su'I've searched all the forum for a similar problem but no luck.
Please stop this nightmare !
Any help GREATLY appreciated -
A Group is indeed a type of ComponentInstance...
It has a definition - there's even a ComponentDefinition.group? test...
See my recent ComponentInstance-add_entities.rb for some pointers...
Try using "group.definition" - I use this to copy a group into a group...### let's assume we already have a group named 'group'... grp=entities.add_group() grp2=grp.entities.add_instance(group.definition,group.transformation) ### although deprecated this might help grp2.make_unique ### final tidy... group.erase! ### now the 'group' is moved inside 'grp', in the same location...
???
grp=entities.add_group(group) ### might work too, but 'Bugsplats' are probable with this method...
I think the secret is to make the empty new group AND put something into its entities asap...
-
I might be doing it wrong, but group.definition is giving an error that .definition is not valid for groups.
-
class Sketchup;;Group def definition return self.entities[0].parent end end
Matt666 pointed out that I omitted this step in the explanation.
This adds the definitionmethod to a group...
It needs to run before you try to call group.definition -
Thanks all for yur help.
I have encountered very weird things with this 'bug', like: create a new empty group, put a face in it, pushpull the face, and list all the entities of the group. I got several faces and a component instance .@unknownuser said:
I think the secret is to make the empty new group AND put something into its entities asap.
Yes, I've tried that too, it works most of the time but not 100%
Pfff, I'll let you know if I find a way to eradicate this bug.
Thank you,
Advertisement