sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    A small "entity to group" problem

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 317 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.
    • artmusicstudioA Offline
      artmusicstudio
      last edited by

      hi,
      i wopuld be greatful for a small tip:

      i have a @main_element,
      which contains some faces

      when i iterate thru the entities, i can check the normal, see the top face and push pull

      i also can create a new group within the @main_element-container and put an edge in it.

      buit when i want to put one of the @ main_element's entities (here it is a face) into this new group,
      i get a "parent" problem, which i don't understand:

      
      
      @selection.each { |entity|
      	
      		if entity.is_a?(Sketchup;;Face) 
      		
      			check_normal_for_horizontal(entity) #my own method
      			puts @bgf_count_normal # 1 is face top
      			if @bgf_count_normal == 1
      				puts "---FACE UP ... IN MAIN-ELEMENT"
      				#			
      				entities = @main_element.entities
                                      #
      				group = entities.add_group
      				entities2 = group.entities
      				point1 = Geom;;Point3d.new(0,0,0)
      				point2 = Geom;;Point3d.new(2000,200,200) #works
       				edges = entities2.add_edges point1, point2
      				#
      				#			
      				loop = entity.outer_loop # does not work
      				edgearray = loop.edges
                                      floor = entities2.add_face(edgearray)
                              end
                       end
                       }
      
      

      why does the new face from edgearray not appear in the group?

      info from console:

      ###############
      ---FACE UP ... IN MAIN-ELEMENT
      Error: #<ArgumentError: Edge has different parent>
      C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/02.rb:959:in `add_face'
      ################

      thanx
      stan

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

        Tip:

        Don't iterate a selection,
        Its referring changes as you remove items!
        Iterate a snapshot array of it
        @selection.to_a.

        Next...

        You can't reassign entities from one context to another.
        Although you CAN 'add entities' in the active_entities context into a group.entities in the same context.
        BUT you can't do it the way you want - because you are attempting to make a face in one context using the edges in another...

        Try something like:
        varray = entity.outer_loop.vertices floor = entities2.add_face(varray)
        You can use an array of vertices as well as points...

        TIG

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          hi tig,

          that's fantastic,

          point 2 : solved ( i already though of retrieving the points , but vertices work perfectly!

          for point 1:

          got it working, super. thanx.

          by the way, is there a code for deliting an array of edges directly ? or do i have to iterate thru the array and erase one after another?

          in my case i create a copy of a face in the new group (>> vertices)
          and wantto delete the original entity incl. edges.

          thanx a lot
          stan

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

            @artmusicstudio said:

            ..., is there a code for deliting an array of edges directly ? or do i have to iterate thru the array and erase one after another?

            use Entities.erase_entities()

            The argument can be a single entity, or an array of entities.

            ALSO... Ruby has an "accordian operator" the * that can be used to expand an array into a argument list, or compress arguments in an array.
            IF erase_entities also takes a list of multiple entities, you could convert the aray to a list like:
            my_ents.erase_entities( *my_edge_array )

            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