TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: reltro on May 03, 2014, 02:32:39 PM
-
Hey People...
Short time ago I wrote a python-script to extract information out of a .pt3 (Font) to generate a lisp-function wich calculates the vertices of a text for the use with grvecs...
curves in the original font are ignored.
Wanna share some Fonts, and if somebody wants, the python-script...
greets
reltro
-
It's interesting, I would like to see the python script too :-D
-
@NICK_VNV: sent it as PM
Greets
reltro
-
Thanks! It works fine :-)
But i can't find the way for covert my font to *.pt3 format which contains not only english letters? (I want to use other languages too) Maybe somebody know?
-
Excellent! Can I get python code too?
-
I also love solution, provided by Lee Mac at his Grtext lisp demo.
http://lee-mac.com/grtext.html (http://lee-mac.com/grtext.html)
It's very flexible on my mind.
(http://imageshack.com/a/img835/8826/y6dd.png)
-
@Inciner:
Python-script as PM
Oh, thats nice... I used LeeMac's Grtext too, but I never got the Point how the Chars are calculated; nice method... :)
But in use the displayed text wasn't very good to read, so I decided to go for an other approach...
@NICK_VNV:
I never used a not englisch/latin Font because I don't need them... So, I can't help.
Beside, there is much more information in the .pt3 than the python-script extract.
If u find a way to use non-latin chars/fonts let us know how to do...
Greets reltro
-
I was drawing cyrillic symbols for Lee Mac's solution right in Libre Office whole yesterday.
Thank you for script! =)
-
If you entmakex your text there is no need
for transforming fonts.
(defun c:test (/ etxt p prvtext scl str txt txtp xog yof)
(setq xof 30
yof -30
scl (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
)
(while (= 5 (car (setq p (grread nil 13 0))))
(setq p (cadr p)
str (mapcar 'rtos p)
txtp (list (+ (car p) (* xof scl)) (+ (cadr p) (* yof scl)))
txt (strcat "X= " (car str) "\\PY= " (cadr str))
)
(setq etxt (list (cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 62 2)
(cons 100 "AcDbMText")
(cons 10 txtp)
(cons 40 (* 15 scl))
(cons 1 txt)
)
)
(if prvtext (entdel prvtext))
(setq prvtext (entmakex etxt))
)
(entdel prvtext)
)
-
Hey ymg...
it is a nice approach...
but, in this case u need also an *error*-handler, or better a vl-catch-all-apply... If not, the mtext will be there if the user hits ESC for Example; but I'm sure u knew this ;)
I prefer the grvecs-method to avoid something like this.
Also, if I need to draw a lot of stuff I prefer the grvecs-method... Put all together in a list and draw it ;)
Greets
-
reltro,
If you want to catch Escape Key, here is the modified code:
(defun c:test (/ etxt p prvtext scl str txt txtp xog yof)
; Error Handler by ElpanovEvgenyi ;
(defun *error* (msg)
(mapcar 'eval varl)
(if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")))
(princ (strcat "\nError: " msg))
)
(if prvtext (entdel prvtext))
(and *AcadDoc* (vla-endundomark *AcadDoc*))
(princ)
)
(setq varl '("CLAYER" "OSMODE" "CMDECHO" "DIMZIN")
varl (mapcar (function (lambda (a) (list 'setvar a (getvar a)))) varl)
)
(setq xof 30
yof -30
scl (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
)
(while (= 5 (car (setq p (grread nil 13 0))))
(setq p (cadr p)
str (mapcar 'rtos p)
txtp (list (+ (car p) (* xof scl)) (+ (cadr p) (* yof scl)))
txt (strcat "X= " (car str) "\\PY= " (cadr str))
)
(setq etxt (list (cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 62 2)
(cons 100 "AcDbMText")
(cons 10 txtp)
(cons 40 (* 15 scl))
(cons 1 txt)
)
)
(if prvtext (entdel prvtext))
(setq prvtext (entmakex etxt))
)
(entdel prvtext)
(*error* nil)
)
-
whats about this? ;)
(vl-catch-all-apply '(lambda (/) (C:test)))
and then pressing Escape? ;)
(sry, just trolling a lil bit)
Greets
-
Would rather use an error handler.
The vl-catch-all-apply will not reset your sysvars or your layer.
ymg
-
whats about a combination of *error*-handler and vl-catch-all-apply?
(defun c:test (/ etxt p prvtext scl str txt txtp xog yof ini*error* catch)
(defun ini*error* (name sysvars / *doc*)
(vla-startundomark (setq *doc* (vla-get-activedocument (vlax-get-acad-object))))
(eval
(list 'defun '*error* '(msg / )
(list
(lambda (name prevErrorHandler SysVars *doc* currentcmdecho / )
(mapcar
'setvar
(mapcar 'car SysVars)
(mapcar 'cdr SysVars)
)
(vla-endundomark *doc*)
(setq *error* prevErrorHandler)
(if msg
(progn
(setvar 'cmdecho 0)
(command-s "_.undo" 1 "")
(setvar 'cmdecho currentcmdecho)
(princ "\n*** error ***\n")
(princ (strcat "\t" name ": " (vl-princ-to-string msg) "\n"))
(*error* msg)
(princ)
)
)
)
(vl-princ-to-string name)
*error*
(list 'quote
(mapcar
'(lambda (a / ) (cons a (getvar a)))
sysvars
)
)
*doc*
(getvar 'cmdecho)
)
)
)
)
(ini*error*
"Grread with MTEXT - ymg"
'("CLAYER" "OSMODE" "CMDECHO" "DIMZIN")
)
(setvar 'osmode 0)
(setq catch
(vl-catch-all-apply
'(lambda ( / )
(setq xof 30
yof -30
scl (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
)
(while (= 5 (car (setq p (grread nil 13 0))))
(setq p (cadr p)
str (mapcar 'rtos p)
txtp (list (+ (car p) (* xof scl)) (+ (cadr p) (* yof scl)))
txt (strcat "X= " (car str) "\\PY= " (cadr str))
)
(setq etxt (list (cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 62 2)
(cons 100 "AcDbMText")
(cons 10 txtp)
(cons 40 (* 15 scl))
(cons 1 txt)
)
)
(if prvtext (entdel prvtext))
(setq prvtext (entmakex etxt))
)
)
)
)
(entdel prvtext)
(if (vl-catch-all-error-p catch)
(progn
(*error* (vl-catch-all-error-message catch))
catch
)
(*error* nil)
)
)
I'm not sure if this is good practice...
reltro
-
whats about a combination of *error*-handler and vl-catch-all-apply?
(defun c:test (/ etxt p prvtext scl str txt txtp xog yof ini*error* catch)
(defun ini*error* (name sysvars / *doc*)
(vla-startundomark (setq *doc* (vla-get-activedocument (vlax-get-acad-object))))
(eval
(list 'defun '*error* '(msg / )
(list
(lambda (name prevErrorHandler SysVars *doc* currentcmdecho / )
(mapcar
'setvar
(mapcar 'car SysVars)
(mapcar 'cdr SysVars)
)
(vla-endundomark *doc*)
(setq *error* prevErrorHandler)
(if msg
(progn
(setvar 'cmdecho 0)
(command-s "_.undo" 1 "")
(setvar 'cmdecho currentcmdecho)
(princ "\n*** error ***\n")
(princ (strcat "\t" name ": " (vl-princ-to-string msg) "\n"))
(*error* msg)
(princ)
)
)
)
(vl-princ-to-string name)
*error*
(list 'quote
(mapcar
'(lambda (a / ) (cons a (getvar a)))
sysvars
)
)
*doc*
(getvar 'cmdecho)
)
)
)
)
(ini*error*
"Grread with MTEXT - ymg"
'("CLAYER" "OSMODE" "CMDECHO" "DIMZIN")
)
(setvar 'osmode 0)
(setq catch
(vl-catch-all-apply
'(lambda ( / )
(setq xof 30
yof -30
scl (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
)
(while (= 5 (car (setq p (grread nil 13 0))))
(setq p (cadr p)
str (mapcar 'rtos p)
txtp (list (+ (car p) (* xof scl)) (+ (cadr p) (* yof scl)))
txt (strcat "X= " (car str) "\\PY= " (cadr str))
)
(setq etxt (list (cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 62 2)
(cons 100 "AcDbMText")
(cons 10 txtp)
(cons 40 (* 15 scl))
(cons 1 txt)
)
)
(if prvtext (entdel prvtext))
(setq prvtext (entmakex etxt))
)
)
)
)
(entdel prvtext)
(if (vl-catch-all-error-p catch)
(progn
(*error* (vl-catch-all-error-message catch))
catch
)
(*error* nil)
)
)
I'm not sure if this is good practice...
reltro
I did this several years ago, but it may be of interest: http://www.theswamp.org/index.php?topic=30660.0
-
I also love solution, provided by Lee Mac at his Grtext lisp demo.
http://lee-mac.com/grtext.html (http://lee-mac.com/grtext.html)
It's very flexible on my mind.
(http://imageshack.com/a/img835/8826/y6dd.png)
Thank you Inciner! :-)
That is a fantastic way to visualise the vector encoding.
If you entmakex your text there is no need
for transforming fonts.
Similar to Alan's linked example, this is also the method I used in my very old Dynamic Information (http://lee-mac.com/dinfo.html) program; however, I much prefer the far cleaner solution of displaying text using temporary vector graphics, rather than many thousands of additions/deletions/modifications to the drawing database (which may also bloat UNDO cache files).
-
Bloating the UNDO cache is definitively a possibility.
Can be prevented that turning UNDO Off at beginning of routine
and back on as routine completes.
Creating and Deleting entities as far as I am concerned is a moot point
as it is designed for this exact purpose. On top of that those grvec vectors
have to live somewhere while you display then.
ymg
-
On top of that those grvec vectors have to live somewhere while you display then.
Yes, but the overhead will be substantially less.
-
On top of that those grvec vectors have to live somewhere while you display then.
:) they live somewhere in the wonderland but I have not to be worried about where this place is :)
-
...however, I much prefer the far cleaner solution of displaying text using temporary vector graphics, rather than many thousands of additions/deletions/modifications to the drawing database (which may also bloat UNDO cache files).
I've never thought about this as an issue. Is this something that has always occurred, or just in newer versions? I do notice that, if I've had c3d open all day, doing a lot of heavy work, c3d can become a little laggy, but restarting acad (not computer) will solve the issue.
-
...however, I much prefer the far cleaner solution of displaying text using temporary vector graphics, rather than many thousands of additions/deletions/modifications to the drawing database (which may also bloat UNDO cache files).
I've never thought about this as an issue. Is this something that has always occurred, or just in newer versions? I do notice that, if I've had c3d open all day, doing a lot of heavy work, c3d can become a little laggy, but restarting acad (not computer) will solve the issue.
I can't say whether it has always been the case, but I've certainly seen some pretty large UNDO.ac$ files in the past, with the 'running out of system memory' message not long to follow. I should imagine restarting AutoCAD cleans up the UNDO cache and the application starts afresh on the next run.
-
AlanJT,
That Undo file certainly grow in the case of such a program
where you keep drawing and erasing to do animation.
However a simple command like
(vl-cmdf "_AUTO" "_OFF")
prevents it from growing.
Been like that for as long as I can remember. (And that's a long way!)
ymg
-
AlanJT,
That Undo file certainly grow in the case of such a program
where you keep drawing and erasing to do animation.
However a simple command like
(vl-cmdf "_AUTO" "_OFF")
prevents it from growing.
Been like that for as long as I can remember. (And that's a long way!)
ymg
I assume you mean
(vl-cmdf "_UNDO" "_AUTO" "_OFF")
-
I assume you mean
Code: [Select]
(vl-cmdf "_UNDO" "_AUTO" "_OFF")
Indeed! :embarrassed:
Sorry! about that.
ymg
-
Interesting. Is there an adverse effect to turning off auto all the time?
Keep in mind, I've not experienced undo issues, nor do I create/erase objects for animation.
-
Execution speed, especially when batch processing dwgs in the thousands may upset peers that prefer to do things the hard (manual) way.
-
Execution speed, especially when batch processing dwgs in the thousands may upset peers that prefer to do things the hard (manual) way.
Then I should be worried. :lol:
-
My favorite setting:
(vl-cmdf "_undo" "_control" "_none")
:evil:
-
Interesting. Is there an adverse effect to turning off auto all the time?
I normally turn it back on on completion of the routine
in the Error Handler, in order to catch the "Escape" artist.
But I certainly like having undo available specially when
testing routines.
ymg
-
Hey People...
Short time ago I wrote a python-script to extract information out of a .pt3 (Font) to generate a lisp-function wich calculates the vertices of a text for the use with grvecs...
curves in the original font are ignored.
Wanna share some Fonts, and if somebody wants, the python-script...
greets
reltro
Great works !
dose these font-vectors maked by some tools ,which has a function tanslate shape into vectors ?
-
hi all, here i attempted dxf-modify method in order to justify code 71 .Then i applied a lambda to determine the best quadrant if the text reaches each end corner, so it can be seen (not exceed screen or hidden)
lastly, applied to suit current UCS. thank you
i remarked with double asterisk **
;"Grread with MTEXT by ymg"
; version: ymg -> reltro -> alanjt
; http://www.theswamp.org/index.php?action=post;msg=521731;topic=46966.30
; similar reference tread http://www.lee-mac.com/grtext.html
; ** --> partial commented with ** attempted by hanhphuc
(defun c:test (/ etxt p prvtext scl str txt txtp xog yof ini*error* catch
vec ); **
(defun ini*error* (name sysvars / *doc*)
(vla-startundomark (setq *doc* (vla-get-activedocument (vlax-get-acad-object))))
(eval
(list 'defun '*error* '(msg / )
(list
(lambda (name prevErrorHandler SysVars *doc* currentcmdecho / )
(mapcar
'setvar
(mapcar 'car SysVars)
(mapcar 'cdr SysVars)
)
(vla-endundomark *doc*)
(setq *error* prevErrorHandler)
(if msg
(progn
(setvar 'cmdecho 0)
(command-s "_.undo" 1 "")
(setvar 'cmdecho currentcmdecho)
(princ "\n*** error ***\n")
(princ (strcat "\t" name ": " (vl-princ-to-string msg) "\n"))
(*error* msg)
(princ)
)
)
)
(vl-princ-to-string name)
*error*
(list 'quote
(mapcar
'(lambda (a / ) (cons a (getvar a)))
sysvars
)
)
*doc*
(getvar 'cmdecho)
)
)
)
)
(ini*error*
"Grread with MTEXT - ymg"
'("CLAYER" "OSMODE" "CMDECHO" "DIMZIN")
)
(setvar 'osmode 0)
(setq catch
(vl-catch-all-apply
'(lambda ( / )
;|**
(setq
xof 30
yof -30
scl (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
)|; ;**
(while
(= 5 (car (setq p (grread nil 13 0))))
(setq Vcp (trans (getvar "viewctr") 1 0) ; ** setq vcp
scl (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
p (trans (cadr p) 1 0 t) ; ** trans
vec ; ** setq vec
(mapcar
'(lambda (x)
(equal (mapcar '>= p Vcp) x)
)
'((T T T) (nil T T) (nil nil T) (T nil T))
) ; ** mapcar
)
(cond ((nth 0 vec)
(setq xof -15
yof -15
)
)
((nth 1 vec)
(setq xof 15
yof -15
)
)
((nth 2 vec)
(setq xof 15
yof 15
)
)
((nth 3 vec)
(setq xof -15
yof 15
)
)
) ; ** cond
(setq
;;; p (cadr p) ; ** removed
str (mapcar 'rtos (trans p 0 1)) ; ** trans UCS
txtp (list (+ (car p) (* xof scl)) (+ (cadr p) (* yof scl)))
txt (strcat "X= " (car str) "\\PY= " (cadr str))
)
(setq etxt (list (cons 0 "MTEXT")
(cons 100 "AcDbEntity")
(cons 62 2)
(cons 100 "AcDbMText")
(cons 10 txtp)
(cons 40 (* 10 scl))
(cons 1 txt)
)
)
;| **
(if prvtext
(entdel prvtext)
)
|; ;**
(if
prvtext
(mapcar '(lambda (x y) (dxfmod prvtext x y))
'(10 40 1 62) (list txtp (* 10 scl) txt 2))
(setq prvtext (entmakex etxt))
) ; ** dxfmod & entmakex
(cond ((nth 0 vec) (dxfmod prvtext 71 3))
((nth 1 vec) (dxfmod prvtext 71 1))
((nth 2 vec) (dxfmod prvtext 71 7))
((nth 3 vec) (dxfmod prvtext 71 9))
) ; ** cond
;;;(setq prvtext (entlast)) ; **
); while
(if prvtext (entdel prvtext))
(princ )
)
)
)
)
;;;(setq prvtext (entmakex etxt)); **
(if (vl-catch-all-error-p catch)
(progn
(*error* (vl-catch-all-error-message catch))
catch
)
(*error* nil)
)
; ** hp#007
(defun dxfmod (_e _i val / lst ) ; (dxfmod entity index new-value )
(setq lst (entget _e)) ; old dxf list
(if (assoc _i lst)
(entmod (subst (cons _i val)
(assoc _i lst)
lst
)
) ;subst old to new
(entmod (append lst (list (cons _i val)))) ; add new to dxf
) ; if
(princ)
); **
-
Hey People...
Short time ago I wrote a python-script to extract information out of a .pt3 (Font) to generate a lisp-function wich calculates the vertices of a text for the use with grvecs...
curves in the original font are ignored.
Wanna share some Fonts, and if somebody wants, the python-script...
greets
reltro
Great works !
dose these font-vectors maked by some tools ,which has a function tanslate shape into vectors ?
Hey chlh_jd...
Sry for the late response...
hm, I think I don't fully understand ur question... Wich kind of shapes do u mean?
The PythonScript I wrote is just a "parser" wich extracts the information found in a .pc3... Just hacked it togheter to fit my needs, so there is no functionality other than calculating the vectors of the Font... Specially for the use with (grvecs ...)
Sent u the PythonScript so u can look at ur own...
reltro
-
reltro,
I'd like to have a look at that script too, if you don't mind.
-
reltro,
I'd like to have a look at that script too, if you don't mind.
sure...
attached is a .py-file (python 3.3 on windows)
use this (http://onlinefontconverter.com/) to convert a font-file to .pt3 and then drag'n'drop it on the .py
greets reltro
-
Thanks, bookmarked.
-
Hey People...
Short time ago I wrote a python-script to extract information out of a .pt3 (Font) to generate a lisp-function wich calculates the vertices of a text for the use with grvecs...
curves in the original font are ignored.
Wanna share some Fonts, and if somebody wants, the python-script...
greets
reltro
Great works !
dose these font-vectors maked by some tools ,which has a function tanslate shape into vectors ?
Hey chlh_jd...
Sry for the late response...
hm, I think I don't fully understand ur question... Wich kind of shapes do u mean?
The PythonScript I wrote is just a "parser" wich extracts the information found in a .pc3... Just hacked it togheter to fit my needs, so there is no functionality other than calculating the vectors of the Font... Specially for the use with (grvecs ...)
Sent u the PythonScript so u can look at ur own...
reltro
Thank you very much .