Hallo liebe Gemeinde,
Ich habe mir vor vor längerer Zeit mal ein ADD-In erstellt welches mir ein Button generiert.
jetzt wollte ich daran was ändern bzw habe was geändert da sind mir ein paar Hinweise in der Fehlerbox aufgefallen.
mein Code funktioniert ohne Probleme, trotzdem sind Warnungen ja immer nichts wirklich gutes.
Daher wollte ich fragen ob mir diese mal zum verhängniss werden können, bzw wie ich diese umgehen könnte. (Vorallem Hinweiß 3)
Hinweiß 1:
Es wurde ein Verweis auf die eingebettete Interopassembly "stdole" aufgrund eines indirekten Verweises auf diese Assembly aus Assembly "Autodesk.Inventor.Interop" erstellt. Ändern Sie ggf. für beide Assembly die Eigenschaft "Interoptypen einbetten".
Hinweiß 2:
Es wurde ein Verweis auf die eingebettete Interopassembly "stdole" aufgrund eines indirekten Verweises auf diese Assembly aus Assembly "Microsoft.VisualBasic.Compatibility" erstellt. Ändern Sie ggf. für beide Assembly die Eigenschaft "Interoptypen einbetten".
Hinweiß 3:
"Public Function ImageToIPictureDisp(img As System.Drawing.Image) As Object" ist veraltet: "Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only.
Hier noch der Code Dazu:
Imports Inventor
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Namespace Bild
<ProgIdAttribute("Bild.StandardAddInServer"), _
GuidAttribute("94cc5267-d85f-4ec8-83e5-ea0e5952c4b4")> _
Public Class StandardAddInServer
Implements Inventor.ApplicationAddInServer
' Inventor application object.
Private m_inventorApplication As Inventor.Application
Private m_ClientID As String
Private WithEvents m_featureHalloButtonDef As ButtonDefinition
#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
' TODO: Add ApplicationAddInServer.Activate implementation.
' e.g. event initialization, command creation etc.
' Convert the Image to a Picture.
Dim picture As stdole.IPictureDisp
(-> Hinweis 3) picture = Microsoft.VisualBasic.Compatibility.VB6.ImageToIPictureDisp(My.Resources.Hallo) (-> Hinweis 3)
' Create the button definition.
Dim controlDefs As ControlDefinitions
controlDefs = m_inventorApplication.CommandManager.ControlDefinitions
m_featureHalloButtonDef = controlDefs.AddButtonDefinition("Weiter zur Zeichnung", "BAddInHallo", _
CommandTypesEnum.kQueryOnlyCmdType, _
m_ClientID, _
"Kollisonssprüfung und Zeichnung öffnen", _
"Weiter zur Zeichnung", _
picture)
If firstTime Then
' Create a new command bar (toolbar) and make it visible.
'Dim commandBars As CommandBars
'commandBars = m_inventorApplication.UserInterfaceManager.CommandBars
'Dim commandBar As CommandBar
'commandBar = commandBars.Add("Buttons", "BAddInButtons(", , m_ClientID)
'commandBar.Visible = True
'Add the controlto the command bar.
'commandBar.Controls.AddButton(m_featureCountButtonDef)
' Get the part features command bar.
Dim partCommandBar As Inventor.CommandBar
partCommandBar = m_inventorApplication.UserInterfaceManager.CommandBars.Item("AMxAssemblyPanelCmdBar")
' Add a button to the command bar, defaulting to the end position.
partCommandBar.Controls.AddButton(m_featureHalloButtonDef)
End If
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.
m_inventorApplication = Nothing
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
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
#End Region
Private Sub m_featureHalloButtonDef_OnExecute(ByVal Context As Inventor.NameValueMap) Handles m_featureHalloButtonDef.OnExecute
Dim Ausgangspfad As String
Ausgangspfad = "S:\Austausch\Fiedler\1. Projektarbeit\Test - Kopie"
Dim ThisApplication As Inventor.Application
ThisApplication = GetObject(, "Inventor.Application")
If ThisApplication.ActiveDocument Is Nothing Then
MsgBox("Keine Baugruppe geöffnet")
Exit Sub
End If
Dim oAsmDoc As AssemblyDocument
If TypeOf ThisApplication.ActiveDocument Is AssemblyDocument Then
oAsmDoc = ThisApplication.ActiveDocument
Else : MsgBox("Geht nur in Baugruppen")
Exit Sub
End If
Dim oAsmDef As AssemblyComponentDefinition
oAsmDef = oAsmDoc.ComponentDefinition
Dim oAllOccurrences As ObjectCollection
oAllOccurrences = ThisApplication.TransientObjects.CreateObjectCollection(oAsmDef.Occurrences)
Dim oResults As InterferenceResults
Try
oResults = oAsmDef.AnalyzeInterference(oAllOccurrences)
Catch ex As Exception
MsgBox("Keine Kollisionen gefunden")
Exit Sub
End Try
Dim oResult As InterferenceResult
Dim totalBody As SurfaceBody
For Each oResult In oResults
If totalBody Is Nothing Then
totalBody = oResult.InterferenceBody
Else
Call ThisApplication.TransientBRep.DoBoolean(totalBody, oResult.InterferenceBody, BooleanTypeEnum.kBooleanTypeUnion)
End If
Next
If totalBody Is Nothing Then
MsgBox("Keine Kollission gefunden")
Else
MsgBox("Kollisison vorhanden")
End If
Dim oDoc As Inventor.Document
Dim Pfad As String
oDoc = ThisApplication.ActiveDocument
Pfad = Left(oDoc.FullDocumentName, Len(oDoc.FullDocumentName) - 3)
ThisApplication.SilentOperation = True
ThisApplication.Documents.Open(Pfad & "idw")
ThisApplication.SilentOperation = False
Dim oDrawDoc As Inventor.DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
Pfad = oDrawDoc.FullDocumentName
Dim oFile As File
oFile = oDrawDoc.File
Dim oFD As FileDescriptor
For i = 1 To 10
Try
oFD = oFile.ReferencedFileDescriptors.Item(i)
If oFD.FullFileName = Ausgangspfad & "\AN.iam" Then
Call oFD.ReplaceReference(Left(Pfad, Len(Pfad) - 3) & "iam")
Call Create_prop(oDrawDoc, "Status", "Zeichnung")
Exit Sub
End If
Catch ex As Exception
End Try
Next
End Sub
Sub Create_prop(ByVal oDoc As Document, ByVal prop As String, ByVal prop_value As String)
Dim opropsets As PropertySets
Dim opropset As PropertySet
Dim oUserPropertySet As PropertySet
Dim i As Integer
opropsets = oDoc.PropertySets
For Each opropset In opropsets
If opropset.Name = "Inventor User Defined Properties" Then oUserPropertySet = opropset
Next opropset
' If Property does not exist then add the new Property
On Error Resume Next
Call oUserPropertySet.Add(prop_value, prop)
' Try to set the Property value if it already exists
For i = 1 To oUserPropertySet.Count
If oUserPropertySet.Item(i).Name = prop Then oUserPropertySet.Item(i).Value = prop_value
Next i
End Sub
Sub Set_Property(ByVal oDoc As Document, ByVal prop_name As String, ByVal prop_value As String)
Dim opropsets As PropertySets
Dim odtPropertySet As PropertySet
opropsets = oDoc.PropertySets
odtPropertySet = opropsets.Item("Inventor User Defined Properties")
odtPropertySet.Item(prop_name).Value = prop_value
End Sub
End Class
End Namespace
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP