Hi @e_frissell
I didn't actually test the rules and event trigger stuff earlier, I just commented that out at the time because my example file didn't have any rule or event triggers present.
But I just did a very quick test and everything worked as expected, except I did run into an issue with the Form browser not updating, so I added @WCrihfield's blink sub to this.
I also noticed that it would make multiple copies of the rule if it was already present, so I added a line to delete the existing and replace it.
Also changed the goto, to use continue for.
Anyway, this version works from me. It copies the rules and event triggers. I don't see the blank names or get the errors. I'm running Inventor 2023 at the moment.
Sub Main
Dim copyFrom As Document = ThisApplication.Documents.Open("myTemplateLocation", False) 'Document to copy from
Dim copyTo As Document = ThisDoc.Document 'Document to copy to
'Copy the rules
CopyRules(copyFrom, copyTo)
'Copy the Event triggers
CopyEventsPropSet(copyFrom, copyTo)
' Copy form
CopyForm(copyFrom, copyTo)
Call BlinkTree
'Save the document to which rules and triggers has been copied
copyTo.Save
copyFrom.close
End Sub
Sub CopyRules(CopyFrom As Document, CopyTo As Document)
For Each oRule As iLogicRule In iLogicVb.Automation.Rules(CopyFrom)
'try to delete the rule if it exists ( so it can be added again)
Try: iLogicVb.Automation.DeleteRule(CopyTo, oRule.Name) :Catch: End Try
If oRule.Name = "Scale" Then Continue For
If oRule.Name = "Date Stamp" Then Continue For
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
Sub CopyForm(CopyFrom As Document, CopyToDoc As Document)
Dim Attset As Inventor.AttributeSet
For Each Attset In CopyFrom.AttributeSets
If Attset.Name Like "iLogicInternalUi*" Then
Try
Attset.CopyTo(CopyToDoc)
Catch ex As Exception
Logger.Error(ex.Message)
End Try
End If
Next
End Sub
Sub BlinkTree
'toggle visibility Of iLogic dockable window To update it
For Each oDW As Inventor.DockableWindow In ThisApplication.UserInterfaceManager.DockableWindows
If oDW.InternalName = "ilogic.treeeditor" Then
oDW.Visible = False
oDW.Visible = True
End If
Next
End Sub
