• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Changing cursor insertion point on bounding box

Scheduled Pinned Locked Moved Developers' Forum
11 Posts 3 Posters 848 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.
  • F Offline
    Frankn
    last edited by 2 Mar 2012, 02:37

    Hi All,
    The default cursor insertion point of a component is the front lower left corner and I'm able to use that to determine where to place components from my plugin but I'd like to change it to some other point. I'm pretty sure I need to combine InputPoint and BoundingBox but I can't figure out how to do so... the only thing my searches came up with is this post... http://forums.sketchucation.com/viewtopic.php?f=180&t=33428&p=294834&hilit=bounding+box+cursor#p294834
    thomthom seems to be asking if it's possible to do so through the API but no answer was given.

    As a reference I'm playing around with the TrackMouseTool which is located in the utilities.rb file and also found this post http://forums.sketchucation.com/viewtopic.php?f=180&t=35353 which has some good info on mouse tracking.

    As always thank you for your time,
    Frank

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 2 Mar 2012, 03:25

      ComponentDefinition#insertion_point=

      You would probably use the BoundingBox instance method corner() to get which of the other points you desire, or the center(), and then feed that to the definition's insertion_point=() method.

      The ComponentDefinition class, inherits a bounds() method from the Drawingelement class.


      Now when you change the insert point, you'll change all the instances of that definition... so if you only wish to change one instance, you should first call make_unique() on it, so it has it's own definition that you can change independently.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 2 Mar 2012, 03:27

        BTW.. I think that someone did create a plugin to do this... user name something like "SiaNYC" ...

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 2 Mar 2012, 03:42

          See also: [ruby-doc] ComponentDefinition.insertion_point=

          Ok here's the plugin I was thinking of:
          [Plugin] Axis components (Sahi)

          There's also:

          [Plugin] Axes Tools (ThomThom)


          One of the best ways to learn, is to see how others have done similar things.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • F Offline
            Frankn
            last edited by 2 Mar 2012, 03:48

            @dan rathbun said:

            See also: [ruby-doc] ComponentDefinition.insertion_point=

            Ok here's the plugin I was thinking of:
            [Plugin] Axis components (Sahi)

            There's also:

            [Plugin] Axes Tools (ThomThom)


            One of the best ways to learn, is to see how others have done similar things.

            Thanks I was just searching for siaNYC and wasn't coming up with anything and I totally agree that seeing how others did something is a great way to learn... let's just say I've copied and pasted plenty of code from other plugins trying to learn and make it do what I wanted. πŸ˜„

            Thanks for the links... I'll be checking those out right now.

            1 Reply Last reply Reply Quote 0
            • F Offline
              Frankn
              last edited by 2 Mar 2012, 06:19

              Ok so I've been looking at those 2 plugins and here's the problem(s) I'm having...

              The plugin from Sahi somewhat does what I'd like to do BUT you need to select an instance first and then when adding a new instance of the component it changes the input point... I want to change the input point after the defintion has been created and before inserting the instance into the model.

              The plugin from thomthom does exactly what I'd like to replicate (minus the input box) but to be honest his programming skills are way over my head when using TTlib2/core.rb. I'm having a hard time following along with what is being done. 😳

              So basically I'm stuck somewhere in the middle of the 2. πŸ˜„

              Here's what I get in Ruby Console as an output, Point3d(1e+030, 1e+030, 1e+030). I can't associate the bounding box corner() to Sketchup::ComponentDefinition:0xb93d2fc.

              Here's the code I've been testing with which returns Point3d(1e+030, 1e+030, 1e+030)...

              corner=boundingbox.corner(6)
              back_top_corner=Geom;;Point3d.new(corner)
              new_insertion_point=definition.insertion_point=back_top_corner
              
              

              So close yet so far... πŸ˜•

              1 Reply Last reply Reply Quote 0
              • F Offline
                Frankn
                last edited by 2 Mar 2012, 07:13

                Ok I found my problem... it was in part of the code I was using from the example found here... https://developers.google.com/sketchup/docs/ourdoc/boundingbox

                I forgot to change bbox = model.bounds to boundingbox=defintion.bounds. πŸ‘Š 😳

                So now I get the correct Point3D output... BUT... now I have a problem with this line...

                instance=model.active_entities.add_instance(definition, new_insertion_point)
                

                Which is what I'm using to add the component to the model when left clicking where I want to place it. So let's say I have a component that is (10, 1, 10) it inserts it at Point3d(0, 1, 10). Afterwards if I get the compoent from the compoent window the cursor selects the component at the correct bunding box corner.

                Basically it's not setting the bounding box insertion location it's using the new_insertion_point as coordinates to insert the component... I think, right??

                Getting a little closer. πŸ˜„

                p.s. sorry if I'm not using the terms instance and defintion correctly, I'm still a little confused by how that works. πŸ˜•

                1 Reply Last reply Reply Quote 0
                • TIGT Online
                  TIG Moderator
                  last edited by 2 Mar 2012, 10:43

                  corner=boundingbox.corner(6) IS a Point3d so use
                  definition.insertion_point=corner
                  no need for other references ?
                  If you never need to use ' corner' again you could streamline it to just this
                  definition.insertion_point=boundingbox.corner(6)

                  You add an instance using a transformation, not a point ?
                  transformation=Geom::Transformation.new(a_point) instance=model.active_entities.add_instance(definition, transformation)
                  The point ' a_point' can be any point in 3d...

                  TIG

                  1 Reply Last reply Reply Quote 0
                  • F Offline
                    Frankn
                    last edited by 2 Mar 2012, 20:14

                    Hi TIG,

                    I tried your suggestions and get the same result. After my plugin builds the component. I select where I'd like to insert into the model but the insertion point remains as the bottom left front corner... aftewrwards if I select compoents from the component browser then it modifies the insertion point to corner(6).

                    Should I be applying these changes outside the def onLButtonDown method? I'm trying that but with no luck so far...

                    Thanks TIG.

                    1 Reply Last reply Reply Quote 0
                    • TIGT Online
                      TIG Moderator
                      last edited by 3 Mar 2012, 11:06

                      The way I'd do it and apply it to all instances is this...

                      Make the Definition, and place an Instance [if you don't already have one].
                      Get the Instance.bounds [assuming it's not scaled] to find your 'new_point'.
                      Make a Vector from the new_point to the old_point [that will fix its length].
                      Here I'll assume the Bounds(0) is the origin and Bounds(6) is the new_point...
                      Make a Translation Transformation using that Vector.
                      Transform all of the Definition's Entities using that Transformation.
                      At that moment all of the Instances will have 'jumped' - so reset them back...
                      Iterate the Definition's Instances applying the Transformation 'Inverse'.
                      Everything now remains where it was in the Model, but the Definition now has its Origin at 'new_point'.
                      Here's some partial code

                      bb=instance.bounds
                      np=bb.corner(6)
                      op=bb.corner(0)
                      ve=np.vector_to(op)
                      tr=Geom;;Transformation.translation(ve)
                      defn.entities.transform_entities(tr, defn.entities.to_a)
                      defn.instances.each{|e|e.transform!(tr.inverse)}
                      
                      

                      πŸ€“

                      TIG

                      1 Reply Last reply Reply Quote 0
                      • F Offline
                        Frankn
                        last edited by 6 Mar 2012, 00:22

                        Thanks TIG, I haven't gotten around to trying what you suggested but I will soon enough. πŸ˜„

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

                        Advertisement