11 posts • Page 1 of 1
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,
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.
BTW.. I think that someone did create a plugin to do this... user name something like "SiaNYC" ...
Ok here's the plugin I was thinking of:
[Plugin] Axis components (Sahi)
[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.
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)...
So close yet so far...
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.
So now I get the correct Point3D output... BUT... now I have a problem with this line...
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.
corner=boundingbox.corner(6) IS a Point3d so use
no need for other references ?
If you never need to use 'corner' again you could streamline it to just this
You add an instance using a transformation, not a point ?
The point 'a_point' can be any point in 3d...
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...
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
Thanks TIG, I haven't gotten around to trying what you suggested but I will soon enough.
11 posts • Page 1 of 1