• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Add_group() method bug ? Need help !

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 336 Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    Didier Bur
    last edited by 9 Apr 2009, 19:51

    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 🎉

    DB

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 9 Apr 2009, 22:33

      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...

      TIG

      1 Reply Last reply Reply Quote 0
      • C Offline
        Chris Fullmer
        last edited by 9 Apr 2009, 23:25

        I might be doing it wrong, but group.definition is giving an error that .definition is not valid for groups.

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

        1 Reply Last reply Reply Quote 0
        • T Offline
          TIG Moderator
          last edited by 10 Apr 2009, 11:54

          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

          TIG

          1 Reply Last reply Reply Quote 0
          • D Offline
            Didier Bur
            last edited by 10 Apr 2009, 19:59

            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,

            DB

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            1 / 1
            • First post
              5/5
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement