[Cross section analysis][VBA]

[Cross section analysis][VBA]

Anonymous
Not applicable
1,190 Views
5 Replies
Message 1 of 6

[Cross section analysis][VBA]

Anonymous
Not applicable

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

 hull.PNGhull_2.PNG

 

My question is about the last point. We use the advanced section analysis tool :

  1. we cut the boat with planes parallel to YZ
  2. starting from the aft of the boat up to the bow with a certain number of planes
  3. after calculating the cross sections, we export the data (section number, cross section area, x position)
  4. we then use excel to locate in x, the section with maximum area

 

advanced_cross_section_analysis.PNGexport_cross_section_analysis.PNG

 

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

 

0 Likes
1,191 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

Hi, I still haven't found a solution for this problem. 

 

Many thanks

0 Likes
Message 3 of 6

YuhanZhang
Autodesk
Autodesk

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.

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 4 of 6

Anonymous
Not applicable

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!

 

 

0 Likes
Message 5 of 6

Anonymous
Not applicable

Hi.

 

Did you find out if the Cross-section analysis tool can be run  with a VBA macro?

 

Best regards!

0 Likes
Message 6 of 6

Anonymous
Not applicable
Hi,

No, I couldn't find the VBA solution, sorry. I'd be happy to know if you
find more information somewhere.

Thank you!
0 Likes