- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a functional ilogic rule to export my inventor dwg/idw as an Autocad file in a dedicated folder.
What I don't get to work is to overwrite the existing Acad file if it allready existst. In that case the rule does nothing.
Meaning I have to delete the existing file by hand and then run the rule again.
remark: strangly enough I use the same code to export to Pdf, and here the problem does not exist.
However: what do I need to do to get it to overwrite, preferrably without an extra question as in "the file exists; overwrite y/n" as we would want to overwrite by default.
here my Original irule:
Sub Main()
question = MessageBox.Show("Wilt u een AutoCad kopie opslaan?", "AutoCad kopie",MessageBoxButtons.YesNo,MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
If question = vbYes 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
'get DWG target folder path
oPath = ThisDoc.Path
oFolder = oPath & "/ACAD"
'Check for the DWG folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
If ThisDrawing.Document.DocumentType = kDrawingDocumentObject Then
'Get the directory file is saved in. Can replace this with specific directory
Dim dwgDir = SysIO.Path.GetDirectoryName(ThisDrawing.Document.FullFileName)
'Get name of file without the extension and add _acad2k to it.
oDataMedium.MediumType = kFileNameMedium
oDataMedium.FileName = dwgDir & "/ACAD" & "\\" & _
SysIO.Path.GetFileNameWithoutExtension(ThisDrawing.Document.FullFileName) & _
"_acad.dwg"
' Check whether the translator has 'SaveCopyAs' options
If DWGAddIn.HasSaveCopyAsOptions(ThisDrawing.Document, oContext, oOptions) Then
'Use Export To DWG to save drawing configuration and set here
Dim strIniFile As String = "P:\_VIRO ZME\inventor\macro\Inventor rules\save_to_ACAD_dwg.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = strIniFile
'Save File
DWGAddIn.SaveCopyAs(ThisDrawing.Document, oContext, oOptions, oDataMedium)
End If
End If
End If
End Sub
Solved! Go to Solution.