Hello everyone,
I am working for a yacht design office. We use inventor to calculate hydrostatics of our hulls like underwater volume, waterplane area and the longitudinal position of the maximum cross section area.
My question is about the last point. We use the advanced section analysis tool :
I would like to know if there is a way to automate tasks 1, 2 and 3 using VBA macros? Are the analysis objects callable in Inventor VBA?
I hope my question is clear enough. I thank you in advance for your advices.
Pierre
Hi Pierre,
I created a sample VBA code to calculate the section areas, it is hard coded with your part document, you can run it to see the results in the Immediate Window:
Sub CalculateSectionAreas() Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument ' get the planar face as base face Dim oBaseFace As Face Set oBaseFace = oDoc.ComponentDefinition.SurfaceBodies(1).Faces(4) oDoc.SelectSet.Select oBaseFace Dim oTipPoint As Vertex Set oTipPoint = oDoc.ComponentDefinition.SurfaceBodies(1).Vertices(1) oDoc.SelectSet.Select oTipPoint Dim dDist As Double dDist = ThisApplication.MeasureTools.GetMinimumDistance(oTipPoint, oBaseFace) Debug.Print dDist ' calculate the section area with a step Dim dStep As Double, iStepCount As Integer iStepCount = 100 dStep = dDist / iStepCount Dim oSk As PlanarSketch Dim oWP As WorkPlane Dim oProfile As Profile Dim dArea As Double Dim oSliceView As ControlDefinition Set oSliceView = ThisApplication.CommandManager.ControlDefinitions("SketchSliceGraphicsCmd") Dim oProjectCutEdges As ControlDefinition Set oProjectCutEdges = ThisApplication.CommandManager.ControlDefinitions("SketchProjectCutEdgesCmd") Dim i As Integer For i = 0 To iStepCount - 1 Set oWP = oDoc.ComponentDefinition.WorkPlanes.AddByPlaneAndOffset(oBaseFace, -dStep * i) Set oSk = oDoc.ComponentDefinition.Sketches.Add(oWP) oSk.Edit oSliceView.Execute oProjectCutEdges.Execute Set oProfile = oSk.Profiles.AddForSolid dArea = oProfile.RegionProperties.Area Dim oCentroidInModel As Point Set oCentroidInModel = oSk.SketchToModelSpace(oProfile.RegionProperties.Centroid) Debug.Print "Section area: " & dArea & " , Centroid: (" & oCentroidInModel.X & "," & oCentroidInModel.Y & "," & oCentroidInModel.Z & ")" oSk.ExitEdit Next End Sub
Hope this helps.
Thank you very much !
It is not exactly what I expected as I wanted to know if the function Cross Section Analysis could be run with a VBA macro. It would be nicer not to do it the hard way as you do but if it's not possible then i'll use your code which works and will surely do the job!
Can't find what you're looking for? Ask the community or share your knowledge.