Advertisement
axi92

VB.NET DWG PDF

Jul 12th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.43 KB | None | 0 0
  1. Imports Inventor
  2. Imports System
  3. Imports System.Drawing
  4. Imports System.Windows.Forms
  5. Imports System.IO
  6. Module Makros
  7.     Dim oDocument As Document
  8.     Dim transObjs As TransientObjects
  9.     Dim oContext As TranslationContext
  10.     Dim oOptions As NameValueMap
  11.     Dim oDataMedium As DataMedium
  12.     Dim oDrawDoc As DrawingDocument
  13.     Dim oReferencedDoc As Document
  14.     Dim oPropValue As String
  15.     Dim oDoc As Document
  16.     Dim Länge_Dateiname_mit_Pfad As Integer
  17.     Dim Name_Pfad As String
  18.     Dim Länge_String As Integer
  19.     Dim Dateiname_mit_Pfad As String
  20.     Dim Dateiname As String
  21.     Dim oPropSets As PropertySets
  22.     Dim oPropSet As PropertySet
  23.     Dim i As Integer
  24.     Dim Pfad As String
  25.     Public Sub DWG(ByVal ThisApplication As Inventor.Application)
  26.         On Error Resume Next
  27.         'DWG Translator AddIn
  28.         Dim DWGAddIn As TranslatorAddIn
  29.         DWGAddIn = ThisApplication.ActiveDocument
  30.  
  31.         oDocument = ThisApplication.ActiveDocument
  32.  
  33.         transObjs = ThisApplication.TransientObjects
  34.  
  35.         oContext = ThisApplication.TransientObjects.CreateTranslationContext
  36.         oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
  37.  
  38.         'Erstellung der NameValueMap Objekte
  39.         oOptions = transObjs.CreateNameValueMap
  40.         'Erstellung des DataMedium Objekts
  41.         oDataMedium = transObjs.CreateDataMedium
  42.  
  43.  
  44.         oDoc = ThisApplication.ActiveDocument
  45.  
  46.  
  47.         '____________________________________________iProperties________________________________________________
  48.         'iProperties Objekte erstellen
  49.         oPropSets = oDoc.PropertySets
  50.  
  51.         'Feld "Status" auswählen
  52.         oPropSet = oPropSets.Item("Design Tracking Properties")
  53.  
  54.         'Status der ipt
  55.         oDrawDoc = ThisApplication.ActiveDocument
  56.         oReferencedDoc = oDrawDoc.ReferencedDocuments.Item(1)
  57.  
  58.         'Speicher für den Wert von "Status"
  59.         oPropValue = oReferencedDoc.PropertySets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").Item("User Status").Value
  60.         '____________________________________________iProperties________________________________________________
  61.  
  62.         Dateiname_mit_Pfad = oDoc.FullFileName
  63.         Länge_Dateiname_mit_Pfad = Len(Dateiname_mit_Pfad)
  64.         Name_Pfad = Mid(Dateiname_mit_Pfad, 1, Länge_Dateiname_mit_Pfad - 4)
  65.         Länge_String = Len(Name_Pfad)
  66.         MsgBox(Name_Pfad)
  67.         i = 1
  68.         Do Until Mid(Name_Pfad, Länge_String - i, 1) = "\"
  69.             i = i + 1
  70.         Loop
  71.  
  72.         Dateiname = Right(Name_Pfad, i)
  73.         Name_Pfad = Mid(Dateiname_mit_Pfad, 1, Länge_Dateiname_mit_Pfad - i)
  74.  
  75.         '_______________________________________________DWG________________________________________________
  76.         If DWGAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
  77.             oOptions.Value("Solid") = True
  78.             oOptions.Value("Surface") = False
  79.             oOptions.Value("Sketch") = False
  80.  
  81.             'DWG Version festlegen
  82.             '23 = ACAD 2000 - AC1015
  83.             '25 = ACAD 2004 - AC1018
  84.             '27 = ACAD 2007
  85.             '29 = ACAD 2010 - AC1024
  86.             oOptions.Value("DwgVersion") = 25
  87.         End If
  88.         '_______________________________________________DWG________________________________________________
  89.  
  90.         'Ordnerauswahl einfügen
  91.         'Pfad = "J:\"
  92.         Pfad = Form1.FolderBrowserDialog1.SelectedPath
  93.  
  94.         If oPropValue = "" Then
  95.             oDataMedium.FileName = Pfad & "\" & Dateiname & ".dwg"
  96.         Else
  97.             oDataMedium.FileName = Pfad & "\" & Dateiname & "_" & oPropValue & ".dwg"
  98.         End If
  99.  
  100.         If Not Pfad = "" Then
  101.             Call DWGAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
  102.             If Form1.alert.Checked = True Then
  103.                 MsgBox("DWG Export abgeschlossen!", MsgBoxStyle.OkOnly, "DWG Erstellt!")
  104.             End If
  105.         Else
  106.             MsgBox("Export abgebrochen, kein Verzeichnis gewählt!", MsgBoxStyle.OkOnly, "Abbruch!")
  107.         End If
  108.     End Sub
  109.     Public Sub PDF(ByVal ThisApplication As Inventor.Application)
  110.         On Error Resume Next
  111.         'PDF Translator AddIn
  112.         Dim PDFAddIn As TranslatorAddIn
  113.         PDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
  114.  
  115.         'Referenz zum aktiven Dokument
  116.         oDocument = ThisApplication.ActiveDocument
  117.  
  118.         oContext = ThisApplication.TransientObjects.CreateTranslationContext
  119.         oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
  120.  
  121.         'NameValueMap erstellung
  122.         oOptions = ThisApplication.TransientObjects.CreateNameValueMap
  123.  
  124.         'DataMedium erstellen
  125.         oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
  126.  
  127.         If PDFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
  128.             'Darstellungsoptionen
  129.             oOptions.Value("All_Color_AS_Black") = 0
  130.         End If
  131.         '_______________________________________________________________________________iProperties___________________
  132.         oPropSets = oDoc.PropertySets
  133.         oPropSet = oPropSets.Item("Design Tracking Properties")
  134.  
  135.         oDrawDoc = ThisApplication.ActiveDocument
  136.         oReferencedDoc = oDrawDoc.ReferencedDocuments.Item(1)
  137.  
  138.         oPropValue = oReferencedDoc.PropertySets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").Item("User Status").Value
  139.         '_______________________________________________________________________________iProperties___________________
  140.  
  141.         Dateiname_mit_Pfad = oDoc.FullFileName
  142.         Länge_Dateiname_mit_Pfad = Len(Dateiname_mit_Pfad)
  143.         Name_Pfad = Mid(Dateiname_mit_Pfad, 1, Länge_Dateiname_mit_Pfad - 4)
  144.         Länge_String = Len(Name_Pfad)
  145.  
  146.         i = 1
  147.         Do Until Mid(Name_Pfad, Länge_String - i, 1) = "\"
  148.             i = i + 1
  149.         Loop
  150.  
  151.         Dateiname = Right(Name_Pfad, i)
  152.         Name_Pfad = Mid(Dateiname_mit_Pfad, 1, Länge_Dateiname_mit_Pfad - i)
  153.  
  154.         'Ordnerauswahl einfügen
  155.         Pfad = Form1.FolderBrowserDialog1.SelectedPath
  156.  
  157.         If oPropValue = "" Then
  158.             oDataMedium.FileName = Pfad & "\" & Dateiname & ".pdf"
  159.         Else
  160.             oDataMedium.FileName = Pfad & "\" & Dateiname & "_" & oPropValue & ".pdf"
  161.         End If
  162.         Call PDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
  163.         MsgBox("PDF Export abgeschlossen!", vbOKOnly, "PDF Erstellt!")
  164.         Process.Start(oDataMedium.FileName)
  165.     End Sub
  166. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement