TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: STEVEDALLAS on February 11, 2008, 11:44:38 AM
-
I know this has probably been posted a few times on here, but here goes.
I need a lisp that can create a new, custom linetype with text in it, per whatever text I type in (such as E or EM or TV)
I have one but it screws up time after time. My lines that I create are not consistent.
Can anyone help?
-
Here is a quickie:
(defun c:makelt (/ str file fn exprt)
(setq str (getstring T "\n Enter string for linetype: ")
file (strcat (getvar 'dwgprefix)
(vl-filename-base (getvar 'dwgname))
"_mylt.lin"
)
fn (open file "w")
exprt (getvar 'expert)
)
(write-line (strcat "*" str ", ---" str "---") fn)
(write-line
(strcat "A,0.5,-0.05,[\""
str
"\",STANDARD,S=0.1,R=0.0,X=-0.0,Y=-.05],"
(rtos (* -0.1 (strlen str))2 3)
)
fn
)
(close fn)
(setvar 'expert 5)
(command ".-linetype" "load" "*" file "")
(setvar 'expert exprt)
(vl-file-delete file)
(princ)
)
-
Here is a quickie:
It may be a quickie, but it sure is a goodie. Thanks for sharing it. I can make use of this one.
-
Glad you can use it Gary :)
-
Very slick there Ron. 8-)
-
Very slick there Ron. 8-)
Thanks :)
-
NICE ONE, RON.
Just what I needed.
-
basic question:
How did you come up with the numbers in the linetype definition (such as S, R, X,Y, etc.)?
The look calculated/specific.
Thanks again.
-
basic question:
How did you come up with the numbers in the linetype definition (such as S, R, X,Y, etc.)?
The look calculated/specific.
Thanks again.
I think I pulled the numbers from a similar linetype in the acad.lin file.
I updated the code above to adjust the gap so the text is always centered regardless of the string length.
-
Thanks Ron
-
You're welcome.
-
Ron:
I reduced the text size on what you posted.
My original intent was to simply reduce the text scale in the linetype from 0.1 to 0.05
My efforts completely threw the centering off.
I can not seem to get it corrected.
Can you advise?
Thanks again.
-
Try this:
(write-line
(strcat "A,0.5,-0.05,[\""
str
"\",STANDARD,S=0.05,R=0.0,X=-0.0,Y=-.025],"
(rtos (* -0.05 (strlen str))2 3)
)
fn
)
-
GOT IT THANKS.
-
what if you change the text style, i switched it to the one my company uses and it screws up the centering of the text
LT-E (arial narrow with italics)
-
what if you change the text style, i switched it to the one my company uses and it screws up the centering of the text
LT-E (arial narrow with italics)
You'll then have to fudge with the offsets to get it to fit properly. Namely, the X= and Y= numbers.
-
cool, thanks
-
Here is a quickie:
(defun c:makelt (/ str file fn exprt)
(setq str (getstring T "\n Enter string for linetype: ")
file (strcat (getvar 'dwgprefix)
(vl-filename-base (getvar 'dwgname))
"_mylt.lin"
)
fn (open file "w")
exprt (getvar 'expert)
)
(write-line (strcat "*" str ", ---" str "---") fn)
(write-line
(strcat "A,0.5,-0.05,[\""
str
"\",STANDARD,S=0.1,R=0.0,X=-0.0,Y=-.05],"
(rtos (* -0.1 (strlen str))2 3)
)
fn
)
(close fn)
(setvar 'expert 5)
(command ".-linetype" "load" "*" file "")
(setvar 'expert exprt)
(vl-file-delete file)
(princ)
)
Hello!
It will be possible to update this routine to allow the creation of linetypes with special characters?
-
Give this one a try. Welcome to the swamp :)
(defun c:makelt (/ dashlen def exprt file fn i
ltdef str strw txtgap txthgt txtstyle x
rjp-txtwdth _rtos rjp-substrsnvalid
)
(vl-load-com)
(defun rjp-txtwdth (str hgt style / d e pts)
;;Returns textstring width, gap from insertion point to start of text, and height
(if (setq e (entmakex (list '(0 . "TEXT")
'(100 . "AcDbEntity")
'(100 . "AcDbText")
'(8 . "rjp-tmptxtlayer")
'(10 0. 0. 0.)
(cons 40 hgt)
(cons 1 str)
(cons 7 style)
)
)
)
(progn (setq pts (textbox (entget e)))
(setq d (distance (car pts) (list (caadr pts) (cadar pts))))
(entdel e)
)
)
(list d (caar pts) (- (cadadr pts) (abs (cadar pts))))
)
(defun rjp-substrsnvalid (str / bad)
(setq
bad (mapcar '(lambda (x) (cons (chr x) (chr (- x 6)))) (vl-string->list "<>/\\:?*|,=~;\""))
)
(apply 'strcat
(mapcar '(lambda (x)
(if (snvalid x)
x
(strcat "inv_" (cdr (assoc x bad)))
)
)
(mapcar 'chr (vl-string->list str))
)
)
)
(defun _rtos (real) (vl-prin1-to-string real))
;; Check for metric
(if (zerop (getvar 'measurement))
(setq i 1)
(setq i 25.4)
)
;;Set these numbers to preference
(setq dashlen 0.25)
(setq txtgap 0.025)
(setq txthgt 0.075)
;;-------------------------------
(setq txtstyle (getvar 'textstyle))
(if
(and (setq str (getstring t "\nEnter string to use in linetype: "))
(not (zerop (strlen str)))
(setq def (rjp-substrsnvalid str))
(setq txthgt (* i
(cond ((getreal (strcat "\nEnter height of text [<" (_rtos txthgt) ">]: ")))
(txthgt)
)
)
)
(setq dashlen (* i
(cond ((getreal (strcat "\nEnter dash length [<" (_rtos dashlen) ">]: ")))
(dashlen)
)
)
)
(setq strw (rjp-txtwdth str txthgt txtstyle))
(setq file (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) "_mylt.lin"))
(setq fn (open file "w"))
(setq exprt (getvar 'expert))
)
(progn
(setq ltdef (strcat "\n*"
def
", ---"
str
"---\n"
"A,"
(_rtos dashlen)
",-"
(_rtos (abs (- txtgap (cadr strw))))
",[\""
str
"\","
txtstyle
",S="
(_rtos txthgt)
",R=.0,X=-.0,Y=-"
(_rtos (* (caddr strw) 0.5))
"],-"
(_rtos (+ txtgap (car strw) (cadr strw)))
)
)
(write-line ltdef fn)
(close fn)
(setvar 'expert 5)
(cond
((not (tblsearch "ltype" def))
(command "._-linetype" "load" "*" file "")
(princ ltdef)
(princ (strcat "\nLinetype " def " loaded..."))
)
((and (not (initget 1 "Y N")) (eq (getkword "\nLinetype exists... Reload it? [Y/N]") "Y"))
(command "._-linetype" "load" "*" file "")
(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport)
(princ ltdef)
(princ (strcat "\nLinetype " def " reloaded..."))
)
)
(setvar 'expert exprt)
(vl-file-delete file)
)
)
(princ)
)
-
ronjonp
Excellent. I appreciate the your attention.
But even now, I dare to ask you to consider also provide for user input of variable that defines the axis of the segment dash
(_rtos (* (caddr strw) 0.5))
Thank you.