2D drafting ruby

30 views
Skip to first unread message

brichins

unread,
Jun 6, 2007, 1:15:30 PM6/6/07
to Google SketchUp Help - Ruby ideas
As we all know, SketchUp is 3D and not 2D, and shouldn't be used the
same way as a 2D drafting program like CAD... unless you really,
really want too! ;)

Here's the idea; I'm doing house plans and site plans from existing
hard copy plans - scan in the plan, trace it, and make changes in
SketchUp, which is the usual way to do it. I am used to panning and
moving around, but sometimes it gets frustrating. There are lots of
applications where I want to do 2D only for a while, often without a
picture, and then switch to 3D, and sometimes back and forth. Mostly
this can be done using Scenes, turn off perspective, etc. However,
when I don't have a picture or have moved on to adjusting things and
the picture is no longer useful, I don't want to keep drawing on an
existing picture or face, I just want to draw lines in 2 dimensions
only, on the XY (or Red/Green if you prefer) plane.

Sometimes I think it would be easier to lock things into 2D. Is there
a way to do a ruby that would *lock* the camera into Top view with
perspective off, and then toggle back to whatever it was switched
from? I know switching pages would work, but that requires setting up
pages every time, on every model.
I realize all these things can be done with existing tools/shortcuts,
except for locking the camera to only pan with the mouse wheel without
having to hold Shift. I hate clicking or shortcut-ing the pan tool,
and it's annoying when I forget to hold shift and have to keep pushing
the "top" button again.

So, overall, not a big thing. I know that I can already do all this -
with several commands instead of one - but Ruby scripting is all about
simplifying and optimizing the way I want to work, right? I'm sure
other people would have use for this too; anyone else get tired of
reading all the posts asking basic questions, often about 2D/3D
issues, to which the answer is always RTFM?

2D TOOL DESCRIPTION AND METHODOLOGY
I don't know enough ruby for this, but I do know that this can be done
and I think I have come up with a reasonably simple way to do it using
existing tools. Basically all I want is a button (shows on/off similar
to the Show Section Planes button, for instance) that wraps up several
commands and toggles them all together as follows:
When "2D" is turned On: switch to top view if not already there, turn
perspective off, and lock camera to pan only (which is probably the
tricky part) when using the mouse wheel. I don't know enough about
ruby to know if you can change the button definition to the Pan tool
and back, or if you can just lock on the Shift modifier for the tool,
which would act the same way.
Then when 2D is turned Off, switch perspective or || projection back
on (whichever was in use before) and give the mouse button back it's
usually functionality. Also, maybe switch to another view, such as
wherever the camera position was before 2D mode was activated or maybe
to a certain scene, but this wouldn't always be desirable. Maybe that
part could have an option setting somewhere if anyone wanted it.

Eventually I want to learn ruby myself, and this would probably be an
easy learning project, but I learn best by digging through other
people's scripts and looking at the pieces. I'd be happy to do the
button icon or having someone else do one if they want. Is anyone up
to tackling such a tool?

TB

unread,
Jun 6, 2007, 4:37:47 PM6/6/07
to Google SketchUp Help - Ruby ideas
I'm pretty sure all this can be done using V6.

Are you looking for a free script, or is this something that you could
justify from a business perspective?

Todd

brichins

unread,
Jun 6, 2007, 5:35:07 PM6/6/07
to Google SketchUp Help - Ruby ideas
I know this can be done generally with existing tools/commands, but
want a ruby that will speed things up. I am using v6 pro. I am looking
for minimal help authoring a free script, or if someone is interested
enough I certainly wouldn't oppose their writing and distributing it.
Mostly I just need to find a good list of classes, methods, and
variables to use in scripting.


brichins

unread,
Jun 6, 2007, 5:51:52 PM6/6/07
to Google SketchUp Help - Ruby ideas
So, I finally found some ruby documentation that I download a while
ago to my other computer. The main thing I'm worried about now is
modifying the mouse button behavior - ideas/help/warnings?

TB

unread,
Jun 6, 2007, 6:16:51 PM6/6/07
to Google SketchUp Help - Ruby ideas
OK, then my understanding is indeed correct. You were wanting to
know if it could be done in Ruby, and I said yes.

Here's your first minimal help.

The complete list of classes and methods you'll be choosing from are
in SketchUp Help>Ruby Help.

Classes and methods you will be interested in are:

Camera.set to reposition the camera.
Camera.perspective to query and set the perspective.

You'll want to write a Tool class to force lines, rectangles, circles,
etc. to only be drawn on the X/Y plane.

You'll want an Observer to follow the user's camera movement, to keep
it pointing down. (This is the part I have not researched myself, but
it should be available in V6.)

You'll want to use the methods in the Toolbar class to add buttons/
Icons for tools.

That should get you started. There are many free scripts out there
that will show you how to use each of the classes and methods
mentions, with the exception of the Camera Observer. Save that for
last. Then, come back, and we can work through it together.

Todd

TB

unread,
Jun 6, 2007, 6:18:53 PM6/6/07
to Google SketchUp Help - Ruby ideas
To track mouse movements and clicks, you'll have to write a Tool
Class. Inside a Tool class, you can implement the various methods
documented in Help>Ruby Help for getting control for button presses,
button releases, yada, yada, yada.

Todd

RickW

unread,
Jun 6, 2007, 7:59:10 PM6/6/07
to Google SketchUp Help - Ruby ideas
If you're not that concerned with drawing in 2d (just viewing), then
life gets much easier - reduced to the camera methods and a view
observer.

brichins

unread,
Jun 7, 2007, 11:20:49 AM6/7/07
to Google SketchUp Help - Ruby ideas
Thanks Todd and Rick! That is exactly what I needed to get started, I
appreciate having 2 pros giving me a hand. To be honest, your scripts
are mostly the ones I've been digging through to get ruby nuts and
bolts down. Thank you for documenting!!
To start with I am just restricting the camera view, and later on when
I get a little more versed in ruby going to full 2D i.e. restricting
drawing to a plane without having to draw one first. Just the XY plane
to start, but eventually I'd like to switch to any plane perpendicular
to the camera to allow for front/side etc. drawing. Exactly which
perpendicular plane will be tricky I think, someone in the Google
groups suggested using a section plane as a reference and moving it
manually to adjust the drawing plane... don't know how exactly that
would work best, but it could be a good starting point.

brichins

unread,
Jun 7, 2007, 11:20:59 AM6/7/07
to Google SketchUp Help - Ruby ideas

brichins

unread,
Jun 7, 2007, 11:21:20 AM6/7/07
to Google SketchUp Help - Ruby ideas

brichins

unread,
Jun 7, 2007, 11:22:16 AM6/7/07
to Google SketchUp Help - Ruby ideas
oops... I said Google but I meant Sketchucation... I'm at google... I
knew that.

brichins

unread,
Jun 7, 2007, 11:41:37 AM6/7/07
to Google SketchUp Help - Ruby ideas
Howard over at Sketchucation had another idea, qoute:

What about this approach for a 2d drafting ruby - disabling an axis,
as opposed to changing perspectives and cameras etc ...
...
A ruby (eg connected to command buttons) that only allows drafting in
2 axes (ie DISABLES one axis).

That way, you could draw in 2d - safe in the knowledge that your
geometry wouldn't be wandering off in the blue (z) direction for
instance.

The buttons would allow you to draw in ANY 2 axes but not a third -
would be VERY useful.

Even drawing in this proposed 2d drawing mode I can still see that it
would be VERY useful to have the ability to be able to have a
perspective view on an object eg drawing detail on the gable end of a
building etc

.....

You could also use this feature then for drawing in plan mode with
perspective off if required - leaving it up to the user to change
cameras, perspectives etc as needed.
...
It would be a ruby that could lock both the red and green axes (for
example) - AT THE SAME TIME.
...
Regards
Howard L'

End quote.

