Hallo zusammen
versuche gerade ein VBA Makro in Vb Net umzustricken.
Habe aber noch etwas Prbleme mit dem Syntax von VB net
Kann mir hier einer auf die Sprünge helfen
BC42104 ' Die Variable wurde verwendet, bevor ihr ein Wert zugewiesen wurde
kann mir aber gerade nicht erklären was ich zuweisen muß.
hioer mein Codeansatz:
Imports Inventor
Imports System.Runtime.InteropServices
Public Class InventorInfo
Private kAssetTypeAppearance As AssetTypeEnum
Private Sub InventorInfo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim m_inventorApp As Inventor.Application = Nothing
Dim m_quitInventor As Boolean = False
' Try to get an active instance of Inventor
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Catch ex As Exception
End Try
' If not active, create a new Inventor session
If m_inventorApp Is Nothing Then
Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
m_inventorApp = System.Activator.CreateInstance(inventorAppType)
m_quitInventor = True
End If
Dim Name1_, Name2_, Num1_, Num2_, Num3_ As String
Dim Name1(), Name2(), Num1(), Num2(), Num3()
ReDim Name1(15), Name2(15), Num1(15), Num2(15), Num3(15)
Dim i, j As Integer
i = 6
Name1(1) = "Schlichten"
Name1(2) = "Schruppen"
Name1(3) = "Einfache Bohrung"
Name1(4) = "Stufenbohrung"
Name1(5) = "Gewinde"
Name1(6) = "Feingewinde"
Name1(7) = "Spezialgewinde"
Name1(8) = "Passbohrung H7"
Name1(9) = "Konturbearbeitung"
Name1(10) = "Feinstbearbeitung"
Name1(11) = "Passbohrung H11"
Name1(12) = "Passbohrung H8"
Name1(13) = "Passbohrung H6"
Name1(14) = "Änderungsbereiche"
Name2(1) = "001 Schlichten"
Name2(2) = "002 Schruppen"
Name2(3) = "003 Einfache Bohrung"
Name2(4) = "004 Stufenbohrung"
Name2(5) = "005 Gewinde"
Name2(6) = "006 Feingewinde"
Name2(7) = "007 Spezialgewinde"
Name2(8) = "008 Passbohrung H7"
Name2(9) = "009 Konturbearbeitung"
Name2(10) = "010 Feinstbearbeitung"
Name2(11) = "011 Passbohrung H11"
Name2(12) = "012 Passbohrung H8"
Name2(13) = "013 Passbohrung H6"
Name2(14) = "014 Änderungsbereiche"
Num1(1) = "255" 'Schlichten
Num2(1) = "175"
Num3(1) = "175"
Num1(2) = "095" 'Schruppen
Num2(2) = "000"
Num3(2) = "000"
Num1(3) = "000" 'Einfache Bohrung
Num2(3) = "175"
Num3(3) = "175"
Num1(4) = "255" 'Stufenbohrung
Num2(4) = "000"
Num3(4) = "255"
Num1(5) = "255" 'Gewinde
Num2(5) = "255"
Num3(5) = "000"
Num1(6) = "255" 'Feingewinde
Num2(6) = "175"
Num3(6) = "000"
Num1(7) = "255" 'Spezialgewinde
Num2(7) = "095"
Num3(7) = "000"
Num1(8) = "000" 'Passbohrung H7
Num2(8) = "000"
Num3(8) = "255"
Num1(9) = "175" 'Konturbearbeitung
Num2(9) = "255"
Num3(9) = "175"
Num1(10) = "255" 'Feinstbearbeitung
Num2(10) = "255"
Num3(10) = "175"
Num1(11) = "095" 'Passbohrung H11
Num2(11) = "095"
Num3(11) = "175"
Num1(12) = "095" 'Passbohrung H8
Num2(12) = "000"
Num3(12) = "095"
Num1(13) = "000" 'Passbohrung H6
Num2(13) = "000"
Num3(13) = "095"
Num1(14) = "000" 'Änderungsbereiche
Num2(14) = "127"
Num3(14) = "255"
For j = 1 To 14
Name1_ = Name1(j)
Name2_ = Name2(j)
Num1_ = Num1(j)
Num2_ = Num2(j)
Num3_ = Num3(j)
'On Error Resume Next
CreateSimpleColorAppearance(Name1_, Name2_, Num1_, Num2_, Num3_)
Next
End Sub
Public Sub CreateSimpleColorAppearance(ByVal Name1 As Object, Name2 As Object, Num1 As Object, Num2 As Object, Num3 As String)
Dim m_inventorApp As Inventor.Application
Dim doc As Document
#Disable Warning BC42104 ' Die Variable wurde verwendet, bevor ihr ein Wert zugewiesen wurde.
doc = m_inventorApp.ActiveDocument
#Enable Warning BC42104 ' Die Variable wurde verwendet, bevor ihr ein Wert zugewiesen wurde.
' Only document appearances can be edited, so that's what's created.
' This assumes a part or assembly document is active.
Dim docAssets As Assets
docAssets = doc.Assets
' Create a new appearance asset.
Dim appearance As Asset
appearance = docAssets.Add(kAssetTypeAppearance, "Generic", Name1, Name2)
Dim tobjs As TransientObjects
tobjs = m_inventorApp.TransientObjects
Dim color As ColorAssetValue
color = appearance.Item("generic_diffuse")
color.Value = tobjs.CreateColor(Num1, Num2, Num3)
Dim floatValue As FloatAssetValue
floatValue = appearance.Item("generic_reflectivity_at_0deg")
floatValue.Value = 0
floatValue = appearance.Item("generic_reflectivity_at_90deg")
floatValue.Value = 0
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
End Class
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP