Nate Holt's Blog

August 9, 2009

User creates custom “Add New Drawing” tool – AutoCAD Electrical

Filed under: Electrical — nateholt @ 9:11 pm

debbie03

Debbie Guenthner wanted to improve the automation department’s efficiency. It was taking a bit too long for the automation drafters at Kice Industries to correctly set up and add a new, blank drawing to an existing AutoCAD Electrical project.

Kice Industries, located in Wichita, Kansas, has a long history of designing and building a wide range of industrial air systems. A key part of these systems is the electrical controls and AutoCAD Electrical has been the tool of choice for this task for the last four years.

Out-of-the-box

Setting up a new drawing and adding it to the current project is fully supported in out-of-the-box AutoCAD Electrical and shown below in the ACE project manager.

debbie02

This would bring up the generic AutoCAD Electrial “Add drawing” dialog where the user would need to browse to an appropriately-sized template drawing, select a “save to” folder, etc.

Debbie wanted to create a Kice-specific “Add drawing” tool that would have Kice drawing-size option selectable by just a button pick. All of the other stuff would take care of itself. Goal: one button pick and off and running!

A VBA Utility

debbie01Debbie decided to write a small Visual Basic utility to provide a simple pick dialog.

The pick on the dialog would launch a small AutoLISP function which would then create the new drawing from the appropriate template. It would then make a call into the AutoCAD Electrical API to add the new drawing to the project drawing list.

But there was one missing piece to making this work seamlessly…

 

 

 

 

A missing piece

Adding a drawing using the built-in “Add Drawing” tool prompts the user for permission to adjust the new drawing’s “Drawing Properties” to match a set of defaults carried in the overall project “.wdp” file (the “?[n]” entries). But there is no equivalent API call to do this. So, her VB utility would do everything very nicely but the user would then need to manually check the new drawing’s Drawing Properties to make sure that they matched up with the project defaults.

Solution – create a small AutoLISP function to “fill in the missing piece”

The solution was pretty straightforward. Read the project defaults from the “.wdp” project file and save to a list. Next read the new drawing’s invisible “WD_M” block attribute values – this block with its attributes is used to store the “Drawing Properties”. Go through these two lists and compare. For each mismatch, update the corresponding WD_M block attribute with the value pulled from the project defaults carried in the “.wdp” file. There it is.

N8 Consultants put together this small AutoLISP function to deal with the missing piece above:

; ** 06-Aug-09 NEHolt  N8 Consultants LLC  http://n8consultants.com
(defun c:match_proj_properties ( / rtrn proj_default_lst wd_m_entname ix
                x oldval newval change_cnt attrname wd_m_attribute_name_lst)
  ; Make active drawing's WD_M block settings match the defaults
  ; carried in the active project's ".wdp" file - the "?[n]" values.
  ; Skip update of drawing "WD_M" block's "SHEET" attribute value.
 
  ; The attributes carried on the WD_M block are extracted into a 77+ element global list
  ; called "GBL_wd_m". The values in this list correspond to the following list of attribute names
  ; in the order they are shown here.
  (setq WD_M_attribute_name_lst
    (list "RUNGHORV" "REFNUMS" "TAGMODE" "TAG-START" "TAG-RSUF" "TAGFMT"
            "WIREMODE" "WIRE-START" "WIRE-RSUF" "WIREFMT" "WINC"
            "RUNGDIST" "DLADW" "SHEET" "XREFFMT" "RUNGINC" "DRWRUNG" "PH3SPACE"
            "DATUMX" "DATUMY" "DISTH" "DISTV" "CHAR_H" "CHAR_V" "HORIZ_FIRST"
            "XY_DELIM" "WIRELAYS" "WIRENO_LAY" "WIRECOPY_LAY" "WIREFIXED_LAY"
            "UNIT_SCL" "FEATURE_SCL"
            "TAG_LAY" "XREF_LAY" "DESC_LAY" "TERM_LAY" "CXREF_LAY"
            "CDESC_LAY" "LOC_LAY" "POS_LAY" "MISC_LAY"
            "WLEADERS" "PLC_STYLE" "ARROW_STYLE"
            "LINK_LAY" "COMP_LAY" "SHEETDWGNAME" "ALT_XREFFMT" "TAGFIXED_LAY"
            "GAP_STYLE" "MISC_FLAGS" "IEC_PROJ" "IEC_INST" "IEC_LOC"
            "WIREREF_LAY" "MISC_DATA" "FAN_INOUT_LAYS" "FAN_INOUT_STYLE"
            "LOCBOX_LAY" "SORTMODE" "XREF_STYLE" "XREF_FLAGS" "XREF_UNUSEDSTYLE"
            "XREF_FILLWITH" "XREF_SORT" "XREF_TXTBTWN" "XREF_GRAPHIC"
            "XREF_GRAPHICSTYLE" "XREF_CONTACTMAP" "XREF_TBLSTYLE"
            "XREF_TBLTITLE" "XREF_TBLINDEX"
            "XREF_TBLFLDNAMS" "XREF_TBLCOLJUST" "WNUM_OFFSET" "WNUM_FLAGS"
            "WNUM_GAP")
  )
  ; -- program begins here -- 
  (setq change_cnt 0)
  (if (setq rtrn (c:wd_proj_wdp_data))
    (progn ; some data returned from active project's ".wdp" file
      (if (setq proj_default_lst (nth 3 rtrn))
        (progn ; have project defaults, now get active dwg's WD_M values
               ; and push into GBL_wd_m global. Return the entity name
               ; of the WD_M block insert in "wd_m_entname".
          (if (AND (setq wd_m_entname (c:wd_reread_dwg_params))
                   GBL_wd_m) ; valid data pulled from WD_M block insert
            (progn ; now cycle through and look for differences between
                   ; the project settings and the active drawing's
                   ; settings. Skip over the SHEET attribute value.
              (setq ix 0) ; index number    
              (foreach newval proj_default_lst
                (setq oldval (nth ix GBL_wd_m))
                (if (AND oldval (listp oldval))
                  (progn ; old value is a Lisp "list". Convert it to comma-delimited string value
                    (setq oldval (wd_1_lst_to_delim_str oldval ","))
                ) )   
                (if (AND newval oldval (/= newval oldval))
                  (progn
                    (setq attrname (nth ix WD_M_attribute_name_lst))
                    (cond
                      ((= ix 13)) ; skip the SHEET number assignment
                      ((not attrname)) ; no target attribute name, skip
                      ((listp oldval) ; old value is a "list", avoid the complication for now
                        (princ "\nList difference skipped old=")(princ oldval)(princ " new=")(princ newval)
                      )
                      (T ; project default is different from active dwg's
                         ; wd_m block setting. Update.
                        (princ "\n")(princ attrname)
                        (princ " old=")(princ oldval)(princ " new=")(princ newval)
                        (c:wd_modattrval wd_m_entname attrname newval nil)
                        (setq change_cnt (1+ change_cnt))
                    ) )
                ) )
                (setq ix (1+ ix))
              )
          ) )
      ) )
  ) )
  (if (> change_cnt 0)(c:wd_reread_dwg_params)) ; make sure to reread the WD_M block's values
  (princ)
) 

 

Debbie added a call to the above utility in her overall Lisp function “(c:project)” … 

(defun c:project()
  (setq name (getvar "DWGPREFIX"))
  (setq dwg (getvar "DWGNAME"))
  (setq filename (strcat name dwg))
  (c:ace_add_dwg_to_project filename nil)
  (c:wd_tb_process_one 0 (list (list 0 0 0 0 0 0 1 1 0 0 1 1 1) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15))
  (c:match_proj_properties)
  (princ)
)

… that is then called from within her VB program…

'Update ladder numbers to match filename
    If frmSheetValues.txtDwgSeries.Text = "C" Then
        ThisDrawing.SendCommand ("wd_ladr_reref ")
    ElseIf frmSheetValues.txtDwgSeries.Text = "IO" Then
        ThisDrawing.SendCommand ("wd_ladr_reref ")
    End If           
        'If true then the new drawing is added to the active project.
    If chkProject.Enabled = True Then
        ThisDrawing.SendCommand "(c:project) "
 

Conclusion

Debbie added these utilities to the Startup Suite. Everything now works perfectly!

1 Comment »

  1. […] I/O drawing tool (trim dangling wires) Multiple projects within a “Super” project (updated) User creates custom “Add New Drawing” tool Quick-fix for blank line issue in PnlPurchBOM “User Post” Support file […]

    Pingback by Index of AutoCAD Electrical Utilities – April 2006 through August 2009 « AutoCAD Electrical Etcetera — September 28, 2009 @ 8:20 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 39 other followers

%d bloggers like this: