read layers in from a comma delimited file

Discussion in 'AutoCAD' started by Jamie Duncan, May 19, 2004.

  1. Jamie Duncan

    Jamie Duncan Guest

    I don't know how to get data from a quattro pro spreadsheet, so our layer master list is exported into a series of .txt files, comma delimited with a .lay extension. This function reads them in and creates the layers. You can use and modify to your hearts desire. It also loads all linetypes from .lin file if you want them.


    Just thought I'd like to share with this ng some of the work I've been able to do with guidance from the top 10...

    Jamie Duncan

    (defun c:arctlaysin (/ ans filena fn temp temp2)
    ;;;(arctvsav) put your variable save function call here
    ;;;this part loads linetype definitions
    (setvar "expert" 3)
    (while (/= ans "N")
    (setq temp (getstring "\nLinetype file to load <ACAD>: ")
    ltfile (if (= temp "") "ACAD" temp)
    temp (findfile (strcat ltfile ".lin"))
    )
    (if temp
    (progn
    (command "linetype" "l" "*" ltfile "")
    (setq ans "N")
    )
    (prompt (strcat "\nLinetype file <" ltfile "> not found - try again."))
    )
    )
    ;;;this part loads paperspace layers for titleblocks, legends etc from a file called sheet.lay
    ;;;modify or delete as you need.
    ;;;note the filename and path is easily modified for your own use

    (setq filena "sheet") (if (null (setq fn (open (strcat ARCTDRVE "/archr/" filena ".lay") "r")))
    (progn
    (setq temp nil)
    (prompt (strcat "\nFile "(strcase filena)" not found - try again."))
    )
    )
    (jddreadlayernames filena fn)

    ;;;allow user to select which set of layers - floor plans, details, elevations etc
    ;;; you can modify this to your own layers and paths

    (setq temp nil)
    (prompt (strcat "\nLayer Config. files will be loaded from the < " ARCTDRVE "/archr > subdirectory. "));;; arctdrve setup at startup
    (while (null temp)
    (initget "Floorplan Detail Siteplan Elevation")
    (setq temp2 (getkword "\nSelect Layers to Load: Floorplan/Siteplan/Detail/Elevation <Floorplan>:"))
    (cond
    ((= temp2 "Floorplan")(setq filena "flrlayer" temp "y"))
    ((= temp2 "Siteplan")(setq filena "site" temp "y"))
    ((= temp2 "Detail")(setq filena "detail" temp "y"))
    ((= temp2 "Elevation")(setq filena "elev" temp "y"))
    ((= temp2 nil)(setq filena "flrlayer" temp "y"))
    )
    (if (null (setq fn (open (strcat ARCTDRVE "/archr/" filena ".lay") "r")))
    (progn
    (setq temp nil)
    (prompt (strcat "\nFile "(strcase filena)" not found - try again."))
    )
    )
    )
    (jddreadlayernames filena fn)
    (prompt "\nImporting of Layer Configuration for this drawing now complete.")
    (setq c:arctlaysin nil)
    ;;;(arctvrst) restore any variables
    (princ)
    )
    (princ)
    (defun jddreadlayernames (filename filepathname / lin pos1 pos2 lname1 lntype1 lcr1 LayerTable theLayer nplt1 flagc)
    (setq lin (read-line filepathname)
    LayerTable (vla-get-layers *doc*)
    )(prompt (strcat "\nAdding new layers, colors and linetypes from " filename " ...\n"))
    (while (and lin (/= lin ""))
    (setq lst2 (cdf_list lin)
    lname1 (nth 0 lst2)
    lntype1 (nth 2 lst2)
    lcr1 (nth 1 lst2)
    flagc T
    lcr1 (if (= (atoi lcr1) 0)(progn (setq flagc nil) 1 )(atoi lcr1))
    )
    (if (not (tblsearch "ltype" lntype1))(setq lntype1 "CONTINUOUS" flagl nil))
    (if (not (< 0 lcr1 257))(setq lcr1 1 flagc nil))
    (setq thelayer (vla-add LayerTable lname1))
    (vla-put-linetype thelayer lntype1)
    (if flagc (vla-put-color theLayer lcr1))
    (if (wcmatch lname1 "*NP*")
    (vla-put-plottable theLayer :vlax-false)
    (vla-put-plottable theLayer :vlax-true)
    )
    (setq lin (read-line filepathname))
    )
    (close filepathname)
    )
     
    Jamie Duncan, May 19, 2004
    #1
  2. Thanks for the contribution, I have one comment:

    Generally, I advise against changing the EXPERT
    system variable, as long as there is a remote
    possibility it will not get reset back to what
    it was when the program began. There's two ways
    that can happen:

    1. Provide no error handler to restore
    system variables you changed.

    2. Provide an error handler, which is
    stopped prematurely by pounding on
    the ESCape key many times.

    Pounding on the ESCape key many times in rapid
    succession can stop an error handler before it
    gets a chance to complete (e.g., before it has
    restored system variables that were changed).
    However in your case, I see no error handler for
    your command (that's not saying there isn't one,
    just that I didn't see it the code you posted).

    While this is true for all system variables, this
    rule is critical for EXPERT: Under no circumstances
    should we ever change it without providing an error
    handler to restore it. But even with one, a user
    can stop it prematurely by doing what I say above.

    The EXPERT system variable was provided as a way
    to circumvent a lot of "are you sure" type prompts.

    However, from a LISP programming perspective it
    is the cure that's worse than the illness, because
    there is no guarantee that EXPERT or any other
    system variable's value will be restored by your
    code. The last thing you want to happen is to have
    your code change this variable without restoring
    it, because that can suppress confirmation prompts
    that a user may depend on. In the case that you're
    changing it to the same value that its normally set
    to by your users, that may not be a problem, but in
    the context of posting this code for others, this
    is a legitmate caveat.

    My own approach is to test EXPERT whenever it's
    value can alter a prompting sequence, and just
    branch accordingly:

    (defun redefine-some-block (name basept ss)
    (command "._-BLOCK" name)
    (if (and (tblsearch "block" name)
    (> (getvar "expert") 1)
    )
    (command "_y")
    )
    (command basept ss "")
    )






    I don't know how to get data from a quattro pro spreadsheet, so our layer master list is exported into a series of .txt
    files, comma delimited with a .lay extension. This function reads them in and creates the layers. You can use and
    modify to your hearts desire. It also loads all linetypes from .lin file if you want them.


    Just thought I'd like to share with this ng some of the work I've been able to do with guidance from the top 10...

    Jamie Duncan
     
    Tony Tanzillo, May 19, 2004
    #2
  3. Jamie Duncan

    Jamie Duncan Guest

    Thanks for the insight Tony,

    the arctvsav & arctvrst functions save and restore the expert variable.
    It's well advised that anyone using this routine should do the same.

    this is one variable that can truly yield unpredictable results when
    (command is invoked.


    Jamie Duncan




    master list is exported into a series of .txt
    and creates the layers. You can use and
    able to do with guidance from the top 10...
     
    Jamie Duncan, May 19, 2004
    #3
  4. Jamie Duncan

    Jamie Duncan Guest

    After rereading your post a second time, I realise that your method is
    preferential to the method I now use (error trapping etc) due to the
    vaguaries of human input

    Thanks


    Jamie Duncan


    master list is exported into a series of .txt
    and creates the layers. You can use and
    able to do with guidance from the top 10...
     
    Jamie Duncan, May 19, 2004
    #4
  5. EXCELLENT advice, thank you for posting this Tony.
     
    michael puckett, May 19, 2004
    #5
  6. Jamie Duncan

    Jamie Duncan Guest

    oh you guys....

    God forbid that a girl should write a nice program, and you should pounce
    'cause she commented out the error trapping she had written, not foreseeing
    the multiple esc's from inpatient users.

    :-(

    Jamie Duncan
     
    Jamie Duncan, May 20, 2004
    #6
  7. I wasn't pouncing on you. That's an unfair perspective.

    Look at it this way: You are able to take advantage
    of lessons that I had to learn *the hard way*.

    And yea, I've dealt with more than my fair share
    of impatient users who insist on pounding on ESCape
    until they see a "Command: " prompt, or the clock
    strikes 5 PM. :)
     
    Tony Tanzillo, May 20, 2004
    #7
  8. I'm sorry you choose to interpret my acknowledgment of Tony's
    staid advice as some kind of veiled shot at you or your fine
    contributions in these forums, it is not. Please carry on.

    oh you guys....

    God forbid that a girl should write a nice program, and you should pounce
    'cause she commented out the error trapping she had written, not foreseeing
    the multiple esc's from inpatient users.

    :-(

    Jamie Duncan
     
    michael puckett, May 20, 2004
    #8
  9. Jamie Duncan

    Jamie Duncan Guest

    Sorry Tony, that was all really tongue-in-cheek!

    I appreciate all the help and insights from pioneers like yourself.

    And sorry if I came off harshly, I really was trying to be humorous.

    Jamie Duncan
     
    Jamie Duncan, May 20, 2004
    #9
  10. Jamie Duncan

    Jamie Duncan Guest

    Read above Michael...I was just playing the tired old card of 'a woman's
    work is never acknowledged unless she errs'

    really was tongue in cheek - other than an old dead CAD guy, I haven't
    noticed much chavinism in this NG at all.

    And thanks for help as well.

    And I wish the both of you a very good day, and a happy long weekend....wait
    that's a canuckleheaded thing.

    "<g>

    Jamie Duncan
     
    Jamie Duncan, May 20, 2004
    #10
  11. WOW, I did not get humour from your post. Guess it's
    time to change the babel fish!

    Long weekend here I come, though I will be coding
    at home for most of it (personal project).

    Cheers and happy posting Jamie :)

    Read above Michael...I was just playing the tired old card of 'a woman's
    work is never acknowledged unless she errs'

    really was tongue in cheek - other than an old dead CAD guy, I haven't
    noticed much chavinism in this NG at all.

    And thanks for help as well.

    And I wish the both of you a very good day, and a happy long weekend....wait
    that's a canuckleheaded thing.

    "<g>

    Jamie Duncan
     
    michael puckett, May 20, 2004
    #11
  12. Jamie Duncan

    Jamie Duncan Guest

    I won't give up my day job and start doing stand-up.

    Jamie Duncan
     
    Jamie Duncan, May 20, 2004
    #12
  13. Jamie Duncan

    Jamie Duncan Guest

    or your fine
    contributions in these forums, it is not. Please carry on.


    Thanks Michael!


    Jamie Duncan
     
    Jamie Duncan, May 20, 2004
    #13
  14. Jamie Duncan

    Phil Guest

    (if (= (getvar humor) 0) (post)(postanyway))


     
    Phil, May 21, 2004
    #14
  15. Jamie - No apology is necessary, no offence taken.

    My failure to use emoticons when I should, often
    results in the impression that I actually mean
    what I say here :)
     
    Tony Tanzillo, May 21, 2004
    #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.