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: 118
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 9199 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 9199 times
Figure 2. The command line prompt.
UCSFig2.png
UCSFig2.png (4.15 KiB) Viewed 9199 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 9199 times
Figure 4. The command line prompt
UCSFig4.png
UCSFig4.png (4.25 KiB) Viewed 9199 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 333 times

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 3314
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 9187 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 9187 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

If a thread is considered as "solved" please change the title of the first post to "[solved] Title...". Thanks!

riverbuoy
Senior Member
Posts: 118
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 338 times

User avatar
Husky
Moderator/Drawing Help/Testing
Posts: 3314
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

If a thread is considered as "solved" please change the title of the first post to "[solved] Title...". Thanks!

riverbuoy
Senior Member
Posts: 118
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

koalabi
Registered Member
Posts: 1
Joined: Sun Nov 15, 2020 6:10 pm

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

Post by koalabi » Sun Nov 15, 2020 6:16 pm

Hi,

I know this thread is now 3 years old but I have purchased a license of QCad and now use it more frequently than previously.

I too miss the UCS functionality of AutoCAD or DraftSight. As highlighted by the OP, it is very useful when drafting regular elements along slopes (like with roof structures). I hope a UCS-like function will be added to QCad in the future.

In the meantime, I have found another way to more or less do the same, less expensively than shown by the OP. Actually, that's just the other way around: you build your elements in the (only) cartesian coordinate systems (preferably in a separate layer and when everything is ready, you use the "Align Reference" function to put the whole subset in place. Afterwards, probably, you will want to transfer these elements to another layer.

It's not UCS, but it's a workable workaround ...

Kind regards

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

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

Post by Husky » Sun Nov 15, 2020 7:40 pm

koalabi wrote:
Sun Nov 15, 2020 6:16 pm
... it is very useful when drafting regular elements along slopes (like with roof structures). I hope a UCS-like function will be added to QCad in the future.
Hi,

I never was in need to use a UCS and I've a hard time to see the benefits of it. Maybe that is just me ... :oops:
You mentioned how useful it would be with e.g. a roof structures. Could you please elaborate, with a roof structure example, what you can do easier with a UCS system instead of using the on board tools of QCAD Pro? Thanks!
Work smart, not hard: QCad Pro

If a thread is considered as "solved" please change the title of the first post to "[solved] Title...". Thanks!

CVH
Premier Member
Posts: 1032
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

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

Post by CVH » Mon Nov 16, 2020 9:28 am

Hi,
a UCS system has indeed large benefits, even in 2D.

In fact, I presume that UCS is partially implemented because DXF files includes this and QCAD shows the drawing in the active UCS.
From the point we open the file in QCAD, the stored active UCS becomes the WCS.
Others are lost.

We can indeed emulate all USC behaviors with the modifying tools on all entities.
(IS OR ISNOT: visual, locked, hidden, frozen....in blocks ...)

That is what this topic is about. The initial proposal goes back to 2012, see:
https://qcad.org/bugtracker/index.php?d ... ask_id=694
Query for 'USC', 'riverbuoy' and related others, follow links.
There are even multiple features requests with that nature.

The difference:
With modifying or the pseudo USC (Usc.js), a lot of math is used to alter every reference of every entity.
Every next pseudo USC state again.
In the end there will be a large accumulated floating point error and you never get back to the initial state.

It's fine for a few MV/RO back and forth.
It's fine for a few states with 'Usc.js'.
And for small entities and near the origin.

Just try it out and the regular pentagon (higher up) will never be regular again.
Especially far from the origin or with larger numbers in general.
1ULP will become near to or will exceed fixed tolerances in QCAD of 1E-12, 1E-9 and so on.
Only a few mathematical functions are correct up to 1ULP. For some that can be up to 10ULP.
Accumulated even much, much more.
The problem with uncertainty is that it is never certain.
You will never know and you never will be able to correct it.

With a real USC the entities are shown in USC but remain static in WCS.
Actions on individuals are translated to WCS and projected back in USC.

The best similarity is 'Paper & pencil'.
One slants/shift a paper to draw on but everything already on the paper stays static.
One doesn't redraw everything slanted/shifted over and over again, one simply slants/shift the paper as needed.
That is the real functionality of a USC in 2D. :wink:

Regards,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

Phred
Registered Member
Posts: 2
Joined: Wed Nov 18, 2020 4:04 am

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

Post by Phred » Wed Nov 18, 2020 5:56 am

I'd agree for UCS. I used to use it frequently in 2D Draftsight. I haven't done any really ambitious drawing for over a year, but if I recall, I used to use it to reproduce already dimensioned objects (ie. I have a physical object and want to create a drawing of it). I would move the UCS to a location where I was working and then enter the same coordinates as I measured. I don't recall why I did it this way but it seemed to be the most obvious and before I found this I recall it being quite frustrating to translate dimensions to different locations. This seems so obvious now that I am wondering how else it is done.

CVH
Premier Member
Posts: 1032
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

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

Post by CVH » Wed Nov 18, 2020 6:12 am

In your specific case ...

EDIT:
>> Rejected
>> See lower

The workaround at the moment is to set (RZ) and lock (RL) your relative zero where your piece its zero is situated.
Downside: one looses some relative zero functionality of the drawing tools, if any.

Or a bit harder for humans is to do everthing in relative distance/offset/angle. :wink:

Regards,
CVH
Last edited by CVH on Wed Nov 18, 2020 9:41 am, edited 1 time in total.
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

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

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

Post by Husky » Wed Nov 18, 2020 8:15 am

@Phred
CVH wrote:
Wed Nov 18, 2020 6:12 am
The workaround at the moment is to set (RZ) and lock (RL) your relative zero where your piece its zero is situated.
Downside: one looses some relative zero functionality of the drawing tools, if any.
I would not second that! Move the whole drawing with a designated reference point to Absolute 0,0. The effect is the same like using a customizable UCS but "backwards" ... :wink: Benefit is that you are able to work with Absolute coordinates AND you are still able to use RZ as usual which is set by QCAD automatically with mostly every tool.

@all
My conclusion so far ...
It looks like nobody is able to provide an example what shows me how important the implementation of an UCS tool would be! More important - to show what you can't do with QCAD because the function is missing ...
It seems that everybody who is asking for it is just trapped in a familiar process within an other programs and would like to stick to that same habit in QCAD too ...

BTW: I don't say it wouldn't be nice to have it in QCAD - I only say that it isn't crucial for architectural or mechanical designs. I'm sure land surveyor will see it differently and I think they have much more reasonable arguments to implement a UCS in QCAD. :wink:
Work smart, not hard: QCad Pro

If a thread is considered as "solved" please change the title of the first post to "[solved] Title...". Thanks!

CVH
Premier Member
Posts: 1032
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

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

Post by CVH » Wed Nov 18, 2020 9:38 am

Husky wrote:
Wed Nov 18, 2020 8:15 am
I would not second that!
I did mention the downsides ... several hours of testing later ...
You are right, It doesn't work out well. Rather like tilting at windmills.

Specific workaround: NEW
- Start a new file.
- Draw the piece in regard with the absolute zero.
- Copy with reference = absolute zero.
- Paste to the main drawing where the piece its zero is situated.
PRO > Common Relative Zero functionality.
PRO > Not a single MV/RO back and forth needed.
PRO > Common uncertainty.
CON > Temporary file. (Not that this matters a lot)

Husky wrote:
Wed Nov 18, 2020 8:15 am
Move the whole drawing with a designated reference point to Absolute 0,0.
CVH wrote:
Mon Nov 16, 2020 9:28 am
It's fine for a few MV/RO back and forth.
Additionally don't forget to Un-Lock, Un-Freeze, Un-Hide all :wink:

The issue is the uncertainty of the floating point error ...
Do this with references sitting XXXXXX.xxx... (6 Integer digits) from the origin and
the uncertainty equals the fixed tolerances that QCAD uses internally.
Do math with such numbers and the uncertainty will vastly exceed the tolerances.
In the end, things will not align how they are expected to do.

Rather similar as hatching large spans or far from the hatch origin.
(About that I know almost everthing there is to know) e_geek

Husky wrote:
Wed Nov 18, 2020 8:15 am
BTW: I don't say it wouldn't be nice to have it in QCAD
CVH wrote:
Mon Nov 16, 2020 9:28 am
UCS is partially implemented ... QCAD shows the drawing in the active UCS.


Husky wrote:
Wed Nov 18, 2020 8:15 am
It looks like nobody is able to provide an example
I'll try to retrieve Andrew's MV/RO solution for the top height of a spline curve.
It's somewhere on the forum.
Valid as it is only one RO back and forth.

The problems start when you do that every few minutes over and over again ...
On top ... You have to measure the angle/shift first and store it (or both) in a variable because it/they are only displayed truncated.
This is exactly what USC.js tries to do for you, but the code isn't flawless.
The biggest downside is that USC.js will never be able to beat the uncertainty, nobody can.

Drawings can be manipulated in real USC endlessly without any increased uncertainty.
And with a few simple clicks or drags.

I don't think that you glue your paper orthogonally on the table to write or draft on. :wink:

Regards,
CVH
QCADpro 3.25.2.1 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

Post Reply

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