Author Topic: Change object/entity line type scale by layer name inside nested blocks  (Read 2749 times)

0 Members and 1 Guest are viewing this topic.

tive29

  • Guest
Googles this lisp sometime back. Was by Tharwat & Kent Cooper.
This lisp changes the linetype scale of the entities & object base on layername. But It does not change those that is inside nested blocks.
I now need it to change those inside nested blocks too.

Need help with the changes to include objects & entities inside nested blocks.

Thank you

Code: [Select]
(defun c:test (/ ly ss)
  ;; Tharwat 06.May.2014  ;;
  ;; altered for list-of-lists approach by Kent Cooper 14 May 2014 ;;
  (setq ly '(("Layer1" 0.5) ("Layer2" 0.75) ("Layer3" 1.5)))
  (if
    (setq ss
      (ssget "_X"
        (list
          '(0 . "CIRCLE,ARC,ELLIPSE,*LINE,RAY,HATCH,REGION")

            ;; [added RAY,HATCH,REGION (people should avoid Hatching on non-continuous-linetype

            ;; Layers, but they do honor linetypes and linetype scale) -- any other possibilities? Leaders

            ;; and Dimensions honor linetypes, but for some reason not linetype scale.]
          (cons 8 (apply 'strcat (mapcar '(lambda (u) (strcat (car u) ",")) ly)))
        ); list
      ); ssget
    ); setq
    ( (lambda (i / sn v)
        (while (setq sn (ssname ss (setq i (1+ i))))
          (if (vlax-write-enabled-p (setq v (vlax-ename->vla-object sn)))
            (vla-put-linetypescale v (cadr (assoc (cdr (assoc 8 (entget sn))) ly)))
          ); if
        ); while
      ); lambda
      -1
    )
  ); if
  (princ)
); defun
(vl-load-com)

ronjonp

  • Needs a day job
  • Posts: 7527
Try this:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ a b ly ss u)
  2.   ;; Tharwat 06.May.2014  ;;
  3.   ;; altered for list-of-lists approach by Kent Cooper 14 May 2014 ;;
  4.   (setq ly '(("Layer1" 0.5) ("Layer2" 0.75) ("Layer3" 1.5)))
  5.   (if (setq ss (ssget "_X"
  6.                       (list '(0 . "INSERT,CIRCLE,ARC,ELLIPSE,*LINE,RAY,HATCH,REGION")
  7.                             ;; [added RAY,HATCH,REGION (people should avoid Hatching on non-continuous-linetype
  8.                             ;; Layers, but they do honor linetypes and linetype scale) -- any other possibilities? Leaders
  9.                             ;; and Dimensions honor linetypes, but for some reason not linetype scale.]
  10.                             (cons 8 (apply 'strcat (mapcar '(lambda (u) (strcat (car u) ",")) ly)))
  11.                       )                 ; list
  12.                )                        ; ssget
  13.       )                                 ; setq
  14.     ((lambda (i / e sn tmp v)
  15.        (while (setq sn (ssname ss (setq i (1+ i))))
  16.          ;; RJP - 5.5.2017 removed vl & added nested items
  17.          (cond ((= "INSERT" (cdr (assoc 0 (entget sn))))
  18.                 (setq e (tblobjname "block" (cdr (assoc 2 (entget sn)))))
  19.                 (while (setq e (entnext e))
  20.                   (if (= "INSERT" (cdr (assoc 0 (entget e))))
  21.                     (setq e (tblobjname "block" (cdr (assoc 2 (entget e)))))
  22.                   )
  23.                   (and (setq tmp (cadr (assoc (cdr (assoc 8 (entget e))) ly)))
  24.                        (entmod (append (entget e) (list (cons 48 tmp))))
  25.                   )
  26.                 )
  27.                )
  28.                ((setq tmp (cadr (assoc (cdr (assoc 8 (entget sn))) ly)))
  29.                 (entmod (append (entget sn) (list (cons 48 tmp))))
  30.                )
  31.          )
  32.        )                                ; while
  33.      )                                  ; lambda
  34.       -1
  35.     )
  36.   )                                     ; if
  37.   (princ)
  38. )
« Last Edit: May 08, 2017, 09:33:55 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

tive29

  • Guest
Hi ronjonp. It works for block 1 level deep only. Please include nested block.

Thanks

tive29

  • Guest
Hi ronjonp. Any luck for the lisp to include nested blocks?

ronjonp

  • Needs a day job
  • Posts: 7527
Try the code above.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

tive29

  • Guest
Try the code above.

Hi ronjonp. Finally got a chance to try it for my work. But unfortunately, the layers inside the blocks & nested blocks did not change the linestype scale. Only the ones not a block are changed.

I attached my drawing for your reference.

Thanks


ronjonp

  • Needs a day job
  • Posts: 7527
This is a much simpler approach:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ l tmp)
  2.   (setq l '(("LAYER1" . 0.5) ("LAYER2" . 0.75) ("LAYER3" . 1.5)))
  3.     (vlax-for b a
  4.       (if (setq tmp (cdr (assoc (strcase (vla-get-layer b)) l)))
  5.         (vl-catch-all-apply 'vla-put-linetypescale (list b tmp))
  6.       )
  7.     )
  8.   )
  9.   (princ)
  10. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

tive29

  • Guest
Thanks ronjonp. Its working now  :smitten:

ronjonp

  • Needs a day job
  • Posts: 7527
Thanks ronjonp. Its working now  :smitten:
Glad to help :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC