Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Find rules in documents

JBerns
Advisor

Find rules in documents

JBerns
Advisor
Advisor

Community,

 

Is there a tool or method available to search a group of Inventor documents to determine which of those files contains iLogic rules or forms?

 

Conventional search tools, such as Windows Explorer, Agent Ransack, etc., have not been effective.

 

Thanks for your time and attention. I look forward to the replies.

 

Kind regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Reply
Accepted solutions (1)
1,540 Views
8 Replies
Replies (8)

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @JBerns,

 

You can try using the attached file (it's an Inventor 2017 file).

 

In contains a form that allows you to select files, and then it opens each file invisibly and looks for ilogic rules, and adds that file name to a text file list if internal rules are found. It only looks for rules, not forms.

 

It's not 100% , in that I've had it "trip" over files when trying to open them, and cause it not to batch the rest of the list, so for that reason it might be best to do smaller batches if you run into issues.

 

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

0 Likes

JBerns
Advisor
Advisor

@Curtis_Waguespack,

 

Thanks for the quick reply and very handy tool!

It processed in seconds, what had taken me nearly an hour to check dozens of files. (a project I inherited)

Perhaps an integrated tool will be in a future version of Inventor. (wish list)

 

Thanks again, Curtis!

 

Regards,

Jerry

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using Inventor 2022
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional

tracey
Enthusiast
Enthusiast

Hi, rather than all docs, how can this be written to find all rules in this assembly, sub assemblies and components? 

I tried:

'Sub Main()
'    Dim oDoc As Inventor.Document
'    oDoc = ThisApplication.ActiveDocument

'    Dim oWord As Object
'    oWord = CreateObject("Word.Application")
'    oWord.Visible = True

'    Dim oDocWord As Object
'    oDocWord = oWord.Documents.Add()

'    oDocWord.Range.Text = "All iLogic code contained in this assembly" & vbCrLf & vbCrLf

'    ListAlliLogicRules(oDoc.ComponentDefinition.Occurrences, oDocWord)
'End Sub

'Sub ListAlliLogicRules(ByVal oOccurrences As ComponentOccurrences, ByVal oDocWord As Object)
'    Dim oOccurrence As ComponentOccurrence
'    For Each oOccurrence In oOccurrences
'        If oOccurrence.SubOccurrences.Count > 0 Then
'            ListAlliLogicRules(oOccurrence.SubOccurrences, oDocWord)
'        End If

'        If oOccurrence.DefinitionDocumentType = kPartDocumentObject Or oOccurrence.DefinitionDocumentType = kAssemblyDocumentObject Then
'            Dim oPartDoc As Inventor.Document
'            oPartDoc = oOccurrence.Definition
'            If oPartDoc.ComponentDefinition.iLogicVBCode.Count > 0 Then
'                oDocWord.Range.Text = oDocWord.Range.Text & "Part Number: " & "Component: " & oPartDoc.DisplayName & vbCrLf

'                Dim oRule As iLogicRule
'                For Each oRule In oPartDoc.ComponentDefinition.iLogicVBCode
'                    oDocWord.Range.Text = oDocWord.Range.Text & "Rule Name: " & oRule.Name & vbCrLf & "End Sub" & vbCrLf
'                Next

'                oDocWord.Range.Text = oDocWord.Range.Text & vbCrLf
'            End If
'        End If
'    Next
'End Sub

but it has errors

0 Likes

tracey
Enthusiast
Enthusiast

This processes:

 

Sub Main	

	
	 Dim oDoc As Inventor.Document
'    oDoc = ThisApplication.ActiveDocument
	
		'check for folder, create it if it does not exist
	If Not System.IO.Directory.Exists("C:\TEMP") Then
		System.IO.Directory.CreateDirectory("C:\TEMP")
	End If
	
	
	Dim oReport As String
	oReport = "C:\TEMP\iLogic Files Report.txt"
	
	'check for file, create it if it does not exist
	If System.IO.File.Exists(oReport) Then
		'do nothing
	Else 
		Call Create_Report (oReport)
	End If
	
		Dim oNVM As NameValueMap
		oNVM = ThisApplication.TransientObjects.CreateNameValueMap
	
	
		i=0
		For Each oItem In MultiValue.List("Part_Files_List")
			'open the indexed file
			Try
			invDoc = ThisApplication.Documents.OpenWithOptions(MultiValue.List("Part_Files_List").Item(i), oNVM, False)
			Trace.WriteLine(MultiValue.List("Part_Files_List").Item(i), "iLogic") 'debug 
			Catch
				GoTo NextItem
			End Try
			'write to staus bar
			ThisApplication.StatusBarText = MultiValue.List("Part_Files_List").Item(i)
			Call Check_For_iLogic (oReport, invDoc)
		
			i=i+1
			If invDoc.FullFileName <> ThisDoc.Document.FullFileName Then
				Try				
				invDoc.Close 'close the file 
				Catch
				End Try
			Else
			End If
			NextItem:
		Next

	']
	
	
	MessageBox.Show("Batch processing files is complete.", _
	"iLogic",MessageBoxButtons.OK,MessageBoxIcon.Information)
	
	Process.Start(oReport) 

End Sub

Sub Check_For_iLogic (oReport As String, oDoc As Document) 


	Auto = iLogicVb.Automation
	Dim iLogicAuto As Object
	iLogicAuto = Auto
	'Dim oDoc As Document
	'oDoc = ThisApplication.ActiveEditDocument
	
	
	'get collection of rules
	Dim rules As Object
	rules = iLogicAuto.rules(oDoc)

	
	'check for rules in the file
	If Not (rules Is Nothing) Then
		Call Write_To_Report (oReport, oDoc)
	End If

End Sub

Sub Create_Report (oReport As String) 

	sDots = "....................."
	Dim oStreamWriter As System.IO.StreamWriter	
	oStreamWriter = IO.File.CreateText(oReport)
	oStreamWriter.WriteLine("Report created: " & vbTab & Now()  )
	oStreamWriter.WriteLine(vbTab & vbTab & vbTab & "Files that contain iLogic Rules")
	oStreamWriter.WriteLine(sDots & vbTab & sDots & sDots  )
	oStreamWriter.Close()
	
End Sub



Sub Write_To_Report (oReport As String, oDoc As Document) 
	'oDocName = ThisApplication.ActiveEditDocument.FullFileName
	oDocName = oDoc.FullFileName
	sDots = "....................."
	Dim oStreamWriter As System.IO.StreamWriter				
	oStreamWriter = IO.File.AppendText(oReport)
	oStreamWriter.WriteLine(oDocName)
	oStreamWriter.Flush()
	oStreamWriter.Close()		

End Sub
0 Likes

tracey
Enthusiast
Enthusiast

This processes:

 

Sub Main	

	
	 Dim oDoc As Inventor.Document
'    oDoc = ThisApplication.ActiveDocument
	
		'check for folder, create it if it does not exist
	If Not System.IO.Directory.Exists("C:\TEMP") Then
		System.IO.Directory.CreateDirectory("C:\TEMP")
	End If
	
	
	Dim oReport As String
	oReport = "C:\TEMP\iLogic Files Report.txt"
	
	'check for file, create it if it does not exist
	If System.IO.File.Exists(oReport) Then
		'do nothing
	Else 
		Call Create_Report (oReport)
	End If
	
		Dim oNVM As NameValueMap
		oNVM = ThisApplication.TransientObjects.CreateNameValueMap
	
	
		i=0
		For Each oItem In MultiValue.List("Part_Files_List")
			'open the indexed file
			Try
			invDoc = ThisApplication.Documents.OpenWithOptions(MultiValue.List("Part_Files_List").Item(i), oNVM, False)
			Trace.WriteLine(MultiValue.List("Part_Files_List").Item(i), "iLogic") 'debug 
			Catch
				GoTo NextItem
			End Try
			'write to staus bar
			ThisApplication.StatusBarText = MultiValue.List("Part_Files_List").Item(i)
			Call Check_For_iLogic (oReport, invDoc)
		
			i=i+1
			If invDoc.FullFileName <> ThisDoc.Document.FullFileName Then
				Try				
				invDoc.Close 'close the file 
				Catch
				End Try
			Else
			End If
			NextItem:
		Next

	']
	
	
	MessageBox.Show("Batch processing files is complete.", _
	"iLogic",MessageBoxButtons.OK,MessageBoxIcon.Information)
	
	Process.Start(oReport) 

End Sub

Sub Check_For_iLogic (oReport As String, oDoc As Document) 


	Auto = iLogicVb.Automation
	Dim iLogicAuto As Object
	iLogicAuto = Auto
	'Dim oDoc As Document
	'oDoc = ThisApplication.ActiveEditDocument
	
	
	'get collection of rules
	Dim rules As Object
	rules = iLogicAuto.rules(oDoc)

	
	'check for rules in the file
	If Not (rules Is Nothing) Then
		Call Write_To_Report (oReport, oDoc)
	End If

End Sub

Sub Create_Report (oReport As String) 

	sDots = "....................."
	Dim oStreamWriter As System.IO.StreamWriter	
	oStreamWriter = IO.File.CreateText(oReport)
	oStreamWriter.WriteLine("Report created: " & vbTab & Now()  )
	oStreamWriter.WriteLine(vbTab & vbTab & vbTab & "Files that contain iLogic Rules")
	oStreamWriter.WriteLine(sDots & vbTab & sDots & sDots  )
	oStreamWriter.Close()
	
End Sub



Sub Write_To_Report (oReport As String, oDoc As Document) 
	'oDocName = ThisApplication.ActiveEditDocument.FullFileName
	oDocName = oDoc.FullFileName
	sDots = "....................."
	Dim oStreamWriter As System.IO.StreamWriter				
	oStreamWriter = IO.File.AppendText(oReport)
	oStreamWriter.WriteLine(oDocName)
	oStreamWriter.Flush()
	oStreamWriter.Close()		

End Sub


0 Likes

tracey
Enthusiast
Enthusiast
This doesn't list rule names in the report out
0 Likes

WCrihfield
Mentor
Mentor

Hi @tracey.  What do you mean by "rather than all docs"?  Can you describe in as much detail as possible, maybe even will bullet points, what exact process you want the code to do?  What type of end result are you trying to achieve.  If you want a list of file names, then what do you plan on doing with that list of file names when the rule is done.  If you plan on doing something with each of those files by code afterwards, then why write them out to external file, instead of keeping them in a collection type variable, then process them near the end.  And if an external file is needed, what type of file?  If the code is to find which files contain iLogic rules then keep a list of those file names, then the most efficient way would be to loop through each referenced document in the main assembly's 'AllReferencedDocuments' property, instead of recursively looping through assembly components.  When looping through components, there are many things that need to be filtered out and/or avoided.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

WCrihfield
Mentor
Mentor

Hi @tracey.  Attached are a some text files containing some similar example iLogic rule codes you can play around with.  One is for getting a list of all referenced documents within an assembly that have internal iLogic rules in them.  Another one is for getting a list of all files in a selected folder that have internal iLogic rules in them.  Right now they are just getting the full file names of the files with rules in them to a List(Of String) type variable, then showing you the contents of that list using an InputListBox.  If you need that list written externally, the simplest way would be to use the iLogic Logger to write them to the iLogic Log.  But if you need them written out some other way, that should probably be requested through a new forum topic other than this one.  There are many ways to write the contents of a list of data out to various other external files.  I hope this helps some.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)