TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ribarm on August 10, 2017, 07:17:56 AM

Title: set CECOLOR matched from picked entity
Post by: ribarm on August 10, 2017, 07:17:56 AM
I have this dumb question, but I don't have a time to play and investigate if there is already something here/there...

I want to pick entity with some color - ACI, True RGB, ByLayer, ByBlock, and then my variable CECOLOR changes accordingly to that color...

Thanks for any input or opinion...
Title: Re: set CECOLOR matched from picked entity
Post by: Lee Mac on August 10, 2017, 08:08:15 AM
An example:
Code - Auto/Visual Lisp: [Select]
  1. ;; CECOLOR from Entity  -  Lee Mac
  2.  
  3. (defun LM:cecolorfromentity ( ent / enx tmp )
  4.     (setvar 'cecolor
  5.         (cond
  6.             (   (cdr (assoc 430 (setq enx (entget ent)))))
  7.             (   (setq tmp (cdr (assoc 420 enx)))
  8.                 (apply 'strcat (mapcar '(lambda ( a b ) (strcat a (itoa b))) '("RGB:" "," ",") (LM:true->rgb tmp)))
  9.             )
  10.             (   (null (setq tmp (cdr (assoc 62 enx))))
  11.                 "BYLAYER"
  12.             )
  13.             (   (zerop tmp)
  14.                 "BYBLOCK"
  15.             )
  16.             (   (itoa tmp))
  17.         )
  18.     )
  19. )
  20.  
  21. ;; True -> RGB  -  Lee Mac
  22. ;; Args: c - [int] True Colour
  23.  
  24. (defun LM:true->rgb ( c )
  25.     (mapcar '(lambda ( x ) (lsh (lsh (fix c) x) -24)) '(8 16 24))
  26. )
Title: Re: set CECOLOR matched from picked entity
Post by: ribarm on August 10, 2017, 08:40:02 AM
Thanks, Lee I knew it was something simple but still little bit mind tricky...

M.R.
Title: Re: set CECOLOR matched from picked entity
Post by: ribarm on August 10, 2017, 10:11:02 AM
Given the fact that you can pick an entity that don't have linetype, lineweight or such specific property (3DSOLID, 3DFACE, ... ), this adaptation is slick, short and extremely useful...

Many thanks to Lee...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:cc ( / s LM:cecolorfromentity LM:true->rgb )
  2.  
  3.   ;; CECOLOR from Entity  -  Lee Mac
  4.  
  5.   (defun LM:cecolorfromentity ( ent / enx tmp )
  6.       (setvar 'cecolor
  7.           (cond
  8.               (   (cdr (assoc 430 (setq enx (entget ent)))))
  9.               (   (setq tmp (cdr (assoc 420 enx)))
  10.                   (apply 'strcat (mapcar '(lambda ( a b ) (strcat a (itoa b))) '("RGB:" "," ",") (LM:true->rgb tmp)))
  11.               )
  12.               (   (null (setq tmp (cdr (assoc 62 enx))))
  13.                   "BYLAYER"
  14.               )
  15.               (   (zerop tmp)
  16.                   "BYBLOCK"
  17.               )
  18.               (   (itoa tmp))
  19.           )
  20.       )
  21.   )
  22.  
  23.   ;; True -> RGB  -  Lee Mac
  24.   ;; Args: c - [int] True Colour
  25.  
  26.   (defun LM:true->rgb ( c )
  27.       (mapcar '(lambda ( x ) (lsh (lsh (fix c) x) -24)) '(8 16 24))
  28.   )
  29.  
  30.   (prompt "\nPick source entity on unlocked layer with desired color for current layer/color usage...")
  31.   (setq s (ssget "_+.:E:S:L"))
  32.   (while (not s)
  33.     (prompt "\nMissed... Try picking source entity on unlocked layer with desired color for current layer/color usage again...")
  34.     (setq s (ssget "_+.:E:S:L"))
  35.   )
  36.   (setvar 'clayer (cdr (assoc 8 (entget (ssname s 0)))))
  37.   (LM:cecolorfromentity (ssname s 0))
  38.   (princ)
  39. )
  40.  

 :lol: