Drawing file requires recovery after saveAs .NET API to other DwgVersion

Patrick_ADEV
Participant
Participant

Drawing file requires recovery after saveAs .NET API to other DwgVersion

Patrick_ADEV
Participant
Participant

Hello,

 

I came over the issue, that any DWG drawing file exported/saved via .NET API to a earlier DwgVersion (e.g. DwgVersion.AC1014) always shows an error message during open.

 

The Error message (also see screenshot below) appears if I choose to export to AutoCAD Version 2014 (DwgVersion.AC1014).

 

Note:

The same code implementation does not produce this issue when exported to AutoCAD 2017 version (or same) version ( DwgVersion.AC1027)

 

Dim obj As Object = Application.GetSystemVariable("DBMOD")
'' Check the value of DBMOD, if 0 then the drawing has not been changed
If Not (System.Convert.ToInt16(obj) = 0) Then
If MsgBox("Do you wish to save this drawing?", MsgBoxStyle.YesNo, "Save Drawing") = MsgBoxResult.Yes Then
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
acDoc.UpgradeDocOpen()
acDoc.Database.SaveAs(acDoc.Name, True, DwgVersion.AC1014, acDoc.Database.SecurityParameters)
End If
Else
logLine("no doc changes")
End If

 

Can anyone help me with this?
Does anyone expirience the same issue?

 

With best regards

Patrick

0 Likes
Reply
Accepted solutions (1)
4,626 Views
14 Replies
Replies (14)

Patrick_ADEV
Participant
Participant

additionally further investigations showed that other export formats also show up issues.
example issue causing DwgVersion for export are:

 

DwgVersion.AC1014=21
DwgVersion.AC1015=23
DwgVersion.AC1021=27
DwgVersion.AC1024=29
DwgVersion.AC1500=22 (not valid)
DwgVersion.AC1800=25 (audit could not correct errors in database)

 

(see also screenshots of the error messages that appear if one tries to re-open any - via .NET API - exported/saveAs dwg)

0 Likes

Patrick_ADEV
Participant
Participant

Additionally INFO (sorry I forgot to add this in the original post):

- I am using .NET API and run this inAutoCAD Mechanical 2017

- doing a manual Save AS (via menu->export->Drawing DWG) and selecting AutoCAD Mechanical 2014 compatibility DOES work, and does not showup issues while opening in AutoCAD again.

0 Likes

ActivistInvestor
Advisor
Advisor

@pbruenner wrote:

Additionally INFO (sorry I forgot to add this in the original post):

- I am using .NET API and run this inAutoCAD Mechanical 2017

- doing a manual Save AS (via menu->export->Drawing DWG) and selecting AutoCAD Mechanical 2014 compatibility DOES work, and does not showup issues while opening in AutoCAD again.


I don't think saving to 'AutoCAD 2014 Mechanical compatibility' is the same as saving to AutoCAD 2014 generic .DWG via the API with the 2014 DwgVersion.

 

There are other things going on when saving to a previous release of a vertical (vertical-specific custom objects must be saved in a format that the previous release can use, which can result in feature-loss), and unless there is an API that allows an 'export' to a previous version of the vertical, the custom objects in the file are most-likely not being converted into a format that's usable in a previous product release. 

Patrick_ADEV
Participant
Participant

@Activist_Investor wrote:

I don't think saving to 'AutoCAD 2014 Mechanical compatibility' is the same as saving to AutoCAD 2014 generic .DWG via the API with the 2014 DwgVersion.

 


Hi,

thank you very much for the quick answer.

I totally get this point that exporting to a generic format might cause incompatibilities.

 

Since i`d like to save(-AS) the current drawing created in AutoCAD 2017 Mechanical to an AutoCAD 2014 Mechanical format compatible drawing using .NET, the question remains what DwgVersion as parameter should be used?

Using db As Database = doc.Database
         db.SaveAs(doc.Name, True, DWG_VERSION,db.SecurityParameters)
End Using

The Enumeration Autodesk.AutoCAD.DatabaseServices.DwgVersion offeres following DwgVersions:

 

Which Enumeration entry ensures the compatibility to AutoCAD Mechanical 2014 ?

 

AC1001
AC1002
AC1003
AC1004
AC1005
AC1006
AC1007
AC1008
AC1009
AC1010
AC1011
AC1012
AC1013
AC1014
AC1015
AC1021
AC1024
AC1027
AC1500
AC1800
AC1800a
AC1To2
AC1To40
AC1To50
AC2100a
AC2400a
AC2700a
AC2To10
AC2To20
AC2To21
AC2To22
Current
Max
MC0To0
Newest
Unknown
0 Likes

ActivistInvestor
Advisor
Advisor

@pbruenner wrote:

@Activist_Investor wrote:

I don't think saving to 'AutoCAD 2014 Mechanical compatibility' is the same as saving to AutoCAD 2014 generic .DWG via the API with the 2014 DwgVersion.

 


Hi,

thank you very much for the quick answer.

I totally get this point that exporting to a generic format might cause incompatibilities.

 

Since i`d like to save(-AS) the current drawing created in AutoCAD 2017 Mechanical to an AutoCAD 2014 Mechanical format compatible drawing using .NET, the question remains what DwgVersion as parameter should be used?


I don't think it is a question of what DwgVersion, it is a question of what API or method you would use to do it.

 

I don't think there's any solution using Database.SaveAs(), if there is a solution it is another API specific to the vertical product, which I'm not terribly familiar with.

 

Hopefully, someone more familiar with the API might know.

0 Likes

Patrick_ADEV
Participant
Participant

Well as far as I know basically there are two API approaches to get the current AutoCAD DWG-document exported to (another versioned) DWG file

1. .NET API via db.SaveAs
2. COM/Interop API via doc.SaveAs

The difference here is which DWG-export parameter to be used.

.NET approach demands an object from Enumeration (listed also above):
Autodesk.AutoCAD.DatabaseServices.DwgVersion

COM/Interop approach demands an object from (another) Enumeration:
Autodesk.AutoCAD.Interop.Common.AcSaveAsType

My investigation so far resulted in the same issue:
In both ways the exported DWG re-opened in a new AutoCAD session displays a warning that the DWG
needs recovery when previosely exported using AC1014 (.NET) or acR14_dwg (COM).


Finally I do not know what is not working and why it is not working as expected.

-> Hopefully anyone has an expanation for this for me (Bug in AutoCAD Mechanical 2017 ?)

BUT:
I found a solution/workaround that seems to work for me:

The DWG does get correctly exported (without any warnings to recover)

if one uses the AutoCAD`s Commandline:

Workaround approach:
FILEDIA -> 0 -> SAVEAS -> AM2014 -> export location

one can use this within the .NET code like:
interopDoc.SendCommand("command ""FILEDIA"" ""0"" & vbCr)
interopDoc.SendCommand("command ""SAVEAS"" ""AM2014"" ""<ANY_FILE_PATH>"" & vbCr)

The resulting DWG document is valid and does not show any recovery warning/DWG errors.

So my final question to the experts among you is:

What is the difference between those three ways (Application->SaveAs / .NET / COM / Command approach) ?

0 Likes

dgorsman
Consultant
Consultant

There is no way to save down vertical content, API or otherwise, that actually converts vertical objects to an earlier version.  The one caveat that I know of, is a *very* brief interval where several versions of Civil3D could cross-communicate for common objects.

 

Out of curiosity, what does it report that it's actually fixing in the DWG file?

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes

ActivistInvestor
Advisor
Advisor
Accepted solution

@pbruenner wrote:


What is the difference between those three ways (Application->SaveAs / .NET / COM / Command approach) ?


The difference is the SAVEAS command is doing more than what either of the SaveAs API methods do, which is evidenced by the fact that there are no DwgVersion enum values that correspond to AM2014 in the SAVEAS command, and I very much doubt that there is any vertical-specific API for doing the equivalent.

 

So, you should just script the SAVEAS command which, contrary to what was written in another post, does perform the conversion of vertical content.

 

For scripting SAVEAS, you can do it more easily and synchronously using the Editor'S Command() method:

 

Document doc = Application.DocumentManager.MdiActiveDocument;

Editor ed = doc.Editor;

Application.SetSystemVariable("FILEDIA", 0)

ed.Command("._SAVEAS", "AM2014" "" "<filename>");

Application.SetSystemVariable("FILEDIA", 1)

dgorsman
Consultant
Consultant

More clearly this time: there is NO WAY to save vertical content to an earlier vertical version.  Mechanical 2015 objects cannot be converted to Mechanical 2012 objects; Civil3D 2017 objects cannot be converted to Civil3D 2012 objects; Plant3D 2016 objects cannot be converted to Plant3D 2014 objects.  Even if the DWG file version is changed to an earlier version, the content version of vertical objects stays the same.  Otherwise there would be no complaints about backwards version compatibility for the vertical products.  Smiley Happy

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes

ActivistInvestor
Advisor
Advisor

@dgorsman wrote:

More clearly this time: there is NO WAY to save vertical content to an earlier vertical version.  Mechanical 2015 objects cannot be converted to Mechanical 2012 objects; Civil3D 2017 objects cannot be converted to Civil3D 2012 objects; Plant3D 2016 objects cannot be converted to Plant3D 2014 objects.  Even if the DWG file version is changed to an earlier version, the content version of vertical objects stays the same.  Otherwise there would be no complaints about backwards version compatibility for the vertical products.  Smiley Happy


You obviously aren't reading the thread, and you cite as your only proof, user complaints about backwards version compatibility. 

 

What is the AMSAVEASACADMXXXX family of commands for?

 

The OP has contradicted your statements by saving down to AutoCAD Mechanical 2014 format without any problem whatsoever.

 

And, perhaps you can explain what all of the entries on the drop-down list in this old screen shot are for, if not for doing what you claim can't be done:

 

SaveAs.jpg

 

 

 

0 Likes

Patrick_ADEV
Participant
Participant

@Activist_Investor wrote:

 

What is the AMSAVEASACADMXXXX family of commands for?

The OP has contradicted your statements by saving down to AutoCAD Mechanical 2014 format without any problem whatsoever. 



The same thought indeed I had, when I read through the possibilities to export a drawing to other formats/versions.

At some point the incompatibility may be not downgradeable - that I do see and agree - but in the most simple case the shown "manual" SaveaS or the Command-SaveAs provide the functionallity to save a DWG to lower version.

However, I think it could be a nice feature to know how to do it via saveAs API (.NET or COM API).

Although the Enumeration(s) of both saveAs API`s (.NET-saveAs and COM-saveAs) suggests that an export to e.g. AM2014 should be possible, it failes.
Failes in terms of export/saveAs is succeeded, but when re-opened in other AutoCAD Session again the dialogue boxes appear demanding a recover of the drawing freshly saved drawing.


dwg_export_recovery_issue.PNG

Perhaps I am doing a mistake here, and hoped to get a clue how to get it working via API (not Command) within this thread.

For the moment I can handle the demand by using the commandline and save the drawing in other (earlier) formats.

Thanks so far.

 

0 Likes

Patrick_ADEV
Participant
Participant

@dgorsman wrote:

There is no way to save down vertical content, API or otherwise, that actually converts vertical objects to an earlier version.  The one caveat that I know of, is a *very* brief interval where several versions of Civil3D could cross-communicate for common objects.

 

Out of curiosity, what does it report that it's actually fixing in the DWG file?


Hi dgorsman,

 

sorry I overread you question/post.

I`d like to cover you with required info for this.

 

So for sake of constructive investigation:


When I open such an "corrupt" drawing that needs recovery (exported via .NET), after I clicked on recover following info is displayed in CMD:


Loading Modeler DLLs.
Scanning completed.
Validating objects in the handle table.
Valid objects 3244   Invalid objects 0
Validating objects completed.                        16 error opening *Model_Space's layout.
Setting layout id to null.
16 error opening *Paper_Space's layout.
Setting layout id to null.
    Salvaged database from drawing.
Reading handle 118 object type AcAmProject
Error 67 (eDwgObjectImproperlyRead)                       Object discarded
Auditing Header
Auditing Tables
Auditing Entities Pass 1
Pass 1 3000    objects audited
Auditing Entities Pass 2
Duplicate name "ACAD_DSTYLE_DIMARC_LENGTH_SYMBOL" in Registered application symbol table.
  Changed to "AUDIT_D_171012142427-0".
Pass 2 3000    objects audited
Auditing Blocks
 22      Blocks audited
Auditing AcDsRecords
Total errors found 4 fixed 4
Erased 1 objects
Opening a Release 14 format file.
Substituting [simplex.shx] for [medtext].
Regenerating layout.
Regenerating model.

dwg_export_recovery_issue6.PNG

 

0 Likes

ActivistInvestor
Advisor
Advisor

From what I've read, there is no API for doing the equivalent of using the SAVEAS command, and specifying an AMXXXX file type.

m.cicognani
Contributor
Contributor

Just for duty to report... 4 years later this problem is still there... saving from Mechanical using API would corrupt the dwg, that will require a recover.

Workaround is to save sending command to the command processor...

Is it my impression or there hasn't been any API improvement since 2019 version (that means spring 2018)?

0 Likes