Writing to Block Attributes in un-opened Drawings - Example App

  • Oh no! An error has occurred!
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • You need to be logged in to do that.
  • Coinciding with the acquisition of VIA Development, Nate joined Autodesk in March of 2003 after a decade stint as an entrepreneur following a two-decade stint as a controls engineer and software applications developer at Owens-Corning. Nate is now the lead product architect for AutoCAD Electrical. He loves this stuff.

    About Nate

Latest Post

  • Writing to Block Attributes in un-opened Drawings - Example App
    February 6, 2007, 07:37 PM Nate Holt

    This little utility illustrates some interesting things you can do with the AutoCAD Electrical API. It shows 1) query of the project database, 2) a simple UI using classic DCL, and 3) writing new attribute values back to block inserts without opening the individual AutoCAD drawings.

    Here's the deal

    You frequently re-use previous AutoCAD Electrical designs for new projects. You run the Copy Project command to create the base new project and run the Title Block update utility to adjust the title blocks.

    Wow, in a few minutes you're a week ahead of where you would have been in your pre-AcadE days. But now you run into a more tedious part of the process. You decide that you need to go through all 500+ drawings in your copied project. You need to adjust each drawing's default "IEC" Installation config value from its existing "CELL01" value to the new project's value of "CELL02". You need to do this before you can run the component re-tag across the new project set and do the final touch-up on the project drawing set.

    So, is there any way around this? Yes... this little utility illustrates one way to do it.

    inst_loc_01.jpg

    You highlight the drawings to process in the top part of the dialog and enter in the new INST and/or LOC value in the bottom part. Hit OK and it should happen (make backup of your work first, just in case!). This should work on AcadE 2007 and above. If you want to play with this sample utility, download the AutoLISP file and the support AutoLISP dialog DCL file.

    To use:
    1. Download both files, put the ".dcl" file somewhere in your Acad path so the utility can find it.
    2. APPLOAD the first file, project_inst_loc.lsp
    3. Type PROJECT_INST_LOC [Enter] at your command line to launch the utility.
    4. Pick dwgs to process and enter the new Inst/Loc values. Hit OK.
    When finished, you may need to do "rebuild" on your project's database file before you see the changes show up.

    How does this thing work?

    Pieces of the program are shown below, but if you want to follow along in full context, open the project_inst_loc.lsp file with a text editor (or AutoCAD's built in Visual LISP editor - type "VLIDE" at command line).

    Let's dissect this thing.

    inst_loc_03.bmp

    Above is where the utility finds the active project's scratch database file name. It dumps the file name into a variable we've called "scratch_fnam". This scratch database is actually a file in Microsoft Access format with a bunch of tables for wires, components, terminals, and such. These tables are automatically kept up-to-date by AutoCAD Electrical.

    The utility does a query on the "FILETIME" table of this scratch database file. This table has pretty much all of the information we need to make this utility do its thing. Each record in this table ties in to one of the drawings defined in our project's ".wdp" file.

    The program pulls out a handful of fields for each record. These include field DWGNAME (the full path/name of the drawing file), the existing IEC "inst" and "loc" values, and the WD_M_HDL field. This is key. It is the AutoCAD "handle" number of the drawing's WD_M settings block. This is the block that includes attributes IEC_INST and IEC_LOC... these are the attributes that we want to be able to examine and possible update with our utility. It will play an important role at the very end of the utility.

    inst_loc_11.bmp

    Now the part above goes through the record data and builds up a list of lines of text data to be displayed in the dialog's drawing selection part of the dialog. Each line carries the INST, LOC, and drawing name for each drawing, separated by "\t" TAB characters. It is just a subset of the full data we pulled from FILETIME but is kept in synch with the full set of data. This list of display data ends up in a variable we've called "dsplst".

    Finding the DCL support file

    Here's where we now prepare to pop open a dialog. First we have to find the support file where this dialog is defined.

    inst_loc_05.bmp

    These lines search in the Acad and the AutoCAD Electrical support paths for the target file. If not found then an error message will display and the program will fall out the bottom and exit back to the command prompt.

    The DCL dialog definition itself

    inst_loc_06.bmp

    Above is the content of the dcl file for our utility. It looks a bit cryptic but compare it with the actual display shown in this posting's first image. You see the title, followed by the column labels for the list box. Next is the "list_box" entry itself. It defines the big pick list. Note that is has a flag "multiple_select" set to "true". This means that you will be able to do a multiple selection in the drawing list (instead of just picking and processing one drawing at a time). Finally we have some controls for the INST and LOC toggles and edit boxes.

    Interaction between the AutoLISP program and the DCL definition

    inst_loc_07.bmp

    The above is probably the most difficult to decipher. The "action_tile" lines define what is to happen when each button, toggle, edit box, or display list subdialog is selected. The "mode_tile" lines preset whether a button is "fuzzed" out or enabled. The three lines starting at "start_lst" outputs our "dsplst" drawing data to the big list box on our dialog.

    Summarizing the dialog part of this: the drawings we multi-select are returned as a list of index numbers in variable "picked". If we toggled the "Change" for INST, then variable "chg_i" is set and "chg_l" is set for change LOC. The actual typed-in values for the INST and LOC edit boxes are carried in variables "new_inst" and "new_loc".

    Figuring out which drawings were selected for processing

    inst_loc_08.bmp

    First we have to convert the long string of space-delimited index values into a list of individual index values. For example, if you selected the first three drawings and the 5th drawing from the list, it would return this text string: "0 1 2 4". We need to break this up into a list of individual index values "0", "1", "2", "4".

    The parallel lists: Data list pulled from FILETIME and the DCL dialog display list

    Okay, now we can map the dwg entries selected in the dialog with the underlying full data pulled from the scratch database's FILETIME table. This will give us the full drawing name AND the "handle" of that drawing's WD_M block. This is the key to mapping our new attribute value(s) back to the drawing's WD_M block insert - on to attribute names IEC_INST and IEC_LOC.

    inst_loc_09.bmp

    Writing the new attribute value to the WD_M block insert

    inst_loc_10.bmp

    This finishes it up. The utility makes a few calls to open the target AutoCAD drawing file and push the attribute value out to the target block (based upon the block's "handle" value that we grabbed from the scratch database file, remember?).

    Hopefully this will work for you. Give it a try. Don't be afraid to modify this if you want to try to do something more specific to your needs.


    UPDATE

    A similar set of calls may be used to read/write Xdata values to entities on an unopened drawing file. They are twins to the "mod_attr_val" functions in the example above. Here are the "attribute" ones used in the original example above. Tried on ACE2008 and worked fine. May work on earlier versions, not sure. Make sure that wdcom1b.fas is APPLOADED.

    (wd_1b_mod_attr_val ff ben atnam atval firstonly updflg) ; write attribute value "atval" out to block insert entity handle "ben" to attribute name "atnam"

    and here is the twin that does Xdata

    (wd_1b_mod_1000_xdata ff hdl appnam data updflg) ; create or update xdata appname "appnam" with value "data" on entity with handle "hdl" on the target drawing

    ... and the read xdata version

    (wd_1b_get_1000_xdata ff hdl appnam) ; returns "appnam" xdata value pulled from entity "hdl"

     

     

    0 Comment | Add Comment Controlling the Machine > All

Comments



You must be logged in to post a comment.

Subscribe to Blog

Want to keep up with the latest? Subscribe to the RSS feed today.

RSS

Tags

You must be logged in to add a tag.

Send to a Peer

You must login to share pages.

Feedback

Tell us what you think of the site.

Send Feedback