Arc Text

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

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

Arc Text

Post by riverbuoy » Sun May 28, 2017 4:15 am

Hi,

I have just finished a command to draw text along a line, arc or circle, which I have called 'textalong'.

This tool is for drawing text aligned along a line, arc or circle. It is limited to using simple text as I could not find a quick and easy way
to find the format of individual characters.

Command: 'textalong', or 'tg'
Shortcut: TG
AlongToolbarOptions.png
AlongToolbarOptions.png (7.3 KiB) Viewed 38308 times
Figure 1. Options toolbar.

Contents: This shows the text to be aligned. You can edit it at any time to change the text.
Height: This is the height of the text. Again you can change it at any time.
Direction: These two buttons indicate whether to draw the text clockwise or counterclockwise.
Fit: If checked then the text is adjusted to fit the length of the line, arc or circle.

This starts by opening the standard text dialogue, letting you enter the text you want, and the font and height.
When you click OK, you are prompted to select an entity. If you select an entity that is not a line, arc or circle, then a warning is printed in the command line. Once a valid entity is selected, you are prompted for the position for the text, and a preview is shown of the text.
Once you click to place the text, the prompt continues to ask for position. If you click another point, another copy of the text is placed at that point. You can change the options in the toolbar to alter the text, height, direction and fit of the text before clicking again. In fact, you can alter these before clicking for the first time.
AlongLine.png
AlongLine.png (19.2 KiB) Viewed 38308 times
Figure 2. Text Along a Line

The line was drawn from left to right, so it's angle is zero. The text above the line is drawn clockwise, and the text below the line is drawn counterclockwise. If the angle of the line was 180 degrees then the text below the line is drawn clockwise, and the text above the line is drawn counterclockwise. Use the direction keys to alter this. This changes the angle of the text to match the angle of the line.
I produced this in one use of the command. I entered the text in the text dialogue and then chose the line. I chose the clockwise direction key, and unchecked 'Fit' (if it was checked). Then I chose the left point of the line. Next I chose the counterclockwise button, and clicked the right point of the line. Then I checked 'Fit' and chose the point for the counterclockwise text under the line. I then chose the clockwise button, and selected the point for the text above the line. I could have also altered the text and its height in the same command.
Finally, you are not constrained to placing the text along the line. You can actually place it anywhere in the drawing.
AlongArc.png
AlongArc.png (21.98 KiB) Viewed 38308 times
Figure 3. Text Along an Arc or Circle

This shows you can place text along an arc, but you are not constrained to placing the text on the arc. But this alters the radius of the arc, so as the mouse pointer gets closer, or further away from the centre of the arc, the arc gets smaller, or bigger, and the text is adjusted to that arc.
This was also produced in one use of the command, like the line drawing above. This time I also changed the text in the contents box.
You can place this anywhere in the drawing, but remember the arc radius gets bigger or smaller.

If you select a circle, this works exactly like the arc. But because the circle has no startpoint or endpoint, if you use 'Fit', the last character of the text is placed immediately before the first character of the text. To get a gap, add one or more spaces to the start or end of the text.

As you get closer to the centre of the arc, you should reduce the height of the text, because the text can get jumbled up, or look slightly misplaced.

I have attached the file 'TextAlong.zip'. This contains a directory called 'TextAlong'. Unzip this directory and place it in the directory 'scripts/Misc/MiscDraw'.

I hope you find this useful, and if you find any bugs, let me know.

Regards

riverbuoy
Attachments
TextAlong.zip
(78.78 KiB) Downloaded 1177 times

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

Re: Arc Text

Post by Husky » Sun May 28, 2017 6:22 am

Hi riverbuoy :D
riverbuoy wrote:I hope you find this useful, and if you find any bugs, let me know.

Regards

riverbuoy
Yes, I find it useful particularly for QCAD/CAM user! It would be nice if this feature would also work - one day - on Polylines and Splines ...

Question: e_surprised

I have trouble on Arcs and Circles to have the right Angle for each letter to the center of the chosen entity. I tried different fonts and alignments .... Is there a trick for me to fix that?
Husky-2017.05.27-02.png
Husky-2017.05.27-02.png (55.09 KiB) Viewed 38305 times
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."

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

Re: Arc Text

Post by riverbuoy » Sun May 28, 2017 3:42 pm

Hi Husky,

Thanks for your feedback.
Husky wrote:It would be nice if this feature would also work - one day - on Polylines and Splines ...
I actually had the idea of doing this for ellipses, splines and polylines, which is why I used 'along' in the name. But when I started to try to do it, I realised the maths is beyond me at the moment. e_confused
Husky wrote:I have trouble on Arcs and Circles to have the right Angle for each letter to the center of the chosen entity. I tried different fonts and alignments .... Is there a trick for me to fix that?
Sorry, this was my fault. I was using the bottom left corner to rotate the letters, and should have been using the bottom centre point. I have now changed this, but it means you have to place the text using the centre point of the first character.

This is turning out to be trickier than I thought. :roll:

However, I have also added an option for letter spacing. This only applies to the arc or circle option at the moment.

This still needs more work.

Anyway, two files have been altered, 'TextAlong.js' and 'TextAlong.ui'. I have attached them. Replace the existing files in 'scripts/Misc/MiscDraw/TextAlong'.

Perhaps you could let me know how you get on.

Thanks

Regards

riverbuoy
Attachments
TextAlong.ui
(3.88 KiB) Downloaded 1169 times
TextAlong.js
(10.91 KiB) Downloaded 1093 times

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

Re: Arc Text

Post by Husky » Sun May 28, 2017 11:12 pm

riverbuoy wrote:I actually had the idea of doing this for ellipses, splines and polylines, which is why I used 'along' in the name. But when I started to try to do it, I realised the maths is beyond me at the moment. e_confused
That would be perfect .............................. and I'm pretty confident you will find a solution. I know you! :wink:
riverbuoy wrote:However, I have also added an option for letter spacing. This only applies to the arc or circle option at the moment.
Yep - the spacing is the other thing and my concern is that will be a really challenge for you. I think the problem is based on the proportional-pitch for each letter. Hmmmmmmmmmmmm an old Typewriter Font with a fixed-pitch could work - Ok, I'm kidding. :D

I confess that I used "brutal" letter combinations for my test and the result is accordingly. Sure you are already aware of it ...
Husky-2017.05.28-05.png
Husky-2017.05.28-05.png (108.84 KiB) Viewed 38282 times
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."

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

Re: Arc Text

Post by riverbuoy » Tue May 30, 2017 3:16 am

Hi Husky,

Thanks again for your efforts. It was very useful.

It was obvious that the letter 'I' was in the wrong place, after any other character. After staring at it for a long time, the answer finally dawned on me. The spacing between successive letters was wrong. This was not obvious, looking at 'ABC' for example, it looked correct because the letters are approximately the same size.

This involves changes to one file - 'TextAlong.js', which I have attached. Replace the existing file with this one.

Note: The spacing still only applies to the arc or circle option (more work to do), and I forgot to mention that the 'Spacing' option has no effect if 'Fit' is checked.

Anyway, perhaps you could let me know what you think. Please be as 'brutal' as you want.

Regards

riverbuoy
Attachments
TextAlong.js
(10.5 KiB) Downloaded 1094 times

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

Re: Arc Text

Post by Husky » Tue May 30, 2017 7:15 am

riverbuoy wrote:Anyway, perhaps you could let me know what you think. Please be as 'brutal' as you want.
I bended the tool with all nasty tricks I could imagine - the spacing was just nice working! I see that you still need to put more work into the tool but till now I think the Letter angle and the spacing works already good on lines, arcs and circles!
Husky-2017.05.29-01.png
Husky-2017.05.29-01.png (45.87 KiB) Viewed 38257 times
Regards
Husky
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."

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

Re: Arc Text

Post by riverbuoy » Mon Jun 19, 2017 11:41 pm

Hi

This is an update to 'TextAlong'. It now supports the alignment points,
scrunch.png
scrunch.png (41.01 KiB) Viewed 38195 times
The above screenshot shows that the text can be scrunched together depending on the alignment point chosen.
On the left, the text is using the 'bottom center' alignment point. The clockwise text is spaced correctly, but the counter clockwise text is scrunched up a bit. You can use the spacing setting to insert more space between the letters. In this case, the text has a height of 2, and a spacing of 0.5 makes the text look better in the bottom 'COUNTER-CLOCKWISE TEXT'.
Similarly, on the right, the 'top center' alignment point is used. In this case the clockwise text is scrunched up, and the counter clockwise text is spaced correctly. Again, using a spacing of 0.5, makes the text look better, as in the top 'CLOCKWISE TEXT'.

Secondly the 'Fit' option now works correctly. Currently the 'Fit' option extends beyond the endpoints of the arc by half the width of the first and last characters.

This involves changes to one file - 'TextAlong.js', which I have attached. Replace the existing file with this one.

regards

