Recently I had a few people ask me about a wiki site where I had posted some sample User Post files. That site is no longer available so I thought I would post something here about user posts and give an example.
Reports in AutoCAD Electrical are pretty flexible but sometimes you just need something that isn't available in the reports. Maybe you want to calculate a cost based on some fields in the report, or you want to include a field that is not available in the report, or you want to combine the data in multiple fields into one field. All this and more can be done with a custom user post file.
Each report has a specific User Post .lsp and .dcl file. You can find the file names in the Help topic, Report Generator Dialog Box, User Post section. It is called a user post file because it is up to the user to write the actual Lisp code. A few samples are supplied with AutoCAD Electrical and framework .lsp and .dcl files are supplied for each report. The files are in the C:\Users\Public\Documents\Autodesk\Acade 2015\en-US\Support folder in a default stand-alone installation.
The .dcl file defines the options on the dialog that appears when you click the User Post button on the Report Generator dialog box.

You edit (using a text editor not a word processor) the .dcl file to change the option labels.

The .lsp file defines what happens for each option on the dialog. Here is part of what the framework .lsp looks like –
; Look for dcl file of same name, open if found.
(if (AND (OR (not GBL_wd_postprocess) ; otherwise bypass dialog
(AND (= user_1 "0") (= user_2 "0") (= user_3 "0")));if no option is pre-selected, also need to popup dialog
(setq dclnam (c:ace_find_file "cbl.dcl" 16))) ; 16=display error dialog if file not found
(progn
(setq dcl_id (load_dialog dclnam))
(if (new_dialog "main_select" dcl_id)
(progn
(set_tile "user1" user_1) ; set toggles per defaults above
(set_tile "user2" user_2)
(set_tile "user3" user_3)
(action_tile "user1" "(setq user_1 $value)")
(action_tile "user2" "(setq user_2 $value)")
(action_tile "user3" "(setq user_3 $value)")
(action_tile "cancel" "(setq cancel 1)")
(start_dialog)
(unload_dialog dcl_id)
) ) ) )
(if (AND wd_rdata (not cancel))
(progn ; user didn't cancel out of dialog, okay to continue
(if (= user_1 "1")
(progn
(princ
(strcat "\n " (c:wd_msg "WLAY031" (list "1" "cbl.lsp") "Nothing defined for user%1 option (see %2)"))
) ) )
(if (= user_2 "1")
(progn
(princ
(strcat "\n " (c:wd_msg "WLAY031" (list "2" "cbl.lsp") "Nothing defined for user%1 option (see %2)"))
) ) )
(if (= user_3 "1")
(progn
(princ
(strcat "\n " (c:wd_msg "WLAY031" (list "3" "cbl.lsp") "Nothing defined for user%1 option (see %2)"))
) ) )
)
)
(c:wd_rtrn_2wd rtrn) ; return post-processed list back to AutoCAD Electrical's report dialog
You edit the .lsp file to add the code to make some change to the report data.
You need to know the field and the field order so you can modify the appropriate values to get the results you want. Most of the user post .lsp files provide a list of the fields in the report data at the beginning of the file. If the sample .lsp file does not provide the list of fields, you can get the fields in the Help topic by searching on "Data Fields to Report" and looking for the report you are interested in. For example, look at the Help topic Cable Summary Data Fields to Report Dialog Box.
Example:
Let's say you wanted to customize the Cable Summary report by combining the DESC1, DESC2, and DESC3 values into in one field, separating each with a space. According to the Report Generator Dialog Box Help topic, the .lsp and .dcl file names are CBL.lsp and CBL.dcl.
So first, I edit the CBL.dcl file to indicate my new option. I change the text as highlighted:
:toggle{key="user1";
label=/*cbl_dcl_006*/"Combine DESC1, DESC2, DESC";
}
Now I am ready to edit the .lsp file. Looking at the CBL.lsp file supplied, I find the fields I am interested in:
0= cable marker tag-ID
1= cable marker - DESC1 description value assignment
2= cable marker - DESC2
3= cable marker - DESC3
4= cable marker - MFG part number assignment
5= cable marker - CAT part number assignment
6= cable marker - ASSYCODE part number assignment
So here is my code snippet that replaces the framework for the first user option:
(if (= user_1 "1") ; picked first option on dialog to combine DESC1, DESC2, DESC3 and put in the DESC1 field
(progn
(setq rtrn '()) ; start a new blank list to add the modified data to
(foreach data wd_rdata ; look at each line in the report
; pull out the 3 lines of description
(setq desc1 (nth 1 data))
(setq desc2 (nth 2 data))
(setq desc3 (nth 3 data))
; string them together adding the space if non-blank
(if (/= desc1 "")
(if (/= desc2 "") (setq desc1 (strcat desc1 " " desc2)))
; else
(setq desc1 desc2)
)
(if (/= desc1 "")
(if (/= desc3 "") (setq desc1 (strcat desc1 " " desc3)))
; else
(setq desc1 desc3)
)
; plug this new value back in the DESC1 field using the supplied wd_nth_subst function
(setq data (wd_nth_subst 1 desc1 data))
; add this line of data into my new list as the first element
(setq rtrn (cons data rtrn))
)
; need to reverse the list since built it by adding on at the front
(setq rtrn (reverse rtrn))
) )
Now it is ready to try. Here is my report before I run the User Post. I won't need the DESC2 and DESC3 fields once it is done, but I am just showing it here so you can see the values.

I run the Cable Summary report and I click User Post on the Report Generator dialog box. So far so good, since I see my new option.

As soon as I click OK, the program runs through my new option and returns to the report. And here is my updated report (I used the Change Report Format to remove the DESC2 and DESC3 fields).

And new in AutoCAD Electrical 2015, you can add a User Post option to your report format (.SET) files. This way the User Post option runs automatically before the report displays. Adding it to the format file also means a user post can be used when you run Automatic Reports.
By Pat Murnen