Controlling the Machine

  • 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

  • Pushing Xdata out to non-opened AutoCAD Electrical drawings
    June 21, 2009 10:21 PMby 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 CommentIn Controlling the Machine >

Previous Post

  • AutoCAD Electrical's report customization - the 'User Post'
    June 15, 2009 07:53 AMby Nate Holt

    We've posted a number of times with specific examples of report 'User Posts'. Here is another but one that is given in much greater detail. This posting might better serve as template for creating your own customizations of AutoCAD Electrical's reports.

    The Challenge

     A European dealer had a customer who wanted his Cable From/To report to repeat the parent cable marker's catalog assignment for each and every child entry in the report.

    For example, here is how a portion of the default report displays.

    The problem for this user is that he wants to see the cable's catalog assignment show up for EVERY core/conductor displayed, not just the first 'parent' entry for the cable.

    In the highlighted section above for cable tag-ID '-W5', the parent core/conductor carries the MFG/CAT catalog assignment (parent = 1 in the CBLP1C2 column). This shows up for the one line in the report for cable -W5. But the remaining child core/conductors (child = 2 in CBLP1C2 column) do not carry the parent's assignment and therefore their entries in the report show blank for the catalog assignment.

    The customer wants all these filled in.

    One work-around is to put the same catalog assignment on each child core/conductor of the cable. This will solve one problem (our Cable From/To report) but will then totally confuse the Bill of Materials report... we'll get a full cable BOM entry for every conductor/core found in a cable.

    So, the only reasonable work-around is to create a "user post".

    The Default User Post for the Cable From/To Report

    There is a default user post AutoLISP utility for each AutoCAD Electrical report type. There is one for this Cable From/To report.

    So, when the normal Cable From/To report displays,  the user selects the "User Post" button on the lower right-hand corner of the report dialog.

    This launches an AutoLISP utility "cablecon.lsp" and passes the block of report data (in form of "list of lists") to this cablecon.lsp utility. The location of this user post program file is displayed in the command window (shown below for ACE2008, subsequent releases have it in "c:\documents and settings\All Users\Documents\Autodesk\Acade 200x\Support\"). This user post utility immediately fires up and displays an options dialog as shown here.

     Our challenge is to add a fourth option to this dialog: "Display catalog assignments on child entries"

     Step 1 - Modify the dialog "DCL" file

    Open the file cablecon.dcl with any ASCII text editor. This file should be in the same folder as the user post utility (path shown in command window above).

    Make a back-up copy. Then carefully modify the original version. Add the fourth option as shown below and save the modified file.

    That should now trigger a fourth toggle to display when the Cable From/To User Post is run. But this new toggle is not "hooked up" to anything. That's the next [more complicated] step.

    Step 2 - Modify the cablecon.lsp file

    Open up this file (path given above) with an ASCII text editor or with the Visual Lisp editor built into AutoCAD / AutoCAD Electrical. Page down a bit to the "main routine" section shown below. Add in the two lines of code as marked. These two lines make the initial link into the new toggle added to the dialog definition file in Step #1.

     

    Now the meat of the addition...!

    Page down to near the bottom of the cablecon.lsp file. Insert the new section as shown here:

    Here is how the above is meant to work...

    When the user selects the 4th toggle on the opening DCL dialog, it sets the "user_4" flag to a value of "1". This triggers this highlighted section of the utility to execute. The first "foreach..." makes an initial pass through each line of passed report data (in list "wd_rdata"). Here is how this first pass works, but a bit of explanation needed first.

    The format of the report data is a list of sublists. Each sublist represents the data for a line in the report. Each line's sublist has about 70 or so elements. What each element means is given in a comment section shown at the top of the user post cablecon.lsp file and is reproduced below.

    ; -- Structure of the "wd_rdata" list of lists passed from ACE:
    ;
    ; (list (list <report line1 data>) (list <report line2 data>) ... )
    ; where each line data sublist consists of a list of the following:
    ; 0 = wire number
    ; 1 = LOC for "from" device
    ; 2 = TAG ID for "from" device
    ; 3 = terminal PIN number for "from" device connection
    ; 4 = LOC for "to" device
    ; 5 = TAG ID for "to" device
    ; 6 = terminal PIN number for "to" device connection
    ; 7 = WIRELAY for wire touching "from" device
    ; 8 = WIRELAY for wire touching "to" device
    ; 9 = line ref of "from" device
    ; 10= line ref of "to" device
    ; 11= SHEET number for "from" device
    ; 12= SHEET number for "to" device
    ; 13= cable marker - TAG ID (if cable marker present in wire)
    ; 14= cable marker - conductor color/number value
    ; 15= cable marker - LOC code
    ; 16= cable marker - MFG part number assignment
    ; 17= cable marker - CAT part number assignment
    ; 18= cable marker - ASSYCODE part number assignment
    ; 19= cable marker - catalog lookup DESC field value
    ; 20= cable marker - catalog lookup QUERY1 field value
    ; 21= cable marker - catalog lookup QUERY2 field value
    ; 22= cable marker - catalog lookup MISC1 field value
    ; 23= cable marker - catalog lookup MISC2 field value
    ; 24= cable marker - catalog lookup USER1 field value
    ; 25= cable marker - catalog lookup USER2 field value
    ; 26= cable marker - catalog lookup USER3 field value
    ; 27= cable marker - DESC1 description value assignment
    ; 28= cable marker - DESC2
    ; 29= cable marker - DESC3
    ; 30= cable marker - 1=parent marker, 2=child marker
    ; 31= TAG:PIN - combined "from" device text consisting of TAG ID and PIN number
    ; 32= TAG:PIN - combined "to" device text consisting of TAG ID and PIN number
    ; 33= SEC assignment for drawing with "from" device
    ; 34= SUBSEC assignment for drawing with "from" device
    ; 35= SEC assignment for drawing with "to" device
    ; 36= SUBSEC assignment for drawing with "to" device
    ; 37= INST assignment of "from" device
    ; 38= INST assignment of "to" device
    ; 39= IEC style name for "from" device
    ; 40= IEC style name for "to" device
    ; 41= TERMDESC value of "from" device wire connection point
    ; 42= TERMDESC value of "to" device wire connection point
    ; 43= wire connection sequence code for "from" device wire connection
    ; 44= wire connection sequence code for "to" device wire connection
    ; 45= PNLWDLEV1
    ; 46= PNLWDLEV2
    ; 47= CMPHDL1 = handle of the "from" component
    ; 48= CMPHDL2 = handle of the "to" component
    ; 49= DWGIX1 = the "from" component's drawing index number
    ; 50= DWGIX2 = the "to" component's drawing index number
    ; 51= DWGNAM1 = the %D drawing name value of the "from" drawing
    ; 52= DWGNAM2 = the %D drawing name value of the "to" drawing
    ; 53= handle of the cable marker
    ; 54= INST of the cable marker
    ; 55= CBLDWGIX drawing index number of the cable marker
    ; 56= entity name of the connected wire on "from" component
    ; 57= entity name of the connected wire on "to" component
    ; 58= wire connection direction of "from" component wire connection
    ; 59= wire connection direction of "to" component wire connection
    ; 60-62 = X,Y,Z of any associated "from" panel layout wire connection
    ; 63= "from" panel footprint representation wire connection direction
    ; 64-66 = X,Y,Z of any associated "to" panel layout wire connection
    ; 67= "to" panel footprint representation wire connection direction
    ; 68 = estimated wire length based upon 60-62 and 64-66

    So, our first pass needs to look for parent entries (index 30 in the sublist) that have non blank catalog assignments (index 17 in the sublist). For each one found in the first pass, it saves that line of data in a variable called "parent_lst".

    Now, with all parent cable markers found, the utility makes a second pass through the lines of report data. It looks for "child" cable marker entries (value of "2" in the 30th index position) and makes sure that the child entry has no current assignment (the index 17 position is blank).

    For each hit, it quickly looks for a parent match (from the "parent_lst" list collected in the first pass). If match on tag-ID and INST and LOC, then it pulls a copy of the parent's MFG/CAT/ASSYCODE  and pushes it into the child's sublist (index positions 16,17, and 18).

    The second pass builds a new, fresh copy of the list of sublists for the report (built in the variable called "rtrn"). The parent entries and children that have no parent match get pushed back into this new version of the data "as is". But the child entries that find a match get their modified version pushed into "rtrn". The version last line shown above replaces the original "wd_rdata" list of data with this modified version.

    This new version of the report data is returned back to the report display dialog. That's about it. The dialog will now display the child entries with the MFG/CAT values filled in ( ! )

     

    0 Comment | Add CommentIn Controlling the Machine >

Subscribe to Blog

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

RSS

Categories

All

Blog Roll

AUTODESK MANUFACTURING COMMUNITY

Ellipsis
The official Autodesk Manufacturing Tech Evangelist blog
Under The Hood
Brian Schanen on Vault, Productstream, and more
In the Machine
Garin Gardiner hosts the official blog of the Inventor Product Team
Controlling the Machine
Archive of Nate Holt's AutoCAD Electrical posts

RECOMMENDED

Being Inventive
The official support blog for the Autodesk Inventor product line
Between the Lines
Shaan Hurley's AutoCAD Blog
It's Alive in the Lab
Scott Shepherd's Lab's Blog
Beyond the Paper
Volker Joseph's DWF Blog
Lynn Allen's Blog
Staying current with AutoCAD and Autodesk

PEER

AutoCAD Electrical Etcetera
Nate Holt shares AutoCAD Electrical tips and tricks.
Autodesk Manufacturing Northern European
The official blog for the Autodesk Northern Europe Manufacturing Technical Team.
Sean Dotson's Site
Sean Dotson's mCAD Tutorials, Forums, Admins & more
The Autodesk Informer
Helpful sites, tutorials, and industry news
CAD Professor
Inventor, Inventor LT, and AutoCAD news and updates.

Send to a Peer

You must login to share pages.

Feedback

Tell us what you think of the site.

Send Feedback