Curtis,
The code you help me with has worked flawlessly for a few years now.
Recently, I began to notice an occasional error popup with the rule.
"Error on line 37 in rule: Manuf-Commer-Spare, in document:
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"
The code is below and line 37 is red.
This is only happening with factory files. We don't use them very often which explains why it hasn't been an issue till recently.
I'm currently working with a large batch of iassemblies and am getting it quite frequently.
The rule is set to run before save.
The properties are created initially in the factory as expected with no errors and no errors happen if save is clicked manually.
I've also added the property values in the table for all the members.
The error only occurs when changing members. If a save is required, the error displays before the save dialogue displays.
Any idea how to prevent the error?
Here is the final code you help me with:
'[Rule creates the component classification properties, "Component Class" & "Spare Part" in parts and assemblies.
'Checks if the properties exists, then creates and applies the default value if it doesn't.
'Component Class - Default in parts and assemblies is set according to the files BOM Structure.
'Spare Part - Default is set to "No".
Dim doc As Document = ThisApplication.ActiveDocument
'[Check if document is not drawing.
If doc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Or _
doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
'Check if file has file name (for new unsaved files)
If doc.FullFileName = "" Then
oReadOnly = False 'set flag for files with no name
Else
Dim fi As New System.IO.FileInfo(doc.FullFileName)
oReadOnly = fi.IsReadOnly 'set flag based on file read only
End If
If oReadOnly = False Then
'Test if properties exist.
Try
iProperties.Value("Custom", "Component Class") = iProperties.Value("Custom", "Component Class")
Catch
iProperties.Value("Custom", "Component Class") = "MANUFACTURED"
End Try
Try
iProperties.Value("Custom", "Spare Part") = iProperties.Value("Custom", "Spare Part")
Catch
iProperties.Value("Custom", "Spare Part") = "NO"
End Try
'Set "Component Class" according to Documents BOMStructure
Dim BOMStructure = doc.ComponentDefinition.BOMStructure
Select Case BOMStructure
Case = 51974'Inseparable
iProperties.Value("Custom", "Component Class") = "MANUFACTURED"
Case = 51970'Normal
iProperties.Value("Custom", "Component Class") = "MANUFACTURED"
Case = 51971'Phantom
iProperties.Value("Custom", "Component Class") = "PHANTOM"
Case = 51973'Purchased
iProperties.Value("Custom", "Component Class") = "COMMERCIAL"
Case = 51972'Reference
iProperties.Value("Custom", "Component Class") = "REFERENCE"
End Select
End If
End If
']
']
Dewayne
Inventor Pro 2023
Vault Pro 2023