Vielen Dank Ralf. Das hat mir sehr geholfen
Hier möchte ich nochmal den Code zur verfügung stellen.
Vielleicht können irgendwannmal einige Leute einen Teil von dem Code gut benutzen.
Zitat:
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32Namespace TestSpeichernNeuinstallation
<ProgIdAttribute("TestSpeichernNeuinstallation.StandardAddInServer"), _
GuidAttribute("f01145cb-dd0d-411b-9975-e49a219b849d")> _
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
' Inventor application object.
Private m_inventorApplication As Inventor.Application
Private WithEvents m_appEvents As Inventor.ApplicationEvents
#Region "ApplicationAddInServer Members"
Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate
' This method is called by Inventor when it loads the AddIn.
' The AddInSiteObject provides access to the Inventor Application object.
' The FirstTime flag indicates if the AddIn is loaded for the first time.
' Initialize AddIn members.
m_inventorApplication = addInSiteObject.Application
m_appEvents = m_inventorApplication.ApplicationEvents
' TODO: Add ApplicationAddInServer.Activate implementation.
' e.g. event initialization, command creation etc.
End Sub
Public Sub Deactivate() Implements Inventor.ApplicationAddInServer.Deactivate
' This method is called by Inventor when the AddIn is unloaded.
' The AddIn will be unloaded either manually by the user or
' when the Inventor session is terminated.
' TODO: Add ApplicationAddInServer.Deactivate implementation
' Release objects.
Marshal.ReleaseComObject(m_inventorApplication)
m_inventorApplication = Nothing
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
End Sub
Public ReadOnly Property Automation() As Object Implements Inventor.ApplicationAddInServer.Automation
' This property is provided to allow the AddIn to expose an API
' of its own to other programs. Typically, this would be done by
' implementing the AddIn's API interface in a class and returning
' that class object through this property.
Get
Return Nothing
End Get
End Property
Public Sub ExecuteCommand(ByVal commandID As Integer) Implements Inventor.ApplicationAddInServer.ExecuteCommand
' Note:this method is now obsolete, you should use the
' ControlDefinition functionality for implementing commands.
End Sub
Private Sub m_appEvents_OnSaveDocument( _
ByVal DocumentObject As Inventor._Document, _
ByVal BeforeOrAfter As Inventor.EventTimingEnum, _
ByVal Context As Inventor.NameValueMap, _
ByRef HandlingCode As Inventor.HandlingCodeEnum) _
Handles m_appEvents.OnSaveDocument
Dim dateiformat As String
dateiformat = DocumentObject.FullFileName
dateiformat = dateiformat.Substring(dateiformat.Length - 4)
If dateiformat = ".idw" Then
If BeforeOrAfter = EventTimingEnum.kBefore Then
If DocumentObject.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Dim sUsername As String = System.Security.Principal.WindowsIdentity.GetCurrent().Name
sUsername = sUsername.Substring(3, sUsername.Length - 3)
Dim sPartNumber As String
sPartNumber = DocumentObject.ReferencedDocuments(1).PropertySets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}").Item("Part Number").Value
Dim sRevision As String
sRevision = DocumentObject.PropertySets.Item("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}").Item("Revision Number").Value
' Get the filename minus the extension.
Dim filename As String
filename = DocumentObject.FullFileName
filename = Left(filename, Len(filename) - 4)
filename = sPartNumber & "_" & sRevision & "_" & sUsername
' Save the current SilentOperation and then turn it on.
' This will suppress the dwf viewer from being displayed.
Dim currentSetting As Boolean
currentSetting = m_inventorApplication.SilentOperation
m_inventorApplication.SilentOperation = True
' Save the file as pdf.
' Überprüft ob Datei bereits vorhanden und fragt ob überschrieben werden soll
' Fragt ob auf Server gespeichert werden soll oder Lokal
If MsgBox("Soll die Datei auf den Server gespeichert werden?", vbYesNo, "Speicherort") = vbYes Then
If My.Computer.FileSystem.FileExists("C:\ServerpfadTest\" & filename & ".pdf") Then
If MsgBox("Die Datei exisitert bereits. Soll die Datei überschrieben werden?", vbYesNo, "Überschreiben") = vbYes Then
DocumentObject.SaveAs("C:\ServerpfadTest\" & filename & ".pdf", True)
MsgBox("Die Datei wurde auf dem Server gespeichert")
Else
MsgBox("Die Datei wurde nicht überschrieben")
' eventuell Code hinzfügen : Wollen Sie die Datei unter anderem Namen speichern?
End If
Else
DocumentObject.SaveAs("C:\ServerpfadTest\" & filename & ".pdf", True)
MsgBox("Die Datei wurde auf dem Server gespeichert")
End If
Else
If My.Computer.FileSystem.FileExists(filename & ".pdf") Then
If MsgBox("Die Datei exisitert bereits. Soll die Datei überschrieben werden?", vbYesNo, "Überschreiben") = vbYes Then
DocumentObject.SaveAs(filename & ".pdf", True)
MsgBox("Die Datei wurde NICHT auf dem Server gespeichert, sondern lokal")
Else
MsgBox("Die Datei wurde nicht überschrieben")
' eventuell Code hinzfügen : Wollen Sie die Datei unter anderem Namen speichern?
End If
Else
DocumentObject.SaveAs(filename & ".pdf", True)
MsgBox("Die Datei wurde Nicht auf dem Server gespeichert, sondern lokal")
End If
' Reset SilentOperation back to its previous value.
m_inventorApplication.SilentOperation = currentSetting
End If
End If
End If
End If
End Sub
#End Region
End Class
End Namespace