Author Topic: CREATE A CUSTOM LINETYPE USING A LISP?  (Read 7315 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Re: CREATE A CUSTOM LINETYPE USING A LISP?
« Reply #15 on: April 25, 2006, 03:20:14 AM »
This didn't work for me

error message
Code: [Select]
Enter line text: <EXISTING>

"C:\DOCUME~1\ANDY~1.HUD\LOCALS~1\Temp\\Temp.lin": Invalid file name.

Error: bad argument type: stringp nil

Also would it be pissible to change this lisp so that the text height could be specified? for the LTscale we use the scale of the drawing, so a text height of  is unreadable.
« Last Edit: April 25, 2006, 03:36:05 AM by Andy Hudson »
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: CREATE A CUSTOM LINETYPE USING A LISP?
« Reply #16 on: April 25, 2006, 09:43:35 AM »
See this line.
Code: [Select]
(setq lt_textl2 (strcat "A,.5,-.2,[\"" linet "\"," tstyle ",S=.1,R=0.0,X=-0.1,Y=-.05],-" linet_w
The S=.1 is the text height when the Text Style height is zero. Otherwise that value is multiplied by the text height.
The value is then multiplied by the LTscale. Because my LTscale is 48 the resulting text height is (48 * .1)= 4.8"
So adjust that S=.1 to suite you situation.

And for the file error try this version.
Code: [Select]
;;================================================================================
;;  Original routine by D. Marker 10-08-1999
;;  revised by CAB 04/21/2006
;;  Added:
;;    Error handler
;;    Text style create
;;    Check for illegal characters in linetype
;;    Delete temp file
;;    Removed dependency on folder C:/temp
;;  Rev 04/25/06
;;    Changed Temp file location
;;   
;;================================================================================
(defun c:ltxt (/ clayer expert linet_w linet_x lt_file lt_fname lt_textl1 lt_textl2
               lt_var2 lt_var3 pnt pt tstyle acadfn
              )
  ;; error function & Routine Exit
  (defun *error* (msg)
    (if
      (not
        (member
          msg
          '("console break" "Function cancelled" "quit / exit abort" "")
        )
      )
       (princ (strcat "\nError: " msg))
    )

    ;;reset all variables here
    (setvar "expert" expert)
    (setvar "clayer" clayer)
    (setvar "celtype" "bylayer")
    (setvar "CMDECHO" usercmd)
  ) ;end error function

  ;;  check for invaild characters "\"*,/:;<=>?\\`|"
  (defun badchar (name / flag)
    (mapcar '(lambda (x)
               (if (vl-position x '(34 42 44 47 58 59 60 61 62 63 92 96 124))
                 (setq flag t)
               )
             )
            (vl-string->list name)
    )
    flag
  )

  (setq usercmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq clayer (getvar "clayer"))
  (setq expert (getvar "expert"))
  (or linet (setq linet "XX"))
  ;;  get line label, disallow numbers as first character
  (while
    (progn
      (setq linet_x (getstring t (strcat "\nEnter line text: <" linet ">")))
      (if (/= linet_x "")
        (setq linet linet_x)
      )
      (if (badchar linet)
        (not (alert "ERROR - Bad character in name."))
        nil
      )
    )
  )
  ;; (setq linet (strcase linet))
  (setvar "expert" 4)
  (setq linet_w (rtos (* (strlen linet) 0.1) 2 1))
  (if (or (tblsearch "style" "STANDARD")
          (entmake
            (list
              '(0 . "STYLE") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbTextStyleTableRecord") '(2 "STANDARD")
              '(70 . 0) '(40 . 0.0) '(41 . 1.0) '(50 . 0.0) '(71 . 0) '(42 . 5.0) '(3 . "simplex") '(4 . "")
             )
          )
      )
    (setq tstyle "STANDARD")
    (progn
      (alert "ERROR creating Standard Text Style")
      (*error* "") ; reset vars
      (exit)
    )
  )
 
  ;;  create a temp file & save the path to it
  (setq acadfn  (findfile "ACAD.PAT")
        lt_file (strcat (substr acadfn 1 (- (strlen acadfn) 8))"Temp.lin")
  )
  ;;(setq lt_file (strcat (getvar "SAVEFILEPATH") "/Temp.lin"))
  (setq lt_fname (open lt_file "w"))
  (setq lt_textl1 (strcat "*" linet "," linet "----" linet "----" linet "----" linet))
  (setq lt_textl2 (strcat "A,.5,-.2,[\"" linet "\"," tstyle ",S=.1,R=0.0,X=-0.1,Y=-.05],-" linet_w))
  (setq lt_var2 (write-line lt_textl1 lt_fname))
  (setq lt_var3 (write-line lt_textl2 lt_fname))
  (close lt_fname)
  ;; load the linetype
  (command "-linetype" "l" linet lt_file "")

  ;;  remove the temp file
  (vl-file-delete (findfile lt_file))

  (setvar "expert" expert)
  (command ".celtype" linet)
  (princ (strcat "\nCurrent Entity linetype set to:" linet))
  (princ)

  ;;  Create a pline with the new linetype
  (if (setq pnt (getpoint "\nPick start point:"))
    (progn
      (command "pline" pnt)
      (while (setq pt (getpoint (getvar "lastpoint")
                                "\nNext point or <Return to terminate>:"))
        (command pt)
      )
      (command)
      (command)
    )
  )
  (*error* "") ; reset vars
  (princ)
  (princ "\n \nLine-Text terminated.  Linetype set to BYLAYER:")
  (princ)
)
(princ " \n Line-Text Loaded... Enter LTXT to execute:")
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

hudster

  • Gator
  • Posts: 2848
Re: CREATE A CUSTOM LINETYPE USING A LISP?
« Reply #17 on: April 25, 2006, 11:40:10 AM »
CAB you are the man

Here is the modified version for a text height of 1.5

Code: [Select]
;;================================================================================
;;  Original routine by D. Marker 10-08-1999
;;  revised by CAB 04/21/2006
;;  Added:
;;    Error handler
;;    Text style create
;;    Check for illegal characters in linetype
;;    Delete temp file
;;    Removed dependency on folder C:/temp
;;  Rev 04/25/06
;;    Changed Temp file location
;;   
;;================================================================================
(defun c:ltxt (/ clayer expert linet_w linet_x lt_file lt_fname lt_textl1 lt_textl2
               lt_var2 lt_var3 pnt pt tstyle acadfn)
  ;; error function & Routine Exit
  (defun *error* (msg)
    (if
      (not
        (member
          msg
          '("console break" "Function cancelled" "quit / exit abort" "")
        )
      )
       (princ (strcat "\nError: " msg))
    )

    ;;reset all variables here
    (setvar "expert" expert)
    (setvar "clayer" clayer)
    (setvar "celtype" "bylayer")
    (setvar "CMDECHO" usercmd)
  ) ;end error function

  ;;  check for invaild characters "\"*,/:;<=>?\\`|"
  (defun badchar (name / flag)
    (mapcar '(lambda (x)
               (if (vl-position x '(34 42 44 47 58 59 60 61 62 63 92 96 124))
                 (setq flag t)
               )
             )
            (vl-string->list name)
    )
    flag
  )

  (setq usercmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (setq clayer (getvar "clayer"))
  (setq expert (getvar "expert"))
  (or linet (setq linet "XX"))
  ;;  get line label, disallow numbers as first character
  (while
    (progn
      (setq linet_x (getstring t (strcat "\nEnter line text: <" linet ">")))
      (if (/= linet_x "")
        (setq linet linet_x)
      )
      (if (badchar linet)
        (not (alert "ERROR - Bad character in name."))
        nil
      )
    )
  )
  ;; (setq linet (strcase linet))
  (setvar "expert" 4)
  (setq linet_w (rtos (* (strlen linet) 2) 2 1))
  (if (or (tblsearch "style" "STANDARD")
          (entmake
            (list
              '(0 . "STYLE") '(100 . "AcDbSymbolTableRecord") '(100 . "AcDbTextStyleTableRecord") '(2 "STANDARD")
              '(70 . 0) '(40 . 0.0) '(41 . 1.0) '(50 . 0.0) '(71 . 0) '(42 . 5.0) '(3 . "simplex") '(4 . "")
             )
          )
      )
    (setq tstyle "STANDARD")
    (progn
      (alert "ERROR creating Standard Text Style")
      (*error* "") ; reset vars
      (exit)
    )
  )
 
  ;;  create a temp file & save the path to it
  (setq acadfn  (findfile "ACAD.PAT")
        lt_file (strcat (substr acadfn 1 (- (strlen acadfn) 8))"Temp.lin")
  )
  ;;(setq lt_file (strcat (getvar "SAVEFILEPATH") "/Temp.lin"))
  (setq lt_fname (open lt_file "w"))
  (setq lt_textl1 (strcat "*" linet "," linet "----" linet "----" linet "----" linet))
  (setq lt_textl2 (strcat "A,5,-1,[\"" linet "\"," tstyle ",S=1.5,R=0.0,X=0.75,Y=-.75],-" linet_w))
  (setq lt_var2 (write-line lt_textl1 lt_fname))
  (setq lt_var3 (write-line lt_textl2 lt_fname))
  (close lt_fname)
  ;; load the linetype
  (command "-linetype" "l" linet lt_file "")

  ;;  remove the temp file
  (vl-file-delete (findfile lt_file))

  (setvar "expert" expert)
  (command ".celtype" linet)
  (princ (strcat "\nCurrent Entity linetype set to:" linet))
  (princ)

  ;;  Create a pline with the new linetype
  (if (setq pnt (getpoint "\nPick start point:"))
    (progn
      (command "pline" pnt)
      (while (setq pt (getpoint (getvar "lastpoint")
                                "\nNext point or <Return to terminate>:"))
        (command pt)
      )
      (command)
      (command)
    )
  )
  (*error* "") ; reset vars
  (princ)
  (princ "\n \nLine-Text terminated.  Linetype set to BYLAYER:")
  (princ)
)
(princ " \n Line-Text Loaded... Enter LTXT to execute:")
(princ)
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: CREATE A CUSTOM LINETYPE USING A LISP?
« Reply #18 on: April 25, 2006, 06:09:59 PM »
Glad I could help. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.