You can store this rule as an external rule, I suspect you have stored it as an internal rule in the document. The external rule is visible to all documents. This post here goes through how to set this up. You will be asked to provide a disk location to save the rule either save it local or on a shared drive. When the rule is done I usually add it to a global form as a button this way it is readily accessible and doesn't involve running it through a vba macro and creating buttons on the browser. See attached image
The extra screen shots showed more of your workflow. I can see you want to get the size of sheetmetal parts. Previously we have chosen to look at the manual entry parameters you use to create the part. There is actually built in properties that we can use to get the flat pattern size once it has been created. So as long as the parts are all created on the same planes and are consistent it should come out accurate. If however parts are derived or have inconstant flat pattern orientation the values could have some errors in there so worth double checking. Another think to check is if the documents all have constant units.
This is the built in property to retrieve the flat pattern sizes after the flat pattern has been created.
SheetMetal.FlatExtentsLength
SheetMetal.FlatExtentsWidth
SheetMetal.FlatExtentsArea
In the rule below I have chosen to created the flat pattern even on non folded parts as it will aid in retrieving the size without much user input. However you could choose to revert to your original d0,d1 method if you don't like this approach. You would need to just change the filter statements around. This post here was helpful to prepare this rule an dis also a good discussion.
Sub Main
DocType = ThisApplication.ActiveDocument.DocumentType
If DocType = DocumentTypeEnum.kAssemblyDocumentObject Then
MessageBox.Show("it's an assembly file - Exiting!", "iLogic")
ElseIf DocType = DocumentTypeEnum.kPartDocumentObject Then
'Get the document we want to work with
Dim partDoc As PartDocument
partDoc = ThisApplication.ActiveDocument
' Call the sub routine to get sheetmetal part sizes
SheetmetalProcessing (partDoc)
'Pass document and parameter to sub routine to export parameters
Try
ParameterExport(partDoc, "extents_length")
ParameterExport(partDoc, "extents_width")
ParameterExport(partDoc, "Thickness")
Catch
MessageBox.Show("One of the parameters is missing", "iLogic")
End Try
' Get the User Defined property set.
Dim UserDefinedPropSet As PropertySet
UserDefinedPropSet = partDoc.PropertySets.Item("Inventor User Defined Properties")
' Get the Size property.
Dim SizeProp As Inventor.Property
Try
SizeProp = UserDefinedPropSet.Item("Size")
Catch
' Failed to get the property, which means it doesn't exist so we'll create it.
UserDefinedPropSet.Add("", "Size")
SizeProp = UserDefinedPropSet.Item("Size")
End Try
'Add an expression to custom property
SizeProp.Expression = _
"=<Thickness> X <extents_width> X <extents_length> LG."
MessageBox.Show("Size: " & SizeProp.Value, "iLogic- Success iProp Updated")
ElseIf DocType = DocumentTypeEnum.kDrawingDocumentObject Then
MessageBox.Show("it's a drawing file - Exiting!", "iLogic")
End If
End Sub
Sub SheetmetalProcessing(oPartDoc as Document)
'See if this part is a sheetmetal part
If oPartDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
Dim oDef As SheetMetalComponentDefinition
oDef = oPartDoc.ComponentDefinition
'Add parameters needed to store flat pattern sizes
AddParameters (oPartDoc)
If oDef.HasFlatPattern = False
'Create flat pattern
oDef.Unfold
'Return to folded part
oDef.FlatPattern.ExitEdit
End If
'After flat pattern creation get size of flat pattern
Parameter("extents_length") = SheetMetal.FlatExtentsLength
Parameter("extents_width") = SheetMetal.FlatExtentsWidth
End If
End Sub
Sub AddParameters(oPartDoc as Document)
'Get reference to reference parameters
Dim oRefParams As ReferenceParameters
oRefParams = oPartDoc.ComponentDefinition.Parameters.ReferenceParameters
Dim extents_length, extents_width, As ReferenceParameter
'Create Parameters
Try
oRefParam = oPartDoc.ComponentDefinition.Parameters("extents_length")
Catch
'If the parameter was not found, then create a new one.
oRefParam = oRefParams.AddByExpression(0, "in","extents_length")
End Try
Try
oRefParam = oPartDoc.ComponentDefinition.Parameters("extents_width")
Catch
'If the parameter was not found, then create a new one.
oRefParam = oRefParams.AddByExpression(0, "in","extents_width")
End Try
End Sub
Sub ParameterExport(oPartDoc As Document, oParam As String)
'Export parameters as custom iproperty (Tick the box)
Dim param As Inventor.Parameter
Dim oFormat As CustomPropertyFormat
param = oPartDoc.ComponentDefinition.Parameters.Item(oParam)
param.ExposedAsProperty = True
'Carry out formatting
oFormat = param.CustomPropertyFormat
oFormat.PropertyType = Inventor.CustomPropertyTypeEnum.kTextPropertyType
oFormat.Units = "in"
oFormat.ShowUnitsString = True
oFormat.Precision = Inventor.CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
End Sub
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan