Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export iLogic rules in notepad files

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
bhavik4244
617 Views, 5 Replies

Export iLogic rules in notepad files

Hello,

 

I have an assembly with many rules and also the components have some rules.

 

Is there any rule (iLogic/VBA) by which I can export and save all rules as notepad file?

 

Thank you.


Bhavik Suthar
5 REPLIES 5
Message 2 of 6

For external rules you can change the extensions to *.txt!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 6

@bradeneuropeArthur 

 

No, I want to export internal rule which made inside the parts and sub assemblies.


Bhavik Suthar
Message 4 of 6
J-Camper
in reply to: bhavik4244

I'm not sure where you want to save the files to, but I believe this is what you want:

Sub Main
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then MessageBox.Show("This rule is designed to only work in assembly documents.", "Wrong Document Type") : Exit Sub
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oPath As String = System.IO.Path.GetDirectoryName(oDoc.FullFileName) & "\iLogicRules\"
Dim RuleText As String 
Dim oRefDoc As Document
'Check for Rules to write
For Each oRefDoc In oDoc.AllReferencedDocuments
	'Make sure Referenced Document exists as an occurrence within this assembly
	If oDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
		Dim iRules As Object = iLogicVb.Automation.Rules(oRefDoc)
		If IsNothing(iRules) Then Continue For 'No rules so skip this document
		For Each iRule As iLogicRule In iRules
			RuleText = iLogicVb.Automation.GetRule(oRefDoc, iRule.Name).Text
			Call WriteToFile(oPath, iRule.Name, RuleText, oRefDoc)
		Next
	End If
Next
End Sub

Sub WriteToFile(FileDirectory As String, RuleName As String, Contents As String, SourceDoc As Document)
	'Verify Directory exists
	If Not System.IO.Directory.Exists(FileDirectory) 
	    System.IO.Directory.CreateDirectory(FileDirectory)
	End If
	'Prepare to write text document
	Dim oWriteName As String = FileDirectory & System.IO.Path.GetFileNameWithoutExtension(SourceDoc.FullFileName) & "-" & RuleName & ".txt" 
	'Create the file using the new name in the new sub folder
	oWrite = System.IO.File.CreateText(oWriteName)	
	'Close file so we can write to it
	oWrite.Close 
	'Fill Text Document
	System.IO.File.WriteAllText(oWriteName, Contents)
End Sub

 

It creates a folder "iLogicRules" in the Directory that the active document lives, then creates a text document fro each rule in each document.  I am making the File names: "DocumentName-RuleName.txt" to be unique.

 

Let me know if you have any questions, or if this is not working as intended.

Message 5 of 6
bhavik4244
in reply to: J-Camper

@J-Camper 

Thanks a lot! It's exactely I want.


Bhavik Suthar
Message 6 of 6
tobias.orlow
in reply to: bhavik4244

Hi Bhavik,

 

You can also have a look at this Inventor app for the same and more purposes: iLogic Rule Batch Tool | Inventor | Autodesk App Store

 

Many thanks,

Tobias

Tobias Orlow
Designated Support Specialist
Customer Success Organization
Linkedin: www.linkedin.com/in/tobiasorlow/

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

Post to forums  

Autodesk Design & Make Report