TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: STEVEDALLAS on February 11, 2008, 11:44:38 AM

Title: need a lisp to create a custom linetype with text in it.
Post 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?
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: ronjonp on February 11, 2008, 03:30:20 PM
Here is a quickie:

Code: [Select]
(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)
)
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: GDF on February 12, 2008, 10:21:47 AM
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.
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: ronjonp on February 12, 2008, 10:24:22 AM
Glad you can use it Gary :)
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: CAB on February 12, 2008, 11:33:33 AM
Very slick there Ron. 8-)
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: ronjonp on February 12, 2008, 12:20:32 PM
Very slick there Ron. 8-)

Thanks :)
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: STEVEDALLAS on February 12, 2008, 01:38:24 PM
NICE ONE, RON.
Just what I needed.
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: STEVEDALLAS on February 12, 2008, 01:49:43 PM
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.
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: ronjonp on February 12, 2008, 03:39:23 PM
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.
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: STEVEDALLAS on February 12, 2008, 05:26:48 PM
Thanks Ron
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: ronjonp on February 12, 2008, 05:29:06 PM
You're welcome.
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: STEVEDALLAS on February 13, 2008, 10:57:35 AM
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.
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: ronjonp on February 13, 2008, 11:25:39 AM
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
  )
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: STEVEDALLAS on February 13, 2008, 11:39:09 AM
GOT IT THANKS.
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: alanjt on March 03, 2008, 09:49:55 AM
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)
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: Josh Nieman on March 03, 2008, 09:52:43 AM
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.
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: alanjt on March 03, 2008, 10:48:49 AM
cool, thanks
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: teknomatika on May 10, 2013, 04:44:40 AM
Here is a quickie:

Code: [Select]
(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?
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: ronjonp on May 10, 2013, 10:37:11 AM
Give this one a try. Welcome to the swamp :)

Code: [Select]
(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)
)
Title: Re: need a lisp to create a custom linetype with text in it.
Post by: teknomatika on May 10, 2013, 10:59:59 AM

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.