Results 1 to 5 of 5

Thread: LISP to Change Layer Color to True Color Defined in Layer Name

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2013-01
    Posts
    1
    Login to Give a bone
    0

    Default LISP to Change Layer Color to True Color Defined in Layer Name

    HELP!!!!!

    I have a graphics vectorization program that will convert raster images into a vectorized dwf with every object in the drawing being a line. Problem is, it creates about 700 layers that all have the default color of white. Great thing is that the color is coded into the layer name. Typical layer name would be "color#5d2924ff". The "color#" is in each layer name. The "5d2924" represents the True Color RGB values in hexadecimal. This example would be 93 red, 41 green, 36 blue. The "ff" represents the hue and is the same for all the layers.

    Here's what I'm trying to accomplish:

    1. Combine all objects on a layer into regions.
    2. Add solid hatches in all the created regions.
    3. Change the color of the objects on a layer to the true color defined by the layer name.

    Is there a simple LISP routine that will do this?

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: LISP to Change Layer Color to True Color Defined in Layer Name

    I found a code snip by Gile (Here on AUGI and at theswamp.org) that converts Hex to Long Integers.

    I modified his code snip to my variable naming standard and built a function to convert your layer names to RGB values with hues.

    It is a good place to start.

    P=

    Code:
    ; Function to convert Layer name to RGB color and hue.
    ; Syntax: (ColorStringConvert "color#5d2924ff") returns '((93 41 36) 255)
    
    (defun ColorStringConvert (strColorCode)
     (list
      (list 
       (HexadecimalToInteger (substr strColorCode 7 2))
       (HexadecimalToInteger (substr strColorCode 9 2))
       (HexadecimalToInteger (substr strColorCode 11 2)) 
      )
      (HexadecimalToInteger (substr strColorCode 13 2))
     )
    )
    
    ; Funtion to convert Hexadecimal to Long Integer
    ; Modified code originally posted to AUGI forums by Gile.
    ; See: http://forums.augi.com/showthread.php?90683-String-to-Hexa
    
    (defun HexadecimalToInteger (strHexadecimal / intInteger intAscii)
     (setq intInteger 0)
     (foreach intAscii (vl-string->list (strcase strHexadecimal))
      (setq intInteger (+ (lsh intInteger 4)
                          
                          (- intAscii
                           (if (<= intAscii 57) 48 55)
                          )
                       )
      )
     )
    )
    AutomateCAD

  3. #3
    I could stop if I wanted to
    Join Date
    2006-04
    Posts
    466
    Login to Give a bone
    0

    Default Re: LISP to Change Layer Color to True Color Defined in Layer Name

    Awsome Peter, if we could get the AutoCAD color code every thing else would be easy coding.

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,096
    Login to Give a bone
    0

    Default Re: LISP to Change Layer Color to True Color Defined in Layer Name

    Quote Originally Posted by aaronic_abacus View Post
    Awsome Peter, if we could get the AutoCAD color code every thing else would be easy coding.
    You might try LeeMac's Colour Conversion page for code to do that.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: LISP to Change Layer Color to True Color Defined in Layer Name

    OK so if you had an object on a layer "color#5d2924ff" this function would change the truecolor of the object to RGB 93, 41, 36 and place the object on layer "0".

    P=



    Code:
    ; Custom function to change an object to the color of the hexidecimal name of its layer.
    
    (defun TrueColor (objSelection / 
                       lstTrueColor
                       objTrueColor
                       strLayerName
                      )
     (and 
      (setq strLayerName  (strcase (vla-get-layer objSelection) T))
      (= (strcase (substr strLayerName 1 5) T) "color")
      (= (strlen  strLayerName) 14)
      (setq objTrueColor (vla-get-truecolor objSelection))
      (setq lstTrueColor (TrueColorList strLayerName))
      (errortrap (quote (vla-put-color objSelection 256)))
      (errortrap (quote (vla-setrgb objTrueColor (car lstTrueColor)(cadr lstTrueColor)(caddr lstTrueColor)) ))
      (errortrap (quote (vla-put-truecolor objSelection objTrueColor)))
      (errortrap (quote (vla-put-layer objSelection "0")))
     )
    )
    
    ; Function to convert Layer name to RGB color and hue.
    
    (defun TrueColorList (strColorCode)
     (list 
      (HexadecimalToInteger (substr strColorCode 7 2))
      (HexadecimalToInteger (substr strColorCode 9 2))
      (HexadecimalToInteger (substr strColorCode 11 2)) 
     )
    )
    
    ; Funtion to convert Hexadecimal to Long Integer
    ; Modified code originally posted to AUGI forums by Gile.
    
    (defun HexadecimalToInteger (strHexadecimal / intInteger intAscii)
     (setq intInteger 0)
     (foreach intAscii (vl-string->list (strcase strHexadecimal))
      (setq intInteger (+ (lsh intInteger 4)
                          
                          (- intAscii
                           (if (<= intAscii 57) 48 55)
                          )
                       )
      )
     )
    )
    
    ; Standard Error Trap
    
    (defun ErrorTrap (symFunction / objError result)
     (if (vl-catch-all-error-p
          (setq objError (vl-catch-all-apply
                         '(lambda (X)(set X (eval symFunction)))
                          (list 'result))))
      nil
      (if result result 'T)
     )
    )
    AutomateCAD

Similar Threads

  1. Replies: 8
    Last Post: 2015-01-06, 01:15 PM
  2. Layer Color Change LISP Routine
    By guardianfiredesign774457 in forum AutoLISP
    Replies: 19
    Last Post: 2013-08-28, 05:08 AM
  3. Change color with -layer without turning layer on?
    By trentmoore in forum AutoCAD Customization
    Replies: 5
    Last Post: 2010-10-26, 05:27 PM
  4. Lisp to change layer color in viewport
    By moonlight_9630 in forum AutoLISP
    Replies: 2
    Last Post: 2008-07-08, 07:31 PM
  5. Replies: 6
    Last Post: 2007-05-30, 05:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •