Exporting DXF and PDF

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Howdy yall,
I have some code (shown below) that, upon save, prompts if I want to export to DXF, and if so, either saves it in a specific place (if the drawing file name meets certain criteria) or in the same directory the drawing is in (if the drawing name does NOT meet specific criteria). I would like to expand this code to cover a little more. Basically, if we have a picture in the drawing, the DXF doesn't include the picture (the nature of a DXF), so I want to use some code (that I found in another post) to check if a picture exists on any sheet, and if so, do the normal DXF export, and ALSO, export all sheets to a PDF. Can anyone point me in the right direction to do this? I haven't done VB in years and when I tried to do this myself, I kept getting all sorts of errors or it just not working. Thanks!
'query user question = MessageBox.Show("is a .DXF Export Required?" & vbNewLine & "WARNING: This operation will overwrite existing DXF files!", "Export to DXF",MessageBoxButtons.YesNo,MessageBoxIcon.Question) 'set condition based on answer If question = vbYes Then 'Bunch of code here to test the file name and set strPath' Else strPath = ThisDoc.PathAndFileName(False) ' Dim strFolder As String strFolder = Left(strPath, Len(strPath)-Len(iProperties.Value("Project", "Part Number"))) End If ' Get the DXF and PDF translator Add-Ins. Dim DXFAddIn As TranslatorAddIn 'Dim PDFAddIn As TranslatorAddIn DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 'PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}") '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 = 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 ' Sets directory for file save Dim DXFDirectory As String DXFDirectory = strFolder ' Sets save name as iProperties value Dim SaveName As String SaveName = iProperties.Value("Project", "Part Number") ' Check whether the translator has 'SaveCopyAs' options If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then Dim strIniFile As String strIniFile = "\\server\Company Engineering Documents\Inventor 2013 Files\Save Templates\DXF Export.ini" ' 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 = ThisDoc.PathAndFileName(False) oDataMedium.FileName = DXFDirectory & SaveName & ".dxf" If ThisDoc.Document.Sheets.Count > 1 Then For sheet_count = 1 To ThisDoc.Document.Sheets.Count If Len(Dir(DXFDirectory & SaveName & "_SHEET_" & sheet_count & ".dxf")) <> 0 Then Kill(DXFDirectory & SaveName & "_SHEET_" & sheet_count & ".dxf") Else If Len(Dir(DXFDirectory & SaveName & ".dxf")) <> 0 Then Kill(DXFDirectory & SaveName & ".dxf") End If Next sheet_count End If 'Publish document. DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'Launch the dxf file in whatever application Windows is set to open this document type with 'i = MessageBox.Show("Preview the DXF file? " & SaveName & " " & strFolder, "DXF Preview",MessageBoxButtons.YesNo,MessageBoxIcon.Question) 'If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName) End If