Hi, on the one hand it seems to me that you should only place the reference to the document as thisdoc.document as I show below
iLogicVb.RunExternalRule("iProperties")
Dim doc As Document = ThisDoc.Document
ProNo = iProperties.Value("Custom", "Project Number")
LinNo = iProperties.Value("Custom", "Line Number")
JobNo = ProNo & "-" & LinNo
SeqNo = iProperties.Value("Custom", "Seq Number")
PRTNo = iProperties.Value("Project", "Part Number")
'Set Job Number iProperty
If iProperties.Value("Custom", "Job Number") <> JobNo Then
iProperties.Value("Custom", "Job Number") = JobNo
iLogicVb.UpdateWhenDone = True
End If
'Set Drawing Number iProperty
If SeqNo = "" Then
DRGNo = ""
Else
DRGNo = ProNo & "-" & LinNo & "-DRG-" & SeqNo
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If doc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then 'Drawing File
Return
Else If doc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then 'Part or Sheet Metal File
If ThisApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" = True Then 'Sheet Metal File
MessageBox.Show("Sheet Metal", "Title")
DXFSeqNo = iProperties.Value("Custom", "DXF Seq Number")
DXFNo = ProNo & "-" & LinNo & "-DXF-" & DXFSeqNo
AltDXFNo = iProperties.Value("Project", "Stock Number")
If DXFSeqNo = "" Then
'MessageBox.Show("Please Enter DXF Number", "Title")
DXFNo = ""
PRTNo = ""
AltDXFNo = ""
Else
PRTNo = DXFNo
AltDXFNo = DXFNo
End If
If iProperties.Value("Custom", "Material Part Number") <> DXFNo Then
iProperties.Value("Custom", "Material Part Number") = DXFNo
iLogicVb.UpdateWhenDone = True
End If
If iProperties.Value("Project", "Stock Number") <> AltDXFNo Then
iProperties.Value("Project", "Stock Number") = AltDXFNo
iLogicVb.UpdateWhenDone = True
End If
Else 'Part File
MatNo = iProperties.Value("Custom", "Material Part Number")
MatNoLength = Len(MatNo)
If MatNoLength = 2 Then
PRTNo = ProNo & "-" & LinNo & "-PRT-" & MatNo
Else
PRTNo = MatNo
End If
' Try
' LengthPar = Parameter.Param("Length")
' Call ThisDoc.Document.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kParameterBOMQuantity, LengthPar)
' Catch
' Call ThisDoc.Document.ComponentDefinition.BOMQuantity.SetBaseQuantity(BOMQuantityTypeEnum.kEachBOMQuantity)
' End Try
End If
Else If doc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then 'Assembly File
PRTNo = DRGNo
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Dim baseUnit As String
'BaseUnit = doc.ComponentDefinition.BOMQuantity.BaseUnits
'If BaseUnit = ""
' BaseUnitW = "Each"
'Else
' BaseUnitW = BaseUnit
'End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Set Part Number iProperty
If iProperties.Value("Project", "Part Number") <> PRTNo Then
iProperties.Value("Project", "Part Number") = PRTNo
iLogicVb.UpdateWhenDone = True
End If
'Set Alt Part Number iProperty
If iProperties.Value("Custom", "Drawing Number") <> DRGNo Then
iProperties.Value("Custom", "Drawing Number") = DRGNo
iLogicVb.UpdateWhenDone = True
End If
''Set base Unit iProperty
'If iProperties.Value("Custom", "Base Unit") <> BaseUnitW Then
' iProperties.Value("Custom", "Base Unit") = BaseUnitW
' iLogicVb.UpdateWhenDone = True
'End If
iLogicVb.UpdateWhenDone = True
When executing the assembly rule, keep in mind that your rule for each part file requests that an external rule be triggered. Be careful with the external rule that asks to be activated, this rule does have reference to the active document "ThisApplication.ActiveDocument" Work on the active assembly, not on the part file you need.
One possibility would be to integrate the external rule within the rule of your part, perhaps diagramming it as subroutines, then you will forget the document reference
Please accept as solution and give likes if applicable.
I am attaching my Upwork profile for specific queries.
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn