Message 1 of 3
Export to DWG and move older version - Several sheets drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have this code to export to PDF and Autocad DWG and move older version to an "OldVersions" folder.
The problem is when the drawing has more than one sheet. The exported dwg file come with "_Sheet_X.dwg" and don't move the older version. I have tried lots of things and tips that I found her, but nothing worked.
Can you help me solve it?
Sub Main
For Each doc As Document In ThisApplication.Documents.VisibleDocuments
If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Call Save_As_DWG_CAD(doc)
End If
Next
For Each doc As Document In ThisApplication.Documents.VisibleDocuments
If doc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Call Save_As_PDF(doc)
End If
Next
MessageBox.Show("All files created", "Ready!", MessageBoxButtons.OK)
End Sub
Sub Save_As_DWG_CAD(oDoc As Document)
oPath = IO.Path.GetDirectoryName(oDoc.FullFileName)
oFileName = IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName) 'without extension
oRevNum = oDoc.PropertySets.Item(1).Item("Revision Number").Value
Dim DWGAddIn As TranslatorAddIn
DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
'oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
'Create a NameValueMap object
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
'Create a DataMedium object
Dim oDataMediumDWG As DataMedium
oDataMediumDWG = ThisApplication.TransientObjects.CreateDataMedium
'oDocument = ThisApplication.ActiveDocument
'oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
'Sets the directory that the file should be saved in
oFolder = oPath & "\2D_CAD"
'checks to see if that directory exists, if not, it is created
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
oFile = oFileName & "_" & oRevNum & ".dwg"
'Saves the file in the desired location
oDataMediumDWG.FileName = oFolder + "\" + oFile
Dim strIniFile As String
strIniFile = "Z:\Biblioteca 3D\Ilogic\saveDWG_CAD.ini"
oOptions.Value("Export_Acad_IniFile") = strIniFile
'Check to see if the file already exists, if it does, ask if you want to overwrite it or not.
If System.IO.File.Exists(oDataMediumDWG.FileName) = True Then
oAnswer = MsgBox( oFile & " already exists." & vbCrLf &
"Do you want to overwrite it?", vbYesNo + vbQuestion + vbDefaultButton2, "DWG ALREADY EXISTS")
If oAnswer = vbNo Then Exit Sub
End If
'Publish document
DWGAddIn.SaveCopyAs(oDoc, oContext, oOptions, oDataMediumDWG)
'Colocar revisao anterior em OldVersions
If oRevNum >= "A" Then
Dim EarlyRev As String = Chr(Asc(oRevNum) -1)
Dim FileCurrentName = oFileName & "_" & EarlyRev & ".dwg"
Dim FileCurrent As String = oFolder & "\" & FileCurrentName
Dim oObs As String = oFolder & "\OldVersions\"
Dim FileObs As String = oObs & FileCurrentName
If Not System.IO.Directory.Exists(oObs) Then
System.IO.Directory.CreateDirectory(oObs)
End If
If System.IO.File.Exists(FileCurrent) = True Then
System.IO.File.Move(FileCurrent, FileObs)
End If
End If
End Sub