Jump to content

Get lines with all layer properties using lisp


Nikon

Recommended Posts

Posted (edited)

Is it possible to get lines with all layer properties using lisp, and next to each line, specify the name of the layer.
Maybe there is already such a lisp?

 

Edited by Nikon
Link to comment
Share on other sites

You can be lucky owe me a cup of coffee.

 

; Oct 2022
; By AlanH makes a legend of used layers and blocks.

(defun RemoveDupes (InLst / OutLst CarElm)
  (while InLst
  (setq
    InLst (vl-remove (setq CarElm (car InLst)) (cdr InLst))
    OutLst (cons CarElm OutLst)
  )
  )
)

(defun makelegend ( /  ss lst lstrem obj pt pt2 ltname x val bname)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setvar 'textstyle "Standard")
(setq oldlay (getvar 'clayer))
(setvar 'clayer "0")
(setvar 'ctab "Model")
(setq ss (ssget "X" (list (cons 410 "Model"))))
(setq lst '())
(repeat (setq x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq lst (cons (list (vla-get-layer obj) (vlax-get obj 'Linetype)) lst))
)
(setq lst (RemoveDupes lst))
(setq lst (vl-sort lst '(lambda (x y) (<  (car x) (car  y)))))


(setq pt (getpoint "\nPick point for line legend "))
(setq pt2 (mapcar '+ pt (list 125.0 0.0 0.0)))

(foreach ltname lst
(command "line" pt (mapcar '+ pt (list 20.0 0.0 0.0)) "")
(command "chprop" (entlast) "" "LA" (car ltname) "LT" (cadr ltname) "S" 0.25 "")
(command "text" (mapcar '+ pt (list 25.0 0.0 0.0)) 2.5 0.0 (car ltname))
(setq pt (mapcar '+ pt (list 0.0 10.0 0.0)))
)

(setq lst '())
(setq attreq 0)

(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  (if (= (vla-get-objectname obj) "AcDbBlockReference")
  (setq lst (cons (vla-get-name obj) lst))
  )
)
(setq lst (RemoveDupes lst))
(setq lst (vl-sort lst '(lambda (x y) (<  x  y))))

(foreach val lst
(if (wcmatch val "*U#*" )
(setq lst (vl-remove val lst))
)
)

(foreach bname lst
  (progn
    (command "text" (mapcar '+ pt2 (list 25.0 0.0 0.0)) 2.5 0.0 bname)
    (command "-insert" bname pt2 1 1 0)
    (setq pt2 (mapcar '+ pt2 (list 0.0 10.0 0.0)))
(setq obj (vlax-ename->vla-object (entlast)))
(vla-GetBoundingBox obj 'minpoint 'maxpoint)
(setq pointmin (vlax-safearray->list minpoint))
(setq pointmax (vlax-safearray->list maxpoint))
(setq ht (- (cadr pointmax)(cadr pointmin)))
(setq xscale (/ 5.0  ht))
(vla-put-xscalefactor obj xscale)
(vla-put-yScaleFactor obj xscale)

  )
)
 
(setvar 'osmode oldsnap)
(setvar 'clayer  oldlay)
(princ)
)
(makelegend)

 

  • Like 1
Link to comment
Share on other sites

Posted (edited)
On 19.05.2024 at 01:40, BIGAL said:

You can be lucky owe me a cup of coffee.

@BIGAL  Thanks a lot! It works great!

 

coffee.png

Edited by Nikon
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...