Run Rules in parts from an assembly

Run Rules in parts from an assembly

donaldleigh
Advocate Advocate
1,337 Views
4 Replies
Message 1 of 5

Run Rules in parts from an assembly

donaldleigh
Advocate
Advocate

Evening all.

 

Inventor 2014.

We have a rule that is run from the top level assembly that copies some Iproperties to every part and Sub assembly. This rule is called "Project Details"

 

Inside each part and Sub assembly we have another rule that generates our part number called "Drawing Part Number Generator" this rule is set to trigger when a iProperty changes. This rule has a if statement that determines if its a part, Sheet Metal or assembly to create different types of part numbers

 

Everything works fine except when I run "Project Details" in the top level assembly the "Drawing Part Number Generator"  rule in each part/Sub assembly is not triggered for each type. example of this would be if I put a message box in the Sheet Metal part of the code this message box will not appear when the "Project Details"in the top level assembly.

I think it has to do with the

Dim doc As Document = ThisDoc.Document
oDoc = ThisApplication.ActiveDocument

 part in the "Drawing Part Number Generator"  rule. Is there a way to fix this.

 

I hope I have explained this well enough.

 

Attached are the rules.

 

Donald

0 Likes
1,338 Views
4 Replies
Replies (4)
Message 2 of 5

bradeneuropeArthur
Mentor
Mentor

could you show us the complete code.

 

Seems that you:

  1. first set Dim doc As Document = ThisDoc.Document
  2. then oDoc = ThisApplication.ActiveDocument

Why twice???

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 5

donaldleigh
Advocate
Advocate

I thought I attached them.

 

Here they are

0 Likes
Message 4 of 5

Sergio.D.Suárez
Mentor
Mentor

 

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

0 Likes
Message 5 of 5

chandra.shekar.g
Autodesk Support
Autodesk Support

@donaldleigh,

 

The object reference ThisDoc.Document may slightly differ from ThisApplication.ActiveDocument in the iLogic environment - so it may refer a different document (e.g. an IPT part).  "ThisDoc" refers to the Autodesk Inventor document in which the rule is written. It is often the active document, but it can also be a part within an assembly. Wherever the rule is stored, ThisDoc gives you access to that document

 

While the object "ActiveDocument" is the currently active document in terms of the Inventor application - it is not necessarily the same document as the document containing the running ilogic rule. For consistency of proper context in your iLogic code always prefer the reference ThisDoc.Document.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network