Message 1 of 7

Not applicable
03-02-2021
03:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have a rule that is meant to be ran from an assembly or weldment. It goes through and identifies which parts are sheet metal, then it populates the custom iproperty 'SQFT' with the square feet the sheet metal's extents take up. However, I have two templates for sheet metal. I only want one of those templates to be affected by the rule. Is there any thoughts on how to do this ? I've had some but I've failed to write a code that doesn't have errors (I'm a semi-beginner)
Here's my code so far:
' Set the units for area: Dim UnitsMultiplier As Double ' Want output in mm^2? 'UnitsMultiplier = 1 ' Want output in cm^2? 'UnitsMultiplier = 0.01 ' Want output in m^2 UnitsMultiplier = 0.000001 ' Set the number of decimal places Dim DecimalPlaces As Integer = 2 'check this file is an assembly Dim doc As Document = ThisApplication.ActiveDocument If doc.DocumentType = kPartDocumentObject Then MessageBox.Show("This rule can only be run in an assembly file!", "Cadline iLogic") Return End If Dim oCustomProps As Inventor.PropertySet Dim oProp As Inventor.Property Dim iCounter As Integer = 0 ' Loop through all referenced docs in assembly For Each oDoc As Document In doc.AllReferencedDocuments If oDoc.DocumentSubType.DocumentSubTypeID = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then ' It is a sheet metal part Dim oSP As PartDocument = CType(oDoc, PartDocument) Dim oDef As SheetMetalComponentDefinition = oSP.ComponentDefinition ' Check that a flat pattern exists on the part in question If IsNothing(oDef.FlatPattern) Then Try ' Try unfolding part oDef.Unfold() Catch ' Failed to unfold part MessageBox.Show("There is no flat pattern in " & oDoc.DisplayName & " - tried flattening and failed. Please open the file and create a flat pattern" ,"JACKRABBIT") Continue For End Try End If ' Get flat pattern Dim oFlatPattern As FlatPattern = oDef.FlatPattern ' Get face area Dim SheetMetalArea As Decimal = oFlatPattern.TopFace.Evaluator.Area ' Get length and width Dim SheetMetalLength As Decimal = oFlatPattern.Length Dim SheetMetalWidth As Decimal = oFlatPattern.Width ' Define custom iProperties oCustomProps = oDoc.PropertySets.Item("Inventor User Defined Properties") ' Create custom iProperty for the 'extents' area of the flat pattern (bounding rectangle area) Try ' Try setting value first oCustomProps.Item("SQFT").Value = Math.Round(SheetMetalLength * SheetMetalWidth * 100 * UnitsMultiplier * 10.7639, DecimalPlaces) Catch ' Custom iProperty doesn't exist - so create it oProp = oCustomProps.Add(Math.Round(SheetMetalLength * SheetMetalWidth * 100 * UnitsMultiplier * 10.7639, DecimalPlaces), "SQFT") End Try End If Next
Solved! Go to Solution.