-1

The script:

Sub CATMain()

  
    Dim partDocument1 As Document
    Set partDocument1 = CATIA.ActiveDocument
    
    Dim part1 As Part
    Set part1 = partDocument1.Part
    
    Dim shapeFactory1 As ShapeFactory
    Set shapeFactory1 = part1.ShapeFactory
    
    Dim myBody As Body
    Set myBody = part1.Bodies.Item("FUEL TANK")
    part1.InWorkObject = myBody
    
    Dim hybridBody1 As HybridBody
    Set hybridBody1 = part1.HybridBodies.Item("Geometrical Set.2")
    
    Dim fileName As String
    fileName = "C:\Users\Izabel Russo\Downloads\FUEL TANK.csv"
    Dim fileNumber As Integer
    fileNumber = FreeFile
    Open fileName For Output As fileNumber
    Print #fileNumber, "Plan, Volume, Area, Mass, Density, Gx, Gy, Gz, IoxG, IoyG, IozG, IxyG, IxzG, IyzG"
    
    Dim i As Integer
    For i = 1 To hybridBody1.HybridShapes.Count
        Dim plane As HybridShapePlaneOffset
        Set plane = hybridBody1.HybridShapes.Item(i)
        Dim reference2 As Reference
        Set reference2 = part1.CreateReferenceFromObject(plane)
        
        Dim reference1 As Reference
        Set reference1 = part1.CreateReferenceFromName("")
        
        Dim split1 As Split
        Set split1 = shapeFactory1.AddNewSplit(reference1, catPositiveSide)
        split1.Surface = reference2
        part1.Update
        
        Dim selection1 As Selection
        Set selection1 = partDocument1.Selection
        selection1.Clear
        selection1.Add myBody
        
        Dim spaWorkbench As Workbench
        Set spaWorkbench = partDocument1.GetWorkbench("SPAWorkbench")
        
        Dim referenceToMyBody As Reference
        Set referenceToMyBody = part1.CreateReferenceFromObject(myBody)
        
        Dim measurable As Measurable
        Set measurable = spaWorkbench.GetMeasurable(referenceToMyBody)
        
        Dim volume As Double
        volume = measurable.Volume
        
        Dim area As Double
        area = measurable.Area
        
        Dim mass As Double
        mass = measurable.Mass
        
        Dim density As Double
        density = measurable.Density
        
        Dim inertia(8) As Double
        measurable.GetInertia inertia
        
        Dim cg(2) As Double
        measurable.GetCOG cg
        
        Print #fileNumber, i & ", " & volume & ", " & area & ", " & mass & ", " & density & ", " & cg(0) & ", " & cg(1) & ", " & cg(2) & ", " & inertia(0) & ", " & inertia(1) & ", " & inertia(2) & ", " & inertia(3) & ", " & inertia(4) & ", " & inertia(5)
        
        selection1.Clear
        selection1.Add split1
        selection1.Delete
        part1.Update
    Next i
    
    Close fileNumber
    
    MsgBox "Done."
End Sub

enter image description here

I want to make splits in a partbody, have already created separate plans; It's a fuel tank, and I need to evaluate fuel consumption data. Me and my mate created this code to run a macrogeometricalset, but something is going wrong.

7
  • can you explain what's not working? Maybe it would be easier to generate a split once and modify the reference surface instead of deleting the feature. btw "Geometrical Set.2" does not exist directly under the part. It's located in a sub-hybridbody Commented Aug 2, 2024 at 16:04
  • I have do make 567 splits on the main body and, with each split, generate a csv file. Isn't even working Commented Aug 5, 2024 at 11:15
  • And what exactly is not working? Have you tried to execute the code step-wise? Do you get an error? Are the splits generated? Commented Aug 5, 2024 at 12:14
  • Nothing is working :/ the script keeps giving compilation error. I've been trying with chatgpt, but its geting worst and worst Commented Aug 5, 2024 at 12:18
  • And in which line do you get a compiler error? What error do you get? Commented Aug 5, 2024 at 12:21

1 Answer 1

0

You should not declare type of measurable then remove this line:

Dim measurable As Measurable

Then to get all your data you need on the main body:

    Dim measurable 'As Measurable /!\ DO NOT DECLARE TYPE As Measurable /!\
    Set measurable = spaWorkbench.GetMeasurable(referenceToMyBody)
    
    Dim volume As Double
    Dim area As Double
    Dim density As Double
    Dim mass As Double

    volume = measurable.volume
    area = measurable.area
    density = part1.density
    mass = density * volume

To get Inertia you should use:

Set oInertias = spaWorkbench.Inertias
Sign up to request clarification or add additional context in comments.

4 Comments

It worked once, but I just generate for mass, volume and density. The rest its so much more important So, I must delete all items using 'measurble', 'Dim' command? I know nothing about vba, use to work with py.
Only Mesurable is the issue.
What are others properties "important" do you need ? Inertia and COG ?
Area, Volume, Density, Mass, Gx, Gy, Gz, IoxG, IoyG, IozG, Ixy, Ixz, Iyz I was tryind to add a printscreen, so it can help you to help me, but couln't get it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.