I have a bit of code that batch processes from a template drawing. It all works fine until I get to the SaveAs() function. I have narrowed down the problem to have something to do with the drawing starting and saving in a paperspace layout. When I run the code with the template saved in model space it works fine but whe the current tab is a paperspace layout I get an error during the saveas() function "eInvalidInput"
I am using VS2008 and Autocad 2011. Is there a difference in saving with a paperspace layout current?
Solved! Go to Solution.
can you show the parts of your code, that:
a) does the opening/loading of the drawing (so we know at least is it loaded in editor or just opened the database)
b) what are the steps you use to change the current layout + (at least described) what happend between change to layout and save
c) how do you save
I think without seeing anything you do we can't answer why "save" should not work.
- alfred -
Thanks Alfred. below is the code. This code works using the CloseAndSave Method with my template drawing saved with "Layout1" as the current space but the SaveAs method does not. If I save the template drawing with Modelspace as the current tab the SaveAs method and the CloseAndSave method both work.
The exception I get is eInvalidInput using the SaveAs method in paperspace.
Private Function BuildProject(ByVal drSession As DataRow) As Int32
'Specify the template to use, if the template is not found
'the default settings are used.
Dim strTemplatePath As String = "MyTemplate.dwt"
Dim acDocMgr As DocumentCollection = Application.DocumentManager
Dim acDoc As Document = acDocMgr.Add(strTemplatePath)
Using acLockDoc As DocumentLock = acDoc.LockDocument
'acDoc.Database.SaveAs("C:\Programming\DotNet Projects\InsightProjects\Insight(" & drSession("ProjectId") & _
' "_" & drSession("UnitNum") & ").dwg", DwgVersion.Current)
acDoc.CloseAndSave("C:\Programming\DotNet Projects\InsightProjects\Insight(" & drSession("ProjectId") & _
"_" & drSession("UnitNum") & ").dwg")
do you need it to be loaded into the editor? Have you tried to just go by using "new database(....)".
I would try that
- alfred -
PS: I have not tried your code now as of limited time, so for others and other ideas ....
>> I will ultimately be needing to plot my layouts.
In that case YES, you have to load it into the editor.
- alfred -
At the end of the day I have to close the drawing anyway so the CloseAndSave method will work just fine. I would like to know why the SaveAs method doesn't work in this instance though as I spent a little time trying to figure out why my code didn't work.
Thanks for your input.
and also I have one idea now: we had a thread (sorry that I don't find it for now) where it was a difference wether you write the filename directly into the statement or you created a variable before that stores the filename + at the .SaveAs statement use then the variable instead of the string(-calculation).
In other words, try this:
dim tFileName as string tFileName = "C:\Programming\DotNet Projects\InsightProjects\Insight(" & _ drSession("ProjectId") & "_" & drSession("UnitNum") & ").dwg" acDoc.Database.SaveAs(tFileName, DwgVersion.Current)
- alfred -
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register