AutoCAD Electrical Forum
Welcome to Autodesk’s AutoCAD Electrical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Electrical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Count .dwgs from .wdp using (c:wd_proj_wdp_data)

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
garet79
720 Views, 5 Replies

Count .dwgs from .wdp using (c:wd_proj_wdp_data)

If I use (nth 1 rtrn) I'll get the count of .dwg files.  In this case I have 5 .dwgs in my .wdp file so count is 5.  I want to use that total to cycle through all my sheets.  When I run line 6 in the VLISP Editor I get 5.  However, the next line gives error: malformed list on input.  I've read that (nth 1 rtrn) returns a list of lists.  I tried the append function but got error: bad argument type: listp 5.  What is line 6 actually giving me and how can I get this code working ?

 

 

1.      (defun c:ns(/ ix dwglist)    
2.                  (c:wd_proj_pick_dlg)
3.            (if GBL_wd_prj
4.                  (progn
5.                         (setq ix (c:wd_proj_wdp_data))
6.                         (setq dwglst (nth 1 ix))                    
7.                (while (> dwglst 0)  
8.                        (if (> dwglst 0)
9.                            (progn    
10.                          (setq dwglst (1 - dwglst))
11.                          (c:aenext)
12.                          )
13.                      )
14.                 )
15.             )
16.          )
17.       (princ)
18.      )

Tags (3)
5 REPLIES 5
Message 2 of 6
PatMurnen_Adsk
in reply to: garet79

The error in the code is actually in this line 

(setq dwglst (1 - dwglst))

 

It has an extra space. It should be 

(setq dwglst (1- dwglst))

 

But, even with that fix I don't believe you can call AENEXT and open drawings using lisp. Each drawing has its own instance of lisp so as soon as you open another drawing the original lisp function is aborted, it would never get through the loop. 

 

Depending on what you are trying to do I have another way to go about this using the AutoCAD Electrical Project-wide Utilities command. With this command you can run a script on any or all of your drawings within a project. The script can contain a call to a lisp function or standard commands on the command line. So, the stuff you were going to put in your loop to do one each drawing is what you would put in the script or lisp. Then you let the Project-Wide Utilities command take care of the loop through the drawings. If you use a lisp within a script you just need to make sure the lisp file is loaded automatically each time a drawing is opened. This can be done by adding it to the startup in the APPLOAD command.

 

So if you want to try this method, your first step is to create a script or lisp function that does what you want on the active drawing. If it is a lisp function, once it works on the active drawing put it in a script file and make sure it still works on the active drawing. Then you can use the Project-wide Tools, check the box to "Run command script file", enter the script file in the dialog and OK. You will be asked to select the drawings to process.

 

Regards,

Pat Murnen

 



Pat Murnen
Principal Content Developer
Product Development – AutoCAD Product Line Group

Autodesk, Inc.

Message 3 of 6
garet79
in reply to: PatMurnen_Adsk

Pat,

 

Thanks for your quick response.  I tried your way and it worked as described.   It's nice but I don't like the fact that you have to create two additional files and you have to add your lisp file to the Startup Suite via APPLOAD.  This process will be on going as more LISP files are created.  This doesn't seem effective to CAD managers that have everything networked.  It doesn't appear it can be saved to a Profile for Workspace?  I was trying to keep all code located in the acaddoc.lsp file since it loads with every drawing.  I'm creating custom tabs with buttons for different code in acaddoc.lsp.  I was trying to use code from acaddoc.lsp to cycle through the total .dwgs.

 

Back to my original question.  I fixed the space and changed (c:aenext) to (c:wd_proj_dnext).  It worked both ways but like you said only on the first sheet.  Once it got to the next sheet it stopped.  If the Project-Wide Utilities can cycle through then there has to be a "User" version.  VBA might be a better API to mimic Project-Wide Utilities?  Thanks again.

Message 4 of 6
PatMurnen_Adsk
in reply to: garet79

I don't know everything that goes on "under the hood" with Project-Wide Utilities but I do know it generates scripts on the fly and calls them at the end of the .lsp code, like a daisy-chain kind of thing. But, it gets complicated. I don't know VBA so I can't say if it would be easier but maybe someone else can help with that.

 

You definitely could put the .lsp code in the acaddoc.lsp that you want to call. You do not need a separate .lsp file that you add to the startup. That is just one way to do it.

 

There is a .lsp API for the Project-Wide Utilities.script functionality that maybe would simplify things so you can call this and not have any dialogs pop up.

 

(c:ace_projwide_script dlst scrfnam)

 

If dlst is nil it processes all drawings in the active project, otherwise it expects a list of drawing names with the full path.

 

scrfnam is the script to process. You can include the full path to the file if it isn't in the default script folder.

 

So once you create the scripts you could program the buttons to call this API with the appropriate script.

 

Anyway, one idea.

 

Regards,

Pat Murnen

 

 

 


Pat Murnen
Principal Content Developer
Product Development – AutoCAD Product Line Group

Autodesk, Inc.

Message 5 of 6
garet79
in reply to: PatMurnen_Adsk

That's it!  Adding (c:ace_projwide_script dlst scrfnam) is the only line in the body of my code now.  Between that API and the Project-Wide Utilities tool I can "check" all my drawings.  FYI, using either method doesn't work if you have to "call" another .scr file from your .lsp.  My file order went .scr to .lsp. back to .scr, which didn't work for me.  I had to move all script to one file and then I loaded my .lsp at the end.  Appreciate all the help.

Message 6 of 6
PatMurnen_Adsk
in reply to: garet79

Glad that worked for you. 

 

Regards,

Pat Murnen



Pat Murnen
Principal Content Developer
Product Development – AutoCAD Product Line Group

Autodesk, Inc.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost