Code:
'Name der Skizze zur Berechnung
Dim sSk as String = "Skizze2"Dim sM As String, sM2 as String 'für Meldungen
'-------------
'Quelle: Querying a sketch profile to get regions. API Sample
Dim oSketch As Sketch
oSketch = ThisApplication.ActiveDocument.ComponentDefinition.Sketches.Item(sSk)
' Create a default profile from the sketch.
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid
' Set a reference to the region properties object.
Dim oRegionProps As RegionProperties
oRegionProps = oProfile.RegionProperties
' Set the accuracy to medium.
oRegionProps.Accuracy = AccuracyEnum.kMedium
Dim Ixx As Double
Dim Iyy As Double
Dim Izz As Double
Dim Ixy As Double
Dim Iyz As Double
Dim Ixz As Double
Call oRegionProps.MomentsOfInertia(Ixx, Iyy, Izz, Ixy, Iyz, Ixz)
'Trägheitsmomente am Koordinaten-Ursprung der Skizze
sM = "Moments @Sketch-Origin: " & vbCrLf
sM &= " Ixx: " & Ixx & vbCrLf
sM &= " Iyy: " & Iyy & vbCrLf
sM &= " Ixy: " & Ixy
Call oRegionProps.PrincipalMomentsOfInertia(Ixx, Iyy, Izz)
'Hauptträgheitsmomente (an den Hauptachsen)
sM2 = "Moments @Main-Axis: " & vbCrLf
sM2 &= " Ix: " & Ixx & vbCrLf
sM2 &= " Iy: " & Iyy & vbCrLf
sM2 &= " Iz: " & Izz
'-------------
'Meldung der Ergebnisse
MsgBox(sM)
MsgBox(sM2)
'Ergebnisse in iProperty ablegen (z.B. zur Anzeige auf einer Zeichnung)
iProperties.Value("Custom", "Beispiel-Name") = sM