Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
tamnn.designer
228 Views, 3 Replies

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

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

3 REPLIES 3
Message 2 of 4

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 - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

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

EESignature

Message 3 of 4

Hi sir,

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

Message 4 of 4

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 - Leading design engineer

LinkedIn | My free Inventor Addin | My Repositories

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

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report