change colours to lineweights

Discussion in 'AutoCAD' started by devon, Mar 14, 2005.

  1. devon

    devon Guest

    Hi,

    I have a set of drawings which I need to change the colours to lineweights.
    I was searching around the forums for a way to change all the layers of a particular colour to a specified lineweight and didnt have much luck.

    How would I go about this?

    Any help wouild be most appreciated.

    Cheers
    Devon
     
    devon, Mar 14, 2005
    #1
  2. Hi,

    In VBA you simply need a method of selecting the items.

    Lets say you make a selection ss of all the objects you want to process.

    Then you can use a case statement

    Sub ChangeLineweightByColour
    On Error Resume next
    Create Selection set here

    For each Object in ss
    Select Case Object.Color
    Case 1
    Object.Lineweight = 0
    Case 2
    Object.Lineweight = 01
    etc.
    Case else
    End Select
    Next
    End Sub



    particular colour to a specified lineweight and didnt have much luck.
     
    Laurie Comerford, Mar 14, 2005
    #2
  3. devon

    mmm Guest

    have a vlisp that runs as part of your startup suite
    have an associate list that maps colours to lineweight like (list (cons
    color1 lineweight1)(color2 linewight15) .....) etc
    step through the layer table - get the layer color and retrieve the
    lineweight
    then vla-put the linewight to the layer object.

    put the llists of files in a text file that has the file names that you need
    to process
    in a script

    open filename
    save
    quit
    open filename2

    etc etc


    or something like this

    Princess Jamie,

    Life shrinks or expands in proportion to one's courage.
    - Anais Nin

    | Hi,
    |
    | I have a set of drawings which I need to change the colours to
    lineweights.
    | I was searching around the forums for a way to change all the layers of a
    particular colour to a specified lineweight and didnt have much luck.
    |
    | How would I go about this?
    |
    | Any help wouild be most appreciated.
    |
    | Cheers
    | Devon
     
    mmm, Mar 14, 2005
    #3
  4. devon

    devon Guest

    Hi MMM,

    This sounds like a perfect method, could you please share that code with me?

    I am only new to lisp and way on the outer with VB.

    Regards,
    Devon
     
    devon, Mar 15, 2005
    #4
  5. devon

    mmm Guest

    (defun c:purgedwgs (/ pfile ; single dwgname
    basedir ; folder to start from
    dwgyear ; dwg has to be last saved before this - old
    not used
    dwglist ; list of dwgnames
    ftxt ; pointer to txtfile
    fscrmega ; one mega helluvascript (pointer)
    scrmeganame ; one mega helluvascript (name)
    fwscr ; local function
    frunscr; local function
    dwglist
    )

    (defun purgedwgserr (st) ; Internal error handler
    (if (or (/= st "Function cancelled")(= st "quit / exit abort"))
    (princ)
    (princ (strcat "\nError: " st))
    )
    (close ftxt)(close fscrmega)
    (command "_shellw" (strcat "del " scrmeganame))
    (command "_shellw" (strcat "del " basedir "*.bak /s/q"))
    (princ)
    )
    (setq *error* purgedwgerr)(setvar "cmdecho" 0)


    ;;; local functions
    ;;; writing to script (same part for every dwg...)
    (defun fwscr (s f)
    (princ
    (strcat "_open" "\n\"" basedir s "\""
    "\n_qsave"
    "\n_close" "\n"
    )
    f
    )
    )
    ;;; running script
    (defun frunscr (sname)
    (cond
    ((null sname))
    ((/= 'str (type sname)))
    ((findfile sname)
    (princ "\nrunning script...")
    (setvar "FILEDIA" 0)
    (command "_script" sname)
    )
    (t (princ "\ncan't run ") (princ sname) (princ "!"))
    )
    )
    ;;; the main thing
    ;;;
    ;;;
    (alert "This command will convert all drawings within a folder. \nSimply
    select a .DWG file within the folder you wish to process. \nImportant -
    make sure you execute this command from a new empty .DWG,\n and that you
    have the ACAD Drawing window maximized")
    (setq basedir (getfiled "Select File in Folder for Purging" "" "dwg" 16))
    (princ basedir)
    (if basedir
    (progn
    (while (/= (substr basedir (strlen basedir) 1) "\\")(setq basedir (substr
    basedir 1 (- (strlen basedir) 1))))
    (princ "\n")(princ basedir)
    (setq ;;;txtfile (strcat basedir "dwglist.txt")
    scrmeganame (strcat basedir "megapurge.scr")
    )
    (princ (strcat "\ntrying to purge all dwgs in " basedir)
    )

    ;;; clear all read only attributes on all dwg files
    (princ "\nclearing Read Only Attributes on Drawing Files...")
    (command "_shellw" (strcat "attrib -r " basedir "*.dwg /s"))

    ;;; list all drawings on e: in .txt file
    (princ "\ncreating dwglist...")
    ;;;(command "_shellw" (strcat "dir " basedir "*.dwg /s/b > "
    txtfile));;; all dwgs
    (setq dwglist (vl-directory-files (substr basedir 1 (- (strlen basedir)
    1)) "*.dwg" 1))

    (cond
    ((null dwglist) (princ "\nno dwgs to process..."))
    ((null (setq fscrmega (open scrmeganame "w")))
    (princ (strcat "\ncan't open " scrmeganame " for writing! "))
    )
    (t
    (princ (strcat "\ncreating scriptfile " scrmeganame " for " (itoa
    (length dwglist)) " dwgs ..." )
    )
    (foreach n dwglist (fwscr n fscrmega) )
    (close fscrmega)
    (princ "\nrunning script ")
    (frunscr scrmeganame) ; running script
    (princ "\nscript running done")
    )
    )
    (command "_shellw" (strcat "del " scrmeganame))
    (command "_shellw" (strcat "del " basedir "*.bak /s/q"))
    ));;;end progn and if
    (princ)
    )

    the above will make th script file and run it

    you need to add a lsip in your startup routines that will change the
    layers..
     
    mmm, Mar 15, 2005
    #5
  6. devon

    devon Guest

    Hi MMM,

    Thanks for the reply.

    I think we have crossed wires.

    I want to run the routine which does ...

    Find all layers with colour 1 and assign the lineweight of 0.35
    Fine all the layers with colour 2 and assign the lineweight of 0.25

    etc etc.

    Any ideas?
    The layer names could change from dwg to dwg, so i need to do this with the colours, not layer names.


    Regards,
    Devon
     
    devon, Mar 15, 2005
    #6
  7. devon

    mmm Guest

    what I gave you is a routine which will allow you to select a drawing and
    then create a script that will allow you to process all drawings within the
    folder...

    now if you put that with the other part you can process a great number of
    drawings quickly.

    --
    Princess Jamie,

    Life shrinks or expands in proportion to one's courage.
    - Anais Nin

    | Hi MMM,
    |
    | Thanks for the reply.
    |
    | I think we have crossed wires.
    |
    | I want to run the routine which does ...
    |
    | Find all layers with colour 1 and assign the lineweight of 0.35
    | Fine all the layers with colour 2 and assign the lineweight of 0.25
    |
    | etc etc.
    |
    | Any ideas?
    | The layer names could change from dwg to dwg, so i need to do this with
    the colours, not layer names.
    |
    |
    | Regards,
    | Devon
     
    mmm, Mar 15, 2005
    #7
  8. devon

    devon Guest

    Hi,

    Sorry, I must be having a brain freeze.
    I don't understand what you mean by "put with other part"

    Devon
     
    devon, Mar 15, 2005
    #8
  9. devon

    mmm Guest

    (vl-load-com)
    (setq *acad* (vlax-get-acad-object)
    *doc* (vla-get-activedocument *acad*)
    *utils* (vla-get-utility *doc*)
    )
    (defun fixmy_layers (/ map_colors the_layer lname1 Layer_Table new_weight)
    (setq LayerTable (vla-get-layers *doc*));;; get all of the layers
    ;;;make a list
    (setq map_colors (list (cons 7 25)(cons 1 35)(cons 2 50)(cons 3 100)));;;
    add to this as you need
    (while (setq the_layer (tblnext "LAYER" (null the_layer)))
    (setq lname1 (vla-item LayerTable (cdr (assoc 2 the_layer)))
    new_weight (cdr (assoc (abs (cdr (assoc 62 the_layer)))
    map_colors))
    )
    (if (and new_weight (/= (cdr (assoc 2 the_layer)) (getvar
    "clayer")))
    (vla-put-lineweight lname1 new_weight)
    )
    )
    );;; end of fun


    Princess Jamie,

    Life shrinks or expands in proportion to one's courage.
    - Anais Nin

    | what I gave you is a routine which will allow you to select a drawing and
    | then create a script that will allow you to process all drawings within
    the
    | folder...
    |
    | now if you put that with the other part you can process a great number of
    | drawings quickly.
    |
    | --
    | Princess Jamie,
    |
    | Life shrinks or expands in proportion to one's courage.
    | - Anais Nin
    |
    | | | Hi MMM,
    | |
    | | Thanks for the reply.
    | |
    | | I think we have crossed wires.
    | |
    | | I want to run the routine which does ...
    | |
    | | Find all layers with colour 1 and assign the lineweight of 0.35
    | | Fine all the layers with colour 2 and assign the lineweight of 0.25
    | |
    | | etc etc.
    | |
    | | Any ideas?
    | | The layer names could change from dwg to dwg, so i need to do this with
    | the colours, not layer names.
    | |
    | |
    | | Regards,
    | | Devon
    |
    |
     
    mmm, Mar 15, 2005
    #9
  10. devon

    mmm Guest

    if you put this last bit in the startup function in acaddatedoc.lsp - it
    will be run for each drawing opened

    --
    Princess Jamie,

    Life shrinks or expands in proportion to one's courage.
    - Anais Nin

    | (vl-load-com)
    | (setq *acad* (vlax-get-acad-object)
    | *doc* (vla-get-activedocument *acad*)
    | *utils* (vla-get-utility *doc*)
    | )
    | (defun fixmy_layers (/ map_colors the_layer lname1 Layer_Table new_weight)
    | (setq LayerTable (vla-get-layers *doc*));;; get all of the layers
    | ;;;make a list
    | (setq map_colors (list (cons 7 25)(cons 1 35)(cons 2 50)(cons 3 100)));;;
    | add to this as you need
    | (while (setq the_layer (tblnext "LAYER" (null the_layer)))
    | (setq lname1 (vla-item LayerTable (cdr (assoc 2 the_layer)))
    | new_weight (cdr (assoc (abs (cdr (assoc 62 the_layer)))
    | map_colors))
    | )
    | (if (and new_weight (/= (cdr (assoc 2 the_layer)) (getvar
    | "clayer")))
    | (vla-put-lineweight lname1 new_weight)
    | )
    | )
    | );;; end of fun
    |
    |
    | Princess Jamie,
    |
    | Life shrinks or expands in proportion to one's courage.
    | - Anais Nin
    |
    | | what I gave you is a routine which will allow you to select a drawing
    and
    | | then create a script that will allow you to process all drawings within
    | the
    | | folder...
    | |
    | | now if you put that with the other part you can process a great number
    of
    | | drawings quickly.
    | |
    | | --
    | | Princess Jamie,
    | |
    | | Life shrinks or expands in proportion to one's courage.
    | | - Anais Nin
    | |
    | | | | | Hi MMM,
    | | |
    | | | Thanks for the reply.
    | | |
    | | | I think we have crossed wires.
    | | |
    | | | I want to run the routine which does ...
    | | |
    | | | Find all layers with colour 1 and assign the lineweight of 0.35
    | | | Fine all the layers with colour 2 and assign the lineweight of 0.25
    | | |
    | | | etc etc.
    | | |
    | | | Any ideas?
    | | | The layer names could change from dwg to dwg, so i need to do this
    with
    | | the colours, not layer names.
    | | |
    | | |
    | | | Regards,
    | | | Devon
    | |
    | |
    |
    |
     
    mmm, Mar 15, 2005
    #10
  11. devon

    devon Guest

    Hi,

    Thanks for all you help, i'm still having trouble getting the routine to change a layer of a colour and give it a weight.

    Sorry, but i my lisp is poor, so you may need to expand on your answer.

    Thanks for the help.

    Cheers.
     
    devon, Mar 15, 2005
    #11
  12. devon

    mmm Guest

    post some of the colour vs lineweights.

    --
    Princess Jamie,

    Life shrinks or expands in proportion to one's courage.
    - Anais Nin

    | Hi,
    |
    | Thanks for all you help, i'm still having trouble getting the routine to
    change a layer of a colour and give it a weight.
    |
    | Sorry, but i my lisp is poor, so you may need to expand on your answer.
    |
    | Thanks for the help.
    |
    | Cheers.
     
    mmm, Mar 15, 2005
    #12
  13. devon

    devon Guest

    Hi,

    Something like this...

    colour 1 = lineweight 0.35
    colour 2 = lineweight 0.5
    colour 3 = lineweight 0.7

    etc etc

    Thanks in advance.
    Devon
     
    devon, Mar 15, 2005
    #13
  14. devon

    mmm Guest

    (vl-load-com)
    (setq *acad* (vlax-get-acad-object)
    *doc* (vla-get-activedocument *acad*)
    *utils* (vla-get-utility *doc*)
    )
    (defun fixmy_layers (/ map_colors the_layer lname1 Layer_Table new_weight)
    (if (tblsearch "layer" "0")(setvar "clayer" "0"))
    (setq LayerTable (vla-get-layers *doc*));;; get all of the layers
    ;;;make a list
    (setq map_colors (list (cons 1 35)(cons 2 50)(cons 3 70)));;;<====look at
    this line add to this as you need
    (while (setq the_layer (tblnext "LAYER" (null the_layer)))
    (setq lname1 (vla-item LayerTable (cdr (assoc 2 the_layer)))
    new_weight (cdr (assoc (abs (cdr (assoc 62 the_layer)))
    map_colors))
    )
    (if (and new_weight (/= (cdr (assoc 2 the_layer)) (getvar
    "clayer")))
    (vla-put-lineweight lname1 new_weight)
    )
    )
    );;; end of fun


    open one of your drawings, load this in and then type (fixmy_layers) at the
    command prompt
    open the layer manager and see what happened
    --
    Princess Jamie,

    Life shrinks or expands in proportion to one's courage.
    - Anais Nin

    | Hi,
    |
    | Something like this...
    |
    | colour 1 = lineweight 0.35
    | colour 2 = lineweight 0.5
    | colour 3 = lineweight 0.7
    |
    | etc etc
    |
    | Thanks in advance.
    | Devon
     
    mmm, Mar 15, 2005
    #14
  15. devon

    devon Guest

    Thanks very much, thats perfect!

    Very much appreciated!
     
    devon, Mar 15, 2005
    #15
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.