I was hoping I could get some advice about an iLogic rule I wrote for Inventor 2016. My goal is to run it in an assembly, have it look at each part contained in that assembly, specify parameters (G_L, G_W, G_T) and have it configure them. Because this configuration drives the final format of the BOM (which can vary from client to client) I often find myself tending to this task manually. I am fairly new to i Logic, but my thought process of accomplishing this is as follows:
1. look at only parts in the document
2. search for a "G_L" parameter
3. set it to export
4. set units to feet
5. Set fractional
6. Set 1/16 precision.
7. (FUTURE STEP) Continue to G_W and G_T parameters and repeat steps 3 thru 6
Below is the Rule I am struggling to troubleshoot:
'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
'look at only part files
If partDoc.DocumentType = kPartDocumentObject Then
'format file name
Dim FNamePos As Long
FNamePos = InStrRev(partDoc.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(partDoc.FullFileName, Len(partDoc.FullFileName) - FNamePos)
Dim userParams As UserParameters
For Each userParams In partDoc.ComponentDefinition.Parameters.UserParameters
Next userParams
p = Parameter.Param("G_L")
p.ExposedAsProperty = True
Dim cFormat As CustomPropertyFormat = p.CustomPropertyFormat
cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
cFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
cFormat.Units = "ft"
'rebuild to update the display
partDoc.Rebuild
End If
Next
iLogicVb.UpdateWhenDone = True
Here is the error I receive when I run the rule:
Error in rule: Rule0, in document: Assembly1
Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.UserParameters'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2FF370FA-BB1C-4C92-BB10-06D94CC8F8F3}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Thank you!
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
'Define the open document
Dim openDoc As Document
openDoc = ThisApplication.ActiveDocument
'Look at all of the files referenced in the open document
Dim partDoc As Document
For Each partDoc In openDoc.AllReferencedDocuments
'look at only part files
If partDoc.DocumentType = kPartDocumentObject Then
'format file name
Dim FNamePos As Long
FNamePos = InStrRev(partDoc.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(partDoc.FullFileName, Len(partDoc.FullFileName) - FNamePos)
Dim userParam As UserParameters
For Each userParam In partDoc.ComponentDefinition.Parameters.UserParameters
If userParam.Name = "G_L" OR userParam.Name = "G_W" OR userParam.Name = "G_T"
userParam.ExposedAsProperty = True
Dim cFormat As CustomPropertyFormat = userParam.CustomPropertyFormat
cFormat.PropertyType = CustomPropertyTypeEnum.kTextPropertyType
cFormat.Precision = CustomPropertyPrecisionEnum.kSixteenthsFractionalLengthPrecision
cFormat.Units = "ft"
End if
Next
'rebuild to update the display
partDoc.Update
End If
Next
openDoc.Rebuild
Thank you so much for your response, @MechMachineMan!! I tried it out and it seems to run for a little longer than the ilogic I posted, but the same error code persists =\
Can't find what you're looking for? Ask the community or share your knowledge.