Changing cursor insertion point on bounding box
-
ComponentDefinition#insertion_point=
You would probably use the
BoundingBox
instance methodcorner()
to get which of the other points you desire, or thecenter()
, and then feed that to the definition'sinsertion_point=()
method.The
ComponentDefinition
class, inherits abounds()
method from theDrawingelement
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" ...
-
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.
-
@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.
-
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...
-
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.
-
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... -
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.
-
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 codebb=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)}
-
Thanks TIG, I haven't gotten around to trying what you suggested but I will soon enough.
Advertisement