News:

When replying to a specific statement be sure to quote the previous post.

Main Menu
TurboCAD 2026 Platinum box
Now available

TurboCAD 2026.2

The latest update for TurboCAD 2026. It installs over any 2026 build and keeps your activation, drawings and settings. Get it from the Start Page or Help > Check for Update.

Constrain Text Horizontally or Vertically; using PPM scripting

Started by Alvin Gregorio, September 04, 2021, 10:01:12 AM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Alvin Gregorio

[carried over from another thread]
Quote from: nikkipollard on September 04, 2021, 07:51:31 AM
Quote from: Jarmi on September 04, 2021, 06:48:24 AM
The ability to constrain text horizontally or vertically.

Would be useful for symbols such as these, where I currently have to superimpose two blocks; one with the symbol, the other with the text as a block attribute:

We had a similar conversation recently.
You might want to try using a parametric symbol instead of a block.
You can add the text Rotation angle as a Parameter.

I was thinking-- in PPM script composing-- to assign different Rotation parameters for:  Everything in the Parametric Symbol except the Text, and the Text.
Then Output everything.
Like in the below.

(from the .tcw's File Summary:)
>The only object is a Paramtric Symbol that I wrote the PPM script for.
>Select the object and-- in Selection Info Palette-- exand the section and subsection Parametric Symbol | Symbol Parameters.
>There you can adjust the different values entries.
>Remember to use Decimal Code for Color changes!  These work accurately in the English system; will need to add a conversion for Metric system.

Units(1[in]);
//Note: If changing Units to mm, Color paramaters Decimal Code will have to be attended to.
//      There a couple of ways of achieving that.

S=Parameter("Symbol/Scale",1,Interval(.0001,1000000000));
PWC=Parameter("Symbol/Pen Width, Cirle",0,Interval(-5,100));
PWA=Parameter("Symbol/Pen Width, Arrow",0,Interval(-5,100));
PlClr=Parameter("Symbol/Arrow and Arc Color (Decimal Code)",0,Interval(-4,16777215));
Rt=Parameter("Symbol/Rotate Symbol",0,Interval(-360,360));

F=Fillet(0.00000001)
R=(S/2);

A=Polyline(Point(R,0),Point(R,-R),Fillet(R),
Point(0,-R),Point(-R,-R),Fillet(R),Point(-R,0));

P=Polyline(
Point(R,0),
Point(R+(R*.34),0),
Point(0,R+R/2),
Point(-R-(R*.34),0),
Point(-R,0),
Point(-R,R),
Fillet(R-.0000000001),
Point(0,R),
Point(R,R),
Fillet(R-.0000000001),
F,
Point(R,0),
F);

SA1=SetProperties(A,"PenWidth"=PWC,"PenColor"=PlClr);

SP1=SetProperties(P,"PenWidth=0",
"BrushStyle"="SOLID","PenColor"=PlClr);

RtPGrp=RotateZ(Group(SA1,SP1),Rt);

Output(RtPGrp)
//--------------------------

Word=Parameter("Font/Text String","A",TEXT);
Ft=Parameter("Font/Text Font","Arial",FONT);
FtSc=Parameter("Font/Text Scale",1,Interval(.0001,1000000000));
RtTxt=Parameter("Font/Rotate Text",0,Interval(-360,360));
FtBld=Parameter("Font/TextBold?",0,CHECKBOX);
FtClr=Parameter("Font/Text Color (Decimal Code)",0,Interval(-4,16777215));

Txt=Text(Word, Tfont, Tstyle);
Tfont= TextFont(2,S*FtSc,0,Ft);
Tstyle= TextStyle(CENTER,MIDDLE,BLD);
Bld=(BOLD);
BLD=IF(FtBld==0,0,Bld);

TxtClr=SetProperties(Txt,"PenColor"=FtClr);
RotTxt=RotateZ(TxtClr,RtTxt);

Output(RotTxt)

Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

nikkipollard

#1
I always try to Add a Rotate - or a Flip Parameter to ppms. It makes them more versatile.
Here is my take on this (and a previous from a long time ago) conversation.
I use Parameter points - so that the line length can be adjusted. - using edit nodes or stretch.
They do work better in 2d mode.

Alvin if you change units at the top of your script to mm - for the metric people - The colours will work without doing anything strange.
It is only when you put a symbol with units that are different to the drawing units that the script will try to convert the colour code to units of the drawing.

I am confused by your fillet size. Why do you need to subtract 0.000001 from R? Doesn't R work?
I was trying to work out how you calculated where the points would be to make that fillet work. I have always used arcs so that is new to me.

Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

nikkipollard

#3
Here is my detail marker

I figured out a way  to measure the font - so that you can get the expected text height (not the text box height)
- regardless of the selected font.
The attached screen shot is what I am trying to calculate. It is still a bit hit and miss when trying to actually centre the text because the reference points arent quite where I think they should be. But the text height is right.

Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Torfinn

V20, V21, 2015 > 2024  Platinum
Deluxe 2015/ 16/ 19
RedSDK enabled
Windows 10 Home Premium (20H2/ 19042.1083) 64 bit, 32 GB
NVIDIA Geforce GTX 780m, 1 GB

Alvin Gregorio

carried over from a different thread
Quote from: Torfinn on September 05, 2021, 08:08:53 AM
Non Rotatable work like a charm in ppm, but can look a bit funny in any perspective view.
Maybe better to rotate the txt opposite from the arrow.
Attached is from Alvins Arrow, with a little adjustment on the txt, bottom left is Top view.

Torfinn


Torfinn-- Out of curiosity, I would be interested in seeing the scripting line(s) you used to make the Text "Non-Rotatable".  I tried previously, using SetProperties in what MacroRecorder indicated to me: "TextTransformation"=512; but that would not work for me in a PPM script.
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

Torfinn

I just added to your line text transformation, so;
TxtClr=SetProperties(Txt,"PenColor"=FtClr,"TextTransformation" = 512);

Torfinn
Edit;
Hmmm, it don't work in v 2021 today, as we got a new built last night.
The rotated character just blink and disappear.

I was in RedSDK in v 2021, in GDI it still work :)
V20, V21, 2015 > 2024  Platinum
Deluxe 2015/ 16/ 19
RedSDK enabled
Windows 10 Home Premium (20H2/ 19042.1083) 64 bit, 32 GB
NVIDIA Geforce GTX 780m, 1 GB

