Hallo,
ich habe ein Problem und komm nicht weiter. Ich möchte die Masse per API
auslesen was auch funktioniert nur ist nach längerem aufgefallen das wenn kein Volumenkörper modelliert wurde ein Laufzeitfehler auftritt. Wie könnte man das bewerkstelligen um sowas abzufangen. Meine Idee wäre gewesen erstmal nach einem Basisfeature bzw. ob überhaupt ein Feature enthalten ist.
Anbei die Passage aus dem Quelltext in dem ich die Abfrage integrieren möchte:
Sub barGewicht()
Dim swApp As Object
Dim Model As Object
Dim retval As Variant
Dim ConfigName As String
Dim View As Object
Dim massProps As Variant
Dim Gewicht As Double
Dim RefModel As Object
Dim Masse As Variant
Set swApp = CreateObject("SldWorks.Application")
swApp.Visible = True
Set Model = swApp.ActiveDoc
If Model Is Nothing Then
keinSWXDok
Exit Sub
End If
If (Model.GetType() = swDocASSEMBLY) Then
retval = Model.ResolveAllLightWeightComponents(True)
End If
massProps = Model.GetMassProperties()
Gewicht = Format(massProps(5), "0.00000000")
If Gewicht > 100 Then
Gewicht = Format(Gewicht, "0")
txtMasse.Text = Gewicht
txtMasse.Text = "ca. " & txtMasse.Text & " kg"
Exit Sub
End If
If Gewicht > 10 And Gewicht < 99.999999 Then
Gewicht = Format(Gewicht, "0.0")
txtMasse.Text = Gewicht
txtMasse.Text = "ca. " & txtMasse.Text & " kg"
Exit Sub
End If
If Gewicht > 1 And Gewicht < 9.999999 Then
Gewicht = Format(Gewicht, "0.00")
txtMasse.Text = Gewicht
txtMasse.Text = "ca. " & txtMasse.Text & " kg"
Exit Sub
End If
If Gewicht > 0.1 And Gewicht < 0.999999 Then
Gewicht = Format(Gewicht, "0.000")
txtMasse.Text = Gewicht * 1000
txtMasse.Text = "ca. " & txtMasse.Text & " g"
Exit Sub
End If
If Gewicht > 0.01 And Gewicht < 0.099999 Then
Gewicht = Format(Gewicht, "0.0000")
txtMasse.Text = Gewicht * 1000
txtMasse.Text = "ca. " & txtMasse.Text & " g"
Exit Sub
End If
If Gewicht > 0.001 And Gewicht < 0.009999 Then
Gewicht = Format(Gewicht, "0.00000")
txtMasse.Text = Gewicht * 1000
txtMasse.Text = "ca. " & txtMasse.Text & " g"
Exit Sub
End If
If Gewicht < 0.001 Then
txtMasse.Text = "< 1 g"
Exit Sub
End If
End Sub
Vorab schon mal Danke für eure Hilfe
Gruß Ralf
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP