sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Trouble adding entity to component definition

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 4 Posters 1.6k Views 4 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.
    • G Offline
      gkd720
      last edited by

      I'm trying to add an instance of a component definition as an entity in another component definition, but I'm getting an error. I searched here but didn't find anything that helped yet. Any thoughts or guidance on how to diagnose and fix? Code and error below, with error line marked. Thanks.

      def self.create_component_definition_piece(width, height, depth, angle)
        @componentDefinitionPiece=@definitions.add "Piece"
        ptLL=[0,0,0]
        ptLR=[width,0,0]
        ptUR=[width,0,height]
        ptUL=[0,0,height]
        new_face = @componentDefinitionPiece.entities.add_face ptLL, ptLR, ptUR, ptUL
        if new_face.normal == [0,-1,0]
          new_face.pushpull depth
        else
          new_face.pushpull -depth
        end
      end
      
      def self.create_component_definition_laddershelves()
        @componentDefinitionLadderShelves=@definitions.add "LadderShelves"
        self.create_component_definition_piece(2.5,48,0.75,0)
        @componentDefinitionLadderShelves.entities.add_instance(@componentDefinitionPiece,@transform000)     <<<<< Error on this line.
      end
      
      # Draw the ladder shelves
      self.create_component_definition_laddershelves()
      transform=Geom;;Transformation.new([0,0,0])
      rotateAndTransform=transform * Geom;;Transformation.rotation([0,0,0],[0,1,0],0)
      @entities.add_instance(@componentDefinitionLadderShelves,rotateAndTransform)
      # puts "Number of entities in LadderShelves=",@componentDefinitionLadderShelves.entities.count
      
      

      Error:

      Error: #<TypeError: reference to deleted ComponentDefinition>
      C:/Users/gkd/SketchupRubyScripts/ladderShelves2.rb:86:in entities' C:/Users/gkd/SketchupRubyScripts/ladderShelves2.rb:86:in create_component_definition_laddershelves'
      C:/Users/gkd/SketchupRubyScripts/ladderShelves2.rb:99:in <module:LadderShelves>' C:/Users/gkd/SketchupRubyScripts/ladderShelves2.rb:5:in <top (required)>'

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Your published code only gives us part of the story.
        The posted error-messages refer to something else !
        Why not make the new 'container' definition first, then create your new definition and add the nested instance ?
        Also you code seems to have no 'model.start...' operation or a 'commit' which might help ??

        TIG

        1 Reply Last reply Reply Quote 0
        • sdmitchS Offline
          sdmitch
          last edited by

          I can't tell you why but if you change

          def self.create_component_definition_laddershelves()
            @componentDefinitionLadderShelves=@definitions.add "LadderShelves"
            self.create_component_definition_piece(2.5,48,0.75,0)
            @componentDefinitionLadderShelves.entities.add_instance(@componentDefinitionPiece,@transform000)
          
          

          to

          def self.create_component_definition_laddershelves()
            self.create_component_definition_piece(2.5,48,0.75,0)
            @componentDefinitionLadderShelves=@definitions.add "LadderShelves"
            @componentDefinitionLadderShelves.entities.add_instance(@componentDefinitionPiece,@transform000)
          
          

          it works! I think it is as TIG suggested, you need to complete the creation of one definition before starting the other.

          Nothing is worthless, it can always be used as a bad example.

          http://sdmitch.blogspot.com/

          1 Reply Last reply Reply Quote 0
          • G Offline
            gkd720
            last edited by

            Wow. Thanks TIG and sdmitch, that works!
            But why might that be? I would think that making a new component definition without yet any entities would not be that fragile or incomplete. Is there any documentation that states this, or suggests this? Why isn't this like declaring a variable but not initializing it? It also would have helped if the error message indicated which component definition it didn't like. Is this a ruby thing or a Sketchup thing? Thanks.

            1 Reply Last reply Reply Quote 0
            • TIGT Offline
              TIG Moderator
              last edited by

              SketchUp's Ruby can do its 'Garbage Collection' as it goes, so if you create a definition [component or group] it will not persist for long unless it contains entities.
              So make it immediately before you use it, that way SketchUp won't tidy up and remove it.
              Once it has entities it will be safe - so add those asap - you could also think about adding a single cpoint and erasing it later once some more entities are added...

              TIG

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                A workaround we employ is to stick a temporary cpoint into the entities (at it's origin,) and then delete it later after we've loaded it up with geometry. The temp cpoint stops SketchUp's garbage collector from deleting the object.

                I'm not here much anymore.

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

                Advertisement