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

    How to make a component-placer tool?

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

      I need to write a simple plugin that will allow a user to place a pre-defined object in the same way they can place one from the Components panel.

      So, user clicks my menu item, my component appears on their cursor, they decide where to place it, click, and then it's in the model. I'll want to do some behind-the-scenes processing before and after, naturally.

      Can someone give me advice on this? I've never made Tool's before... is that what I need here?

      1 Reply Last reply Reply Quote 0
      • D Offline
        draftomatic
        last edited by

        Hmm, I suppose I could distribute a component library with my plugin and allow users to use the built-in component panel. I could observe the definition so that I can hook into when it's placed, but I won't know when they BEGIN to place it.

        It seems to me that writing a custom tool for this would be difficult. Someone please tell me I wouldn't have to use onMouseMove to make the component follow the cursor while being placed!

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

          Model.place_component
          http://code.google.com/intl/no/apis/sketchup/docs/ourdoc/model.html#place_component

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

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

            ...or... entities.add_instance(definition, transformation) ?

            TIG

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

              @tig said:

              ...or... entities.add_instance(definition, transformation) ?

              Then he'd have to replicate the whole of the Place Component functionality in a tool...

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

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

                @thomthom said:

                @tig said:

                ...or... entities.add_instance(definition, transformation) ?

                Then he'd have to replicate the whole of the Place Component functionality in a tool...

                But he was talking about a 'tool'...
                This way his tool can get a picked-point and then insert a component at that point, then repeat if desired...
                Your way is much easier, but it will dump him out of the plugin code at the insertion, so no chance of repeat inserts in the same instance of the class [at least without incredible convolution??] ?

                TIG

                1 Reply Last reply Reply Quote 0
                • D Offline
                  draftomatic
                  last edited by

                  Thanks for the help fellas.

                  @tig said:

                  But he was talking about a 'tool'...
                  This way his tool can get a picked-point and then insert a component at that point, then repeat if desired...
                  Your way is much easier, but it will dump him out of the plugin code at the insertion, so no chance of repeat inserts in the same instance of the class [at least without incredible convolution??] ?

                  I can listen to DefinitionObserver# onComponentInstanceAdded to get back into Ruby after insertion.

                  This is a neat way to create a tool that's not a Tool. πŸ˜† πŸ˜† πŸ˜†

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

                    @draftomatic said:

                    Thanks for the help fellas.

                    @tig said:

                    But he was talking about a 'tool'...
                    This way his tool can get a picked-point and then insert a component at that point, then repeat if desired...
                    Your way is much easier, but it will dump him out of the plugin code at the insertion, so no chance of repeat inserts in the same instance of the class [at least without incredible convolution??] ?

                    I can listen to DefinitionObserver# onComponentInstanceAdded to get back into Ruby after insertion.

                    This is a neat way to create a tool that's not a Tool. πŸ˜† πŸ˜† πŸ˜†

                    And you also need to listen to the ToolsObsever to check if the user activates another tool - instead of actually placing the component.

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

                    1 Reply Last reply Reply Quote 0
                    • D Offline
                      draftomatic
                      last edited by

                      @unknownuser said:

                      And you also need to listen to the ToolsObsever to check if the user activates another tool - instead of actually placing the component.

                      That doesn't seem to be an issue. onComponentInstanceAdded gets fired when the component is placed, not when you activate the tool.

                      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