Message 1 of 3

Not applicable
01-22-2018
12:13 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Goal: Export to dwg with a custom filename based on sheetname.
Problem: This iLogic code (cobbed together from examples on the web) is creating multiple DWG files and adding the sheet name at the end. I already have the sheetname within the filename, so I don't want Inventor to add it again at the end. I use a similiar code for PDFs and it works great.
SyntaxEditor Code Snippet
' Get the DWG translator Add-In. Dim DWGAddIn As TranslatorAddIn DWGAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC2-122E-11D5-8E91-0010B541CD80}") 'Set a reference to the active document (the document to be published). Dim oDocument As Document oDocument = ThisApplication.ActiveDocument Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = kFileBrowseIOMechanism 'oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMedium As DataMedium oDataMedium = ThisApplication.TransientObjects.CreateDataMedium ' Check whether the translator has 'SaveCopyAs' options If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then Dim strIniFile As String strIniFile = "C:\Autodesk 2018\Configuration 2018\DWGconfiguration2018.ini" ' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile End If oPath = ThisDoc.Path oFolder = oPath & "\DWG" '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 'Define the drawing Dim oDrawing As DrawingDocument oDrawing = ThisDoc.Document Dim oSheet As Sheet Dim lPos As Long Dim rPos As Long Dim sLen As Long Dim sSheetName As String Dim iSheetNumber As Integer 'step through each drawing sheet For Each oSheet In oDrawing.Sheets 'find the seperator in the sheet name:number lPos = InStr(oSheet.Name, ":") 'find the number of characters in the sheet name sLen = Len(oSheet.Name) 'find the sheet name sSheetName = Left(oSheet.Name, lPos -1) 'find the sheet number sSheetNumber = Right(oSheet.Name, sLen -lPos) Dim oDesc1 As String Dim oDesc2 As String Dim oDesc3 As String Dim oDescription As String oDesc1 = iProperties.Value("Custom", "DrawingTitle_Line1") oDesc2 = iProperties.Value("Custom", "DrawingTitle_Line2") oDesc3 = iProperties.Value("Custom", "DrawingTitle_Line3") If (oDesc1 = Nothing And oDesc2 = Nothing And oDesc3 = Nothing) Then oDescription = "" Else If (oDesc1 <> Nothing And oDesc2 = Nothing And oDesc3 = Nothing) Then oDescription = " " & oDesc1 Else If (oDesc1 = Nothing And oDesc2 <> Nothing And oDesc3 = Nothing) Then oDescription = " " & oDesc2 Else If (oDesc1 = Nothing And oDesc2 = Nothing And oDesc3 <> Nothing) Then oDescription = " " & oDesc3 Else If (oDesc1 <> Nothing And oDesc2 <> Nothing And oDesc3 = Nothing) Then oDescription = " " & oDesc1 & " " & oDesc2 Else If (oDesc1 = Nothing And oDesc2 <> Nothing And oDesc3 <> Nothing) Then oDescription = " " & oDesc2 & " " & oDesc3 Else If (oDesc1 <> Nothing And oDesc2 <> Nothing And oDesc3 <> Nothing) Then oDescription = " " & oDesc1 & " " & oDesc2 & " " & oDesc3 End If If sSheetName = "-" Then oFileName = iProperties.Value("Custom", "DrawingNumber") & "-R" & iProperties.Value("Custom", "Revision") Else oFileName = iProperties.Value("Custom", "DrawingNumber") & "-" & sSheetName & "-R" & iProperties.Value("Custom", "Revision") End If 'Set the PDF target file name oDataMedium.FileName = oFolder & "\" & oFileName & oDescription & ".dwg" 'Publish document. Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) Next '------end of iLogic-------
Solved! Go to Solution.