Author Topic: How to align text in this lisp  (Read 3318 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1421
How to align text in this lisp
« on: December 14, 2019, 05:40:15 AM »
Hi all,
I upgrade LEE lisp to mach my needs
and I want to make change so I want some one to help

Code - Auto/Visual Lisp: [Select]
  1. ;; Layer Legend  -  Lee Mac
  2. ;; Generates a set of lines at a user-specified point and of a given length
  3. ;; with associated layer name text sorted alphabetically for every layer in a drawing.
  4. ;; https://www.cadtutor.net/forum/topic/64214-legends-lisp/
  5.  
  6. (defun c:LLD () (c:LayerLegend))
  7.  
  8. (defun c:LayerLegend ( / df i l ln p1 pt sp dsc ent nm lst desc objs)
  9.  
  10.   (defun *error* (msg)
  11.     (LM:endundo (LM:acdoc))
  12.     (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
  13.       (princ (strcat "\nError: " msg))
  14.       )
  15.     (princ)
  16.     )
  17.   (defun layercount:assoc++ (key lst / itm)
  18.     (if (setq itm (assoc key lst))
  19.       (subst (cons key (1+ (cdr itm))) itm lst)
  20.       (cons (cons key 1) lst)
  21.       )
  22.     )
  23.   (if
  24.     (and
  25.       (setq pt (getpoint "\nSpecify Point for Legend: "))
  26.       (setq pt (trans pt 1 0))
  27.       (setq ln (* 100 (getvar 'TEXTSIZE)))
  28.       (setq sp (* 2.5 (getvar 'TEXTSIZE)))
  29.       (setq i -1)
  30.       )
  31.     (progn
  32.         (vlax-for obj blk
  33.           (setq lst (layercount:assoc++ (vla-get-layer obj) lst))
  34.           (if
  35.             (and
  36.               (= "AcDbBlockReference" (vla-get-objectname obj))
  37.               (= :vlax-true (vla-get-hasattributes obj))
  38.               )
  39.             (foreach att (vlax-invoke obj 'getattributes)
  40.               (setq lst (layercount:assoc++ (vla-get-layer att) lst))))))
  41.  
  42.       (while (setq df (tblnext "LAYER" (null df)))
  43.         (if (/= 16 (logand 16 (cdr (assoc 70 df))))
  44.           (setq l (cons (cdr (assoc 2 df)) l))
  45.           )
  46.         (setq l (acad_strlsort l))
  47.         )
  48.  
  49.     (foreach n l
  50.       (setq ent (vlax-ename->vla-object (tblobjname "LAYER" n)))
  51.       (setq objs (assoc n lst))
  52.       (setq objs (cdr objs))
  53.       (setq dsc (vlax-get-property ent 'Description))
  54.       (setq nm  (vlax-get-property ent 'name))
  55.       (entmakex (list
  56.                   (cons 0 "LINE")
  57.                   (cons 8 n)
  58.                   (cons 6 "ByLayer")
  59.                   (cons 62 256)
  60.                   (cons 10 (setq p1 (polar pt (* 1.5 pi) (* (setq i (1+ i)) sp))))
  61.                   (cons 11 (polar p1 0. ln))
  62.                   (cons 370 -1)
  63.                   )
  64.                 )
  65.  
  66.       (entmakex (list (cons 0 "TEXT")   ;***
  67.                  (cons 1 (strcat n " - Objs: " (itoa objs) " - Desc: " dsc))            ;* (the string itself)
  68.                  (cons 6 "BYLAYER")     ; Linetype name
  69.                  (cons 7 (getvar 'TEXTSTYLE))           ;* Text style name, defaults to STANDARD, not current
  70.                  (cons 8 n)             ; layer
  71.                  (cons 10 p1)           ;* First alignment point (in OCS)
  72.                  (cons 11 p1)           ;* Second alignment point (in OCS)
  73.                  (cons 39 0.0)          ; Thickness (optional; default = 0)
  74.                  (cons 40 (getvar 'TEXTSIZE))           ;* Text height
  75.                  (cons 41 1.0)          ; Relative X scale factor, Width Factor, defaults to 1.0
  76.                  (cons 62 256)          ; color
  77.                  (cons 71 0)            ; Text generation flags
  78.                  (cons 72 0)            ; Horizontal text justification type
  79.                  (cons 73 1)            ; Vertical text justification type
  80.                  (cons 210 (list 0.0 0.0 1.0))
  81.                  (cons 370 -1)
  82.                       )))
  83.   (princ)
  84.   )))
  85.  

ribarm

  • Gator
  • Posts: 3265
  • Marko Ribar, architect
Re: How to align text in this lisp
« Reply #1 on: December 14, 2019, 06:42:11 AM »
You could try to make ACAD_TABLE entity instead... Text inside cells would be aligned as your wish...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: How to align text in this lisp
« Reply #2 on: December 15, 2019, 12:14:40 AM »
If you use mtext a tab is supported, you can add tabs in a string using (chr 9)

(cons 1 (strcat n " - Objs:" (chr 9)  (itoa objs) (chr 9) " - Desc: " (chr 9) dsc)) ; not tested
A man who never made a mistake never made anything

Dlanor

  • Bull Frog
  • Posts: 263
Re: How to align text in this lisp
« Reply #3 on: December 15, 2019, 06:41:39 AM »
You could change the font to a monospaced eg Lucida Console which would make controlling the length of each sub string easier.