Pushing Xdata out to non-opened AutoCAD Electrical drawings

  • Controlling the Machine is no longer being updated. Don't worry, though, you can still follow Nate Holt at his new blog, AutoCAD Electrical Etcetera. You'll find it at http://nateholt.wordpress.com. Or you can subscribe to his feed to get latest words of wisdom automatically: http://nateholt.wordpress.com/feed/. You also can continue to view the Controlling Machine archives for Nate's AutoCAD Electrical tips and tricks.

    About Nate

Latest Post

  • Pushing Xdata out to non-opened AutoCAD Electrical drawings
    June 21, 2009, 10:21 PM Nate Holt

    A user's custom application needed a little performance boost. Opening and closing multiple drawings to gather data was just too time consuming.

    In this posting, the rarely-used "USER" table in the active project's database file will illustrate results of pushing certain extended entity data (i.e. "Xdata") out to non-opened project drawings. This data then automatically flows into the USER table and is immediately available (with a very short time delay) for project-wide queries and tasks.

    What is the project scratch database's USER table?

    Extended entity data (Xdata) assigned to wire numbers, schematic components and terminals, and panel footprints and panel terminals is automatically pulled into this table IF the Xdata appname is in this format:

    VIA_WD_USERnnn

    ... where nnn = 000 through 199. The data pulled into the table is limited to 255 character values. This means that a single wire number or component inserted into any drawing of the project can have up to 200 of these VIA_WD_USERnnn Xdata values, each with 255 characters, and have all of this data automatically maintained in the project scratch database USER table.

    What data should be pushed into these Xdata value assignments? That's up to you!

    Example... let's say that you want to remember connecting wire lug / ferrule assignments for certain component terminal pin connections. Here are the three motor starter contacts related to motor starter coil M414. Let's say that we want to mark each of these three child symbols with some wire connection "lug" assignment.

     

    Each component symbol (i.e. block insert) on this drawing carries an AutoCAD "handle" assignment (automatically assigned by the AutoCAD drawing editor as the block insert instance is popped into the schematic). For example, the bottom child contact's handle assignment is "2A0". Remember this. It will be used to link things up a bit later.

    The Example Xdata Assignment / Editor utility

    Launching the attached utility pops up this opening dialog. This lists all drawings in the current, active project. You pick which drawing and what component category to process. Here we'll select the DEMO02 drawing and "Schematic components".

    The utility queries the COMP table in the active project's scratch database file and finds all schematic components that are on the selected DEMO02 drawing (via query on field DWGIX). This dialog immediately displays:

     

    Now we pick on the three child instances of M414 and add some proposed Xdata values. Let's say that the first Xdata value will be for the component's first "01" wire connection and the second for the "02" wire connection.

     

     After making the proposed assignments for the three child contacts, the dialog displays above. The Xdata has not yet been written out to the un-opened DEMO02.dwg drawing file. It is written as soon as select the "Save changes" button.

    At this point, the utility runs through this part of its program:

    (if (not cancel3)
      (progn ; save this block of data to target drawing
        (setq changed nil)
        (princ "\nWriting Xdata changes back to drawing...")
        ; Open the drawing file
        (setq filehdl (wd_dbx_open picked_dwgnam "w"))
        (foreach rec comp_plus_user_data_lst
          ; rec = (list compdata user_lst_for_this_comp oldvals newvals)
          ; The 3rd and 4th elements only present if the xdata was
          ; edited for the given component.
          (if (= (length rec) 4)
            (progn
              (setq compdata (nth 0 rec)) ; DWGIX,INST,LOC,HDL,TAGNAME
              (setq hdl (substr (nth 3 compdata) 3)) ; strip off the "h=" prefix
              (setq user_lst_for_this_comp (nth 1 rec))
              (setq oldvals (nth 2 rec)) ; values 000 through 009
              (setq newvals (nth 3 rec))
              ; Compare old and new values for each of the USERxxx
              ; entries. On a change, go ahead and push the new
              ; value out to the target component (via its handle)
              (setq ix 0)
              (foreach new newvals
                (if (not old)
                  (setq old nil)
                ; ELSE
                  (setq old (nth ix oldvals))
                ) 
                (if (AND new (/= new old))
                  (progn ; different, push it out
                    (setq str (itoa ix))
                    (cond
                      ((< ix 10)(setq str (strcat "USER00" str)))
                      ((< ix 100)(setq str (strcat "USER0" str)))
                    )
                    ; Push this xdata value out to the target component (via its
                    ; "hdl" handle) on the opened dwg file (file handle "filehdl").
                    ; Xdata tag name is "VIA_WD_USER<suffix>"
                    (wd_1b_mod_1000_xdata filehdl hdl (strcat "VIA_WD_" str) new T)
                    (setq changed T)
                    (princ "\n")(princ (nth 4 compdata))(princ " (")
                    (princ hdl)(princ ") ")
                    (princ (strcat "VIA_WD_" str))
                    (princ "=")
                    (princ new)
                ) )
                (setq ix (1+ ix))   
              )
          ) )   
        )
        (if changed
          (progn ; close the drawing and save changes
            (princ "\n")
            (wd_dbx_close filehdl T)
          )
        ; ELSE
          (progn ; no xdata written to this drawing file.
                 ; Close with "no save"
            (wd_dbx_close filehdl nil)
        ) )
        (setq filehdl nil) 
      )

    The highlighted lines are key. These enable the Xdata values to be written out to the target components on the un-opened AutoCAD drawing file. This seems to work fine on ACE2008 through ACE2010. Did not try other versions.

    In a few moments, AutoCAD Electrical's normal auto-freshen of the project scratch database will sense that drawing DEMO02.dwg time/date stamp has changed and its data needs to be "freshened". Suddenly these Xdata assignments show up in the USER table ( ! )

     

    The link between the component's records in the USER table and the component's records in the COMP table can be established via match-ups with the DWGIX and HDL field values.

    Note: There is potential for confusion. The "nnn" part of the VIA_WD_USERnnn xdata name is zero-based but when it is extracted into the USER table, the "SUFFIX" value is one-based. This means that USER000 will map to suffix 001 in the USER table, USER001 to 002, ... USER199 maps to 200.

    Conclusion

    So, there it is. You can push custom data to components on filed drawings and then have that data automatically show up on the project's scratch database file.

    Download sample utility here

    files/29101_29200/29171/file_29171.dcl - rename USER_TABLE_DEMO.DCL and put it into any AutoCAD Electrical support folder

    files/29101_29200/29181/file_29181.lsp - rename USER_TABLE_DEMO.LSP

    To run:  APPLOAD the lsp file. Then type USER_TABLE_DEMO [Enter] at the "Command:" prompt.

    This sample utility seems to work in either SDI or MDI mode.

    0 Comment | Add Comment Controlling the Machine >

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