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.
Solved! Go to Solution.
Solved by Andrii_Humeniuk. Go to Solution.
Solved by Andrii_Humeniuk. Go to 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 - 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.
Hi sir,
can you show me the where is the line to choose the template file to coppy into all part and sub-assembly ?
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.
Can't find what you're looking for? Ask the community or share your knowledge.