- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So I was able to figure it out reasonable successfully, and figured I'd share the code for anybody interested. The code cycles through all the faces of each surface, then runs the Measure Area command. I couldn't figure out how to read the value from the text box that pops up (and Application.MeasureTools doesn't have a GetArea function) so I need to copy the area into an input box manually. This then uses a mass/ sq.m density to calculate the mass of the surface and plug it into the Mass property of the part.
If anyone has suggestions on how to copy the area from the text box (or use another code snippet to measure the area) into a variable, that would be great!
Sub SurfaceMeasurement()
'Check all referenced docs
Dim oDoc As Inventor.Document
Dim oSurfaceBodies As WorkSurface
Dim oFace As Face
Dim oControlDef As ControlDefinition
Dim faceCollection As ObjectCollection
Dim area As Double
Dim density As Double
Dim mass As Double
mass = 0
Set oDoc = ThisApplication.ActiveDocument
oDoc.SelectSet.Clear
Set faceCollection = ThisApplication.TransientObjects.CreateObjectCollection(Null)
'set surface bodies visibility
For Each oSurfaceBodies In oDoc.ComponentDefinition.WorkSurfaces
'oSurfaceBodies.Visible = wfBoolean
For Each oFace In oSurfaceBodies.SurfaceBodies.Item(1).Faces
faceCollection.Add oFace
' oDoc.SelectSet.Select oFace
Next
oDoc.SelectSet.SelectMultiple faceCollection
Set oControlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppMeasureAreaCmd")
oControlDef.Execute
area = InputBox("Please enter the area (mm^2): ", "Area")
density = InputBox("Please enter the mass per m^2: ", "Density")
mass = mass + area * density * 0.000001
Next
MsgBox "The mass is " & CStr(mass) & " kg."
oDoc.ComponentDefinition.MassProperties.mass = mass
End Sub