Solved! Go to Solution.
Solved by Balaji_Ram. Go to Solution.
Solved by mobj. Go to Solution.
Hi,
>> When using the SaveAs method: db.SaveAs(dwgfile.FullName, true, DwgVersion.AC1024, null); I get some strange results:
>> 1: No .BAK files are created
SAVEAS never creates a BAK as it is a new filename and it let's the old/previous DWG unmodified, so no need for a BAK ... only the SAVE (without "...AS") creates a BAK.
>> 2: When the saved DWG files are used as reference files, the reference manager freezes if another user has the reference open.
Can you upload two drawings? One saved by your .NET routine and another one saved from your AutoCAD manually?
BTW: what AutoCAD version do you use, if you have a vertical product, which one, and last but not least what servicepack?
- alfred -
PS: your code is not readable here, if you want anyone to try it (without editing it a lot) then upload the sourcefile, that's easier for helpers!
@Alfred.NESWADBA wrote:Hi,
>> When using the SaveAs method: db.SaveAs(dwgfile.FullName, true, DwgVersion.AC1024, null); I get some strange results:
>> 1: No .BAK files are created
>SAVEAS never creates a BAK as it is a new filename and it let's the old/previous DWG unmodified, so no need for a BAK ... only the SAVE (without >"...AS") creates a BAK.
Then I don't understand the reference guide. 🙂
"[MarshalAs(UnmanagedType.U1)] bool bBakAndRename
Input bool indicating whether or not to create a .bak file and change document name in AutoCAD"
I'm saving the file using the same filename, thus overwriting the existing file. So I'm expecting a .BAK file. Similar to SAVEAS from AutoCAD.
I'm not sure of the SAVE() method, as I need to specifiy the file format.
>> 2: When the saved DWG files are used as reference files, the reference manager freezes if another user has the reference open.
>Can you upload two drawings? One saved by your .NET routine and another one saved from your AutoCAD manually?
I've uploaded two files. One file that has been processed using the code, and the other is a AutoCAD SAVEAS of the processed file.
>BTW: what AutoCAD version do you use, if you have a vertical product, which one, and last but not least what servicepack?
I'm using AutoCAD2013 iwth the latest ServicePack. Also ACA2013 is installed, but I'm starting acad.exe without the ACA loaded.
>- alfred -
>PS: your code is not readable here, if you want anyone to try it (without editing it a lot) then upload the sourcefile, that's easier for helpers!
Yes, I know... But I have some problems with formatting the text.. I'll try to upload the code.
Hi,
>> I'm saving the file using the same filename
Sorry, I didn't think about that you use SAVEAS but let the filename be the same (.SAVE would be enough) 😉
To your code (haven't tried it yet) .. does it fall into the exception handling? If so you are trying to .Dispose the database twice. that the only thing I saw with a short look to it.
- alfred -
PS: great you got the text here working with FF (I'm running FF too).
>> I'm saving the file using the same filename> Sorry, I didn't think about that you use SAVEAS but let the filename be the same (.SAVE would be enough) 😉
Well, when using .SAVE() I now get an "eFileInternalErr" exception...
-edit: the explanation for the error is here: http://forums.autodesk.com/t5/NET/Database-Save-and-eFileInternalErr/td-p/2140848
> To your code (haven't tried it yet) .. does it fall into the exception handling? If so you are trying to .Dispose the database twice. that the only thing I saw with a short look to it.
No, I don't get any exceptions when using the SAVEAS method. Also the .dispose method is outcommented outside the Catch section. So it's not used.
- Morten -
Hi,
>> Also the .dispose method is outcommented outside the Catch section. So it's not used.
.Dispose is done at the end of "Using xxx", so the additional db.Dispose in the catch area would be the one that is to much (but at least I'm not sure if the end of "Using" might be checking that, I'm not working with "Using" statement).
Do you have a drawing before your code was running over it, for the moment I have not seen any difference between those 2 drawings except of the current view.
>> Well, when using .SAVE() I now get an "eFileInternalErr" exception...
Oops, do you get that error always or only with some specific DWG files?
What happens if you open a new empty drawing and do the same workflow?
- alfred -
Hi,
and one additional idea: you run the .SAVEAS before the transaction is disposed, it might be more save to do the save afterwards.
- alfred -
>> Also the .dispose method is outcommented outside the Catch section. So it's not used.
>.Dispose is done at the end of "Using xxx", so the additional db.Dispose in the catch area would be the one that is to much (but at least I'm not sure if >the end of "Using" might be checking that, I'm not working with "Using" statement).
Ok, I'll have a look at that..
>Do you have a drawing before your code was running over it, for the moment I have not seen any difference between those 2 drawings except of the >current view.
Yup. I've attached the original drawing. Also, I can't see any difference btw. the two drawings.
>> Well, when using .SAVE() I now get an "eFileInternalErr" exception...
> Oops, do you get that error always or only with some specific DWG files?
> What happens if you open a new empty drawing and do the same workflow?
I don't know. I've just tested this with the current drawing.
>and one additional idea: you run the .SAVEAS before the transaction is disposed, it might be more save to do the save afterwards.
Good idea! I'll try the .SAVEAS before disposing the transaction as well as after so see if there's any difference
I think I've found the solution to one of the problems - Reference Manager freezes when the reference file is open at another user.
Before .SAVEAS, you need to generate/enable previewbitmap.
So, when inserting this line:
db.RetainOriginalThumbnailBitmap = true;
before:
db.SaveAs(dwgfile.FullName, true, DwgVersion.AC1024, null);
The dwg files seems to work, when used as a reference.
Now, the remaining problem:
I want the .SAVEAS to create a .BAK file when overwriting the existing DWG file.
Hi Morten,
The "bBakAndRename" parameter of the SaveAs method is only applicable while saving the document that is already open in AutoCAD.
If you try this code after you open a drawing in AutoCAD, you will find a .bak file getting created.
Document doc = Application.DocumentManager.MdiActiveDocument; doc.Database.SaveAs(doc.Name, true, DwgVersion.AC1024, null);
If it is not open in AutoCAD, you can create a backup of the database just after the ReadDwgFile without relying on SaveAs.
Regards,
The "bBakAndRename" parameter of the SaveAs method is only applicable while saving the document that is already open in AutoCAD.
If you try this code after you open a drawing in AutoCAD, you will find a .bak file getting created.
Document doc = Application.DocumentManager.MdiActiveDocument; doc.Database.SaveAs(doc.Name, true, DwgVersion.AC1024, null);If it is not open in AutoCAD, you can create a backup of the database just after the ReadDwgFile without relying on SaveAs.
Thanks!. I was not sure about the difference between reading the DWG file into a new database using:
db.ReadDwgFile
or loadning the file into AutoCAD using:
Document doc = Application.DocumentManager.Open