create layer names from text file and add prefix using LISP

Discussion in 'AutoCAD' started by Tom Hanley, Jan 5, 2005.

  1. Tom Hanley

    T.Willey Guest

    Look for a routine called "StrParse". It has been posted quite a bit.

    Tim
     
    T.Willey, Jan 7, 2005
    #21
  2. Tom Hanley

    ECCAD Guest

    (Defun C:LLC ()
    ;T.HANLEY FOR L&T 1/5/05
    ;CREATES LAYERS FOR INDIVIDUAL LOTS
    (Setvar "Cmdecho" 0)
    (Setq A (Getint "\nStarting LOT number: "))
    (Setq B (Getint "\nEnding LOT number: "))
    (setq fil "S:/DRAFTING STANDARDS/LOTLAYERS.TXT")
    (If (> A B)
    (Setq E -1)
    (Setq E 1)
    ); if
    (Repeat (+ 1 (Abs (- A B)))
    (SETQ LNFILE (OPEN fil "R"))
    (while (SETQ LN (READ-LINE LNFILE))
    (Setq lay (STRCAT "LOT" (Itoa A) "-" LN))
    (Command "_LAYER" "M" lay "")
    ); while
    (CLOSE fil)
    (Setq A (+ A E))
    ); repeat
    (Setvar "Cmdecho" 1)
    ); function

    Try above:
    Bob
     
    ECCAD, Jan 7, 2005
    #22
  3. Tom Hanley

    ECCAD Guest

    (Defun C:LLC ()
    ;T.HANLEY FOR L&T 1/5/05
    ;CREATES LAYERS FOR INDIVIDUAL LOTS
    (Setvar "Cmdecho" 0)
    (Setq A (Getint "\nStarting LOT number: "))
    (Setq B (Getint "\nEnding LOT number: "))
    ;(setq fil "S:/DRAFTING STANDARDS/LOTLAYERS.TXT")
    (setq fil "c:/acad/LOTLAYERS.TXT")
    (If (> A B)
    (Setq E -1)
    (Setq E 1)
    ); if
    (Repeat (+ 1 (Abs (- A B)))
    (SETQ LNFILE (OPEN fil "R"))
    (while (SETQ LN (READ-LINE LNFILE))
    (if LN
    (progn
    (Setq lay (STRCAT "LOT" (Itoa A) "-" LN))
    (Command "_LAYER" "M" lay "")
    ); progn
    ); if
    ); while
    ;; Problem here..(CLOSE fil)
    (CLOSE LNFILE)
    (Setq A (+ A E))
    ); repeat
    (Setvar "Cmdecho" 1)
    ); function

    -------- problem was, (close fil)..needs to be (close lnfile) instead. fil is the filename, lnfile is file pointer.

    Cheers:
    Bob
     
    ECCAD, Jan 8, 2005
    #23
  4. Tom Hanley

    ECCAD Guest

    (Defun C:LLC ()
    ;T.HANLEY FOR L&T 1/5/05
    ;CREATES LAYERS FOR INDIVIDUAL LOTS
    (Setvar "Cmdecho" 0)
    (Setq A (Getint "\nStarting LOT number: "))
    (Setq B (Getint "\nEnding LOT number: "))
    (setq fil "S:/DRAFTING STANDARDS/LOTLAYERS.TXT")
    (If (> A B)
    (Setq E -1)
    (Setq E 1)
    ); if
    (Repeat (+ 1 (Abs (- A B)))
    (SETQ LNFILE (OPEN fil "R"))
    (while (SETQ LN (READ-LINE LNFILE))
    (if LN
    (progn
    (Setq lay (STRCAT "LOT" (Itoa A) "-" LN))
    (Command "_LAYER" "M" lay "")
    ); progn
    ); if
    ); while
    ;; Problem here..(CLOSE fil)
    (CLOSE LNFILE)
    (Setq A (+ A E))
    ); repeat
    (Setvar "Cmdecho" 1)
    ); function

    Whoops, forgot to redo the:
    (setq fil "S:/DRAFTING STANDARDS/LOTLAYERS.TXT")
    Above corrected.

    Bob
     
    ECCAD, Jan 8, 2005
    #24
  5. Tom Hanley

    Tom Smith Guest

    FWIW, here's my version. It adds color and lintype info for the layers,
    declares variables local, only reads the text file once, and resets the
    previous current layer when done. Similar to Tom Haw's suggestion ,
    LOTLAYER.TXT file must be of the format:

    "Sewer" 1 "dashed"
    "Sewer-text" 2 "hidden"
    "Water" 2 "dashed"
    "Water-text" 3 "continuous"
    "Utils" 4 "dashed"
    "Utils-text" 5 "Hidden"

    (Defun C:LLC (/ cmdecho clayer startlotnum endlotnum incr fil lin laylst
    lotnum layname)
    ;T.HANLEY FOR L&T 1/5/05
    ;CREATES LAYERS FOR INDIVIDUAL LOTS
    (initget 7)
    (setq startlotnum (getint "\nStarting lot number: "))
    (while (not endlotnum)
    (initget 7)
    (setq endlotnum (getint "\nEnding lot number: "))
    (if (> startlotnum endlotnum)
    (setq endlotnum nil)))
    (setq fil "S:/DRAFTING STANDARDS/LOTLAYERS.TXT")
    (while (setq lin (read-line fil))
    (setq laylst (cons (read (strcat "(" lin ")" )) laylst)))
    (close fil)
    (setvar "cmdecho" 0)
    (setq
    laylst (reverse laylst)
    cmdecho (getvar "cmdecho")
    clayer (getvar "clayer"))
    (foreach lst laylst
    (setq lotnum startlotnum)
    (while (< lotnum endlotnum)
    (setq layname (strcat "LOT" (itoa lotnum) "-" (nth 0 lst)))
    (command "-layer" "make" layname "color" (nth 1 lst) "" "ltype" (nth 2
    lst) "" "")
    (setq lotnum (1+ lotnum))))
    (setvar "cmdecho" cmdecho)
    (setvar "clayer" clayer)
    (princ))
     
    Tom Smith, Jan 10, 2005
    #25
  6. Tom Hanley

    Tom Smith Guest

    FWIW, here's my version. It adds color and lintype info for the layers,
    Sorry, posted too fast. Corrected below ...

    (Defun C:LLC (/ cmdecho clayer startlotnum endlotnum incr fil lin laylst
    lotnum numstr layname)
    ;T.HANLEY FOR L&T 1/5/05
    ;CREATES LAYERS FOR INDIVIDUAL LOTS
    (initget 7)
    (setq startlotnum (getint "\nStarting lot number: "))
    (while (not endlotnum)
    (initget 7)
    (setq endlotnum (getint "\nEnding lot number: "))
    (if (> startlotnum endlotnum)
    (setq endlotnum nil)))
    (setq fil (open "S:/DRAFTING STANDARDS/LOTLAYERS.TXT" "r"))
    (while (setq lin (read-line fil))
    (setq laylst (cons (read (strcat "(" lin ")" )) laylst)))
    (close fil)
    (setvar "cmdecho" 0)
    (setq
    laylst (reverse laylst)
    cmdecho (getvar "cmdecho")
    clayer (getvar "clayer"))
    (foreach lst laylst
    (setq lotnum startlotnum)
    (while (<= lotnum endlotnum)
    (setq
    numstr (if (< lotnum 10)
    (strcat "0" (itoa lotnum))
    (itoa lotnum))
    layname (strcat "LOT" numstr "-" (nth 0 lst)))
    (command "-layer" "make" layname "color" (nth 1 lst) "" "ltype" (nth 2
    lst) "" "")
    (setq lotnum (1+ lotnum))))
    (setvar "cmdecho" cmdecho)
    (setvar "clayer" clayer)
    (princ))
     
    Tom Smith, Jan 10, 2005
    #26
  7. Tom,

    Here is a program that I wrote do add layers from files. If you have A2005
    it will also add a description of the layers. This program allows you to
    create your own custom files to insert as well, the only thing I doesn't do
    is add prefix or suffix to the layer name (they have to be in the file
    already)

    Give it a whirl or just use snippet. Have fun :eek:)


    --
    =================================
    Timothy Spangler

    AutoCAD 2005
    =================================
     
    Timothy Spangler, Jan 10, 2005
    #27
  8. Tom Hanley

    Tom Hanley Guest

    Tom,
    I am trying this routine out and it works fine. How would you change it to
    make it file the file in a search path instead of giving and absolute
    address. I have two kinds of users. One uses the network files and one uses
    synchronized directories on their laptops. I need to be able to use search
    path. Also, I was thinking of adding layer descriptions as well but can't
    find the dxf code for that field.
    Thx,
    Tom Hanley
     
    Tom Hanley, Jan 11, 2005
    #28
  9. Tom Hanley

    Paul Turvill Guest

    Check out the (findfile ...) function.
    ___
     
    Paul Turvill, Jan 11, 2005
    #29
  10. Tom Hanley

    Tom Smith Guest

    I am trying this routine out and it works fine. How would you change it to
    If the file is anywhere on the search path, just change

    (setq fil (open "S:/DRAFTING STANDARDS/LOTLAYERS.TXT" "r"))

    to

    (setq fil (open (findfile "LOTLAYERS.TXT" "r")))

    where findfile will return the full path/filename of the first instance of
    the file that's found on the path.
    That's a 2005 feature & I don't have that installed. Search this NG for a
    lisp that Rudy Tovar contributed which will add a layer description. It's
    going to add another level of complexity to the routine because it uses
    active x to change the drawing, quite a far cry from the command function
    call used in your lisp so far. Personally, given the example names you've
    posted, I can't imagine that anyone would ever need a description to figure
    out what the "Lot01-Sewer-text" layer contains.
     
    Tom Smith, Jan 11, 2005
    #30
  11. Tom Hanley

    Tom Hanley Guest

    Thanks guys...that works fine now.

     
    Tom Hanley, Jan 11, 2005
    #31
  12. Tom Hanley

    Paul Turvill Guest

    Not quite ...

    (setq fil (open (findfile "LOTLAYERS.TXT") "r"))
    ___
     
    Paul Turvill, Jan 11, 2005
    #32
  13. Tom Hanley

    Tom Smith Guest

    Not quite ...

    Thanks Paul!
     
    Tom Smith, Jan 11, 2005
    #33
  14. Tom,

    I tried to use the DXF code the first time and found that unless there
    is a layer with a description already in the drawing you will get an
    error. With to the help of a few generous poster in this newsgroup I
    was convinced that ActiveX is the way to go for that. Here is the code
    for adding description:

    ;; Create layer description
    (if(= 16.1 (atof(getvar "acadver")))
    (progn
    (setq VLA-Obj(vla-Add (vla-Get-Layers
    (vla-Get-ActiveDocument(vlax-Get-Acad-Object)))LyrName))
    (vla-Put-Description VLA-Obj LyrDescr))))

    Don't forget the (vl-load-com)

    You have to check for the version or you will get an error as well.

    As far as the flexible setup, on the first run I check the registry for
    the Base Directory if it isn't there then I use findfile to find the
    lisp file, once I find the file I write the directory to the registry
    for the next time. I also then add the directory to the search path.
    Below is the code.

    ;; Create directory structure
    (if (vl-registry-read "HKEY_CURRENT_USER\\Software\\Layer Creator"
    "BaseDirectory"); check for base directory
    (progn
    (setq BaseDirectory (vl-registry-read
    "HKEY_CURRENT_USER\\Software\\Layer Creator" "BaseDirectory")); If it
    exsists set variable
    (if (not(vl-file-directory-p BaseDirectory)); Check veriable to make
    sure it is correct
    (progn
    (setq BaseDirectory (vl-filename-directory (findfile(getfiled
    "Locating Layer Creator Directory" "Layer Creator" "lsp" 8)))); If not
    locate new directory
    (vl-registry-write "HKEY_CURRENT_USER\\Software\\Layer Creator"
    "BaseDirectory" BaseDirectory); Write new directory to registry
    )
    )
    )
    (progn
    (setq BaseDirectory (vl-filename-directory (findfile(getfiled
    "Locating Layer Creator Directory" "Layer Creator" "lsp" 8)))); If it
    does not exsist locate new directory
    (vl-registry-write "HKEY_CURRENT_USER\\Software\\Layer Creator"
    "BaseDirectory" BaseDirectory); Write new directory to registry
    )
    )
    ;; Add Base directory to search path
    (setq temp (getenv "ACAD"))
    (if (not (wcmatch temp BaseDirectory))
    (progn
    (setq temp (strcat temp ";" BaseDirectory))
    (setenv "ACAD" temp)
    )
    )
    I am working on a set of routine to search and add the base directory to
    the reg and search path and also to remove it from the search path after
    the program ends to clean up the environment. Don't quite have the time
    right now to put the finishing touches on it.

    HTH

    TIM
     
    Timothy Spangler, Jan 11, 2005
    #34
  15. A bit off-topic, but...

    I also need to support laptops, but I simply use Windows 2000/XP's Offline
    Files feature to handle the "off network" issue. To the users it appears
    that the network files are still there. That way I don't need to do any
    extra work to sync files/folders.

    --
    R. Robert Bell


    Tom,
    I am trying this routine out and it works fine. How would you change it to
    make it file the file in a search path instead of giving and absolute
    address. I have two kinds of users. One uses the network files and one uses
    synchronized directories on their laptops. I need to be able to use search
    path. Also, I was thinking of adding layer descriptions as well but can't
    find the dxf code for that field.
    Thx,
    Tom Hanley
     
    R. Robert Bell, Jan 12, 2005
    #35
  16. Tom Hanley

    Tom Hanley Guest

    I am using a program called second copy to sync our laptops with network
    directories but I'd like to know more about those XP network off line tools?
     
    Tom Hanley, Jan 13, 2005
    #36
  17. While you are connected to the network, right-click on the folder or file
    you wish to have available off-line. Select the Offline Files item on the
    context menu.

    You can opt to sync on both login/logoff, or only logoff. For my RO users, I
    select the logoff only option (syncing on login would make no sense for a RO
    file!).

    Windows then copies the file to a hidden location on the hard drive. When
    the user is off the network, the files appear to be in the _original network
    location_.

    Therefore, I can use the same profile for both networked and off-network
    users.

    --
    R. Robert Bell


    I am using a program called second copy to sync our laptops with network
    directories but I'd like to know more about those XP network off line tools?
     
    R. Robert Bell, Jan 13, 2005
    #37
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.