Simulate 'User Coordinate System' using 'rotate' and 'move'.

This forum is for 'Work-in-Progress' QCAD user developed script Add Ons and Plug-ins.

Please use this forum to request/submit your script Add-Ons & Plug-in idea's.

Moderators: andrew, Husky, J-J

Post Reply
riverbuoy
Senior Member
Posts: 107
Joined: Thu Oct 03, 2013 5:37 pm

Simulate 'User Coordinate System' using 'rotate' and 'move'.

Post by riverbuoy » Sun Sep 17, 2017 2:10 am

Hi,

The 'User Coordinate System' (UCS) was developed in AutoCAD (and other CAD programs) to help draw 3D models. However, it can also be useful in 2D drawing.
It works by specifying a direction for the X and Y axis, and selecting a point for the origin. In AutoCAD you can save multiple named UCS definitions which you can switch between. In QCAD, Andrew has already added some code in preparation for implementing UCS.
Until then, I thought it might be useful to simulate this by using 'rotate' to set a direction for the X axis (obviously in 2D the Y axis direction isn't used), and to use 'move' to simulate moving the origin. I decided not to use multiple named definitions, but just implement the ability to set a direction for the X axis, and move the origin, and finally to provide a command to return the drawing to its original orientation and location (as it can be tricky to keep track of the origin after multiple moves and rotations).

Example 1.
UCSExample.png
UCSExample.png (6.5 KiB) Viewed 3175 times
I came up with three commands.

1. 'ucs', shortcut 'UC'.
This allows you to set a direction for the X axis.

Figure 1. The ucs toolbar.
UCSFig1.png
UCSFig1.png (5.73 KiB) Viewed 3175 times
Figure 2. The command line prompt.
UCSFig2.png
UCSFig2.png (4.15 KiB) Viewed 3175 times
You set the direction in the options toolbar, or you can select an entity and its angle will be put in the direction box. Not all entities have an angle associated with them. For example arcs, circles, polylines etc. do not have an angle property, so if you pick an entity that doesn't have an angle, an error message is shown in the command line, but you can continue to select another entity. Once you have set the angle you can click on the 'Tick' icon to run the command, or alternatively you can press the 'return' or 'enter' key on the keyboard to run the command.
The 'direction' is actually an angle which is aligned with the X axis. If you draw a line parallel to the X axis, going from left to right, it will have the angle represented by the X axis when the drawing is returned to its original orientation. In the example above, setting the direction to 72 will rotate the drawing so that side 2 of the pentagon will be horizontal to the X axis. Any lines drawn parallel to the X axis, going from left to right, will have an angle of 72 degrees. Lines going from right to left will have an angle of 72 + 180 (252) degrees.
(Note: you can use a mathematical expression in the box, so to get side 3 parallel to the X axis you can enter 144 or '2*72').
Also note that the value in the direction box is an absolute value, and not a relative angle.


2. 'ucsorigin', shortcut 'UO'.
This allows you to move the origin.

Figure 3. The ucsorigin toolbar
UCSFig3.png
UCSFig3.png (5.66 KiB) Viewed 3175 times
Figure 4. The command line prompt
UCSFig4.png
UCSFig4.png (4.25 KiB) Viewed 3175 times
You enter the X and Y coordinates of the point you want as the origin, in the options toolbar. Alternatively you can select the point with the mouse and the coordinates of that point are put in the X and Y coordinate boxes. Once you have set the coordinates, you can click on the 'Tick' icon to run the command, or press the 'return' or 'enter' key om the keyboard.
This command moves the selected point to the origin, and all the entities are moved the same amount.


3. 'ucs2wcs', shortcut 'UW'.
This sets the drawing to its original location and orientation, i.e. move from the 'User Coordinate System' (ucs) to the 'World Coordinate System' (wcs).
This command doesn't require any user input.

As I am sure you have spotted, the main drawback to this approach, is the amount of time it takes to rotate and/or move the entire drawing. On my computer I tested this with two sample drawings. The first drawing contains just over 5,700 entities, and takes 4 seconds to rotate, and 3 seconds to move. The second drawing contains just over 12,000 entities and takes 19 seconds to rotate, and 17 seconds to move. Your computer may be faster or slower than this. So it is up to the user to decide if this is acceptable.
(Note: the larger drawing takes much longer to process because it contains many blocks, hatches, polylines, text blocks and dimensions. Each of these count as one entity, but contain multiple lines, all of which need to be processed).

These commands store the direction and origin in two variables, UCSORG stores the offset to the original origin point, and UCSXDIR stores the direction of the X axis. These variables are stored in the drawing when it is saved. If you save the drawing while it is rotated and/or moved, the variables are stored in the drawing, so you can close down QCAD, and when you reopen the drawing you can use 'UW' to return the drawing to its original orientation and location. I would then save it again.

A cautionary note: Do not use the 'UNDO' command with these commands. Use 'UW' to reverse any changes. The 'UNDO' command will undo a rotation or move, but it doesn't know to change the variables, so the variables and drawing are out of sync.
If this happens, you will have to set the orientation and location manually. Once you have the drawing correct you then need to run a small script file called 'clearucs.js'. This sets the variables to their default values. The script file is in the 'ucs2wcs' directory. Use the menu option 'Misc->Development->Run Script' option (shortcut 'XC'), and select the file and run it. The drawing and variables will now be in sync again, so save the drawing.

I have attached the file 'UCS.zip', which contains three directories (one for each command). Extract these directories to the 'scripts/Edit' directory. The commands appear in the 'Edit' menu.
You can obviously do all this manually, but I think these commands may be useful, especially if you do this often.

Regards

riverbuoy
Attachments
UCS.zip
(29.57 KiB) Downloaded 56 times

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 2099
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Simulate 'User Coordinate System' using 'rotate' and 'move'.

Post by Husky » Sun Sep 17, 2017 6:26 am

Hi riverbuoy :D

I played a little bit with this new tool and like to share my two cents. As you know I'm the typical 0815 user :wink:

1. UCS - Set direction of X axis

a.) The name is confusing to me. Why only x axis? It will rotate the x and y axis and a name like Rotate absolute 0 would be more plausible to me.
Husky-2017.09.16-01.png
Husky-2017.09.16-01.png (22.91 KiB) Viewed 3163 times
b.) All tools in QCAD are using for what ever kind of rotation a positive value to rotate counter clockwise. Why rotates your tool with a positive value clockwise?
c.) If I launch this tool it looks like it reads the mouse pointer position. Unfortunately it start immediately even in "empty" areas of the drawing and reports
Husky-2017.09.16-02.png
Husky-2017.09.16-02.png (5.26 KiB) Viewed 3163 times
d.) the tool works also with single line "entity input" but I don't have the info or an alert that it doesn't works with polylines etc.

e.)... the not working undo problematic is critical in my opinion. Your UW command is maybe a workaround immediately after I use UC but what happens if I have to undo many steps (20 or so) in my drawing and one of those steps was a UC ...


2. UCS - Set origin point / Reset UCS to WCS
A few user have already ask for this feature - I'm sure you will make them happy!
In my opinion it works already like a charm. I have only one little thing what could be improved.
After launching the tool I'm able to pick a point in the drawing for the new location. I have then the desired x/y position in the option box posted but I have no visual information in the drawing. Other tools like move or rotate will freeze the crosshairs at the chosen position what helps to keep track of what happens where ...
Work smart, not hard: QCad Pro

riverbuoy
Senior Member
Posts: 107
Joined: Thu Oct 03, 2013 5:37 pm

Re: Simulate 'User Coordinate System' using 'rotate' and 'move'.

Post by riverbuoy » Sun Sep 17, 2017 10:06 pm

Hi Husky,

Thanks for your feedback.
Husky wrote:c.) If I launch this tool it looks like it reads the mouse pointer position. Unfortunately it start immediately even in "empty" areas of the drawing and reports
Yes, you are right. This is clearly wrong, so I have attached the fixed file, 'ucs.js'. Replace the existing file in the 'ucs' directory.
Husky wrote: d.) the tool works also with single line "entity input" but I don't have the info or an alert that it doesn't works with polylines etc.
The error message, which now works correctly, is shown if you pick an entity that does not have a getAngle function.
Husky wrote:a.) The name is confusing to me. Why only x axis? It will rotate the x and y axis and a name like Rotate absolute 0 would be more plausible to me.
What you are doing is rotating the XY plane around the Z axis. But think of it as setting the direction of the X axis. When you start a drawing the X axis is pointing to the right, which represents an angle of zero degrees. So you are changing the angle (or direction) the X axis represents. So lines drawn parallel to the X axis, from left to right, will have that angle when the direction is set back to zero.
Changing the X axis direction, you are actually rotating the XY plane around the Z axis. If you were to change the Y axis direction, you are actually rotating the YZ plane around the X axis. QCAD, being 2D only, doesn't have a YZ plane. For a fuller explanation I suggest you google 'Autocad UCS'. This will bring up a list of links with fuller explanations of the UCS command.
Husky wrote:I have then the desired x/y position in the option box posted but I have no visual information in the drawing.
The origin point is represented by two red lines like a plus sign (+). Where they intersect is the origin point. If you can't see it then it is not in the current view. When you move the origin, the two lines should appear at the point you selected.
Husky wrote:e.)... the not working undo problematic is critical in my opinion. Your UW command is maybe a workaround immediately after I use UC but what happens if I have to undo many steps (20 or so) in my drawing and one of those steps was a UC ...
Good question. At the moment I don't have a good answer, except to say that I haven't ever needed to undo 20 or more steps. As I explained, you would need to manually rotate and move the drawing, and then run the script file 'clearucs.js'.

