Message 1 of 1
Add a new column to ipart table with an iLogic rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I wrote an iLogic rule to create new parameter "MetalMass" in ipart and I want to update the rule to add this parameter "MetalMass" in the ipart table.
Sub Main() ' Ensure the document is an active part document Dim oPartDoc As PartDocument Try oPartDoc = ThisApplication.ActiveDocument Catch MessageBox.Show("No active part found.", "Error") Exit Sub End Try If oPartDoc.DocumentType <> kPartDocumentObject Then MessageBox.Show("This rule must be run in a part document.", "Error") Exit Sub End If ' Check if the part is a sheet metal part; if not, exit with a message If ThisApplication.ActiveDocument.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then MessageBox.Show("This rule requires a sheet metal part. The active document is not a sheet metal part.", "Error") Exit Sub End If ' Access the iPart table (Factory) Dim oPartCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition Dim oTable As iPartFactory = oPartCompDef.iPartFactory ' Check if iPart table exists If oTable Is Nothing Then MessageBox.Show("This part does not have an iPart table.", "Error") Exit Sub End If ' Access the model parameters Dim oParams As Parameters = oPartCompDef.Parameters iProperties.Value("Custom", "MetalMass") = 0 Dim oRow As iPartTableRow For Each oRow In oTable.TableRows ' Make this the active row so the model will recompute oTable.DefaultRow = oRow ' Update the document to ensure parameter values reflect the active row oPartDoc.Update() Thickness = oParams.Item("Thickness").Value Dim extents_area As Double = SheetMetal.FlatExtentsArea Dim MetalVolume As Double = (extents_area * Thickness) / 1000000000 Dim MetalDensity As Double = iProperties.Mass / (iProperties.Volume / 1000000000) Dim MetalMass As Double = Round(MetalVolume * MetalDensity, 2) iProperties.Value("Custom", "MetalMass") = MetalMass Next ' Activate the first row oTable.DefaultRow = oTable.TableRows.Item(1) ' Update document to reflect changes oPartDoc.Update() InventorVb.DocumentUpdate() ThisApplication.ActiveDocument.Update() MessageBox.Show("All parameters updated for all iPart rows!", "Success") End Sub