Hallo Gemeinde
Habe ein kleines Add-In geschrieben, welches jeweils beim schliessen eines Dokuments ein DWF-File an einen gewünschten Ort speichert. Damit kann ich meine INV-Files Lokal sichern, und den Netzwerkusern DWF-Files zur Verfügung stellen. Ist sicher nicht schön Programmiert, aber es funxt.
Nun noch eine Frage: Wie debbuge ich am besten ein AddIn? Die Anleitung in der API-Hilfe hat bei mir nichts gebracht (nicht funktioniert). Wie macht Ihr das?
Gruss Roland
Option Explicit
Private invApp As Inventor.Application
Private OrdnerName As String
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Implements ApplicationAddInServer
Private WithEvents invAppEvents As ApplicationEvents
Private Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean)
Set invApp = AddInSiteObject.Application
Set invAppEvents = invApp.ApplicationEvents
OrdnerName = GetOrdnerName
If OrdnerName = "" Then
MsgBox "Pfad ist ungültig" + vbCrLf + " Textfile " & GetSystemDir & "Inventor_DWFSpeichern_Pfad.txt ändern."
End If
End Sub
Private Property Get ApplicationAddInServer_Automation() As Object
End Property
Private Sub ApplicationAddInServer_Deactivate()
Set invApp = Nothing
Set ApplicationAddInServer = Nothing
End Sub
Private Sub ApplicationAddInServer_ExecuteCommand(ByVal CommandID As Long)
End Sub
Private Sub invAppEvents_OnCloseDocument(ByVal DocumentObject As Inventor.Document, ByVal FullFileName As String, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, HandlingCode As Inventor.HandlingCodeEnum)
If OrdnerName = "" Or FullFileName = "" Then Exit Sub
If BeforeOrAfter = kBefore And DocumentObject.DocumentType = kDrawingDocumentObject Then 'Vor dem schliessen der Datei
If DateiSpeichern(OrdnerName & GetDateiPfad) = False Then
MsgBox "DWF-Speichern fehlgeschlagen"
End If
End If
End Sub
Private Function GetOrdnerName() As String
'Sucht im Systemverzeichnis die Datei Inventor_DWFSpeichern_Pfad.txt und liest sie aus
Dim SystemOrdner As String
Dim temp As String
SystemOrdner = GetSystemDir
If Dir(SystemOrdner & "Inventor_DWFSpeichern_Pfad.txt") = "" Then
'Datei nicht gefunden
temp = InputBox("Bitte Speicherort der DWF-Dateien angeben", "DWF-Speichern")
Open SystemOrdner & "Inventor_DWFSpeichern_Pfad.txt" For Output As #1
Print #1, temp
Close #1
Else
Open SystemOrdner & "Inventor_DWFSpeichern_Pfad.txt" For Input As #1
Line Input #1, temp
Close #1
End If
If Right(temp, 1) <> "\" Then temp = temp & "\"
If Dir(temp, vbDirectory) = "" Then
GetOrdnerName = ""
Else
GetOrdnerName = Trim(temp)
End If
End Function
Private Function GetSystemDir() As String
'Windows-System-Verzeichnis ermitteln
Dim temp As String
Dim lResult As Long
temp = Space$(256)
lResult = GetSystemDirectory(temp, Len(temp))
temp = Left$(temp, lResult)
If Right$(temp, 1) <> "\" Then temp = temp + "\"
GetSystemDir = temp
End Function
Private Function GetDateiPfad() As String
Dim oDoc As Inventor.Document
Dim PfadWorkspace As Variant
Dim Dateiname As Variant
Dim i As Integer
Set oDoc = invApp.ActiveDocument
If oDoc.FullFileName = "" Then Exit Function
Dateiname = Split(oDoc.FullFileName, "\")
PfadWorkspace = Split(invApp.FileLocations.Workspace, "\")
For i = UBound(PfadWorkspace, 1) + 1 To UBound(Dateiname, 1) - 1 'Pfad zusammensetzen
GetDateiPfad = GetDateiPfad & Dateiname(i) & "\"
Next i
GetDateiPfad = GetDateiPfad & Dateiname(UBound(Dateiname, 1)) 'Dateiname hinzufügen
GetDateiPfad = Left(GetDateiPfad, Len(GetDateiPfad) - 4) & ".DWF"
End Function
Function DateiSpeichern(Dateiname As String) As Boolean
Dim oDoc As Inventor.Document
Dim ArrayDateiname As Variant
Dim i As Integer, temp As String
Set oDoc = invApp.ActiveDocument
ArrayDateiname = Split(Dateiname, "\")
temp = ArrayDateiname(0) 'Laufwerksbezeichnung
For i = 1 To UBound(ArrayDateiname, 1) - 1
temp = temp & "\" & ArrayDateiname(i)
If Dir(temp, vbDirectory) = "" Then
If MsgBox("Pfad existiert nicht. Erstellen?" + vbCrLf + temp, vbQuestion + vbYesNo, "Pfad erstellen") = vbYes Then
MkDir temp
Else
Exit Function
End If
End If
Next i
If oDoc.DocumentType = kDrawingDocumentObject Then
If MsgBox("DWF-Datei speichern ?" & vbCrLf & temp & "\" & ArrayDateiname(UBound(ArrayDateiname, 1)), vbQuestion + vbYesNo, "DWF speichern") = vbYes Then
Call oDoc.SaveAs(temp & "\" & ArrayDateiname(UBound(ArrayDateiname, 1)), True)
End If
End If
DateiSpeichern = True
End Function
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP