SketchUcation Plugin Store

 

 

changing cursor insertion point on bounding box

changing cursor insertion point on bounding box

Postby Frankn » Fri Mar 02, 2012 3:37 am

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... 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 viewtopic.php?f=180&t=35353 which has some good info on mouse tracking.

As always thank you for your time,
Frank
Frankn
 
Posts: 64
Joined: Sat Apr 25, 2009 5:53 am
Name: Frank

Re: changing cursor insertion point on bounding box

Postby Dan Rathbun » Fri Mar 02, 2012 4:25 am

    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.
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4087
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 2013
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: changing cursor insertion point on bounding box

    Postby Dan Rathbun » Fri Mar 02, 2012 4:27 am

    BTW.. I think that someone did create a plugin to do this... user name something like "SiaNYC" ...
    User avatar
    Dan Rathbun
    Top SketchUcator
     
    Posts: 4087
    Joined: Tue Oct 06, 2009 3:06 am
    Location: Florida, USA
    Name: Dan Rathbun
    Operating system: Windows
    SketchUp version: 2013
    License type: Pro
    SketchUp use: education
    Level of SketchUp: Advanced

    Re: changing cursor insertion point on bounding box

    Postby Dan Rathbun » Fri Mar 02, 2012 4:42 am

      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.
      User avatar
      Dan Rathbun
      Top SketchUcator
       
      Posts: 4087
      Joined: Tue Oct 06, 2009 3:06 am
      Location: Florida, USA
      Name: Dan Rathbun
      Operating system: Windows
      SketchUp version: 2013
      License type: Pro
      SketchUp use: education
      Level of SketchUp: Advanced

      Re: changing cursor insertion point on bounding box

      Postby Frankn » Fri Mar 02, 2012 4:48 am

      Dan Rathbun wrote:
        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. :D

        Thanks for the links... I'll be checking those out right now.
        Frankn
         
        Posts: 64
        Joined: Sat Apr 25, 2009 5:53 am
        Name: Frank

        Re: changing cursor insertion point on bounding box

        Postby Frankn » Fri Mar 02, 2012 7:19 am

        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. :oops:

        So basically I'm stuck somewhere in the middle of the 2. :D

        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)...
        Code: Select all
        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... :?
        Frankn
         
        Posts: 64
        Joined: Sat Apr 25, 2009 5:53 am
        Name: Frank

        Re: changing cursor insertion point on bounding box

        Postby Frankn » Fri Mar 02, 2012 8:13 am

        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/ ... oundingbox

        I forgot to change bbox = model.bounds to boundingbox=defintion.bounds. :knockout: :oops:

        So now I get the correct Point3D output... BUT... now I have a problem with this line...
        Code: Select all
        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. :?
        Frankn
         
        Posts: 64
        Joined: Sat Apr 25, 2009 5:53 am
        Name: Frank

        Re: changing cursor insertion point on bounding box

        Postby TIG » Fri Mar 02, 2012 11:43 am

        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
        User avatar
        TIG
        Global Moderator
         
        Posts: 13997
        Joined: Mon Nov 12, 2007 7:24 pm
        Location: Northumbria UK
        Name: TIG
        Operating system: Windows
        SketchUp version: 2013
        License type: Pro
        SketchUp use: architecture
        Level of SketchUp: Advanced

        Re: changing cursor insertion point on bounding box

        Postby Frankn » Fri Mar 02, 2012 9:14 pm

        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.
        Frankn
         
        Posts: 64
        Joined: Sat Apr 25, 2009 5:53 am
        Name: Frank

        Re: changing cursor insertion point on bounding box

        Postby TIG » Sat Mar 03, 2012 12:06 pm

        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
        Code: Select all
        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)}
        :geek:
        TIG
        User avatar
        TIG
        Global Moderator
         
        Posts: 13997
        Joined: Mon Nov 12, 2007 7:24 pm
        Location: Northumbria UK
        Name: TIG
        Operating system: Windows
        SketchUp version: 2013
        License type: Pro
        SketchUp use: architecture
        Level of SketchUp: Advanced

        Re: changing cursor insertion point on bounding box

        Postby Frankn » Tue Mar 06, 2012 1:22 am

        Thanks TIG, I haven't gotten around to trying what you suggested but I will soon enough. :)
        Frankn
         
        Posts: 64
        Joined: Sat Apr 25, 2009 5:53 am
        Name: Frank

        SketchUcation One-Liner Adverts

        by Ad Machine » 5 minutes ago

        Need SketchUp Books, Models, Styles or Textures? Check out our One Stop Shop for SketchUp.

        Premium Members get 20% discount!

        Ad Machine
        Robot
         
        Posts: 2012


        Return to Developers' Forum

        Who is online

        Users browsing this forum: Bing [Bot] and 3 guests