Author Topic: need a lisp to create a custom linetype with text in it.  (Read 15566 times)

0 Members and 1 Guest are viewing this topic.

Josh Nieman

  • Guest
Re: need a lisp to create a custom linetype with text in it.
« Reply #15 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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: need a lisp to create a custom linetype with text in it.
« Reply #16 on: March 03, 2008, 10:48:49 AM »
cool, thanks
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

teknomatika

  • Guest
Re: need a lisp to create a custom linetype with text in it.
« Reply #17 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?

ronjonp

  • Needs a day job
  • Posts: 7526
Re: need a lisp to create a custom linetype with text in it.
« Reply #18 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)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

teknomatika

  • Guest
Re: need a lisp to create a custom linetype with text in it.
« Reply #19 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.