• Login
sketchucation logo sketchucation
  • Login
πŸ”Œ Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

Integration tool by using paste in place

Scheduled Pinned Locked Moved Developers' Forum
15 Posts 3 Posters 269 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.
  • N Offline
    njeremy2
    last edited by 31 May 2012, 12:56

    Hello everybody !

    I'm starting to write a new plugin : Integration tool
    This plugin is used to integrate a draw into a group.

    Before this plugin when I want to integrate a draw into the group, I select it, I cut it, I select my group where I want to put it and then I select "paste in place".

    With that plugin, I want to automatise that.

    Here some screenshots of what I need to do.

    http://img43.imageshack.us/img43/5116/34052751.png

    http://img213.imageshack.us/img213/3936/99450751.png

    http://img26.imageshack.us/img26/4799/cutk.png

    http://img848.imageshack.us/img848/8043/pasteinplace.png

    How should work my plugin :
    -I select the drawing I want to add
    -I start/activate the plugin
    -A messageBox comming : "Select the group where you want to integrate"
    -I select the group
    -The drawing is inside the group !

    I just start to write the structure of code. I made research for "send_action" for cutting and paste my drawing
    https://developers.google.com/sketchup/docs/ourdoc/sketchup#send_action

    Can I use "onLButtonDown" for selecting my group when the drawing is selected ?

    Can you help me to give me some leads to reach this objective ?

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 31 May 2012, 13:14

      You can use the PickHelper to determine you are drawing on a face inside a group and then draw directly inside that group.

      @njeremy2 said:

      I just start to write the structure of code. I made research for "send_action" for cutting and paste my drawing

      Your approach seem to be translating directly what you do in SketchUp - by copying and pasting. But with when using the Ruby API there are usually other (and better) ways to do thing. (Remember, when you want to make a grouped box when using SketchUp UI you draw the cube then group it - with the API you create the group and draw directly into the group - different approach.)

      What I don't understand is why you want to do this... you want to avoid opening/closing the groups?

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

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 31 May 2012, 13:20

        What you can do manually is not accessible through the API.
        There are send_actions for Edit's Copy and Paste, but not Paste-In-Place.
        Also opening entities contexts is not possible...
        But here is a work around...

        You preselect some 'things', so we know things=model.selection.to_a
        Having the 'group' picked bu the mouse click in the Tool tells us group.entities - and that is where the next to be preselected ' things' is to end up...
        Now make a 'temporary group' of the 'things' [it's safe to make it directly - this time - because the selection must be in the active_entities ! if the entities are cross-threaded it WILL Bugsplat!]
        tempgroup=model.active_entities.add_group(things)
        Now add an instance of the new ' tempgroup' to the group.entities thus:
        inst=group.entities.add_instance(tempgroup.entities.parent, tempgroup.transformation*(group.transformation.inverse))
        then explode the instance and erase the original selection that is still grouped:
        inst.explode tempgroup.erase!

        • clones of the 'things' are now inside the group and the originals are gone.

        I haven't tested this code - I typed from memory - so try it and adjust as appropriate...

        TIG

        1 Reply Last reply Reply Quote 0
        • N Offline
          njeremy2
          last edited by 31 May 2012, 13:56

          @thomthom said:

          You can use the PickHelper to determine you are drawing on a face inside a group and then draw directly inside that group.

          @njeremy2 said:

          I just start to write the structure of code. I made research for "send_action" for cutting and paste my drawing

          Your approach seem to be translating directly what you do in SketchUp - by copying and pasting. But with when using the Ruby API there are usually other (and better) ways to do thing. (Remember, when you want to make a grouped box when using SketchUp UI you draw the cube then group it - with the API you create the group and draw directly into the group - different approach.)

          What I don't understand is why you want to do this... you want to avoid opening/closing the groups?

          I avoid nothing, I haven't got a special way to do that but I don't know how to start the plugin πŸ˜•

          So if understand well, Tig advise me to get the selection and put it into temporary group.
          Then put this tempgroup into the existing "GROUP1" ? then explode GROUP1 and erase tempgroup ?

          At the end, there is no group if I explode GROUP1 ? (is it what you said ? I think I don't understand lol 😳 )

          Anyway, if the tempgroup is into GROUP1 with your solution it's good for me !

          I will try this now !

          1 Reply Last reply Reply Quote 0
          • N Offline
            njeremy2
            last edited by 31 May 2012, 14:39

            @thomthom said:

            You can use the PickHelper to determine you are drawing on a face inside a group and then draw directly inside that group.

            Yes you can do that but my boss tell me that someone forget to go inside the group before drawing, that's why he asks me to do this plugin ...

            ... we have stupid sketchup users in france πŸ˜„

            1 Reply Last reply Reply Quote 0
            • N Offline
              njeremy2
              last edited by 31 May 2012, 15:35

              this line doesn't work :

              inst=group.entities.add_instance(tempgroup.entities.parent, tempgroup.transformation*(group.transformation.inverse))
              

              What "transformation" module is use for ?
              Because in "Automatic Sketchup.pdf" transformation* doesn't exist.
              It's write : The transformation method is used to retrieve the transformation for the group.
              But what transformation ?

              I'm stuck here, I'm coming back tomorrow

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 31 May 2012, 20:01

                What error messages do you get ?
                Any group/instance has a transformation.
                We use it here to get the temp group into the group in the same relationships ...

                TIG

                1 Reply Last reply Reply Quote 0
                • N Offline
                  njeremy2
                  last edited by 1 Jun 2012, 07:38

                  @tig said:

                  What error messages do you get ?
                  Any group/instance has a transformation.
                  We use it here to get the temp group into the group in the same relationships ...

                  There is no error messages but this line isn't executed.

                  %(#BF0000)[model = Sketchup.active_model
                  things = model.selection.to_a
                  UI.messagebox "initialization ok"

                  	tempgroup=model.active_entities.add_group(things)
                  	UI.messagebox "add group ok"
                  	inst=group.entities.add_instance(tempgroup.entities.parent, tempgroup.transformation*(group.transformation.inverse))
                  	UI.messagebox "add_instance ok"]
                  

                  I put messageBox each line to see if the code is executed or not.
                  "add instance ok" didn't appear so I guess is not working

                  Into outliner, I see the plugin create a new group for my thing which is selected but it isn't integrated inside the initial group.

                  http://img204.imageshack.us/img204/7599/75074987.png

                  http://img268.imageshack.us/img268/7420/addgroup.png

                  http://img20.imageshack.us/img20/7563/copied.png

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TIG Moderator
                    last edited by 1 Jun 2012, 08:19

                    Where in your code are you getting 'group' as a reference to the group into which you want to move the selected 'things' ?
                    It will be set by picking a group with the Tool, but as a test now you can 'preselect' it earlier by highlighting the 'group' and having an extra line early on like this...
                    model=Sketchup.active_model **group=model.selection[0]**
                    then deselect the 'group' and select the 'things' to be added, then continuing with the code...
                    things = model.selection.to_a ...
                    If you do it line by line in the Ruby Console what is the result?

                    I have just tested it this way and it works perfectly...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • N Offline
                      njeremy2
                      last edited by 1 Jun 2012, 09:38

                      Here is my file,

                      When I test it, I select my drawing which I want to add in group.
                      Then this plugin create group with that drawing put it cannot execute the next line (with transform)

                      I didn't test it in RUBY console into sketchup

                      file reupload at 11h49 - France


                      testintegration.rb

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        TIG Moderator
                        last edited by 1 Jun 2012, 10:56

                        This is messed up...
                        Run it with the Ruby Console open to see all of the error messages...
                        You click the mouse-button, have a pick_helper but then set @group to be the the first item in the model.selection which is of course one of the things to be added into the 'group' ???
                        Also you haven't defined 'model' in the code so it'll fail at that step anyway...
                        Try something like this:

                        def onLButtonDown(flags, x, y, view)
                          pickHelper = view.pick_helper
                          pickHelper.do_pick(x, y)
                          allPicked=pickHelper.all_picked
                          @group = nil
                          allPicked.each{|e|@group=e if e.is_a?(Sketchup;;Group)}
                          unless @group
                            UI.messagebox("That's NOT a Group !")
                            return nil
                          end
                          self.integration()
                          Sketchup.send_action("selectSelectionTool;")
                        end
                        

                        The pick_helper stuff needs recasting...
                        I added an 'exit' to the select tool.
                        Also you should trap in 'activate' for an empty selection as they'd be nothing to tempgroup/add_ later...
                        Here's an adjusted version that works...
                        Also I'd also call the tool class something like 'Jeremy_integration_tool' ???


                        ###testintegration.rb

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • N Offline
                          njeremy2
                          last edited by 1 Jun 2012, 12:33

                          Oh wooow! thank you TIG ! πŸ˜„

                          It works great ! you are fabulous ! πŸ‘

                          When I look the code, it's different than what I tought !
                          Just a little question, if you initialise "@group=nil" is it the same if you do that : "@group=[]" ?
                          Because after picking, you put each group you found inside "@group".

                          Voila ! thank you so much πŸ˜‰

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            thomthom
                            last edited by 1 Jun 2012, 12:38

                            @njeremy2 said:

                            Just a little question, if you initialise "@group=nil" is it the same if you do that : "@group=[]" ?

                            No - @group=[] == @group=Array.new

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

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              TIG Moderator
                              last edited by 1 Jun 2012, 12:46

                              You must set any reference that you want to use later outside of a block - so when it is set inside the {} block it is still accessible to the rest of the code.
                              @group=nil sets an empty reference
                              BUT
                              @group=[] makes an empty array.

                              In the {} IF there's a selected group then @group is set to be it @group=e if....
                              Otherwise it stays as ' nil'.
                              Then the test
                              unless @group ...
                              says if group is ' nil' you didn't pick on a group, so we exit with a message...

                              The current code doesn't 'insert' the group into @group, it makes it its reference.
                              However, if you were 'collecting things' into an array initially made as groups=[] ... then you would use
                              groups << e if... rather than the singular @group=e if..., that way you get a 'list' of matching objects...

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • N Offline
                                njeremy2
                                last edited by 4 Jun 2012, 13:40

                                oh ok!
                                Thanks to all ! I understand now πŸ˜„

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

                                Advertisement