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.
Solved! Go to Solution.
Solved by J-Camper. Go to Solution.
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 !
No, I want to export internal rule which made inside the parts and sub assemblies.
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.
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
Can't find what you're looking for? Ask the community or share your knowledge.