PDA

View Full Version : Open drawing read-only via command line



JasonSelf
2004-12-11, 12:37 AM
Does anyone know if I can open a drawing read only by the command line only? here is sudo-code to what I think should happen.

filedia
0
Open
filename.dwg <ReadOnly>

Any help would be appreciated,
Jason Self

RobertB
2004-12-11, 02:03 AM
The easiest way to do it is to use the (open) statement in append mode, then open the drawing in the editor. That makes it readonly.

peter
2004-12-13, 12:54 PM
The VBASTMT command can do that

Type this as the expression after running the vbastmt

The true is the flag for read-only

(vl-cmdf "vbastmt"
"acadapplication.documents.open \"c:/acad/312vg.dwg\",TRUE")

Peter Jamtgaard

JasonSelf
2004-12-13, 05:11 PM
Thanks for the tips, but upon further thinking I came to another question....

This particular lisp is designed to write a script and then call the script to do batch plotting of our drawings. It kinda forces certain settings etc. etc. The problem is happening because on some installations (and mine has started doing it) it asks me if I want to open a drawing read only...this throws my script into complete chaos. The drawings that are being selected are not read-only they are not open by anyone else but for some reason autocad thinks it is when this script starts to run.....oddly enough, if I manually run the script that is generated it does not tell me that drawings are read only, in fact it works exactly as it should.

I don't know if that tells anybody anything or not but if anyone has seen anything like this I would appreciate any tips.

Thank you,
Jason

kennet.sjoberg
2004-12-13, 10:44 PM
Be sure that You do not have anyone of the drawings in "Window drop down list" or the active one in the script You are trying to run.

: ) Happy Computing !

kennet

JasonSelf
2004-12-15, 09:53 PM
This is happening with no other drawings open, except for a fresh new drawing to run the lisp from. I have set the lisp up to actually check to see if the active drawing is new or not. The odd thing is that If with this script I select only one file it seems to run correctly. I am using DOSLib to select the files to be processed.

kennet.sjoberg
2004-12-15, 10:20 PM
Can You post a generated script file ? (no hands)
with at least 3 drawing names to process.

: ) Happy Computing !

kennet

JasonSelf
2004-12-15, 10:34 PM
open
I:/Jobfi~QB/2004/04-0321/T-1.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/A-1.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/A-2.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/A-3.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/A-4.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/A-5.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/A-6.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/A-7.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/E-1.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/E-2.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/M-1.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/M-1.1.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close
open
I:/Jobfi~QB/2004/04-0321/P-1.0.dwg
osmode
16
filedia
0
-layout
s
24x36
-plot
yes
24x36
DesignJet 1050C.pc3
Arch D - 24 x 36 In. (landscape)
Inches
Landscape
No
window
(list 0.0 23.5)
(list 36.0 0.0)
1:1
C
yes
Intertech Lineweight.ctb
yes
yes
yes
no
yes

no
yes
._Close





It generates slightly differently depending on autocad versions, this one is for 2005. It has some lines that may appear rhetorical but it has to do with things that load at each drawing open, running this via the command 'script' works perfectly, its calling it with the lisp that gives me problems. I would have to post alot of stuff to get the lisp working. but here is the important part.

It calls this


(defun RUNSCRIPT ()
(command "script" "c:/distribute.scr")
)

kennet.sjoberg
2004-12-16, 06:57 AM
_CLOSE N
open

or

_CLOSE Y
open

N when save, Y when not save

: ) Happy Computing !

kennet

JasonSelf
2004-12-16, 02:46 PM
That is not where the problem is occuring, I think I know your exact thought with that statement. AutoCAD 2k4 and lower asks if you don't make any drawing changes and all you do is zoom or print, however AutoCAD 2k5 and greater does not, in the script generated if a 2k4 machine is the one running it, it has the Y and the N. The script does not get passed the first open command when it is being run from the lisp so it never reaches the first close command.

kennet.sjoberg
2004-12-16, 10:38 PM
In the end of the -plot command You may have one empty row to mush
yes
<-------------
no
yes
._Close

: ) Happy Computing !

kennet

kennet.sjoberg
2004-12-16, 10:54 PM
...and missing one empty line in the begining of the plot command
Command: -PLOT Detailed plot configuration? [Yes/No] <No>: Y
Enter a layout name or [?] <Model>:

