09-28-2017
02:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
09-28-2017
02:56 AM
I found this code a while back and wanted to edit it to change the file name and the location the files save in. Currently it goes through open drawings exporting them as the file name with _acad2k saving the files in the original files location. However i would like the file name to be populated by the iproperties part number and revision and file path to be a folder on my c drive.
Imports SysIO = System.IO
Sub Main()
'See if there are any open views
If (ThisApplication.Views.Count > 0) Then
'Setup Translator to dwg
Dim DWGAddIn As TranslatorAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}")
Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium = ThisApplication.TransientObjects.CreateDataMedium
'Go through each view and save if it's a drawing document
For Each view As View In ThisApplication.Views
If view.Document.DocumentType = kDrawingDocumentObject Then
'Get the directory file is saved in. Can replace this with specific directory
Dim dwgDir = SysIO.Path.GetDirectoryName(view.Document.FullFileName)
Get name Of file without the extension And add _acad2k To it.
oDataMedium.MediumType = kFileNameMedium
oDataMedium.FileName = dwgDir & "\\" & _
SysIO.Path.GetFileNameWithoutExtension(view.Document.FullFileName) & _
"_acad2k.dwg"
' Check whether the translator has 'SaveCopyAs' options
If DWGAddIn.HasSaveCopyAsOptions(view.Document, oContext, oOptions) Then
'Use Export To DWG to save drawing configuration and set here
Dim strIniFile As String = "C:\Export Copy Main Directory\dwg\Format2000DONOTDELETE.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
'Save File
Call DWGAddIn.SaveCopyAs(view.Document, oContext, oOptions, oDataMedium)
End If
End If
Next
End If
End Sub
Solved! Go to Solution.