Setting values using a data from a CSV table

Discussion in 'AutoCAD' started by sfidler, Feb 29, 2004.

  1. sfidler

    sfidler Guest

    Hello all,

    I am trying to put together a tool to handle layering standards for our company, primarily dealing with what layer blocks and annotation are created on. Most of our drawings use our clients' plot style/color settings, so I need to incorporate enough flexibility for the program to select the proper colors. Although we use a few dozen layers, they use only a few colors or styles. I should also mention that although I have written some fairly simple VBA macros for excel in the past, this is my first stab at writing anything for autocad.

    After starting down a kind of "blunt force" approach in lisp that would set a user variable to indicate the client name and then use if/then/else to assign the proper color if layer creation were necessary, I realized that besides being inelegant to begin with, I would need to edit the actual code if we added a client. False start, five yard penalty, repeat the down.

    After some reconsideration, I think the answer lies in storing the settings in a few comma-delimited files that can be easily appended when we get new clients. The actual function would be run from a custom menu that would pass arguments for what block is inserted and what layer it should be on. Here's a pseudo-code version of what I think I need to do:

    'SETUP:
    'put a CLIENT variable into a custom dictionary
    'compare CLIENT to a CSV text file, and return a corresponding integer CLIENTNUM. If drawing uses in-house style, return 0
    'store CLIENTNUM in the dictionary.

    'LAYERHANDLER:
    'check if MYLAYER exists
    'if yes, store OLDLAYER, make MYLAYER active, unlocked, on thawed and vthawed, insert block/annotation, the restore OLDLAYER (don't want to change property after the fact using something like entlast because some commands might make mulitple entities)
    'if no, compare MYLAYER to CSV file, get its default color, compare that to another CSV that translates our colors into client colors and get proper color or style, etc., create layer with that color, then add the object(s).

    'sample CSV record from first file:
    'LAYERNAME, LINETYPE, PLOT/NONPLOT, DEFAULTCOLOR,

    'sample CSV record from second file- this way I don't have to make new entries for every single layer:
    DEFAULTCOLOR, CLIENT1COLOR, CLIENT2COLOR,...

    'Thus proper color would be in field corresponding to CLIENTNUM+1

    I think I have accumulated most of what I need from the discussion group, help files and various websites, but I have no clue as to how to reference the comma-delimited files.

    Thanks in advance for your help. Those of you who give so freely of your time and knowledge on this board are truly invauluable to those of us learning, and have my appreciation.

    Shawn
     
    sfidler, Feb 29, 2004
    #1
  2. Shawn,

    While it coud certainly be done with a csv file, I wouldn't waste the
    effort doing it that way. It's far better to use an INI file for this.
    Since Microsoft uses this method, there are functions built into the
    WIN32API specifically designed tto accomodate this. Refer to the following
    article [nd source codee] by Randy Birch: Using INI Files to Save
    Application Data - The Basics [ http://tinyurl.com/2r4fz ].

    Another equally acceptable way is to use an XML file. Best bet is to look
    at planet-source-code.com for examples.

    Good luck,

    Mike

    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Feb 29, 2004
    #2
  3. sfidler

    sfidler Guest

    Mike,

    Thanks for the suggestions. I think I see how this works and understand how I'll need to organize my data using the .ini file, so I'm taking a run at it.

    Could you clarify a bit for me the advantage of going this route rather than csv? Is it simply because I won't need to reconstruct as much of the wheel because the functions are already in place, or will there be an advantage at the performance end?

    Thanks,
    Shawn
     
    sfidler, Feb 29, 2004
    #3
  4. Shawn,

    You've got it in a nutshell - both INI and XML are 'organised' and easier
    to read without having to parse the entire file like with a CSV formatted
    file. The lack of parsing would transmit to performance, too. There are
    lots of INI wrappers available as well as ample examples so there isn't
    much work to do other than find one that works for you.

    Mike
    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Mar 1, 2004
    #4
  5. Does the Layer Translator not meet your needs?

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Mar 1, 2004
    #5
  6. One small point of correction. Most XML parsers use the DOM model which
    indeed reads the entire contents of the file into memory. Even so, XML is
    quicker and easier to work with than CSV.

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Mar 1, 2004
    #6
  7. sfidler

    sfidler Guest

    What I forgot to mention in my original post is that we're still running autocad 2000, so the layer translator isn't available.

    Shawn
     
    sfidler, Mar 1, 2004
    #7
  8. sfidler

    jbryant4 Guest

    "There are lots of INI wrappers available as well as ample examples"...... What about XML "wrappers"...I assume "wrappers" are pre-written functions to handle XML data....I have a very large program that reads .txt files to generate drawings.....I need to re-write it to read XML files instead....Are there functions out there that can read XML files and set variable values?....If so, it would sure save me some time...Thanks in advance.
     
    jbryant4, Mar 2, 2004
    #8
  9. Sure, there's lots of XML classes too. Go to either planet-source-code or
    codehound and search on xml.
     
    Mike Tuersley, Mar 2, 2004
    #9
  10. The XML DOM is the "wrapper" for XML storage.



    AcadX for AutoCAD 2004 Beta 1
    http://mysite.verizon.net/~vze2vjds/acadx/AcadX16.zip


    "wrappers" are pre-written functions to handle XML data....I have a very large program that reads .txt files to generate
    drawings.....I need to re-write it to read XML files instead....Are there functions out there that can read XML files
    and set variable values?....If so, it would sure save me some time...Thanks in advance.
     
    Tony Tanzillo, Mar 2, 2004
    #10
  11. sfidler

    jbryant4 Guest

    I searched thour the site, and found alot of XML stuff, but not exactly what I am looking for....Here is my situation.....I have to read an XML file which contains data that I need to generate the drawing. I am assumming I will need to do this in VBA. I have several thousands lines of LISP code that actually generates the drawing from the data extracted from the XML file. I will not convert this to VBA, therefore it will remain in LISP. What I am looking for a some simple routines to read the XML file for the required data (about 100 pieces of information). Then I think I can assign all this data to a LISP list, which can be read by the LISP routines....Not very experienced in VBA, so any help, or advice, will not be wasted. Thanks
     
    jbryant4, Mar 3, 2004
    #11
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.