nikkipollard

Quote from: Alvin Gregorio on September 06, 2021, 08:44:45 AM
carried over from a different thread
Quote from: Torfinn on September 05, 2021, 08:08:53 AM
Non Rotatable work like a charm in ppm, but can look a bit funny in any perspective view.
Maybe better to rotate the txt opposite from the arrow.
Attached is from Alvins Arrow, with a little adjustment on the txt, bottom left is Top view.

Torfinn


Torfinn-- Out of curiosity, I would be interested in seeing the scripting line(s) you used to make the Text "Non-Rotatable".  I tried previously, using SetProperties in what MacroRecorder indicated to me: "TextTransformation"=512; but that would not work for me in a PPM script.

I think I misunderstood what non rotating text meant. I didn't realise it depended on the view, I thought it was relative to the world X and Y Rotating - Or not rotating the text seems like a better option.  But remember that a ppm has it's own coordinate system  so if you rotate the ppm the user coordinate system should rotate too. I am not sure I completely understand why the ppm I shared (with parameter points) can be rotated in 2d mode and the Text still stays upright. But I am not complaining. The text works the way I thought non rotate text would work.
Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

#8
Quote from: nikkipollard on September 06, 2021, 11:58:54 PM
... I am not sure I completely understand why the ppm I shared (with parameter points) can be rotated in 2d mode and the Text still stays upright....

Just like I did Nikki, you have a rotate Parameter for the Text's angle characteristic.

You have:
>in the Output: Marker
>the Marker identifier is to a Group function, which includes Marker4
>the Marker4 identifier is a Move function which includes the identifier t2
>t2 is a RotateZ function on a Move function; that Move function specifies t1 being the Object to move, the Parameter RT being the angle to rotate the Move
>the Parameter RT is inserted with a default value of 0 (degrees)

That's why the Text in the Parametric Symbol stays at 0° when rotated.
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

nikkipollard

#9
Yes Alvin I know what I did. But if I didn't have the parameter points in the ppm and I rotated the ppm the text would rotate when the ppm rotates. With the parameter points in the symbol the behaviour is different.
Try rotating your ppm and then mine and you will see the difference.

Both these ppms were rotated using the Rotation Handle in 2d mode.
It seems like my ppm (with Parameter points) stays in the world work plane whilst your ppm acts like a block - as expected.
Would you even need a "rotate Symbol " Parameter. if there was 1 parameter point in your symbol?

Just tested it -
If you put one Parameter Point in - The Symbol wont Rotate at all. You would need 2 parameter 2 points. and then measure  the rotation angle - like I did


Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

Quote from: nikkipollard on September 07, 2021, 05:20:27 AM
Yes Alvin I know what I did. But if I didn't have the parameter points in the ppm and I rotated the ppm the text would rotate when the ppm rotates. With the parameter points in the symbol the behaviour is different.
Try rotating your ppm and then mine and you will see the difference.

Yes, I see the difference.
Which behavior do you prefer or think is more 'correct'-- yours? or mine?
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)

Torfinn

Most common is like Alvin did i believe, most read friendly is like Nikki did IMO, also the sample TS of the tread this spring out from had horizontal txt in his example with rotated arrow's.

Torfinn
V20, V21, 2015 > 2024  Platinum
Deluxe 2015/ 16/ 19
RedSDK enabled
Windows 10 Home Premium (20H2/ 19042.1083) 64 bit, 32 GB
NVIDIA Geforce GTX 780m, 1 GB

nikkipollard

I don't Know in this situation it's very convenient. Not so much when you want it to behave like a block. But all you have to do is switch to 3d mode.
I experimented a bit with your code. Now I can change the rotation of your arrow in the inspector bar.
I think that's pretty cool

Units(1[in]);
//Note: If changing Units to mm, Color paramaters Decimal Code will have to be attended to.
//      There a couple of ways of achieving that.

S=Parameter("Symbol/Scale",1,Interval(1,1000000000));
PWC=Parameter("Symbol/Pen Width, Cirle",0,Interval(-5,100));
PWA=Parameter("Symbol/Pen Width, Arrow",0,Interval(-5,100));
PlClr=Parameter("Symbol/Arrow and Arc Color (Decimal Code)",0,Interval(-4,16777215));
//Rt=Parameter("Symbol/Rotate Symbol",0,Interval(-360,360));

F=Fillet(0.001)
R=(S/2);

P0 = ParameterPoint(0,0,0,0)
x0=PointX(P0)
y0=PointY(P0)
P1 = ParameterPoint(1,1,0,0)
x1=PointX(P1)
y1=PointY(P1)
sx=x1-x0
sy=y1-y0
alfa=atan(sy,sx)


A=Polyline(Point(R,0),Point(R,-R),Fillet(R),
Point(0,-R),Point(-R,-R),Fillet(R),Point(-R,0));

P=Polyline(
Point(R,0),
Point(R+(R*.34),0),
Point(0,R+R/2),
Point(-R-(R*.34),0),
Point(-R,0),
Point(-R,R),
Fillet(R-.0000000001),
Point(0,R),
Point(R,R),
Fillet(R-.0000000001),
F,
Point(R,0),
F);

SA1=SetProperties(A,"PenWidth"=PWC,"PenColor"=PlClr);

SP1=SetProperties(P,"PenWidth=0",
"BrushStyle"="SOLID","PenColor"=PlClr);

RtPGrp=Group(SA1,SP1);
ShowArrow=RotateZ(Move(RtPGrp,x0,y0),alfa,x0,y0)
Output(ShowArrow)
//--------------------------

Word=Parameter("Font/Text String","A",TEXT);
Ft=Parameter("Font/Text Font","Arial",FONT);
FtSc=Parameter("Font/Text Scale",1,Interval(.0001,1000000000));
RtTxt=Parameter("Font/Rotate Text",0,Interval(-360,360));
FtBld=Parameter("Font/TextBold?",0,CHECKBOX);
FtClr=Parameter("Font/Text Color (Decimal Code)",0,Interval(-4,16777215));

Txt=Text(Word, Tfont, Tstyle);
Tfont= TextFont(2,S*FtSc,0,Ft);
Tstyle= TextStyle(CENTER,MIDDLE,BLD);
Bld=(BOLD);
BLD=IF(FtBld==0,0,Bld);

TxtClr=SetProperties(Txt,"PenColor"=FtClr);
RotTxt=RotateZ(TxtClr,0);
Show1 = Move(RotTxt,x0,y0)
RefP=RefPoint(x0,y0)

Output(RefP,Show1)

Nikki
TC20 platinum, TC 2015 platinum
TC 2017 with lightworks
TC 2021 platinum
Windows 11 Home 22h

Alvin Gregorio

Quote from: nikkipollard on September 07, 2021, 06:19:06 AM
I don't Know in this situation it's very convenient. Not so much when you want it to behave like a block. But all you have to do is switch to 3d mode.
I experimented a bit with your code. Now I can change the rotation of your arrow in the inspector bar.
I think that's pretty cool
]code[

I ran my script and Nikki's script through and online "text difference checker"-- hwww.diffchecker.com

Pretty handy for stuff like this.   Timesaver.
Alvin Gregorio
TurboCAD: v2024_Plat (31.0.77.1); v2022_Plat; v2020_Plat; v2019_DL; v20.2_PP
Lenovo Thinkpad P20Y laptop; Windows 11 Pro; i7-11800H 2.30GHz, 8-core; 32GB RAM; NVIDIA T1200
3D_Printer: Ender-3 S1 (NOT Pro)