Filtering certain templates from a rule.

Filtering certain templates from a rule.

Anonymous
Not applicable
478 Views
6 Replies
Message 1 of 7

Filtering certain templates from a rule.

Anonymous
Not applicable

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
0 Likes
Accepted solutions (1)
479 Views
6 Replies
Replies (6)
Message 2 of 7

bradeneuropeArthur
Mentor
Mentor

How are these two templates differentiated? 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 7

Anonymous
Not applicable

They are both a sheet metal template.  One will always have the word 'Dakota' in the vendor iprop field.

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Since I still don't know which template you want this code to effect, and which template you don't want this code to effect, I just chose one to show you how.  I included the following 'check' just inside the loop, that looks at the Vendor iProperty value for that part, and if it 'Contains' the word "Dakota", I have it set to 'Continue For', which makes it skip to the next referenced document, without processing that part any further.

This is what that bit of code looks like:

'Check if this Sheet Metal Part has 'Dakota' in the Vendor iProperty value
If CStr(oPDoc.PropertySets.Item("Design Tracking Properties").Item("Vendor").Value).Contains("Dakota") Then
	'either continue or don't continue
	Continue For 'skip to next document in loop
End If

 

Here's the whole code:

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
		MsgBox("An Assembly Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument

	' 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

	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 oADoc.AllReferencedDocuments
		'check if it is a Sheet Metal Part
		If oDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then Continue For
		Dim oPDoc As PartDocument = oDoc
		Dim oSMDef As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
		
		'Check if this Sheet Metal Part has 'Dakota' in the Vendor iProperty value
		If CStr(oPDoc.PropertySets.Item("Design Tracking Properties").Item("Vendor").Value).Contains("Dakota") Then
			'either continue or don't continue
			Continue For 'skip to next document in loop
		End If
		
		' Check that a flat pattern exists on the part in question
	    If IsNothing(oSMDef.FlatPattern) Then
			Try ' Try unfolding part
				oSMDef.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 = oSMDef.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 = oPDoc.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
	Next
End Sub

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

Anonymous
Not applicable

@WCrihfield 

 

I tried that code at the assembly level, and it still filled the SQFT value in both parts, even though, only one of them has 'Dakota' written in the 'Vendor' field.  Both templates are a sheet metal template, only difference is that one will have different iproperty values filled out on it, as the other will be mostly empty to start with.

 

image.png

0 Likes
Message 6 of 7

Anonymous
Not applicable

Just noticed that I have the word capitalized.  Now it worked !. Thank you !

0 Likes
Message 7 of 7

bradeneuropeArthur
Mentor
Mentor

Good to hear that it is solved!

To solve upper an lowercase:

bradeneuropeArthur_0-1614799855037.png

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes