• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

write a text string with variable font size

  • Thread starter Thread starter Angelo2449
  • Start date Start date

Angelo2449

Guest
Hello everyone,
I look for the solution with which to write, by autolisp, a text string with variable height.
the text should be so structured:
- first n characters with height 20
- the following with height 5
all in a string.
Does anyone have an idea?
Thank you.
 
We enter the world of mtext, where formatting can lead to suicide.
an example land-land could be this:
Code:
(entmake)
(list
(cons 0 "mtext")
(cons 8 "pippo")
(cons 100 "acdbentity")
(cons 100 "acdbmtext")
(cons 10 '(5.0 10.0))
(cons 40 20.0)
(cons 7 "arial")
(cons 1 "testo alto 20 {\\h0.25x;testo alto cinque}")
)
)
that creates a mtext
in point (5,10)
on the "pippo" layer
with font = "arial"
with initial height = 20
with final height = 20x0.25 = 5
 
Thanks for the answer, I'm trying to figure out how to intervene in the program that I try hard to write (as you will understand I am a neophyte and try to draw from the experience of those who know more than me!).
This is the branch of the dxf file that my program generates:
circle
8
circles ' layer
62
1
10
1498789.579000 ' coordinate east circle
20
5042431.954000' coordinated north circle
40
0.50
0
text
5
0
8
text
62
1
10
Community law, EC Court of Justice
20
5042432.454000' coordinated north text
40
40
0.40
50
0
1
p1 (165.03) - 4420571.480,698896.546,4529362.926' string written text
0
clearly the string will have to be formatted so that the same will result then with variable height (before the large indent (0.40) from the small indent (0.05).
Thank you.
 
Hello everyone,
according to the indications of the friends who answered me, I wrote this code:
Code:
(defunc c:change height (/)

(setq string nil)
(sing)
(= string nil)
(setq string (entsel "\nselect the point name: ")
)

(setq string (entget (car string)))
(setq txt1 (cdr 1 string)))
(princ txt)

(setq text1 (substr txt1 1 3)) ; the first 3 characters
(Sectq text2 (substr txt1 4) ; from 4 onwards)
;(command "_mtext" pauses "_j" "_bl" "_w" 50 (strcat text1 "{\\h0.2x;" text2 "}") ") "
)
the result is a string with two heights of the text placed at a point identified by the command _mtetxt

I would like, however, that instead of asking for the insertion point of the new text, the program would update directly the selected string at the start (string).
Thank you.
 
how I can apply your instructions to:
Code:
(setq string "aaaaaabbbbbbb")
...... instructions
(setq result "aaaaa" with height 20 and "bbbbb" with height 5)
grazie.
 
....I would like, however, that instead of asking for the insertion point of the new text, the program would update directly the selected string at the start (string).
Thank you.
only mtexts can display different text heights, if the string you want to change belongs to a mtext you can update it, otherwise not.
Give us some information, I haven't figured out what's going on.
 
I wrote this code that works benign:
Code:
(defunc c:change height (/)

(setq string nil)
(sing)
(= string nil)
(setq string (entsel "\nselect the point name: ")
(setq element (car string))
)

(setq string (entget (car string)))
(setq txt1 (cdr 1 string)))

(setq cxy (assoc 10 string))
(setq cox)
(setq coy (caddr cxy)
(princ " - ")
(princ cox)
(princ ",")
(princ coy)
(princ " - ")
(command "_erase" element ")
(setq coox (rtos cox)
(setq cooy (rtos coy)
(setq address (strcat coox "," cooy))

(setq text1 (substr txt1 1 3)) ; the first 3 characters
(Sectq text2 (substr txt1 4) ; from 4 onwards)
;(command "_mtext" "50,50" "_j" "_bl" "_w" 50 (strcat text1 "{\\h0.2x;" text2 "}") "
(command "_mtext" address "_j" "_bl" "_w" 50 (strcat text1 "{\\h0.2x;" text2 "}") ")
)
as you can see, the program changes the selected text in a modified with variable height (according to the set parameters).
if you can optimize it, advice is welcome.
I would now like, with code implementation, to write the routine that, by examining all strings contained in > .dwg < and intercepted through a code (e.g. > "**" + element number < contained in the single string, to change each intercepted string.
Two problems:
1 - the number of strings present (in > .dwg < there are only strings and circles written by reading the > .dxf < file generated by basic).
2 - search for each string cyclically with an appropriate command.
Thank you.
 
Code:
[B](setq ttt (ssget "_x"(0. "text,mtext")(1. "a*,b*")))[/B] [COLOR="#FF0000"]capture all text and mtext starting with "a" or "b"[/COLOR]
[B](repeat (setq n (sslength ttt))[/B] [COLOR="#FF0000"][/COLOR][COLOR="#FF0000"];Life for the number of objects found[/COLOR]
[B](setq tt (ssname ttt)[/B] [COLOR="#FF0000"];ad each cycle provides [B]name[/B] of the object[/COLOR]
[B]<[COLOR="#0000FF"]do something to the object[/COLOR]>[/B]
)
 
thanks gp, it works perfectly.
I have implemented your code with my :
Code:
(defun c:cstr (/)

(setq ttt (ssget "_x"(0 . "text,mtext")(1 . "p*"))))

(repeat (setq n (sslength ttt))
(setq tt (ssname ttt (setq n (1-n))))

(setq string)
(setq txt1 (assoc 1 string))
(setq txt1 (cdr txt1))
(setq lungh (- (strlen txt1) 63)

(setq cxy (assoc 10 string))
(setq cox)
(setq coy (caddr cxy)
(command "_erase" tt")
(setq coox (rtos cox)
(setq cooy (rtos coy)
(setq address (strcat coox "," cooy))

(setq text1 (substr txt1 1 lungh)); point name
(setq text2 (substr txt1 (+ lungh 1))); from the name of the point onwards
(command "_mtext" address "_j" "_bl" "_w" 50 (strcat text1 "{\\h0.1x;" text2 "}") ")

)
)
and I get the result I wanted, thank you again.
 
thanks gp,
I put into practice jl your suggestion and apparently everything works, this is code :
Code:
(defun cstr (/)

(setq ttt (ssget "_x"((0 . "text,mtext")(1 . "p*")))))

(repeat (ssslength ttt)
(setq tt (sssname ttt (setq n (1-n))))

(setq string (entget tt))
(setq txt1 (assoc 1 string))
(setq txt1 (cdr txt1)
(setq lungh (- (strlen txt1) 60)

(setq cxy (assoc 10 string))
(setq cox (cadr cxy))
(setq coy (caddr cxy))
(command "_erase" tt "")
(setq coox (rtos cox))
(setq cooy (rtos coy))
(setq indirizzo (strcat coox," cooy))

(setq testo1 (substr txt1 2 lungh) ; nome del punto
(setq testo2 (substr txt1 (+ lungh 2)) ; dal nome del punto in poi
(command "_mtext" indirizzo "_j" "_bl" "_w" 50 (strcat testo1 "{\\h0.1x;" testo2 "}")

)
strings are changed and appear in the desired way or, the first part with large characters and the second with small characters.
the next step, when I select the string, the same is returned not as it appears but containing the control characters used to achieve the > large - small < effect.
This is the code of command including the results:
Code:
(defun reference (/)

(if)
(progn)
(startapp "c:\\transformer\\\helpinlinea\\rif.exe "c:\\transformer\\\helpinlinea\\rif.tkn")
(exit)
)
)

(if)
(alert "the reference line has already been inserted")
)

(Sectq and 1 nil)
(sing)
(= ed1 nil)
(setq ed1 (entsel "\nselect the reference line : ")))
)

(setq ed1 (entget (car ed1)))
(setq txt1 (cdr 1 ed1))
(setq txt2 (cdr 10 ed1))
(princ "\n")
(princ txt)
;p2 (164.93)
(princ "\n")
(princ txt)
;(1.4988e+06 5.04244e+06 0.0)
(princ "\n")

(setq lung (strlen txt1))
(setq lungnomebase (- lung 77)
(setq basic name (substr txt1 1 lungnomebase))
(princ "\n")
(princ basic name)
;p2
(princ "\n")
(princ lung)
;
(princ "\n")

(setq notax)

(setq station)
(setq notex (getstring t "\nnota de station > cm sr re st pi to ct < : ")))

(cond)
((= notax "cm" ) (setq notax "miniated nail"))
((= notax "sf" ) (setq notax "spigolo fabricated"))
((= notax "sr" ) (setq notax "spigolo fence"))
((= notax "re" ) (setq notax "recinction"))
((= notax "st" ) (setq notax "sign to the ground"))
((= notex "pi" ) (setq notax "picchetto"))
((= notax "to" ) (setq notax "tombino"))
((= notax "ct" ) (setq notax "centro tombino"))
)

(setq pos1 (- (strlen txt1) 58)
(setq xyz (substr txt1 pos1 34)
(princ "\n")
(princ xyz)
;4420568.319,698901.058,4529365.156
(princ "\n")

(setq cxb (substr xyz 1 11)
(princ cxb)
;4420568.319
(princ "\n")
(setq cyb (substr xyz 13 10)
(princ cyb)
;698901.058
(princ "\n")
(setq czb (substr xyz 24 11)
(princ czb)
;4529365.156
(princ "\n")

(setq cxbb (atof cxb))
(princ cxbb)
;4.42057e+06
(princ "\n")
(setq cybb (atof cyb))
(princ cybb)
;69890
(princ "\n")
(setq czbb)
(princ czbb)
;4.52937+06
(princ "\n")

(setq note2 (strcat name puntobase " - " notax " - " station))
(setq reference (strcat "1|" station "|" xyz "|0.000 wgs84-rtf2000]|" note2 "|")
(setq secondline "6|l1|14122017-20:12|14122017-20:12|rtk|pdop=1|")
(setq stringa1 (strcat reference "" second line)
(princ string)
;1|80000|4420568.319,698901.058,4529365.156|0.000 wgs84-rtf2000]|p2 - recinzione - 80000| 6|l1|14122017-20|:1214122017-20:12|rtk|pdop=1|
(princ "\n")

(Sectq and nil)

(sing)
(and (/= re "s") (/= re "n")
(s/n) : ")
(setq re (getstring))
(seq re (strcase re)
)

(f)
(= s)
(progn)
(setq fp1 (open "c:\\\trasformer\\\\librettopregeo.dat" "a"))
(write-line reference fp1)
(write-line secondline fp1)
(close fp)
)
)

(setq ind)
(setq index(strcat ind nomepuntobase))

(seq primariga 1)
(alert string)

)
as you notice, to get the string as I need it, I have to purify it.
the code annexed herein is included in a much longer term > pre.lsp <, after the first use of the reference < command, to a new reference of the same, I obtain this error :
Code:
impossible to call (command) from* error* without first calling (*push-error-using-command*).
we recommend conversion (command) of calls to (command-s).
and to continue I must recharge again > pre.lsp <, so to every use of > reference <!
I can't find what causes this behavior.
Thank you.
 
Now I don't have time to look into your list, but the first thing that comes to mind is that you have to reset the variables after using the routine, that is, "locate them."
to do this you must place them after the bar in the line of the defun, e.g.:(defun c:pippofranco ( / ed1 txt1 txt2)so every launch starts virgins.
 
thanks gp,
I have made the variables private but the problem mentioned above remains or I cannot reload the command.
I also noticed another problem:
applying the command that modifies the strings, if there are two overlapping strings even partially, the relative modified texts do not appear in the position in which they should be but result with the same horizontal alignment, one above the other.
Hard!
Thank you.
(p.s., it seems to me that the problem manifests itself with the original zoom, if I go on the particular, it seems to me, everything is fine. )
 
when inserting entities into the drawing you must take into account the active osnap that interfere by changing the insertion point.
this function is used to activate / deactivate osnap:
; turn on or off osnap, equivalent to f3 key
(defun setosnaponoff(mode/osmode)
(setq osmode (getvar "osmode")
(if)
(if) osmode 16384)
(Setvar "osmode" (- osmode 16384))
)
(if) osmode 16384)
(setvar "osmode" (+ osmode 16384))
)
)
)
 
thanks rpor66, successfully executed with osmode set to 0.
Now we need to find the solution to the other problem reported.
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top