sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Question about "open" groups.

    Scheduled Pinned Locked Moved Developers' Forum
    22 Posts 5 Posters 1.8k Views 5 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.
    • C Offline
      CPhillips
      last edited by

      My FFD plugin creates a group of construction points. If the user has the group open the position of the points (all entites) is given in world space not group space.

      How can I detect if the group is "open"? Or is there some other way to get untransformed positions?

      Thanks
      Chris

      1 Reply Last reply Reply Quote 0
      • W Offline
        Whaat
        last edited by

        This might be what you want:

        m=Sketchup.active_model
        ents=m.active_entities
        
        parent=ents.parent
        
        if parent.class==Sketchup;;ComponentDefinition
           if parent.group?
               trans=parent.transformation
               p "in group #{parent.name}"
               p  trans.origin
           end
        end
        

        SketchUp Plugins for Professionals

        1 Reply Last reply Reply Quote 0
        • C Offline
          CPhillips
          last edited by

          @whaat said:

          This might be what you want:

          m=Sketchup.active_model
          > ents=m.active_entities
          > 
          > parent=ents.parent
          > 
          > if parent.class==Sketchup;;ComponentDefinition
          >    if parent.group?
          >        trans=parent.transformation
          >        p "in group #{parent.name}"
          >        p  trans.origin
          >    end
          > end
          

          Thanks. That answers the first question "how to tell if a group is open".

          But the code above doesn't work for me. "parent" is a ComponentDefinition and that class doesn't have a transformation. (unless i did something wrong?)

          I found the instance of the group but when the object is open the .transformation is identity.

          The real question I guess is if a group is open how can you get its real transformation?

          Chris

          1 Reply Last reply Reply Quote 0
          • AdamBA Offline
            AdamB
            last edited by

            Unfortunately, I think you just have to observe them by adding an instance of this:

            
            class MyInstanceObserver < Sketchup;;InstanceObserver
            
            	def onOpen(inst)
            		puts "onOpen"
            	end
            	def onClose(inst)
            		puts "onClose"
            	end
            end
            
            

            Developer of LightUp Click for website

            1 Reply Last reply Reply Quote 0
            • T Offline
              todd burch
              last edited by

              You can tell if you are in Group or Component edit by comparing Sketchup.active_model.entities to Sketchup.active_model.active_entities. If they are the same, you are not in Group/Comp edit.

              Todd

              1 Reply Last reply Reply Quote 0
              • C Offline
                CPhillips
                last edited by

                Ok, now I can detect that it is open. But how can I tell what the unopened groups transform is. As soon as a group is opened its transform becomes identity. I even tried to get it in a observer and by the time the onOpen is called it is already transformed.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  todd burch
                  last edited by

                  Post a small script that illustrates what you are having trouble with.

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    CPhillips
                    last edited by

                    @unknownuser said:

                    Post a small script that illustrates what you are having trouble with.

                    Create a group and select it. Then type:

                    group=Sketchup.active_model.selection[0]
                    Then:
                    group.transformation.to_a.inspect

                    Note the transformation.

                    Now open the group and execute the same line.
                    group.transformation.to_a.inspect

                    When open the transformation will always be:
                    [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]

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

                      But the Group's transformation stays the same even if its entities are changed... so what's the point trying to get something you already know? Sorry if I'm missing the obvious.

                      Hi

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        todd burch
                        last edited by

                        OK, you're right.

                        What are you trying to do? Can you use the group's transformation origin and apply that to any translation you need to do for your cpoints?

                        1 Reply Last reply Reply Quote 0
                        • C Offline
                          CPhillips
                          last edited by

                          @unknownuser said:

                          OK, you're right.

                          What are you trying to do? Can you use the group's transformation origin and apply that to any translation you need to do for your cpoints?

                          I could if I could get the original transformation. But as I said its set to identity as soon as you open the group.

                          When I create the group of construction points I set an attribute that has its initial position in the group. Then the user opens the group, manipulates the points and I compare the new position to the position stored in the attribute. It works fine if the group is closed but if it is still open the points are transformed into world space instead of group space so I am comparing apples and oranges.

                          @jim said:

                          But the Group's transformation stays the same even if its entities are changed... so what's the point trying to get something you already know? Sorry if I'm missing the obvious.

                          The groups transform does not stay the same. Not only is the transform zeroed but the location of all the points is world relative instead of group relative. If I have a point at position (1,1,1) in a group when I open the group its position will be (1,1,1) + whatever the transformation.origin of the unopened group is. Not to mention the effects of rotation and scaling.

                          It seems when you open a group Sketchup transforms all the entities in that group by the groups transform and then sets the group transform to identity.

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            todd burch
                            last edited by

                            I had a similar issue recently and I simply had to tell the user that the operation he was trying to perform was not allowed while in Group edit. This was because of the bugs dealing with working with groups and being out of context when in group/component edit.

                            That's the way the ball bounces.

                            1 Reply Last reply Reply Quote 0
                            • C Offline
                              CPhillips
                              last edited by

                              @unknownuser said:

                              I had a similar issue recently and I simply had to tell the user that the operation he was trying to perform was not allowed while in Group edit. This was because of the bugs dealing with working with groups and being out of context when in group/component edit.

                              That's the way the ball bounces.

                              Thats disappointing.

                              Thanks Todd.

                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                CPhillips
                                last edited by

                                I found a work around but its a little gross. I don't fully trust observers not to crash Sketchup.

                                I put a entityObserver on my lattice group and then in onChangeEntity I store the current transformation in an attribute. Then when a user moves a point I check to see if the group is open (via observer) and if so I transform my control points by the inverse of the stored transform. That gives me a group relative point. whew.

                                Thanks for the help.
                                Chris

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  todd burch
                                  last edited by

                                  I figured it out!

                                  If your group is open, get any entity in the group, and do this:

                                  entity.parent.origin

                                  That will give you the origin of the group's transformation. Viola!

                                  Todd

                                  1 Reply Last reply Reply Quote 0
                                  • C Offline
                                    CPhillips
                                    last edited by

                                    @unknownuser said:

                                    I figured it out!

                                    If your group is open, get any entity in the group, and do this:

                                    entity.parent.origin

                                    That will give you the origin of the group's transformation. Viola!

                                    Todd

                                    When I try that the parent is ComponentDefinition and that doesn't have .origin. Did I miss a step?

                                    Chris

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      todd burch
                                      last edited by

                                      Oops. Sorry.

                                      entity.parent.insertion_point

                                      Todd

                                      1 Reply Last reply Reply Quote 0
                                      • C Offline
                                        CPhillips
                                        last edited by

                                        @unknownuser said:

                                        Oops. Sorry.

                                        entity.parent.insertion_point

                                        Todd

                                        Ah! That does seem to work. Its only a point though, any way to get the rest of the transformation?

                                        Thanks Todd!

                                        1 Reply Last reply Reply Quote 0
                                        • T Offline
                                          todd burch
                                          last edited by

                                          My hat of guessing says...

                                          tr = Geom::Transformation.new(entity.parent.insertion_point)

                                          Todd

                                          1 Reply Last reply Reply Quote 0
                                          • T Offline
                                            todd burch
                                            last edited by

                                            ...but I don't think that will take care of any rotation. 😞

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

                                            Advertisement