Coppy rules to all Parts / Sub-assemblies which dont have rule before.

Coppy rules to all Parts / Sub-assemblies which dont have rule before.

tamnn.designer
Contributor Contributor
369 Views
3 Replies
Message 1 of 4

Coppy rules to all Parts / Sub-assemblies which dont have rule before.

tamnn.designer
Contributor
Contributor

Hi Sir,

I have old projects which don't have any rules before. Now i want to use external Rule to copy all rule into all children part and all sub-assembly as the pictures above.

Many thanks and best regards.

123.jpg

0 Likes
Accepted solutions (2)
370 Views
3 Replies
Replies (3)
Message 2 of 4

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @tamnn.designer . Try this code that I took here and modified a bit.

Sub Main
	Dim copyFrom As AssemblyDocument = ThisDoc.Document
	For Each copyTo As Document In copyFrom.AllReferencedDocuments
		If copyTo.IsModifiable Then
			'Copy the rules
			CopyRules(copyFrom, copyTo)
			'Copy the Event triggers
			CopyEventsPropSet(copyFrom, copyTo)
			'Save
			copyTo.Save()
		End If
	Next
End Sub
Sub CopyRules(CopyFrom As Document, CopyTo As Document)
	For Each oRule As iLogicRule In iLogicVb.Automation.Rules(CopyFrom)
		Dim oCopy As iLogicRule = iLogicVb.Automation.AddRule(CopyTo, oRule.Name, "")
		oCopy.Text = oRule.Text
	Next
End Sub
Sub CopyEventsPropSet(CopyFrom As Document, CopyTo As Document)
	Dim oPropSet As Inventor.PropertySet = CopyFrom.PropertySets("{2C540830-0723-455E-A8E2-891722EB4C3E}")
	Try
		CopyTo.PropertySets("{2C540830-0723-455E-A8E2-891722EB4C3E}").Delete()
	Catch
	End Try
	Dim newPropSet As Inventor.PropertySet = CopyTo.PropertySets.Add("_iLogicEventsRules", "{2C540830-0723-455E-A8E2-891722EB4C3E}")
	For Each prop As Inventor.Property In oPropSet
		newPropSet.Add(prop.Value, prop.Name, prop.PropId)
	Next
End Sub

 

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

0 Likes
Message 3 of 4

tamnn.designer
Contributor
Contributor

Hi sir,

can you show me the where is the line to choose the template file to coppy into all part and sub-assembly ?

0 Likes
Message 4 of 4

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

The code I wrote for you copies the rules from the main assembly to sub-assemblies and parts. In the code that I referred to in the previous message, you can choose the file from which you copy and the file to which you copy rules.

So in the link it's line 2 for the file you're copying from and line 3 for the file you're copying to.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature