Some help needed for tool to draw and rotate lines



I’m working on a new tool called MirrorMe.
Therefore I need the tool to draw 4 lines that constitute a face.
See drawing:

The face has two handles that allow rotatng the plane over the respective axis.
Any ideas, or hints are higly aprriciated.



That looks like the same as the right-click “Flip Along”.

Flipping (rotating) is different than mirroring.



Hi Dan,

No, i’m sorry, I didn’t explain to well:

This wil be a new Tool with:

def activate

def onMouseMove(flags, x, y, view)

The fat black lines are temporairy lines drawn by the tool. When set, the face wil chop the shape.
Then copies the leftover-shape, mirrors it on the set face, and glues it back on. Like so:

So its a bit like native Flip Along, but not restricted to the axes because you can set the plane anyway
you like. And the shape will copy and add itself by deafault.

You see?


My “Mirror” plugin does the mirroring about any plane determined by three picked points.

My “Cut_to_plane” takes three picked points and from that defined plane it deletes the unwanted half of the object.
If you want to draw a temporary rectangular face use the view.draw* tools within your Tool.draw commands…
In more recent SketchUp versions you can define a color with transparency to apply to that face.
I suspect you want the temporary-rectangle to extend across the object’s bounds rather than the three picked points.
To get that, first get the plane from the three-points, then get the object.bounds.
From the bounds you can get the .max and .min points of its enclosing ‘box’.
You can also use the max.z on a clone of the min and min.z on a clone of the max.
You now have four points defining the ‘box’.
You already have the ‘normal’ [obtainable from the plane], so you can define a ‘line’ [point, vector] passing through these points.
You can then use the Geom methods to get an intersection of the defined plane and each of those lines.
You now have those four points projected onto the plane.
From those you can determine the extents of the enclosing rectangle on that plane and then use those points to ‘draw’ the Tool’s temporary graphics for that rectangle…

By combining the ideas in those, then constructing “your” tool would be easy enough…


thanks TIG,

In my version, the black rectangle is visible at activation of the tool.
Any thoughts on how to manipulate the rectangle? Moving (along perp) and rotating?



Hello! Is there anyone who can help me??


Have you at least looked at the code in my plugins examples ?



I looked at your code. Both plugins provide the same means for the user to draw lines with the tool. And these lines then define a plane needed for the action. ( ie cut to plane or mirror to plane).
Drawing such lines with a tool is no problem for me.

But in my case the plugin itself will place the temporary rectangle. Much like inserting a section-plane.
This rectangle is the equivalent of your 3 points.At time of insertion its aligned with the center of the object. Then the user can can translate the plane along its normal, and rotate it about 2 axes.
So my question is: how can the user manipulate this temporary rectangle drawn by the plugin?

I hope you now see what’s my problem :grinning:

PS: I know that invoking the sectionplane can be done from the api but not in v8 (my version).
Am I right?


You miss my point.
The user picking points in a Tool does NOT have to end up with something being drawn.
A picked point can be used to calculate a translation or a rotation transformation as you decide…
After the rectangle is make you can even attach it to the cursor so that it moves with the mouse [not even a picked point just an input point read from the mouse-position], until a button click fixes its location or rotation…
Look at the code in my 2dTextTool RB… that has an option to place the text on Z-plane - the text is made as a component definition and an instance is placed at the ORIGIN, then that instantly jumps onto the mouse’s cursor and moves with it but always changing the point’s Z to match the Z-plane’s - a single button click the fixes its location and places it there at the right Z.
You can adapt its code to position and rotated your ‘rectangle’ object.
Like in many examples like the LineTool - you use ‘@state’ to determine what stage the processing is at - you start off at say @state=-1 and once your rectangle object is made/placed/referenced, you set @state=0; test is @state==0 to locate and reset to @state=1 on-click, test is @state==1 to rotate about X and reset to @state=2 on-click, test is @state==2 to rotate about Y and reset to @state=3 on-click etc etc…