This sounds like it could be easier to implement (?); however, what if
you want a plane that isn't axial, such as a gable on a building wing
that is 45 degrees from the rest of the house? In that case you'd
still need all 3 axes. Is there a simple way to constrain the line
being drawn to be perpendicular to the camera's line of sight? I
basically know the math for that (cos between vectors = 0) but not
sure how to check on the fly while the pencil (or whatever tool) is
moving and active...

brichins

unread,
Jun 7, 2007, 12:05:37 PM6/7/07
to Google SketchUp Help - Ruby ideas
Hmm, how did I post the same thing 3 times above? blasted refresh
button...

TB

unread,
Jun 7, 2007, 4:56:53 PM6/7/07
to Google SketchUp Help - Ruby ideas
There probably no reason a plane could not be used to restrict drawing
in 2D. Only takes 3 points to identify a plane.

Todd

brichins

unread,
Jun 7, 2007, 6:18:20 PM6/7/07
to Google SketchUp Help - Ruby ideas
But which plane, at what distance from the camera? If you use the
camera direction (camera.up I think?) you already have a line (2
points!) and only have to check orthogonality to that line, and you
could draw on any of the (parallel) planes the camera is facing. In
some instances it might be good to choose an exact plane (XY or a
given surface), or at other times just constrain the drawing tool to
the same plane as the starting point; that is, the first point clicked
would define the drawing plane.

brichins

unread,
Jun 8, 2007, 12:00:27 PM6/8/07
to Google SketchUp Help - Ruby ideas
Okay, so I started on this yesterday and am having some difficulty
with the camera (last post: meant camera.direction not camera.up).
Anyone willing to have a look at this and tell me where I'm going
wrong? (Todd, hint, hint) Also I made some quick .png's for the
toolbar just to see if it worked; the .rb and the .png's are here:
http://homerbob.8m.com/misc/

TB

unread,
Jun 8, 2007, 12:20:24 PM6/8/07
to Google SketchUp Help - Ruby ideas
On Jun 7, 5:18 pm, brichins <brianrich...@gmail.com> wrote:
> But which plane, at what distance from the camera?

Hey, this is your baby! You tell me! I would suspect that if you
want to constrain drawing to a given plane, you would want to know
what the plane is. Therefore, one technique you could use would be to
pick a face (which always has at a minimum 3 points) to choose your
plane. Otherwise, the user needs to tell you (through a series of
mouse picks) where to form the virtual drawing plane.

Also, constraining drawing to 2D does not dictate that the camera
vector be perpendicular to the plane.

As far as a distance... you have to pick that. Or, let the user pick
it with a single left click, and you can use the camera's direction to
derive your plane from that user-picked point (in which case the
camera would be perpendicular to the plane).

I'll look at your code.

Todd

TB

unread,
Jun 8, 2007, 12:22:50 PM6/8/07
to Google SketchUp Help - Ruby ideas
Access to your folder is forbidden.

Todd

brichins

unread,
Jun 8, 2007, 12:33:39 PM6/8/07
to Google SketchUp Help - Ruby ideas
I think I'd like to have the plane determined by the first mouse
click; haven't touched the plane lock aspect yet though, just getting
the camera and mouse control down.

Reposted .rb as .txt; should be good now.

brichins

unread,
Jun 8, 2007, 1:31:17 PM6/8/07
to Google SketchUp Help - Ruby ideas
updated .rb file (have started pseudocode for plane definition, camera
tracking, and tool tracking) and moved files to:

http://homerbob.8m.com/su/

TB

unread,
Jun 8, 2007, 1:52:11 PM6/8/07
to Google SketchUp Help - Ruby ideas
Now there are no files listed in the folder list.

Todd

brichins

unread,
Jun 8, 2007, 2:03:18 PM6/8/07
to Google SketchUp Help - Ruby ideas
You must have beat me there; the link above is working for me and
shows three files: 2 .png and a .txt (I can't link to those directly
due to host settings.) Reposting link for convenience.

http://homerbob.8m.com/su/

TB

unread,
Jun 8, 2007, 2:31:23 PM6/8/07
to Google SketchUp Help - Ruby ideas
OK, I got it this time. I'll look at this sometime soon.

Todd

Reply all
Reply to author
Forward
0 new messages