<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Updating old drawings with iLogic rules in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6520189#M66380</link>
    <description>&lt;P&gt;There are only a few rules and I'd like the triggers to be on exit, on save and on opening&lt;/P&gt;</description>
    <pubDate>Wed, 24 Aug 2016 15:02:55 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-08-24T15:02:55Z</dc:date>
    <item>
      <title>Updating old drawings with iLogic rules</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6490895#M65997</link>
      <description>&lt;P&gt;I've created a macro (VBA)&amp;nbsp;which updates old drawings to the new templates borders and styles etc. These new templates have iLogic rules which also need to be transferred to the drawings, along with the triggers. I'm able to call external rules when I run this macro but I need them to have the right trigger. iTriggers only work with internal rules(?) which the old templates don't have and although this &lt;A href="http://beinginventive.typepad.com/being-inventive/2012/02/injecting-ilogic-code-and-ilogic-event-triggers-automatically.html" target="_blank"&gt;http://beinginventive.typepad.com/being-inventive/2012/02/injecting-ilogic-code-and-ilogic-event-triggers-automatically.html&lt;/A&gt; kind of does the right thing I&amp;nbsp;can't expect everyone&amp;nbsp;to have to open it and add the correct rules when they're updating a drawing- any suggestions?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 10:14:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6490895#M65997</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-10T10:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Updating old drawings with iLogic rules</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6492248#M66009</link>
      <description>&lt;P&gt;To clarify, would you like to apply some &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Event Triggers&lt;/FONT&gt;&lt;/STRONG&gt; or &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;iTriggers&lt;/FONT&gt; &lt;/STRONG&gt;to &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;Internal &lt;/FONT&gt;&lt;/STRONG&gt;or &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;External&lt;/FONT&gt; &lt;/STRONG&gt;rules?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 17:16:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6492248#M66009</guid>
      <dc:creator>MegaJerk</dc:creator>
      <dc:date>2016-08-10T17:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Updating old drawings with iLogic rules</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6493479#M66024</link>
      <description>&lt;P&gt;Event Trigger to external rules is what I'm going with (sorry for the rambling) but they need to be set up through VBA&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2016 07:20:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6493479#M66024</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-11T07:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: Updating old drawings with iLogic rules</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6514109#M66295</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/725444"&gt;@MegaJerk﻿&lt;/a&gt;&amp;nbsp;Do you think this can be done?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 10:26:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6514109#M66295</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-22T10:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Updating old drawings with iLogic rules</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6514172#M66299</link>
      <description>&lt;P&gt;My bad on not getting back to you sooner.&lt;BR /&gt;&lt;BR /&gt;Is it possible?&lt;BR /&gt;&lt;BR /&gt;Absolutely… but, it’s going to be a journey.&lt;BR /&gt;&lt;BR /&gt;Another question I have is, how many external rules need eventTriggers, and which types of eventTriggers are you interested in using (that is - Before Save, On Model Change, etc. etc.)??&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2016 11:10:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6514172#M66299</guid>
      <dc:creator>MegaJerk</dc:creator>
      <dc:date>2016-08-22T11:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Updating old drawings with iLogic rules</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6520189#M66380</link>
      <description>&lt;P&gt;There are only a few rules and I'd like the triggers to be on exit, on save and on opening&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2016 15:02:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6520189#M66380</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-24T15:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Updating old drawings with iLogic rules</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6521047#M66387</link>
      <description>&lt;P&gt;Hi aliceloneragan,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I use this to copy event triggers from my templates. I set up external rules with event triggers&amp;nbsp;in the templates, and then I have this&amp;nbsp;"Copy Event Triggers rule" called from various other external rules as needed. I almost never use internal rules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep in mind, I repurposed a rule I found on line, and so there is likely some extra stuff in there that is not needed, etc. I never did go back through it and clean it up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a batch processor also:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://forums.autodesk.com/t5/inventor-general-discussion/any-way-to-automatically-update-all-related-drawings/m-p/6467841#M606820" target="_blank"&gt;http://forums.autodesk.com/t5/inventor-general-discussion/any-way-to-automatically-update-all-related-drawings/m-p/6467841#M606820&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;BR /&gt;Best of luck to you in all of your Inventor pursuits,&lt;BR /&gt;Curtis&lt;BR /&gt;&lt;A href="http://inventortrenches.blogspot.com" target="_blank"&gt;http://inventortrenches.blogspot.com&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Imports System.Collections.Generic
'code taken and modified from:
'http://adndevblog.typepad.com/manufacturing/2015/01/add-external-ilogic-rule-to-event-trigger.html

Sub Main
Trace.WriteLine("Event Driven Rules Copy", "iLogic") 'debug 

	Dim oTemplateDoc As Document
	Dim oTemplate As String 
	
	'check file type 
	If ThisApplication.ActiveEditDocument.DocumentType = kDrawingDocumentObject Then
	'If ThisDoc.Document.DocumentType = kDrawingDocumentObject Then
		oTemplate = "\\server\departments\CAD\Inventor\Templates\Standard.idw"   'file to copy events from
	ElseIf ThisApplication.ActiveEditDocument.DocumentType = kPartDocumentObject Then
	'ElseIf ThisDoc.Document.DocumentType = kPartDocumentObject Then
		oTemplate = "\\server\departments\CAD\Inventor\Templates\Standard.ipt"   'file to copy events from
	Else
		oTemplate = "\\server\departments\CAD\Inventor\Templates\Standard.iam"   'file to copy events from
	End If
	
	'file to copy events to
	oInput =  ThisApplication.ActiveEditDocument.FullFileName 
	If oInput = "" Then 'catch a new file with no path
		Return
	End If	
	
	'open the template
	oTemplateDoc = ThisApplication.Documents.Open(oTemplate, False)
	CopyEventsToDocuments(oTemplateDoc)
	oTemplateDoc.Close 
End Sub

Private Const m_ourGuid As String = "{2C540830-0723-455E-A8E2-891722EB4C3E}"
Private savedEnabled As Boolean
Dim oInput As String

Public Sub CopyEventsToDocuments(ByVal sourceDoc As Document)
	Dim sourcePropSet As PropertySet = GetEventRulesPropertySet(sourceDoc)
	Dim inputs() As String = { oInput} 
	Dim destinationFileNames As List(Of String) = New List(Of String)(inputs)
	If (destinationFileNames Is Nothing) Then Return
	savedEnabled = iLogicVb.Automation.RulesOnEventsEnabled
	iLogicVb.Automation.RulesOnEventsEnabled = False
	Try	
		CopyEventsToAllDocuments(sourcePropSet, sourceDoc, destinationFileNames)
	Finally		
		iLogicVb.Automation.RulesOnEventsEnabled = savedEnabled
	End Try

End Sub

Function GetEventRulesPropertySet(ByVal sourceDoc As Document) As PropertySet
	Try
		Return sourceDoc.PropertySets(m_ourGuid)
	Catch ex As Exception
		Return Nothing
	End Try
End Function

Function VerifyRulesPropertySet(ByVal propSet As PropertySet) As Boolean
	If (propSet Is Nothing) Then Return True
	' See if any rules are internal instead of external.  We can't copy those.
	For Each prop As Inventor.Property In propSet
		Dim strValue As String = prop.Value.ToString
		If (Not strValue.StartsWith("file://")) Then Return False
	Next
	Return True
End Function


Sub CopyEventsToAllDocuments(ByVal sourcePropSet As PropertySet, ByVal sourceDoc As Document, ByVal destinationFileNames As List(Of String))
	For Each fileName As String In destinationFileNames
		If (String.Equals(sourceDoc.FullFileName, fileName)) Then Continue For
		CopyEventsToDocument(sourcePropSet, fileName)
	Next
End Sub

Sub CopyEventsToDocument(ByVal sourcePropSet As PropertySet, ByVal fileName As String)
	'Dim doc As Document = FindOpenDocument(fileName)

	Dim openedHere As Boolean = False

	If (doc Is Nothing) Then
		doc = ThisApplication.Documents.Open(fileName, True)
		openedHere = True
	End If
		
	CopyEventsPropertySetToDocument(sourcePropSet, doc)
	iLogicVb.Automation.RulesOnEventsEnabled = savedEnabled

End Sub

Sub CopyEventsPropertySetToDocument(ByVal sourcePropSet As PropertySet, ByVal doc As Document)
	' If an event-driven rules property set already exists, delete it.
	Dim oldPropSet As PropertySet = GetEventRulesPropertySet(doc)
	If (oldPropSet IsNot Nothing) Then
		oldPropSet.Delete()
	End If
	If (sourcePropSet Is Nothing OrElse sourcePropSet.Count = 0) Then Return
	Dim destPropSet As PropertySet = doc.PropertySets.Add("_iLogicEventsRules", m_ourGuid)
	For Each prop As Inventor.Property In sourcePropSet
		destPropSet.Add(prop.Value, prop.Name, prop.PropId)
	Next
	EnsureDocumentInterest(doc)
End Sub

Const iLogicId As String = "{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}"

Sub EnsureDocumentInterest(ByVal doc As Document)
	If (ThisApplication.SoftwareVersion.Major &amp;lt; 15) Then Return ' Inventor 2010 or before
	If (DocumentHasiLogicInterest(doc)) Then Return
	Dim dataVersion As Integer = 20090512
	Dim newInterest As DocumentInterest = doc.DocumentInterests.Add(iLogicId, "iLogic", DocumentInterestTypeEnum.kInterested, dataVersion, Nothing)
End Sub

Function DocumentHasiLogicInterest(ByVal doc As Document) As Boolean
	Dim interest As DocumentInterest = FindDocumentInterest(doc, iLogicId)
	If (interest IsNot Nothing) Then
		If (interest.InterestType = DocumentInterestTypeEnum.kInterested) Then
			Return True
		End If
		interest.Delete()
	End If
	Return False
End Function

Function FindDocumentInterest(ByVal doc As Document, ByVal clientId As String) As DocumentInterest
	For Each interest As DocumentInterest In doc.DocumentInterests
		If (String.Equals(interest.ClientId, clientId, StringComparison.OrdinalIgnoreCase)) Then
			Return interest
		End If
	Next
	Return Nothing
End Function&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Aug 2016 20:54:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/updating-old-drawings-with-ilogic-rules/m-p/6521047#M66387</guid>
      <dc:creator>Curtis_Waguespack</dc:creator>
      <dc:date>2016-08-24T20:54:14Z</dc:date>
    </item>
  </channel>
</rss>

