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

    Reference to deleted Group

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 3 Posters 388 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.
    • J Offline
      JudyO
      last edited by

      I don't know if I am in the right place for trivial question, but I'll try.

      I am a beginner, I write a plugin for sewing patterns according to input body measurements.
      These are 2D drawings.

      There are many edges and sometimes I need to rotate some of them.
      I create a group and add the relevant edges to the group.
      I then rotate the group
      Then I explode the group.

      Then I wish to rotate another group of edges, some of which were already rotated in the previous group.

      And this is where all fails. When I create the second group SOME of the edges that were in the previous group cause error message "reference to deleted Group".

      This is so strange, some edges have no problem, others are stuck.

      How to disconnect the relation between the edge entity and its old group that was already exploded?

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

        Why not post some of your code?
        It's hard to see what the problem is form a 'narrative'...

        You either want to refer to something else, or somehow trap for !x.valid? etc.
        It will be fixable... 😄

        TIG

        1 Reply Last reply Reply Quote 0
        • J Offline
          JudyO
          last edited by

          OK TIG, I'll cut some of the code and post it soon (I'm a bit embarrassed, it probably looks terrible)

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Are you holding on to references to the edges from your first group?

            Btw, why do you create a group, then explode it? Is it just to transform them in bulk? Shifting entities in and out of groups adds an extra layer of complexity.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • J Offline
              JudyO
              last edited by

              OK, I cut some of the code, sorry it is so long, I marked the problem place.

              #-------------------------------------------------------------
              def sample
              
              model = Sketchup.active_model
              entities = model.active_entities
              
              
              #-----------------------
              #Create edges for the back;
              
              $pt_N_pt_N11		= entities.add_edges $pt_N11, $pt_N
              $pt_N1_pt_N11 		= entities.add_edges $pt_N1, $pt_N11
              $pt_S3_pt_L 		= entities.add_edges $pt_S3, $pt_L
              $pt_S3_pt_S1		= entities.add_edges $pt_S3,$pt_S1
              $pt_S3_pt_N1		= entities.add_edges $pt_S3, $pt_N1
              $pt_N_pt_W		= entities.add_edges $pt_N, $pt_W
              $pt_L_pt_L1		= entities.add_edges $pt_L, $pt_L1
              $pt_W4_l_pt_BWD		= entities.add_edges $pt_W4_l, $pt_BWD
              $pt_S1_pt_N1		= entities.add_edges $pt_S1, $pt_N1
              $pt_BWD_pt_W3_l 	= entities.add_edges $pt_BWD, $pt_W3_l
              $pt_W_pt_W3_l		= entities.add_edges $pt_W, $pt_W3_l
              $pt_W4_l_pt_W6_l	= entities.add_edges $pt_W4_l, $pt_W6_l
              $pt_L_pt_L2 		= entities.add_edges $pt_L, $pt_L2
              $pt_L1_pt_W6_l		= entities.add_edges $pt_L1, $pt_W6_l
              $pt_BW3_pt_L		= entities.add_edges $pt_BW3, $pt_L
              
              #-----------------------
              # Create a group from these edges;
              
              back_edges_group = entities.add_group $pt_BW3_pt_L,
              $pt_N1_pt_N11,
              $pt_S3_pt_L,
              $pt_N_pt_N11,
              $pt_S3_pt_S1,
              $pt_S3_pt_N1,
              $pt_N_pt_W,
              $pt_L_pt_L1,
              $pt_W4_l_pt_BWD,
              $pt_S1_pt_N1,
              $pt_BWD_pt_W3_l,
              $pt_W_pt_W3_l,
              $pt_W4_l_pt_W6_l,
              $pt_L_pt_L2,
              $pt_L1_pt_W6_l
              
              
              #-----------------------
              #Find rotation angle;
              
              v_tmp1 = $pt_L1 - $pt_W6_l
              v_tmp2 = $pt_L1 - $pt_W5_l
              angle = v_tmp1.angle_between v_tmp2
              
              #-----------------------
              #Rotate the group;
              
              trans_rotation = Geom;;Transformation.rotation $pt_L1 ,$v_z_axis, angle
              back_edges_group.transform! trans_rotation
              
              #-----------------------
              #Explode the group;
              
              back_edges_group.explode
              
              
              #-------------------------------------------------------------
              # Create another group, only for the back upper dart;
              
              back_upper_dart_edges_group = entities.add_group $pt_BW3_pt_L,
              $pt_S3_pt_L,
              $pt_S3_pt_S1
              
              ###########################################################
              ####THE ABOVE LAST EDGE CAUSES "REFERENCE TO DELETED ENTITY"
              ####ALTHOUGH THE 2 EDGDES ABOVE IT WERE ALSO IN THE PREVIOUS GROUP.
              ####IF THIS EDGE IS REMARKED OUT ALL IS WELL
              ###########################################################
              
              
              #-----------------------
              #find angle between L-L1 and L-BW3;
              
              v_tmp1 = $pt_L - $pt_L1
              v_tmp2 = $pt_L - $pt_BW3
              angle = v_tmp2.angle_between v_tmp1
              
              #-----------------------
              #Rotate the group;
              
              trans_rotation = Geom;;Transformation.rotation $pt_L ,$v_z_axis,  angle
              back_upper_dart_edges_group.transform! trans_rotation
              
              #-----------------------
              #Explode the group;
              back_upper_dart_edges_group.explode
              
              end
              
              
              1 Reply Last reply Reply Quote 0
              • J Offline
                JudyO
                last edited by

                I am not sure.

                It is a sewing pattern.
                for example: I need to close a dart on the waist line, this causes edges left (or right) to the dart to rotate.

                After this rotation I wish to close another dart, say at the shoulder. This causes another group of edges to rotate, some of which were already rotated before.

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  You're holdin gon to entity references across operations you cannot expect it do. When you explode it will trigger SketchUp's merge functionality and that modifies the entities.

                  Why not just create the edges as they should be - instead of adding some edges, then grouping and rotating them?

                  Also, when you add a group with entities via Ruby, add the group first - then add the entities directly into them. Saves you a step and avoid potential problems there are by transferring entities between contexts.
                  But in this case I don't see the point of the group at all - since you are exploding it...

                  Got some screenshots or pictures to illustrate what you're making your code do?

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    JudyO
                    last edited by

                    Thank you Thomas,
                    The reason I gave each edge a name (a reference?) is because after the first rotation I don’t know anymore the start and end points of the edge. I can’t recreate the edge for the next rotation.

                    Or do I? Is there a way to get the end points of an edge?
                    But then, I will still need the reference to it.
                    That was my thinking.

                    The reason I added all the edges at the group creation is that I found no other way to do it – add an edge by its name to an existing group.
                    I would like to.

                    I attach two skp file, the first one is a basic bodice pattern, where all the points are calculated.
                    The second one is after closing two darts
                    (I don't know if the files were uploaded, we'll see)


                    Bodice 1st stage


                    Bodice 2nd stage

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      JudyO
                      last edited by

                      Following this conversation I realized I am doing something Sketchup was not meant to do, So I switched to rotating points instead of edges, and rotate them one by one instead of in a group.
                      I still need to keep references to the points (not to the edges), but so far it looks OK.
                      Thank you

                      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