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

  • Mass update - attribute re-namer tool - AutoCAD Electrical
    May 20, 2009 10:32 PMby Nate Holt

    This came up recently. It's not a perfect solution but seemed to make the user happy. He had a number of old schematic designs made with generic blocks with attributes. He wanted some AutoCAD Electrical compatibility for simple things like BOM reporting.

    The key is to rename the attributes to be those that AutoCAD Electrical expects to find. Here is a utility that seems to work. It process all block inserts on the active drawing. For each block it scans the block for all its attributes. It compares each attribute to a list of "old" names. On a match it gets the corresponding new name and renames the attribute on-the-fly.

    Seems to work!

    This AutoLISP program is reproduced here. The old versus new attribute name list is in the top part of the program. Edit this file and replace the old/new attributes appropriately. Save the file, APPLOAD it, and run it!

    ; 20-May-09 NEHolt created
    (defun c:attr_rename_list (  / x_en enn edd ss slen ix atnam
               namelist hit blk_ent
               matchname newed x)
      ; Process all block instances on active drawing. Check each
      ; attribute for match on first element in list below. On any
      ; match, rename the attribute to the new name given in the
      ; second element.
     
      ; ***********   ATTRIBUTE OLD versus NEW names list   ******************
      (setq namelist (list
          ; list old name and new name. Old name can contain wild cards.
          (list "ID" "TAG1")  ; list old name and new name.
          (list "TEXT-1" "DESC1")
          (list "TEXT-2" "DESC2")
          (list "TERMINAL1" "TERM01")
          (list "TERMINAL2" "TERM02")
          (list "PARTNUM" "CAT")
          (list "VENDOR" "MFG")
      ) ) 
      ; **********************************************************************
     
      ; Extract selection set of all block inserts on active drawing 
      (setq ss (ssget "_X" '((0 . "INSERT"))))
      (if (/= ss nil)
        (progn
          (setq slen (sslength ss))
          (setq ix 0)
          (while (< ix slen)
            (setq blk_ent (ssname ss ix)) ; get next block insert to process       
            (setq ix (1+ ix)) ; increment for next time
            (setq enn (entnext blk_ent))
            (setq edd (entget enn)) 
            (while (AND enn (/= (cdr (assoc 0 edd)) "SEQEND")
                                (/= (cdr (assoc 0 edd)) "INSERT") )
              (if (= (cdr (assoc 0 edd)) "ATTRIB")
                (progn
                  (setq atnam (cdr (assoc 2 edd)))
                  (setq hit nil)
                  (foreach x namelist
                    (if (not hit)
                      (progn ; no match yet, keep processing
                        (setq matchname (car x))               
                        (if (wcmatch atnam matchname)
                          (progn ; found exact match or wild-card match
                            ; Change name now. Substitute in new name.
                            (setq newed (subst (cons 2 (cadr x)) (assoc 2 edd) edd))
                            (entmod newed) ; update the title block instance
                            (entupd blk_ent)
                            (princ "\n")
                            (princ atnam)
                            (princ " --> ")
                            (princ (cadr x))
                            (setq hit 1) ; flag that found
                    ) ) ) )
                  )
                )
              )    
              ; go to next sub ent in block instance and loop back up
              (if (setq enn (entnext enn)) (setq edd (entget enn)))
          ) )
          (setq ss nil) ; release the selection set
        )
      )
      (princ) ; prettier
    )

    Download a copy of the utility here: files/27801_27900/27811/file_27811.lsp

    Rename it to something like attr_rename_list.lsp. Then to run it, APPLOAD this file and type attr_rename_list [Enter] at the AutoCAD command prompt.

    1 Comment | Add CommentIn Controlling the Machine >

Previous Post

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