Lisp / Script combo to save as, nwcout, and others

Lisp / Script combo to save as, nwcout, and others

Anonymous
Not applicable
3,057 Views
7 Replies
Message 1 of 8

Lisp / Script combo to save as, nwcout, and others

Anonymous
Not applicable

So my most recent adventure into lisp / scripting I'm trying to automate the following process. We have about 5-20 files we run these operations on daily. The below process process repeats for the files that we've worked on that day. 

 

Here's what I have so far in my lsp. 

 

 

(setq cpath (getvar "dwgprefix")); get current drawing path
(setq subfolder "subfolder_we_save_to"); passing subfolder name
(setq newpath (strcat cpath subfolder)); add the new sub-folder to the end of the current path
(command "saveas" "" (strcat newpath "\\" (getvar "dwgname"))"_Yes"); saveas with new path and existing dwg name
(command "xref" "U" "*"); unload xrefs
(command "purge" "A" "*" "n"); purge
(command "plan" "W"); planview
(command "zoom" "E"); zoom to extents
(command "ucs" "V"); set ucs to view
(command "filedia" "0" "nwcout" (strcat (getvar 'DwgPrefix) (vl-filename-base(getvar 'DwgName))) "filedia" "1"); nwcout as same file name in same folder

 

here's my script.

(load "my.lsp")
_.qsave
_.close
(open "next_file.dwg")
(load "my.lsp")
_.qsave
_.close
(open "next_file.dwg")
(load "my.lsp")
_.qsave
_.close

because we have fabrication parts, and when you open the file it asks about the database to use, and credentials - I am opening the first file in the list of files, and selecting the database/login info then executing the script that starts by loading the lisp file, saving, and closing. 

 

The problem is that after the NWCOUT the drawing doesn't close, and the next one doesn't open. It seems that the lisp executes / ends cleanly - although I'm not really sure. 

 

EDIT - Here's the command window after running the script that executes the lisp. 

Command: SCR
SCRIPT
Command: (load "my.lsp")
saveas
Current file format: AutoCAD 2013 Drawing
Enter file format [R14(LT98&LT97)/2000(LT2000)/2004(LT2004)/2007(LT2007)/2010(LT2010)/2013(LT2013)/Standards/DXF/Template] <2013>: Save drawing as <C:\...\test_1.dwg>: C:\...\test_1.dwg A drawing with this name already exists.
Do you want to replace it? <N> _Yes
Command: xref
Current project path:  BEND SWIP
Enter an option [?/Bind/Detach/Path/pathType/Unload/Reload/Overlay/Attach] <Attach>: U
Enter xref name(s) to unload: *
No matching and loaded xref names found.
Command: purge
Enter type of unused objects to purge [Blocks/DEtailviewstyles/Dimstyles/Groups/LAyers/LTypes/MAterials/MUltileaderstyles/Plotstyles/SHapes/textSTyles/Mlinestyles/SEctionviewstyles/Tablestyles/Visualstyles/Regapps/Zero-length geometry/Empty text objects/Orphaned data/All]: A Enter name(s) to purge <*>: * Verify each name to be purged? [Yes/No] <Y>: n
No unreferenced blocks found.
No unreferenced layers found.
No unreferenced linetypes found.
No unreferenced text styles found.
No unreferenced shape files found.
No unreferenced dimension styles found.
No unreferenced mlinestyles found.
No unreferenced plotstyles found.
No unreferenced table styles found.
No unreferenced materials found.
No unreferenced visual styles found.
No unreferenced multileader styles found.
No unreferenced groups found.
No unreferenced Detail view styles found.
No unreferenced Section view styles found.
Command: plan
Enter an option [Current ucs/Ucs/World] <Current>: W Regenerating model.
Command: zoom
Specify corner of window, enter a scale factor (nX or nXP), or
[All/Center/Dynamic/Extents/Previous/Scale/Window/Object] <real time>: E
Command: ucs
Current ucs name:  *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: V
Command: filedia
Enter new value for FILEDIA <1>: 0
Command: nwcout
File name <test_1.nwc>:C:\...\test_1
C:\...\test_uploads3\test_1.nwc
Command: filedia
Enter new value for FILEDIA <0>: 1
Command:

Thanks for the help! 

 

Shane

 

0 Likes
Accepted solutions (1)
3,058 Views
7 Replies
Replies (7)
Message 2 of 8

cadffm
Consultant
Consultant
Accepted solution
Your Lisp and Script is, how should i say, only loaded in the current file.

If you close the file or switch to another one, there is no script what can do the next steps!

Thats how mdi works.
What you want is possible in sdi (close all drawings except your first, set SDI to 1).

Load the script..
But you need one edit: Remove your close statements!

In sdi only one document is active,
You can not close the document, only switch to another..

After this test set sdi to 0 again.

Sebastian

Message 3 of 8

Kent1Cooper
Consultant
Consultant

NWCOUT is not a vanilla-AutoCAD native command, but a NavisWorks add-on, and therefore [I believe*] can't be used in a (command) function -- that only recognizes native AutoCAD command names.  *If the way the NavisWorks overlay incorporates it makes it qualify as a "native" command, maybe, but more likely it's something equivalent to an Express Tool, which would have the same limitation.  Easy check:  try simply (command "nwcout") by itself at the command line, and see what happens.

 

If it's made with (defun C:NWCOUT ...), the way to run one of those in AutoLisp is [outside any (command) function]:

 

(C:NWCOUT)

 

including the parentheses.  But arguments aren't allowed -- you can't then feed it your drawing path/name.  However, you should be able to call it in a Script  with just

 

NWCOUT

 

but whether you can then give it a drawing path/name, I'm not sure -- I'll leave it to you to experiment, or Search for ways to feed input [that needs to be built from System Variables, etc.] to custom-defined commands in Scripts.

Kent Cooper, AIA
0 Likes
Message 4 of 8

Anonymous
Not applicable

thanks for the help, and suggestions - I'll give these two a try.

0 Likes
Message 5 of 8

Anonymous
Not applicable

 

  

0 Likes
Message 6 of 8

Anonymous
Not applicable

Hi there - 

Thanks for your suggestion. The change to SDI (set to 1) and removing the close statements got me pointed in the right direction. I updated the lisp to the folowing and now I can run through each file and do what we're looking for! 

 

Although, I can't do it when launching from script. Something with my lisp doesn't end / close right so the script is terminated (i'm guessing).

 

Much appreciate the help.

Message 7 of 8

Stephen.DonaldsonH5DU3
Participant
Participant

I am dealing with the same issue here.  The last post states There was a fix, but no code was shown.  Does anyone have an update?

0 Likes
Message 8 of 8

Fahad_YK
Enthusiast
Enthusiast

Do You have any updates about this?

0 Likes