- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
I'm trying to use a simple iLogic Rule for a very specific purpose - I have an upper-level assembly with subassemblies and these subassemblies include Frame Generator structural parts. I've customized these structural parts to have a "Mango_mass" parameter (lbmass units) that calculates the mass of a part by multiplying the generated length (G_L) of the frame with a linear density custom parameter that I've included as well (Mango_density, lbmass/ft).
What I'm wanting to do is, from the top-level assembly, cycle through each lower-level assembly and part in the whole model tree, test if that component has a parameter called "Mango_mass", and if it does, add it to a running tally. I simply want the total mass of the structure.
I am not familiar with iLogic at all, and I believe this is the only use I'll ever have for it, so I figure it's not worth the time learning the language for just this task. So I used ChatGPT 🙂 It's gotten most of the way, but it's having a bit of trouble with a couple of lines in the code. Here's what it's given me:
' Initialize a variable to store the total mass Dim totalMass As Double = 0 ' Subroutine to iterate through all components and sum the "Mango_mass" parameter Sub SumMangoMass(oCompDef) ' Loop through each occurrence in the assembly For Each oOccurrence As ComponentOccurrence In oCompDef.Occurrences Dim oSubCompDef As ComponentDefinition = oOccurrence.Definition ' Check if the occurrence is an assembly If TypeOf oSubCompDef Is AssemblyComponentDefinition Then ' Recursively call this subroutine for subassemblies SumMangoMass(oSubCompDef) Else ' Check if the part has a "Mango_mass" parameter Try ' Try to get the parameter Dim oParameter As Parameter = oSubCompDef.Parameters.Item("Mango_mass") ' Check if the parameter is numeric If oParameter.ParameterType = ParameterTypeEnum.kModelParameter AndAlso oParameter.Units = UnitsTypeEnum.kPoundMassUnits Then ' Add the parameter value to the total mass totalMass += oParameter.Value End If Catch ex As Exception ' Ignore exceptions for missing parameters End Try End If Next End Sub ' Main execution ' Access the top-level assembly Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition ' Call the subroutine to sum the Mango_mass parameter Call SumMangoMass(oCompDef) ' Output the total mass MessageBox.Show("Total Mango Mass: " & totalMass & " lbmass", "Mass Calculation")
When this code is pasted into Inventor, there's an error line below "Call" in the line "Call SumMangoMass(oCompDef)". The error says "Class member declaration expected."
I'm hoping this is a simple fix. (Please don't spend a lot of time here, it's not a big deal if I can't get it to work.) If you think of something, I'd love a suggestion!
Thanks a lot!
Nate
Solved! Go to Solution.