Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 532

Slicing a part and getting mass / section properties from resulting bodies

$
0
0

By Balaji Ramamoorthy

If you wish to slice a part and get mass properties of the resulting bodies and the section properties along the section plane, here are the steps that would be needed using the Inventor API :

1. Slice the part by creating a "SplitFeature" and using the SplitBody API to retain both the resulting bodies.

2. Create two part documents (either visible or otherwise)

3. Copy the surface bodies created in step-1 to the new part documents.

4. Retrieve the Mass properties from the part documents.

5. To retrieve the section properties, use the bodies created in Step-1 and use the ImprintBodies API to identify the overlapping faces.

6. Get the section property from the overlapping faces using the Face.Evaluator. If you need any further information on the section properties, those can be computed from the Face.EdgeLoops and Face.Edges collection.

Here is a VBA code snippet :

Dim  oPartDoc As  PartDocument
Set  oPartDoc = ThisApplication.Documents.Add( _
 DocumentTypeEnum.kPartDocumentObject, _
 ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject))
Dim  oDef As  PartComponentDefinition
Set  oDef = oPartDoc.ComponentDefinition
Dim  oSketch As  PlanarSketch
Set  oSketch = oDef.Sketches.Add(oDef.WorkPlanes.Item(3))
Dim  oTG As  TransientGeometry
Set  oTG = ThisApplication.TransientGeometry
Call  oSketch.SketchLines.AddAsTwoPointRectangle( _
 oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(6, 3))
Dim  oProfile As  Profile
Set  oProfile = oSketch.Profiles.AddForSolid()
Dim  oBaseExtrude As  ExtrudeFeature
Set  oBaseExtrude = _
 oDef.Features.ExtrudeFeatures.AddByDistanceExtent( _
 oProfile, 4, PartFeatureExtentDirectionEnum.kPositiveExtentDirection, _
 PartFeatureOperationEnum.kJoinOperation)
Set  oSketch = oDef.Sketches.Add(oDef.WorkPlanes.Item(3))
Dim  oLine As  SketchLine
Set  oLine = oSketch.SketchLines.AddByTwoPoints( _
 oTG.CreatePoint2d(2, -1), oTG.CreatePoint2d(3, 2))
Set  oLine = oSketch.SketchLines.AddByTwoPoints( _
 oLine.EndSketchPoint, oTG.CreatePoint2d(2, 4))
Set  oProfile = oSketch.Profiles.AddForSurface()
Dim  oCutExtrude As  ExtrudeFeature
Set  oCutExtrude = _
 oDef.Features.ExtrudeFeatures.AddByDistanceExtent( _
 oProfile, 5, PartFeatureExtentDirectionEnum.kPositiveExtentDirection, _
 PartFeatureOperationEnum.kSurfaceOperation)
Dim  oWorkSurface As  WorkSurface
Set  oWorkSurface = oCutExtrude.SurfaceBody.Parent
Dim  oSplit As  SplitFeature
Set  oSplit = oDef.Features.SplitFeatures.SplitBody( _
 oWorkSurface, oDef.SurfaceBodies(1))
Dim  oMatrix As  Matrix
Set  oMatrix = ThisApplication.TransientGeometry.CreateMatrix
 oMatrix.SetTranslation _
 ThisApplication.TransientGeometry.CreateVector(0, 0, 10)
Dim  oPartDoc1 As  PartDocument
Set  oPartDoc1 = ThisApplication.Documents.Add(kPartDocumentObject, _
 ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject), False )
 oPartDoc1.FullFileName = "C:\\Temp\\Part1.ipt"
Dim  oBody1 As  SurfaceBody
Set  oBody1 = oDef.SurfaceBodies.Item(1)
Call  oPartDoc1.ComponentDefinition.Features.NonParametricBaseFeatures.Add( _
 oBody1, oMatrix)
Dim  oMassProps1 As  MassProperties
Set  oMassProps1 = oPartDoc1.ComponentDefinition.MassProperties
 oMassProps1.CacheResultsOnCompute = False
Dim  M1 AsDouble
 M1 = oMassProps1.Mass
Dim  Volume1 AsDouble
 Volume1 = oMassProps1.Volume
 MsgBox "Mass 1 : (kg) " & M1 & vbNewLine & "Volume 1: (cm^3) " _
& Volume1, vbInformation, "Split Body-1"
Dim  oPartDoc2 As  PartDocument
Set  oPartDoc2 = ThisApplication.Documents.Add(kPartDocumentObject, _
 ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject), False )
 oPartDoc2.FullFileName = "C:\\Temp\\Part2.ipt"
Dim  oBody2 As  SurfaceBody
Set  oBody2 = oDef.SurfaceBodies.Item(2)
Call  oPartDoc2.ComponentDefinition.Features.NonParametricBaseFeatures.Add( _
 oBody2, oMatrix)
Dim  oMassProps2 As  MassProperties
Set  oMassProps2 = oPartDoc2.ComponentDefinition.MassProperties
 oMassProps2.CacheResultsOnCompute = False
Dim  M2 AsDouble
 M2 = oMassProps2.Mass
Dim  Volume2 AsDouble
 Volume2 = oMassProps2.Volume
 MsgBox "Mass 2 : (kg) " & M2 & vbNewLine & "Volume 2: (cm^3) " _
& Volume2, vbInformation, "Split Body-2"
Dim  newBody1 As  SurfaceBody
Dim  newBody2 As  SurfaceBody
Dim  body1OverlapFaces As  Faces
Dim  body2OverlapFaces As  Faces
Dim  body1OverlapEdges As  Edges
Dim  body2OverlapEdges As  Edges
Call  ThisApplication.TransientBRep.ImprintBodies( _
 oBody1, oBody2, True , _
 newBody1, newBody2, body1OverlapFaces, body2OverlapFaces, _
 body1OverlapEdges, body2OverlapEdges)
For  i = 1 To  body1OverlapFaces.Count
Dim  overlapFace1 AsFace
Set  overlapFace1 = body1OverlapFaces.Item(i)
     MsgBox "Section Area (cm^2) : " & overlapFace1.Evaluator.Area
Next

Viewing all articles
Browse latest Browse all 532