Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Apply iLogic rule to several files

15 REPLIES 15
Reply
Message 1 of 16
karthur1
5197 Views, 15 Replies

Apply iLogic rule to several files

I have an iLogic rule that I want to add to several files that are already existing. Is there an "easy" way to do this other than opening each and every file, creating a new rule, pasting in the code and then saving the file?
If I had a macro that would create the rule I could run it with KwikBatch.

Using R2010/11
15 REPLIES 15
Message 2 of 16
japike
in reply to: karthur1

I'm just starting out in iLogic myself, so this may not be right, but isn't that what external rules are for?
Jeff
Peace,
Jeff
Inventor 2022
Message 3 of 16
MjDeck
in reply to: karthur1

I would recommend looking at external rules. They can't be triggered by changes in particular parameters, but they can be triggered by other events.

If you're sure you want the same internal rule in several documents, here's a macro that will do it:

{code}
Sub AddRule()

Dim iLogicAuto As Object
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub

Dim doc As Document
Set doc = ThisApplication.ActiveDocument

Dim ruleName As String
ruleName = "MyRule"

Dim oldRule As Object
Set oldRule = iLogicAuto.GetRule(doc, ruleName)
If (Not oldRule Is Nothing) Then Exit Sub

Dim ruleText As String
ruleText = ReadAllText("C:\MyRule.txt")

Dim newRule As Object
Set newRule = iLogicAuto.AddRule(doc, ruleName, ruleText)

End Sub

Function ReadAllText(strPath As String) As String
' From http://www.vbknowledgebase.com/?Id=23&Desc=Read-Text-File-into-string-VB6
On Error GoTo ErrTrap
Dim intFileNumber As Integer

If Dir(strPath) = "" Then Exit Function
intFileNumber = FreeFile
Open strPath For Input As #intFileNumber

ReadAllText = Input(LOF(intFileNumber), #intFileNumber)
ErrTrap:
Close #intFileNumber
End Function


Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Dim addIns As ApplicationAddIns
Set addIns = oApplication.ApplicationAddIns

Dim addIn As ApplicationAddIn
Dim customAddIn As ApplicationAddIn
For Each addIn In addIns
If (addIn.ClassIdString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then
Set customAddIn = addIn
Exit For
End If
Next

If (customAddIn Is Nothing) Then Exit Function

customAddIn.Activate
Set GetiLogicAddin = customAddIn.Automation
End Function

{code}

Mike Deck
Software Developer
Autodesk, Inc.

Message 4 of 16
rob.j.ross
in reply to: MjDeck

Mike,

 

This is useful code.  Thanks for posting it.  I have not been able to find out how to programmatically place a rule under a specific Event Trigger after it has been added to the document.  For exampIe, I would like to add "MyRule" under the BeforeSaveDocument event trigger with VB.  How is this done?  Also, where can I find info on all iLogicAuto members?  Thanks.

 

Rob

____________________________
Inventor Professional 2014 64 Bit
Windows 7 Professional
NVIDIA Quadro FX 4600
Dual Intel Xeon E5540 CPUs
16GB DDR3 Ram
Message 5 of 16
BMiller63
in reply to: MjDeck

Rob and I may be asking for the same thing, but can this be used to add an external rule to every to the current file and added to a particular save event?

Message 6 of 16
rob.j.ross
in reply to: BMiller63

I am not too familiar with external rules so maybe I am going about this wrong but I am in the process of writing an iLogic Manager macro that will apply or remove rules from files.  Mike's code adds the rule to the file but does not place it under an event trigger.  We have thousands of pre-iLogic Inventor files that I would like to apply iLogic to without having to go in and manually add rules under event triggers.  The event trigger rule placement is the last thing that I need to complete it.

____________________________
Inventor Professional 2014 64 Bit
Windows 7 Professional
NVIDIA Quadro FX 4600
Dual Intel Xeon E5540 CPUs
16GB DDR3 Ram
Message 7 of 16
BMiller63
in reply to: rob.j.ross

Rob,

I think we'relooking for the same solution. I perfer the external rule as then there is a single file to edit, to update the rule universaly.

 

But I'd like to have it automatically added to the save event as well.

Message 8 of 16
rob.j.ross
in reply to: BMiller63

As far as I can tell you still have to set the event triggers for each file with an external rule(correct me if I am wrong here).  Either way you have to deal with it at an internal per file level to some degree.  I think I can deal with having internal rules on the files because I will be able to mass update, add or remove them to all files in a folder via the API.  Come to think of it, iLogic would be a nice addition to the Task Manager options for doing this don't you think?

____________________________
Inventor Professional 2014 64 Bit
Windows 7 Professional
NVIDIA Quadro FX 4600
Dual Intel Xeon E5540 CPUs
16GB DDR3 Ram
Message 9 of 16
rob.j.ross
in reply to: rob.j.ross

Is it even possible to locate a rule under an event trigger with the API?  Does anyone know of or use a better method for applying iLogic to "old" files?

____________________________
Inventor Professional 2014 64 Bit
Windows 7 Professional
NVIDIA Quadro FX 4600
Dual Intel Xeon E5540 CPUs
16GB DDR3 Ram
Message 10 of 16
jeff_jordan
in reply to: rob.j.ross

CPRob,

 

I see it's been a while since you've worked on this.  Did you find a solution?  I'm looking for the same thing.  I've set up external rules to be triggered by save events in the templates.  Any file created from the templates triggers the correct ilogic rules.  But for any file created outside of our templates (such as content center files, frame generator, wire and harness, etc...), they don't have the rules in their event triggers.  Did you find an easy way to get the rules automatically inserted into the event triggers?  I don't even mind using a form to do it.

 

I've read http://inventortrenches.blogspot.com/2011/08/built-for-speed-running-ilogic-rules.html which attempts to do this using an add-in, but you can't assign the rules to any other event.

 

Autodesk Product Design Suite Ultimate 2015 (Inventor 2015 Pro SP1, Vault 2015 Pro Update 1)
MacbookPro OSx 10.9, Boot Camp
Windows 7, 64-bit
Intel Core i7 2.6 GHz
16GB
SSDs
NVIDIA GeForce GT 750M with 2GB of GDDR5
Message 11 of 16

Hi jeff_jordan,

 

Here's another part of the puzzle to be aware of if you've not already seen it:

http://beinginventive.typepad.com/being-inventive/2011/10/creating-ilogic-rules-automatically.html

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com  

 

 

 

Message 12 of 16
rob.j.ross
in reply to: jeff_jordan

Jeff, I did not find a solution to this.  My solution ended up being adding the desired external rules under the event triggers manually.  It took forever.  I asked Mike Deck who is the iLogic expert at Autodesk if this could be done and he said no.  I also asked Brian Ekins and he suggested that I try doing it with an Add-In instead.  It seems simple to me to expose this functionality via the API.  Adding the rule is useless if you cannot place it under an event trigger.  I am sure there are many people like us who would like to add iLogic to their old files.  A while back I looked into Jurgen's solution posted on the link you mentioned but it did not solve the issue as you described and appeared to be a rather complex workaround. 

____________________________
Inventor Professional 2014 64 Bit
Windows 7 Professional
NVIDIA Quadro FX 4600
Dual Intel Xeon E5540 CPUs
16GB DDR3 Ram
Message 13 of 16
jeff_jordan
in reply to: rob.j.ross

Thanks guys!  I feel like Autodesk forgot about content center files, accelerators (frame generator, etc...), and legacy parts when they designed their system.  I am using iLogic to enforce some iProperties that are later observed in Vault for property compliance.  The iLogic rule itself was designed to REDUCE errors.  Adding the rule manually INCREASES the risk of user error.  Manually adding the rule defeats the whole purpose.  I hope, like you, that Autodesk realizes the significance of this.

Autodesk Product Design Suite Ultimate 2015 (Inventor 2015 Pro SP1, Vault 2015 Pro Update 1)
MacbookPro OSx 10.9, Boot Camp
Windows 7, 64-bit
Intel Core i7 2.6 GHz
16GB
SSDs
NVIDIA GeForce GT 750M with 2GB of GDDR5
Message 14 of 16
jeff_jordan
in reply to: jeff_jordan

CPRob, it's amazing that a year later there is still no solution to this problem.  I feel for you!  But it's also telling as to how slow Autodesk reacts to issues like this.

 

Hoping for the best!

Autodesk Product Design Suite Ultimate 2015 (Inventor 2015 Pro SP1, Vault 2015 Pro Update 1)
MacbookPro OSx 10.9, Boot Camp
Windows 7, 64-bit
Intel Core i7 2.6 GHz
16GB
SSDs
NVIDIA GeForce GT 750M with 2GB of GDDR5
Message 15 of 16
rob.j.ross
in reply to: jeff_jordan

If anyone would like this functionality let Brian Ekins know - http://modthemachine.typepad.com/  At AU this year he mentioned that he is always looking for ideas for things to include in the next API release. 

____________________________
Inventor Professional 2014 64 Bit
Windows 7 Professional
NVIDIA Quadro FX 4600
Dual Intel Xeon E5540 CPUs
16GB DDR3 Ram
Message 16 of 16
MegaJerk
in reply to: jeff_jordan

Just to get Jeff_Jordan up to date, I have worked on this problem some, and have a solution in the form of an application that I made in order to automate rule creation / event triggers. 

More info can be found in this thread : http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/API-set-an-Event-Trigger-for-an-ilogic...

Note that the application also comes with source code if you want to do some messing around with the inner workings!

Hope that it helps you out some!  



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub

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

Post to forums  

Autodesk Design & Make Report