TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: tive29 on May 05, 2017, 01:40:54 AM

Title: Change object/entity line type scale by layer name inside nested blocks
Post by: tive29 on May 05, 2017, 01:40:54 AM
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)
Title: Re: Change object/entity line type scale by layer name inside nested blocks
Post by: ronjonp on May 05, 2017, 09:52:56 AM
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. )
Title: Re: Change object/entity line type scale by layer name inside nested blocks
Post by: tive29 on May 06, 2017, 02:27:30 AM
Hi ronjonp. It works for block 1 level deep only. Please include nested block.

Thanks
Title: Re: Change object/entity line type scale by layer name inside nested blocks
Post by: tive29 on May 09, 2017, 11:39:25 PM
Hi ronjonp. Any luck for the lisp to include nested blocks?
Title: Re: Change object/entity line type scale by layer name inside nested blocks
Post by: ronjonp on May 10, 2017, 12:02:32 AM
Try the code above.
Title: Re: Change object/entity line type scale by layer name inside nested blocks
Post by: tive29 on May 11, 2017, 08:27:46 PM
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

Title: Re: Change object/entity line type scale by layer name inside nested blocks
Post by: ronjonp on May 12, 2017, 08:56:46 AM
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. )
Title: Re: Change object/entity line type scale by layer name inside nested blocks
Post by: tive29 on May 12, 2017, 10:48:06 AM
Thanks ronjonp. Its working now  :smitten:
Title: Re: Change object/entity line type scale by layer name inside nested blocks
Post by: ronjonp on May 12, 2017, 11:25:37 AM
Thanks ronjonp. Its working now  :smitten:
Glad to help :)