: ) Happy Computing !

kennet

kennet.sjoberg
2004-12-16, 11:05 PM
You can also write the plot command in one lisp line in the script file
-----------------------------------V-- extra Enter for the model/layout
(command "-plot" "Yes" " " "24x36" "DesignJet 1050C.pc3" "Arch D - 24 x 36 In. (landscape)" "I" "L" "N" "W" "0.0,23.5" "36.0,0.0" "1:1" "C" "Y" "Intertech Lineweight.ctb" "Y" "Y" "Y" "N" "Y" "N" "Y" )

You can try to cut and paste that line into AutoCads command line and see if You get a plot.

: ) Happy Computing !

kennet

ps.
when or if You write the plot command line in to a script file,
replace all " with \42 inside the parenthesis.
(write-line "(command \42-plot\42 \42Yes\42 . . . . .)" ScriptFil )
ds.

JasonSelf
2004-12-20, 02:11 PM
I somehow mis stated my problem. The script on its own works perfectly as it is. But for some reason when it is called via the lisp routine it finds the first drawing read-only. My current fix is to just cancel processing and run the generated script manually....This is not ture on all machines.

kennet.sjoberg
2004-12-20, 11:45 PM
I am sorry, i miss leaded my self to,
the plot command seems correct to me and the function runscript to.
I am running a similar plot/batch routine my self ( almost 4000 rows of code ) and using doslib to select files
(setq add2plot (dos_getfilem "Select files" (getvar "DWGPREFIX" ) "Drawing ( *.dwg )|*.dwg"|| ) )
and the only differences I now can see is that my filenames is long like :
("C:\\Program\\AutoCAD 2002\\Sample\\" "Expo Headquarters model.dwg")
and Your filnames is truncated like :
I:/Jobfi~QB/2004/04-0321/T-1.0.dwg
Maybe that mess up Your AutoCAD2005, I am running AutoCAD 2002

I am sorry I can not find any answer.

: ) Happy Computing !

kennet

richard.binning
2004-12-21, 02:47 PM
I somehow mis stated my problem. The script on its own works perfectly as it is. But for some reason when it is called via the lisp routine it finds the first drawing read-only. My current fix is to just cancel processing and run the generated script manually....This is not ture on all machines.
Since you are already using the doslib functions...you might try something like the following:




;detect if file is marked "Read Only" and choose to open it anyway
(if (dos_openp fname)
(progn
;file is Read Only so open it that way
;save it to a unique name so we can save it
;prior to running etransmit command
;(alert "Open Read Only?")
(write-line (strcat "open " fname) file1)
(write-line (strcat "YES") file1)
(setq fname2 (strcat fname1 "_DeleteMe.dwg"))
(write-line (strcat "saveas " "2000 " fname2) file1)
(setq file2 (open datfile "a"))
;open the file to write
(write-line fname2 file2)
(close file2)
(setq delFlag "T")
);progn
(progn
;file is available for use
(write-line (strcat "open " fname) file1)
(setq delFlag "F")
);progn
);end if


RLB

RobertB
2004-12-21, 03:19 PM
Since you are on 2005, the script I looked at really begs the question: Why aren't you simply using Publish?

kennet.sjoberg
2004-12-21, 08:01 PM
Look what I found in acad help file . . . a gust from my previous post. . .

Script files fail when using long file names and directory names
--------------------------------------------------------------------------------
Issue
Script files do not execute properly when you use long file names or directory names in the script. For example, if you included the path c:\my project\floor plan.dwg in a script, the program would look for a file named floor and ignore the rest of the file name. Spaces in file names are interpreted to be the end of the path.
Solution
To use long file names or directory names in a script file, you must enclose the entire path in double quotes, as in the following example:
"c:\my project\floor plan.dwg"
The text inside the quotes is read as one object.


: ) Happy Computing !

kennet

ps.
I write my script command as lisp commands when possible like
(setvar "OSMODE" 111 ) and the long plot command
(command "._plot" "Y" "" . . . . .)
ds.

JasonSelf
2004-12-21, 10:40 PM
Since you are on 2005, the script I looked at really begs the question: Why aren't you simply using Publish?

I am not using publish because my users are not able to keep there settings in drawings set to standards. I am not sure what the disfunction is....okay I do, but regardless my users are unwilling to allow that to be a viable option...I just rather write something that forces things rather than enter a loosing battle over it.....so much for optimism, and to be honest I wrote the bulk of my batch program before publish was even an option, Thanks for the tip though. Nowhere in my code do I use long file names, they are too much of a pain to deal with, thankfully "dir /x" exists, and the drawings that it is claiming are read-only.....most definately are not. Oddly if I select 1 file only it works perfectly, if I were to select 2 or more it gives me the read only remark in err.

lcolville
2005-01-14, 10:13 PM
Try writing a fake-out command named "yes".

(defun c:yes ( )
(princ)
)

Place this in your script file after the open command.
If the script needs the yes in response to a read-only drawing it will be there.
If it doesn't need the yes it will just print a blank line to the command line.
This can also be used after a close that may want you to save changes.
Make sure to load the yes command with a .mnl file or a (load "yes") for each drawing
in your script.

lcolville

kennet.sjoberg
2005-01-17, 12:02 AM
lcolville, are You really sure ?

: ) Happy Computing !

kennet

kjbusacker
2006-09-05, 11:08 PM
Hi Kennet - Did you ever find a solution to this? I have a similar problem trying to write code to a temporary script to get drawings to open read-only and calling the list I get from DOSLIB.

Thanks.

Kevin

kennet.sjoberg
2006-09-06, 05:43 AM
Hi Kennet - Did you ever find a solution to this? . . .
Nope

: ) Happy Computing !

kennet

kjbusacker
2007-07-30, 07:52 PM
Jason - I was revisiting this thread and didn't see a solution to your question which is very similar to my own. Did you ever find a solution?

Spanky
2007-08-22, 02:15 PM
The easiest way to do it is to use the (open) statement in append mode, then open the drawing in the editor. That makes it readonly.

What is append mode?

RobertB
2007-08-22, 04:58 PM
What is append mode?

(open "Test.dwg" "a")

3D Jack
2008-12-24, 03:13 AM
I am trying to do the same thing or very similar thing but with a different approach to the plotting. I want all drawings to open as read-only and then plot. I have used Peter Jamtgaards VBA method he posted and put it into my lisp program and it opens the drawings in read-only mode, which is great. As soon as I open the drawing I then load my special plotting program. The next line is 4 variables that were set earlier followed by the command to run the plot program. The problem is the plot takes place on the empty drawing file instead of the drawing that I just opened read only. If I manually copy and paste each line to the acad textscr it works. However; running as a script it does not. It appears that acad is in such a hurry to run the plot it can't wait on the current drawing being opened to get open before it runs. I get a plot but it is a blank sheet of paper instead of the drawing that is being opened. I would think with the Open command active it could not do anything until that command is finished. I have added a regenall to the script trying to add a delay but regen an empty drawing is nanoseconds. Below is the script and I am hoping someone knows how to get it to not run the plot command until the drawing has been opened. I put the (vl-load-com) as the first line of the script but that did not fix the problem. I need the window to have focus I guess it is. Thanks a bunch for any and all help, Jack.


(vl-cmdf "vbastmt" "acadapplication.documents.open \"C:/JackStuff/LSP/LSP_1PickPlotting/1ROTest.dwg\",TRUE")
regenall
(load (strcat ASRC_Lsp "PlotAll851117"))
(setq Kpltr "\\\\asc-anc-print1\\AES-ANC-1065" kshtsize "11x17" kpens "Monochrome.ctb" kpl "Landscape")
KISSPrintAll

RobertB
2009-01-07, 08:04 PM
Why not just use the Publish command? Use named page setups to control the plot parameters and then you can simply use Publish.

kjbusacker
2009-01-07, 08:13 PM
We also use page setups, but via a customized lisp/script combination. I have used PUBLISH before, but don't find it quite as user-friendly as batch plotting from a lisp. The fact PUBLISH opens read-only is definitely a huge benefit.


Why not just use the Publish command? Use named page setups to control the plot parameters and then you can simply use Publish.

3D Jack
2009-01-08, 04:15 PM
The main reason I don't use publish is the company has five different layers that need to be turned on and off for various conditions. I have written a program that does a setup for how you want the layers to display or be on/off. Once the setup is done then I can have the plot script load the program that controls the watermark layers and runs it so all drawings have the same appearance. Also most user's here don't want to use Publish for assorted reasons. Currently I show user's how to delete the drawings that have been plotted when the script fails due to someone having a drawing open. Then they run the program to create the script from the remaining drawings and turn that script loose. Fortunately this is rare but the open read only would be nice. I have gone to developer support and I am told that it could be done with VB but I have never programmed in VB and I should retire in another few years. Thanks for the replies, Jack.

RobertB
2009-01-08, 05:49 PM
... I have gone to developer support and I am told that it could be done with VB but I have never programmed in VB and I should retire in another few years. Thanks for the replies, Jack.That's why I mentioned Publish. Visual LISP cannot continue to run in a new active document. It will only run in the context of the original document. However, as long as the newly opened document is not made active, you can use ActiveX from Visual LISP to affect that document. Most of the stuff you can do in VBA you can do in Visual LISP via ActiveX.

3D Jack
2009-01-09, 02:03 AM
Thanks again Robert but I am not following what you are saying. I searched the VL help and I found 'VLA-ACTIVATE" but when I got to the description for it, that is written in VB which drives me crazy. If I am in VLisp I want VLisp help not VBA help. Here is what the help shows for vla-activate:


Sub Example_ActivateMethod()
' This example creates two new drawings and activates each drawing in turn.

Dim NewDrawing1 As AcadDocument
Dim Newdrawing2 As AcadDocument
Set NewDrawing1 = ThisDrawing.Application.Documents.Add("")
Set Newdrawing2 = ThisDrawing.Application.Documents.Add("")

Dim drawing As AcadDocument
For Each drawing In ThisDrawing.Application.Documents
drawing.Activate
MsgBox "Drawing " & drawing.name & " is active."
Next drawing
End Sub

Unforunately the vast majority of my AutoLISP programming was from before VL came into being. I am not good with all of the VL commands and there are hundreds of them and there are no good books with samples to learn from. I recently purchased Jerry Winters book VB.NET Programming for Customizing AutoCAD. This will probably totally fry what few remaining activateable brain cells that I have left but I am going to risk it.

irneb
2009-01-09, 06:18 AM
The vla-activate thing does work ... half-way. What I'd suggest is rather use a SCR file which loads your LSP then runs the code. To do this for multiple drawings use ScriptPro from AutoDesk website.

3D Jack
2009-01-09, 04:50 PM
I will have to download scriptpro and see what it does. In trying to make this work I manually manipulated my script file so that it would open a drawing. After the drawing was opened I had it do a simple line command and draw a line. Even though the open drawing was at the front it drew the line on the empty drawing that has to be open in order to run scripts or whatever. If you have time, could you tell me what the advantage of scriptpro is or what I should be looking for? Thank you very much.

irneb
2009-01-12, 05:55 AM
ScriptPro is basically an external program which opens AutoCAD with a particular DWG, then passes the lines in a SCR file to the command line through ActiveX. It's not a very involved thing - it mostly uses AutoCAD's own functionality. There's a few advantages to ScriptPro:

You can perform the same SCR on as many DWG's as you like. It only opens 1 DWG at a time in a single ACAD session.
Leave it "overnight" to run on a multitude of DWG's at the end it lists all commands performed and results from the text screen, so you can see if there were any errors.
You can save a "Project" containing a specific SCR & set of DWG's so you can simply open that PRJ and run it again without having to reselect all the DWG's.
It can run in the background and uses a separate AutoCAD session, so you can still perform other work (even in AutoCAD).
Each SCR file is written only for a current DWG. You don't need to program for multiple DWG's (which makes Commands & Lisp much easier).One nigly prob I've found is that it sometimes (not often, but it happens) doesn't load all the custom LSP / ARX / etc before starting the commands in the SCR ... so if you use these it shows an Unknown Command error. Way arround this is to include the LISP in the SCR or load it through a call to (load ...) or (arxload ...) in the SCR.

What you may not like is that it opens a new Session of AC for each DWG then closes after the SCR has finished.