Author Topic: Changing layer Colour code  (Read 2355 times)

0 Members and 1 Guest are viewing this topic.

Shade

  • Guest
Changing layer Colour code
« on: April 21, 2008, 02:26:54 PM »
I need help with the following code, i can't seem to figure out my mistake  :ugly:
I receive the following error
; error: ActiveX Server returned an error: Parameter not optional

Variable CLRS is a list of the following..
(("1" . "10") ("2" . "20") ("3" . "30") ("4" . "40") ("5" . "50") ("6" . "60") ("7" . "70") ("8" . "80") ("9" . "90") ("10" . "100") ("11" . "110") ("12" . "120") ("13" . "130") ("10" . "1") ("20" . "2") ("30" . "3") ("40" . "4") ("50" . "5") ("60" . "6") ("70" . "7") ("80" . "8") ("90" . "9") ("100" . "10") ("110" . "11") ("120" . "12") ("130" . "13"))


Code: [Select]
   (vlax-map-collection
    (vla-get-layers
      (vla-get-activedocument (vlax-get-acad-object))
    )
    '(lambda (x)
        (setq OLD (itoa (vla-get-color X))
        NEW (cdr (assoc OLD CLRS))
)     
(vla-put-color X NEW)
      );lambda
   );map

Any help would be appreciated.... :mrgreen:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Changing layer Colour code
« Reply #1 on: April 21, 2008, 02:30:44 PM »
Colors are numbers not strings.  So if you change all the strings to numbers you should be good.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Changing layer Colour code
« Reply #2 on: April 22, 2008, 11:02:20 AM »
could you tell what exacly you'r trying to do ?

...("10" . "100")("10" . "1")  ...
??
Keep smile...

daron

  • Guest
Re: Changing layer Colour code
« Reply #3 on: April 22, 2008, 11:35:33 AM »
Code: [Select]
(vla-put-color X NEW) It appears he's trying to put color numbers based off of layer names.

mkweaver

  • Bull Frog
  • Posts: 352
Re: Changing layer Colour code
« Reply #4 on: April 23, 2008, 09:50:58 AM »
Colors are integers until you start dealing with colorbook colors or truecolors.  Then it gets a bit more complicated and you have to deal with truecolor objects.  I have used the following to create a truecolor object from a textstring retrieved from a data file:
Code: [Select]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Routine: MakeTColor ;;;
;;;  Purpose: Create a TrueColor object ;;;
;;;  Arguments: Color - the layer color: ;;;
;;;   If an integer, or a string that converts directly to an integer, then it's an ;;;
;;;   ACI color If a string with a leading "T" and no embeded dollar sign ("$") ;;;
;;;   then remainder of the string is an RGB treble (RRRGGGBBB) If a string with an ;;;
;;;   embeded dollar sign then portion before the $ is the colorbook name, and the ;;;
;;;   portion following the $ is the color name.  If there is no corresponding ;;;
;;;   colorbook found then an error is returned with the colorbook name.  If the ;;;
;;;   color argument is nil, then nil is returned. ;;;
;;;  Returns: A truecolor object ("AutoCAD.AcCmColor") ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun MakeTColor(col / colorbook colorname tcolorobj temp)
  (setq
    tcolorobj (vla-getinterfaceobject
(vlax-get-acad-object)
(strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))
) ;_ end of vla-getinterfaceobject
    col (if (= 'INT (type col))
  (itoa col)
  col
  )
    )
  (cond
    ((null col) nil)
    ;;this is a colorbook color
    ((setq temp (vl-string-position (ascii "$") col))
     (and
       (setq colorbook (substr col 1 temp)
     colorname (substr col (+ temp 2))
     ) ;setq`
       (not (vl-catch-all-error-p
      (vl-catch-all-apply
'vla-SetColorBookColor
(list tcolorobj colorbook colorname)
) ;_ end of vl-catch-all-apply
      ) ;_ end of vl-catch-all-error-p
    ) ;_ end of not
       tcolorobj
       ) ;_ end of and
     ) ;end colorbook color
    ;;this is a truecolor
    ((= "T" (strcase (substr col 1 1)))
     (vla-put-colormethod tcolorobj acColorMethodByRGB)
     (vla-SetRGB
       tcolorobj
       ;;(TrueColor-make
       (atoi (substr col 2 3))
       (atoi (substr col 5 3))
       (atoi (substr col 8 3))
       ;;)
       ) ;_ end of vla-SetRGB
     tcolorobj
     ) ;end of truecolor
    ;;It must be an ACI color
    (T
     (vla-put-colormethod tcolorobj acColorMethodByACI)
     (vla-put-colorindex tcolorobj (atoi col))
     tcolorobj
     ) ;end T
    )
  )


This truecolor object would then be applied to the layers truecolor property.

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Changing layer Colour code
« Reply #5 on: April 24, 2008, 03:03:12 PM »
Maybe this can help you...

Code: [Select]
(defun LayerUpdate (CLRS / Layer_name Layer_color item Layers)
  (setq Layers (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
       )
  )
  (vlax-for n Layers
    (setq layer_name (vla-get-name n))
    (setq Layer_color (itoa (vla-get-color n)))
    (if (setq item (assoc Layer_color CLRS))
      (vla-put-color n (atoi (cdr item)))
;(vla-put-layeron n :vlax-true)
;(if (/= layer_name (strcase (getvar "clayer")))
;    (vla-put-freeze n :vlax-false))
;(vla-put-lock n :vlax-false)
;(vla-put-linetype n "LINETYPE")
;(vla-put-plottable n ":vlax-true or :vlax-false")
    )
    (vlax-release-object Layers)
  )
)
Keep smile...