Hope this helps

Regards

riverbuoy
Attachments
Ucs.js
(5.2 KiB) Downloaded 56 times

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 2099
Joined: Wed May 11, 2011 9:25 am
Location: USA

Re: Simulate 'User Coordinate System' using 'rotate' and 'move'.

Post by Husky » Mon Sep 18, 2017 7:35 am

Hello riverbuoy,

I think this is a typical situation between a programmer and a 0815 user. Probably we wont come on the same branch but here are a few addional thoughts - and I'm sure similar questions would be ask by other user ...
riverbuoy wrote: What you are doing is rotating the XY plane around the Z axis.
That is why I'm confused - the result doesn't tells me what I did. The result shows me that I rotated the drawing around Absolute 0/0.
X/Y has still the same orientation like before. If I switch the grid on - same orientation. If I then use other tools - same orientation.
Long story short: The UCS isn't rotated, only the drawing. The name "UCS - Set direction of X axis" is misleading in my eyes.
riverbuoy wrote: For a fuller explanation I suggest you google 'Autocad UCS'. This will bring up a list of links with fuller explanations of the UCS command.
Yep I did and it just supported my initial thoughts ...
BTW - do you have an example what could be accomplished with a rotated UCS system in QCAD what isn't already doable with QCAD Board tools?

Husky wrote: I have then the desired x/y position in the option box posted but I have no visual information in the drawing.
riverbuoy wrote:The origin point is represented by two red lines like a plus sign (+). Where they intersect is the origin point. If you can't see it then it is not in the current view. When you move the origin, the two lines should appear at the point you selected.
Sorry - that wasn't what I meant. I know how and where to find the Absolute zero point. :wink:
I meant a visual information what shows me where the NEW absolute Zero point would be before I confirm it. Cross hairs / point or similar.

Regards
Work smart, not hard: QCad Pro

riverbuoy
Senior Member
Posts: 107
Joined: Thu Oct 03, 2013 5:37 pm

Re: Simulate 'User Coordinate System' using 'rotate' and 'move'.

Post by riverbuoy » Mon Sep 18, 2017 3:38 pm

Hi Husky,

Sorry about the confusion. I think my explanation was poor, so I will try again. Here goes...

First 'Direction'. We normally give directions using points of the compass, such as EAST, WEST, NORTH, SOUTH, SOUTH-WEST, NORTH-EAST etc. However these are imprecise, so navigation systems, and surveyors, etc. use degrees, minutes and seconds to indicate precise directions. So when you start a new drawing the X axis points EAST, or zero degrees. So although we are using degrees, we are using them to represent a direction, and not a rotation.

The X and Y axis are fixed on the screen, so they don't move. So to get the X axis to point NORTH, for example, we have to rotate the drawing 90 degrees clockwise, or 360-90 = 270 degrees counter-clockwise. The result is the same. Now the X axis is pointing NORTH (90 degrees) on the drawing. This is the same as rotating the paper on a drawing board.

Why you would want this?

If you were drawing the floor plan of a pentagon shaped building, for example, it is much easier and quicker to do it if the walls are parallel to the X and Y axis. As you point out, QCAD has tools to allow you to draw lines at any angle, but when laying out floor plans, this feels unnatural and slow, and prone to introducing errors.

If I understand you correctly, you would like something drawn on screen at the point you selected for the new origin. The idea of having the X and Y coordinates in the toolbar is so you can check them before confirming. If you confirm and think it is wrong, then you can just type 'UO' and try again. You can make as many origin changes and direction changes as you want.

I hope this helps clarify things a bit more.

Regards

riverbuoy

Post Reply

Return to “QCAD 'Script Add-On & Plug-in challenge' - Work in Progress”