Set lineweight based on object's color

Discussion in 'AutoCAD' started by sregister, Oct 19, 2004.

  1. sregister

    sregister Guest

    The following code takes a while to process. Is there a faster method?

    I want to set all objects' lineweights based on their color and the corresponding lineweight values in a ctb file. This is a piece of a translation routine that cycles through all objects in the drawing.

    (defun i:mapcolortolwt (Obj / clri cn lst lst009 lst018 lst025 lst035 lst050 lst070 lst080 lst100)
    (setq clri (vla-get-ColorIndex (vla-get-TrueColor Obj))
    lst009 '(5)
    lst018 '(3 16 18 20 31 41 100 111 140 231 241 244 255)
    lst025 '(2 9 24)
    lst035 '(7 8 10 15 17 22 23 25 30 141)
    lst050 '(4 11 14 19 26 29 60 191 210 220)
    lst070 '(6 21)
    lst080 '(12 27)
    lst100 '(13 28)
    )
    (setq lst (append lst009 lst018 lst025 lst035 lst050 lst070 lst080 lst100))
    (setq cn 254)
    (while (> cn 0)
    (if (not (member cn lst))
    (setq lst013 (cons cn lst013))
    )
    (setq cn (- cn 1))
    )
    (cond
    ((= clri acByLayer) (vlax-put-property Obj "Lineweight" acLnWtByLayer))
    ((= clri acByBlock) (vlax-put-property Obj "Lineweight" acLnWtByBlock))
    ((member clri lst009) (vlax-put-property Obj "Lineweight" acLnWt009))
    ((member clri lst013) (vlax-put-property Obj "Lineweight" acLnWt013))
    ((member clri lst018) (vlax-put-property Obj "Lineweight" acLnWt018))
    ((member clri lst025) (vlax-put-property Obj "Lineweight" acLnWt025))
    ((member clri lst035) (vlax-put-property Obj "Lineweight" acLnWt035))
    ((member clri lst050) (vlax-put-property Obj "Lineweight" acLnWt050))
    ((member clri lst070) (vlax-put-property Obj "Lineweight" acLnWt070))
    ((member clri lst080) (vlax-put-property Obj "Lineweight" acLnWt080))
    ((member clri lst100) (vlax-put-property Obj "Lineweight" acLnWt100))
    (T (vlax-put-property Obj "Lineweight" acLnWtByLwDefault))
    )
    (princ)
    )
     
    sregister, Oct 19, 2004
    #1
  2. sregister

    David Kozina Guest

    Just a couple of comments, fwiw.

    Looks like lst013 will be quite lengthy, can it be set as the T cond (w/o
    trying to do a member check?) - or put it just before the T cond.

    Also, more importantly, if this is 'a piece of a translation routine', keep
    in mind for each and every object you are sending to this puppy, you are
    building lst013 and appending the other lists, again, and again,
    repetitively, over and over... :)

    So, why not create/build the lst###s *ONCE* OUTSIDE the function and send
    them to the function as arguements (or a nested data list)? I would think
    it should help.

    hth,
    David Kozina
     
    David Kozina, Oct 19, 2004
    #2
  3. sregister

    David Kozina Guest

    Another thing...

    You might consider creating/sending to the function a master association
    list based on color number:

    (setq *LnWt_alst*
    '(...
    (6 . acLnWt070)
    (7 . acLnWt035)
    ...
    )
    );_end setq

    then just use
    (vlax-put-property Obj "Lineweight" (cdr (assoc clri *LnWt_alst*)))
    in place of the entire cond statement.
     
    David Kozina, Oct 19, 2004
    #3
  4. sregister

    sregister Guest

    Thanks David,

    While I was waiting for a response I did put the lists outside in the main function and it is faster.

    I may try using the T condition instead of lst013. I was going back and forth on that thinking using T for any true color objects, but since I have now made the code to only to look at the color index, that makes sense.

    Thanks for your suggestions. My code is definitely faster now.
     
    sregister, Oct 19, 2004
    #4
  5. sregister

    sregister Guest

    Another part of the routine looks at screening from the ctb file and maps it to a named plot style in our standard stb. Could you build a list from a ctb that has each pen/color mapped to a lineweight and screen value? I hope that makes sense. It would be great to specify a ctb file and the association lists get built from it.
     
    sregister, Oct 19, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.