View Full Version : Open all drawings read only
aturgeon
2009-07-22, 04:39 PM
Alright, so I have this program I am using to extract information from a batch of AutoCAD drawings all at once. Sometimes people have the drawings open, other times they don't. when I generate the script, it verifies all the drawings as either being open at the time or closed at the time of the script creation. The script runs through all the drawings as long as those drawings that were open/closed when the script was created remain as so. However, if someone opens a drawing/closes a drawing during the process and the script comes to that drawing during that change, it will halt. Failure.
My question is, would there be a command line switch, autoLISP, or some other modification I could make so that ALL DRAWINGS would be opened read-only? This way, regardless if they are open or not, it opens it read-only. I don't need to save changes to the drawings but I want to be able to open every drawing via commandline (for the script) without having any dialog boxes (so it doesn't halt). Any ideas? Thanks.
rkmcswain
2009-07-22, 07:55 PM
The open method supports read-only.
(vl-load-com)
(if (zerop (getvar "SDI"))
(vlax-invoke-method
(vla-get-documents (vlax-get-acad-object))
'Open
"C:\\mydrawing.dwg"
:vlax-true
)
)
aturgeon
2009-07-22, 11:02 PM
So there is no way to set up an opening method without defining the specific drawing to be opened within the open command? No way to redfine the _OPEN command to open as read-only regardless if it is open or not?
aturgeon
2009-07-22, 11:51 PM
What about WRITESTAT? (if (= (getvar "WRITESTAT") 1) (command "_OPEN" "Y")?
rkmcswain
2009-07-23, 12:05 AM
No way to redfine the _OPEN command to open as read-only regardless if it is open or not?
Like this?
(vl-load-com)
(command "._undefine" "open")
(defun C:open ()
(setq fn (getfiled "Select Drawing" "" "dwg" 0))
(if (zerop (getvar "SDI"))
(vlax-invoke-method
(vla-get-documents (vlax-get-acad-object))
'Open
fn
:vlax-true
)
)
)
aturgeon
2009-07-23, 08:46 PM
Almost. Is there a way to suppress the dialog?
aturgeon
2009-07-23, 09:40 PM
Could you just use (getstring "") somewhere in the lisp to make it take on the value of the next input?
rkmcswain
2009-07-23, 10:05 PM
Almost. Is there a way to suppress the dialog?
That is what the first bit of code did... :?:
I'm confused now...
aturgeon
2009-07-23, 10:40 PM
well i liked redefining the open command to always open read-only, but then I wanted to have it prompt for the next line (the drawing path and filename) to open that drawing read only. I modified it a bit to say:
(vl-load-com)
(if (zerop (getvar "SDI"))
(vlax-invoke-method
(vla-get-documents (vlax-get-acad-object))
'Open
(getstring "")
:vlax-true
)
)
That hangs up because the automatically generated list produces file names in quotes.
then I tried
(vl-load-com)
(command "._undefine" "open")
(defun C:open ()
(if (zerop (getvar "SDI"))
(vlax-invoke-method
(vla-get-documents (vlax-get-acad-object))
'Open
(getstring "")
:vlax-true
)
)
)
which works kinda, but then it returns to the host drawing (Drawing1) to run the script instead of the drawing it opened read-only...
I'm confused as well... this batch script generator (Hurricane) doesn't seem to like my methods of trying to open things read-only. I can load the lisp into AutoCAD to redefine the OPEN command, but then it doesnt accept the filename in quotes.
Maybe it can't be done this way and I am best off just putting the program on a user that has read-only access to drawings and then running the program from there. That way the script will open all the drawings up read-only as well as use the batch script generator correctly unless you can think of a way to modify the lisp. Thanks for all your effort though.
rkmcswain
2009-07-23, 11:39 PM
Not sure why you are inserting the (getstring) in there.
Get your filenames first, then feed them to the original function.
Also, you can turn off smilies to avoid the smiley in your code, and the CODE tags are and
aturgeon
2009-07-27, 05:28 PM
The reason I have (getstring) is because the next line of the script is the filepath (which is automatically generated from a list). Hence why I need the input to be there. The second method in my previous post is the closest I have gotten to get exactly what I want.
First, it opens some random "Drawing1.dwg"
Then, it calls the _OPEN redefined and the getstring prompts for the next line of the script.
After the script enters the filename, it opens the drawing read-only.
Just when you think it is about to work, it goes back to "Drawing1.dwg" and runs my script instead of on the read-only drawing.
Then, it closes the read-only drawing and opens the next one, but then also runs the script on the Drawing1.dwg...
Basically it would be so much easier to just set the default _OPEN method from readonly being FALSE to TRUE. Oh well.
aturgeon
2009-07-27, 06:24 PM
Actually, is there a command to switch between open drawings? (usually I use CTRL+TAB) Is there some way to do this in the command line or redefine something in AutoCAD to do this?
rkmcswain
2009-07-27, 07:07 PM
Actually, is there a command to switch between open drawings?
You could use the "Activate" method on the drawing that you want to be current.
aturgeon
2009-07-27, 08:16 PM
I have been trying the activate method, I can't get it to work. If I have two active documents open, how do I change the active AutoCAD document? Could you give me an example without using a specific file name?
rkmcswain
2009-07-27, 08:58 PM
I have been trying the activate method, I can't get it to work. If I have two active documents open, how do I change the active AutoCAD document? Could you give me an example without using a specific file name?
This should work, I have not tested it though...
(vl-load-com)
(defun SetDwgCurrent (name)
(vlax-invoke-method
(vlax-invoke-method
(vla-get-documents
(vlax-get-acad-object))
'Item
name
)
'Activate)
)
;;
;; call it like this
;; (setdwgcurrent "abcd.dwg")
aturgeon
2009-07-27, 09:32 PM
*sigh* I think I am just going to call it quits. It activates the drawing but then it hangs up in the middle of the script. I assume it is because the script is essentially interrupted and cannot run anymore.
I tried embedding the project in the drawing and then running it that way, which works, but I use this same method to close the drawing and reset the active drawing to Drawing1 but when it tries to open the next drawing I get an automation error for some reason... I don't know how else to go about this, I guess it is just too complicated. Thanks for all your help though.
RobertB
2009-07-28, 12:30 AM
*sigh* I think I am just going to call it quits. It activates the drawing but then it hangs up in the middle of the script. I assume it is because the script is essentially interrupted and cannot run anymore.Visual LISP cannot continue across multiple active documents. The original function will only coninue in the original drawing.
You need to move to .NET for multiple document support, or use Visual LISP on the other documents without activating them.
aturgeon
2009-07-28, 03:31 PM
You are right! So I took that into consideration and rewrote that last part and it works for the most part... Hurricane just does stupid stuff when you close a drawing on a different computer during the processing.
Just a summary of what worked:
First, I used a lisp to open the drawings read-only within Hurricane. I called it Read-only.lsp. It contained the following:
(vl-load-com)
(command "._undefine" "open")
(defun C:open ()
(if (zerop (getvar "SDI"))
(vlax-invoke-method
(vla-get-documents (vlax-get-acad-object))
'Open
(getstring "")
:vlax-true
)
)
)
It redefines the open command to open drawings read-only, then prompt the user (script) to give it a filename.
I then went into Options->Prefs to change the open method to a custom method, _OPEN I changed the pre-batch script to load this lisp into AutoCAD with (load "ReadOnly.lsp")
The second big step involved redefining the close procedure. It turned out that it would open a host drawing to run the script from (Drawing1) but then it would close with the normal close procedure. Therefore, I used VBA to create a short little close method of any other open drawings without saving changes:
Dim DWGS As AcadDocuments
Dim ADWG As AcadDocument
Sub Main()
Set DWGS = ThisDrawing.Application.Documents
Set ADWG = DWGS.Item(1)
If ADWG.Active = False Then ADWG.Close (False)
End Sub
Finally, I called this procedure within the post-user script (command "-vbarun" "filelocation/Project.dvb!Close.Main") in order to close the read-only drawing.
The rest of my vba procedure worked because it was embedded in the read-only drawing, therefore I did not have to call out any external procedures to get it to do what I want. In addition, it ran on the read-only document rather than the host (Drawing1).
Thanks to all who helped out! Maybe this will help others in the future as well.
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.