Sub Main ' Create a new drawing document using the default template. Dim oModel As Document = ThisDoc.Document 'check if part is sheet metal If Not oModel.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Logger.Error(oModel.DisplayName & " is not a sheet metal part. Export is cancelled.") Exit Sub End If 'Get Component definition Dim oSMCD As SheetMetalComponentDefinition oSMCD = oModel.ComponentDefinition 'check if sheet metal part is multibody part. If yes this rule stops If oSMCD.HasMultipleSolidBodies = True Then Logger.Error("Multi solid sheetmetal part can not be exported") Exit Sub End If 'Check if PArt contains a flatpattern, if not we will create one. If oSMCD.HasFlatPattern = False Then oSMCD.Unfold oSMCD.FlatPattern.ExitEdit oModel.Save2(True) End If 'Set UnitofMeasure Dim UOM As UnitsOfMeasure UOM = oModel.UnitsOfMeasure 'Get model info for general note on drawing Dim oThickness, oExtentW, oExtentL, oDescription, oMaterial As String 'Converts length unit to a string Dim Units As String = UnitString(UOM.LengthUnits) 'get Thickness value from parameter oThickness = UOM.ConvertUnits(oSMCD.Parameters.Item("Thickness").Value, kDatabaseLengthUnits, kDefaultDisplayLengthUnits) 'Get flatpattern extents Width and round value with 1 decimal oExtentW = Round(UOM.ConvertUnits(oSMCD.FlatPattern.Width, kDatabaseLengthUnits, kDefaultDisplayLengthUnits), 1) 'Get flatpattern extents Length and round value with 1 decimal oExtentL = Round(UOM.ConvertUnits(oSMCD.FlatPattern.Length,kDatabaseLengthUnits,kDefaultDisplayLengthUnits),1) 'Get/Set property:Description oDescription = oModel.PropertySets.Item("Design Tracking Properties").Item("Description").Value 'Get/Set property:Material oMaterial = oModel.PropertySets.Item("Design Tracking Properties").Item("Material").Value 'create formatted text string for general note Dim oText As String oText = oDescription oText &= "
" & "Thickness: " & oThickness & Space(1) & Units oText &= "
" & "Size: " & oExtentL & Space(1) & Units & " x " & oExtentW & Space(1) & Units oText &= "
" & "Material: " & oMaterial 'create drawing in background Call createdrawing(oModel, oText) End Sub Sub createdrawing(ByRef oModel As Document, ByRef oText As String) 'create new draing document (not visible) based on standard drawing template Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kDrawingDocumentObject), False) 'get the first sheet Dim oSheet As Sheet oSheet = oDrawDoc.Sheets(1) 'remove border if exsist If Not oSheet.Border Is Nothing Then oSheet.Border.Delete End If 'remove Titleblock if exsist If Not oSheet.TitleBlock Is Nothing Then oSheet.TitleBlock.Delete End If 'Set reference to TransientGeomety Dim oTG As TransientGeometry oTG = ThisApplication.TransientGeometry ' Create the placement point object. Dim oPoint As Point2d oPoint = oTG.CreatePoint2d(oSheet.Width / 2, oSheet.Height / 2) ' Create a new NameValueMap object Dim oBaseViewOptions As NameValueMap oBaseViewOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Set the options to use flatpattern when creating the base view. oBaseViewOptions.Add("SheetMetalFoldedModel", False) 'create drawing view of flatpattern Dim oView As DrawingView oView = oSheet.DrawingViews.AddBaseView(oModel, oPoint, 1, kDefaultViewOrientation, kHiddenLineRemovedDrawingViewStyle, , , oBaseViewOptions) 'retrieve dimensions oSheet.DrawingDimensions.GeneralDimensions.Retrieve(oView) 'Add general note on drwing oSheet.DrawingNotes.GeneralNotes.AddFitted(oTG.CreatePoint2d(oPoint.X, (oPoint.Y - (oView.Height / 2) -3)), oText) 'create filename for dxf. in this case we will use the same file path and name but only change extension to dxf. Dim oDXFfilename As String oDXFfilename = IO.Path.ChangeExtension(oModel.FullFileName, ".dxf") 'do the export to dxf, when dxf exsist and is in use this resluts in error Try Call ExportDXF(oDrawDoc, oDXFfilename) Catch Logger.Error("File in use, export failed") End Try 'close the drawing without save oDrawDoc.Close(True) End Sub Sub ExportDXF(ByRef oDocument As Document, ByRef oDXFfilename As String) ' Get the DXF translator Add-In. Dim DXFAddIn As TranslatorAddIn DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = 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 DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then 'Set custom location of the export configuration file (ini file). Dim strIniFile As String strIniFile = "D:\Software settings\Inventor\2022\Design Data\DWG-DXF\exportdxf2022.ini" 'check if inifile exsists, if not the default configurationfile will be used If Not IO.File.Exists(strIniFile) Then Logger.Info("file: " & strIniFile & " does not exsist. The default ini file will be used") strIniFile = "C:\Users\Public\Documents\Autodesk\Inventor " & Left(ThisApplication.SoftwareVersion.DisplayVersion,4) & "\Design Data\DWG-DXF\exportdxf.ini" End If ' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile End If 'Set the destination file name oDataMedium.FileName = oDXFfilename 'export document. Call DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) End Sub Function UnitString (ByRef oUnitType As UnitsTypeEnum)As String 'Get Document Unit String Select Case oUnitType Case UnitsTypeEnum.kMillimeterLengthUnits UnitString = "mm" Case UnitsTypeEnum.kCentimeterLengthUnits UnitString = "cm" Case UnitsTypeEnum.kInchLengthUnits UnitString = "in" Case UnitsTypeEnum.kFootLengthUnits UnitString = "ft" Case UnitsTypeEnum.kMeterLengthUnits End Select End Function