riverbuoy
Attachments
TextAlong.js
(11.89 KiB) Downloaded 1087 times

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

Re: Arc Text

Post by Husky » Wed Jun 21, 2017 5:00 am

Again - one step further. Thank you!
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."

TSG
Premier Member
Posts: 337
Joined: Thu Oct 08, 2015 9:39 am
Location: Germany

Re: Arc Text

Post by TSG » Wed Jun 21, 2017 9:56 am

Nice work, but your script doesn't work in a German QCAD Pro version (selection fails).
Is it possible to get a language independent version?

regards Thomas
Ich will nicht streiten. Ich will nur deutlich machen, dass ich Recht habe und DU NICHT.

User avatar
andrew
Site Admin
Posts: 9019
Joined: Fri Mar 30, 2007 6:07 am

Re: Arc Text

Post by andrew » Wed Jun 21, 2017 10:04 am

riverbuoy: entityTypeToString returns the entity type translated to the current locale.

You can use the enum returned by entity.getType() instead:

Code: Select all

var type = entity.getType();
if (type !== RS.EntityLine && type !== RS.EntityArc && type !== RS.EntityCircle) {
...
}

Code: Select all

type = this.entity.getType();

...

switch (type) {
    case RS.EntityLine:
        ...
        break;
    case RS.EntityArc:
        ...
        break;
    case RS.EntityCircle:
        ...
        break;
}

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

Re: Arc Text

Post by riverbuoy » Thu Jun 22, 2017 1:00 am

Hi Andrew,

Thanks for the fix.

Here is the fixed file.

Regards

riverbuoy
Attachments
TextAlong.js
(11.89 KiB) Downloaded 1048 times

TSG
Premier Member
Posts: 337
Joined: Thu Oct 08, 2015 9:39 am
Location: Germany

Re: Arc Text

Post by TSG » Thu Jun 22, 2017 8:34 am

Thanks a lot. Now it works in german version.
I found a little problem. When I try to fit a text on an arc the text is written backwards.
TextAlong.png
TextAlong.png (872.98 KiB) Viewed 38149 times
regards Thomas
Ich will nicht streiten. Ich will nur deutlich machen, dass ich Recht habe und DU NICHT.

TSG
Premier Member
Posts: 337
Joined: Thu Oct 08, 2015 9:39 am
Location: Germany

Re: Arc Text

Post by TSG » Thu Jun 22, 2017 12:15 pm

Sorry, now I see the truth ...
The text direction depends on the arc drawing direction.
If I draw the arc counterclockwise the text is written forward.
If I draw the arc clockwise the text is written backward.
That makes sense.

regards Thomas
Ich will nicht streiten. Ich will nur deutlich machen, dass ich Recht habe und DU NICHT.

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

Re: Arc Text

Post by Husky » Thu Jun 22, 2017 6:27 pm

TSG wrote:That makes sense.
Not in my point of view! :shock: I don't think you should put a user into a situation in which he/she has to watch the direction of an arc is drawn to get "the right outcome" of this or any other tool. Sure - the direction of an arc etc is very important for the CAD / Program itself but a user normally doesn't cares what happens behind closed curtains and how an arc is created - he/she just need an arc.

BTW: It doesn't works on lines - the tool ignores the direction of a line. What would here be the rule?
Work smart, not hard: QCad Pro
Win10/64, QcadPro, QcadCam version: Current.
If a thread is considered as "solved" please change the title of the first post to "[solved] Title..."

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

Re: Arc Text

Post by riverbuoy » Thu Jun 22, 2017 11:03 pm

Hi TSG and Husky,
TSG wrote:I found a little problem. When I try to fit a text on an arc the text is written backwards.
Actually this is a bug, which I missed. I have now, hopefully, fixed this. I have tested this with both types of arcs and it appears to be correct now. Perhaps you could test this for me. I have attached the altered file.
Husky wrote:BTW: It doesn't works on lines - the tool ignores the direction of a line. What would here be the rule?
The text angle is set to the angle of the line. If the angle of the line is zero degrees, then the text angle is set to zero, when the direction is clockwise. If the angle of the line is 180 degrees, then the text angle is set to 180 degrees when the direction is clockwise. So the text starts at the start point and goes towards the end point of the line, when the direction is clockwise. If you change the direction to counter-clockwise, then 180 degrees is added to the text angle, so the text now starts at the endpoint of the line and goes towards the start point.
Hopefully this clears the confusion.

Regards

riverbuoy
Attachments
TextAlong.js
(12 KiB) Downloaded 1363 times

Post Reply

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