Ilogic Rule to run through all the drawing templates and delete a rule , working from the top level assembly.

Ilogic Rule to run through all the drawing templates and delete a rule , working from the top level assembly.

ricky_galetaSGGSQ
Participant Participant
1,035 Views
9 Replies
Message 1 of 10

Ilogic Rule to run through all the drawing templates and delete a rule , working from the top level assembly.

ricky_galetaSGGSQ
Participant
Participant

Hi All ,

 

I have recently joined a new company , 

 

we have a problem that many years ago someone wrote an Illogic rule and attached it to the standard template folder.

 

 

ricky_galetaSGGSQ_0-1690200753034.png

 

the Problem is that since then we have created around 8000 parts. this create PDF rule is causing issues with other rules as it triggers when the document is closed.

 

Since we use copy Design a lot this issue still remains when bringing older Models and drawings forward . 

 

Can someone help me with some code that from the assembly top level to open all drawings in that assembly and remove the create PDF Rule.

 

or if there is any other fixes to this issue that would be a great help.

0 Likes
Accepted solutions (1)
1,036 Views
9 Replies
Replies (9)
Message 2 of 10

Frederick_Law
Mentor
Mentor

The rule should not run if it's not in the trigger list.

So remove it from trigger.

0 Likes
Message 3 of 10

ricky_galetaSGGSQ
Participant
Participant
Thanks ,

it is in the trigger list.

but if its built into the standard template we would have to go trough all our old drawings and remove them ? this means when we use copy Design feature in vault - I would first have to go through 70-80 drawings to remove this trigger? This is stopping use using batch Exporters as how we want them to work.


0 Likes
Message 4 of 10

Andrii_Humeniuk
Advisor
Advisor

Hi @ricky_galetaSGGSQ . The biggest problem is to get the drawings of the parts from the upper assembly. I wrote an example rule for you that deletes the rule named "Create PDF" (line 5). This rule can get the name of the component and look for a match in the directory "C:\project1\drawings\" (line 4). If this option does not work for you, the best way would be to describe your situation in more detail, where and under what name your drawings are stored, in order to better understand what logic to write to find them.

Sub main()
	Dim oDoc As Document = ThisDoc.Document
	If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
	Dim sDrawPath As String = "C:\project1\drawings\"
	Dim sNameRule As String = "Create PDF"
	Dim oAsmDoc As AssemblyDocument = oDoc
	Dim oDrawFullName As String
	oDrawFullName = GetDrawingDoc(oAsmDoc, sDrawPath)
	If String.IsNullOrEmpty(oDrawFullName) Then
		Call DeleteRule(oDrawFullName, sNameRule)
		oDrawFullName = Nothing
	End If
	For Each oRefDoc As Document In oAsmDoc.AllReferencedDocuments
		oDrawFullName = GetDrawingDoc(oRefDoc, sDrawPath)
		If String.IsNullOrEmpty(oDrawFullName) Then
			Call DeleteRule(oDrawFullName, sNameRule)
			oDrawFullName = Nothing
		End If
	Next
End Sub

Private Function DeleteRule(ByVal oDrawFullName As String, ByVal sRuleName As String)
	Try
		Dim oDocs As Documents = ThisApplication.Documents.Open(oDrawFullName, False)
		iLogicVb.Automation.DeleteRule(oDDoc, sRuleName)
		oDDoc.Save()
		oDDoc.Close()
	Catch : End Try
End Function

Private Function GetDrawingDoc(ByVal oDoc As Document, ByVal sDrawPath As String) As String
	Dim sDrawName As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullDocumentName)
	If System.IO.File.Exists(sDrawPath & sDrawName & ".idw") Then
		Return sDrawPath & sDrawName & ".idw"
	Else If System.IO.File.Exists(sDrawPath & sDrawName & ".dwg") Then
		Return sDrawPath & sDrawName & ".dwg"
	End If
	Return Nothing
End Function

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

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

EESignature

Message 5 of 10

Frederick_Law
Mentor
Mentor

Trigger is not in the file, I believe.

Remove it from the trigger first.

0 Likes
Message 6 of 10

Frederick_Law
Mentor
Mentor
Accepted solution

Or try this with On Open trigger:

sub Main()
iLogicVb.Automation.DeleteRule(ThisDoc.Document,"Create PDF")
End sub

 

Message 7 of 10

ricky_galetaSGGSQ
Participant
Participant

This works , Seems to be a simple Solution thankyou.

 

 

0 Likes
Message 8 of 10

WCrihfield
Mentor
Mentor

Hi @ricky_galetaSGGSQ.  There is a free Autodesk authored add-in within the Autodesk App Store called "iLogic Rule Batch Tool".  That tool will allow you to process entire folders full of files at a time.  You could likely use that to look at entire directories at a time, and it will let you filter for what file types you want it to effect within the folders, and it has the ability to delete rules (and a lot of other other functionality).

 

When you open your Event Triggers dialog and find that rule within, which tab is it shown in?  Can you show us a screenshot of the whole Event Triggers dialog, with that rule shown in it?  If it is only found on the "This Document" tab, then the setting is only effecting that one document (not all documents, or all documents of a specific type).  We have access to the settings in the This Document tab by code.  But if it is on one of the other tabs, you should simply be able to remove it one time from that dialog.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 10

ricky_galetaSGGSQ
Participant
Participant

Hi Thankyou for your response .

 

I've always wondered whether a Batch tool , will definitely check it out! 

 

the event trigger is in the document tab , someone created this years ago and subsequently it is now found in the templates for thousands of parts.

 

screenshot below.

 

ricky_galetaSGGSQ_0-1690205859977.png

 

 

 

 

 

0 Likes
Message 10 of 10

WCrihfield
Mentor
Mentor

OK, thanks.  I see that there are other rules listed in there or being triggered by events.  If that was not the case, I was going to suggest a simple additional step of deleting the hidden PropertySet where those settings are being stored.  But if there are other rules involved, that would not be a good idea.  A rule could cycle through the properties within that hidden property set, and delete any properties that have the name of that rule as their value, though.  But since this seems to be an 'internal' rule (saved within the same document), instead of an external rule, simply deleting the rule should fix the problem just fine, without the additional step.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes