WBlock and Close without save or after OOPS

WBlock and Close without save or after OOPS

jagostinho74
Collaborator Collaborator
1,943 Views
13 Replies
Message 1 of 14

WBlock and Close without save or after OOPS

jagostinho74
Collaborator
Collaborator

Hello,

 

I am trying to edit a line of code I got from this post by Mike O'Flaherty to create a macro for WBlock.

 

I would like it to prompt for user input on the insertion point for the new dwg and after that select all visible objects and close without saving or after restoring the deleted objects by the wblock command.

 

But for some reason the macro stops right after writing the new block dwg file.

What might be wrong in this code?

 

^C^Cqsave;qsave;(setq or_tm (getvar"tilemode"))(princ);(setvar"tilemode" 1)(princ);(command".ucs" "W" "zoom" "e")(princ);(command "wblock" (strcat(getvar"dwgprefix")(getvar"dwgname")) "Y" "" "non" pause "all" "" "")(princ);;(command"oops");(command"zoom" "E");(command"delay" 1000);(setvar"tilemode"or_tm)(princ);(command "close" "yes")

 

Thank you for your help.

J

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Accepted solutions (4)
1,944 Views
13 Replies
Replies (13)
Message 2 of 14

pendean
Community Legend
Community Legend
Are you (or your users) limited to only the LT versions of AutoCAD?
0 Likes
Message 3 of 14

ВeekeeCZ
Consultant
Consultant

It should be ease to write a LISP instead of this jumble of LISP and MACRO.

 

But... it could be just me, but... Would you add a noun to 'close' and 'save' words to understand which drawing should be (not) saved and closed? thx.

 
0 Likes
Message 4 of 14

jagostinho74
Collaborator
Collaborator

Not limited at the moment, but could possibly be in the future @pendean .

Why do you ask?

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Message 5 of 14

jagostinho74
Collaborator
Collaborator

@ВeekeeCZ , the messy line of code is due to me being a novice at writing Macros or/and LISP.

I have only opted for using the LISP as I found that it works a little better than the macro I was writing.

 

Not clear to me on your request when you say "Would you add a noun to 'close' and 'save' words to understand which drawing should be (not) saved and closed? thx."

 

sorry. can you clarify?

 

Thank you for your time to help me with this matter.

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Message 6 of 14

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok... why do you need to specify a point? Shouldn't it be just 0,0? If not,change '(0 0) back to pause.

 

^C^Cqsave;qsave;(setq or_tm (getvar"tilemode"))(princ);(setvar"tilemode" 1)(princ);(command".ucs" "W" "zoom" "e")(princ);(command "wblock" (strcat(getvar"dwgprefix")(getvar"dwgname")) "Y" "" "non" '(0 0) "all" "")(command"oops");(command"zoom" "E");(command"delay" 1000);(setvar"tilemode"or_tm)(command "close" "yes")

 

BTW This 'macro' won't work in LT because... it uses mostly LISP expressions.

0 Likes
Message 7 of 14

jagostinho74
Collaborator
Collaborator

@ВeekeeCZ , I need to specify a point, yes. But that's it. After selecting the point I would like it to close the doc without saving.

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Message 8 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

@jagostinho74 wrote:

... After selecting the point I would like it to close the doc without saving.


In that case, and since you appear to be overwriting the current drawing, I see no reason to save and restore the TILEMODE value, or to do the Oopsing and Zooming after the Wblocking.  Would not something like this [untested] be enough?

 

^C^Cqsave qsave (setvar"tilemode" 1) (command "_.ucs" "W" "_.zoom" "e" "wblock" (strcat (getvar"dwgprefix") (getvar"dwgname")) "Y" "" "non" pause "all" "" "" "_.close" "yes")

Kent Cooper, AIA
Message 9 of 14

jagostinho74
Collaborator
Collaborator

thank you for your help @Kent1Cooper 

 

the code you sent me does close the file but when I open it after it is blank.

I ran it again but w/o the "_.close" command at the end and it looks that it is performing a Qsave after the WBlock. How can this be since no save command is being given after the Wblock, I am thinking?

Please read a copy/paste from the command line for the latter.

 

Also, curious behaviour is that the preset OSNAP do not work when prompted for the WBlock origin point.

====================

Command: qsave
Command: qsave
Command: (setvar"tilemode" 1) 1
Command: (command "_.ucs" "W" "_.zoom" "e" "wblock" (strcat (getvar"dwgprefix") (getvar"dwgname")) "Y" "" "non" pause "all" "" "") _.ucs
Current ucs name: *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: W
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: wblock Enter name of output file: C:\Users\jagostinho\OneDrive - ChapmanTaylor\Desktop\Drawing1.dwg C:\Users\jagostinho\OneDrive - ChapmanTaylor\Desktop\Drawing1.dwg already exists, do you want to replace it? [Yes/No] <N>: Y
Enter name of existing block or
[= (block=output file)/* (whole drawing)] <define new drawing>: Specify insertion base point: non int
Invalid point.
Specify insertion base point:
Select objects: all 11 found
Select objects:
Command: QSAVE
Command: nil

==================

 

 

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Message 10 of 14

cadffm
Consultant
Consultant
Accepted solution

"non"

starts the object snap override "non" => NO snap like osmode 0

 

remove "non" and it will work as expected

 

 

Sebastian

Message 11 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

@jagostinho74 wrote:

.... it is performing a Qsave after the WBlock. How can this be since no save command is being given after the Wblock, I am thinking?....


Do you have one more Enter [""] than needed to finish the Wblock command?  That could be recalling the last outside-a-(command)-function command, which was the Qsave preceding.

Kent Cooper, AIA
Message 12 of 14

jagostinho74
Collaborator
Collaborator

thank you @cadffm .

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Message 13 of 14

jagostinho74
Collaborator
Collaborator

that was exactly it, @Kent1Cooper 

thank you

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Message 14 of 14

jagostinho74
Collaborator
Collaborator

final line of code, after all your help.

Thank you.

 

It starts the WBlock command to include all elements. Starts with the Zoom Extents to get the whole drawing visible, prompts for an insertion point w/ OSNAP on, then overwrites the current DWG with the contents with the new block, then closes the DWG w/o saving.

 

^C^Cqsave qsave (setvar"tilemode" 1) (command "_.ucs" "W" "_.zoom" "e" "wblock" (strcat (getvar"dwgprefix") (getvar"dwgname")) "Y" "" pause "all" "" "_.close" "yes")

Assistant BIM/CAD Manager

Manchester, UK


0 Likes