Search internal rules in multiple parts and replace text

Search internal rules in multiple parts and replace text

Anonymous
Not applicable
559 Views
4 Replies
Message 1 of 5

Search internal rules in multiple parts and replace text

Anonymous
Not applicable

Good Day,

 

I have a main assembly with sub-assemblies and those sub-assemblies have internal rules.

Each one of those sub-assemblies have an identical rule to each other.

 

From my main assembly is there a way to go to each sub assembly,  open the rule,  search for text and replace it with other text?

 

This is so that I do not need to go to each rule and modify them manually.

There are many.

 

0 Likes
Accepted solutions (2)
560 Views
4 Replies
Replies (4)
Message 2 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

See example below. This code will find the rule named RuleName in all subassemblies and replace the text "Hello" with "Good bye" in them 🙂

Dim oAsm As AssemblyDocument = ThisDoc.Document
For Each oRefDoc As Document In oAsm.ReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		Try
		Dim oRule As iLogicRule = iLogicVb.Automation.GetRule(oRefDoc, "RuleName")
		oRule.Text = oRule.Text.Replace("Hello", "Good bye")
		Catch
		End Try
	End If
Next
0 Likes
Message 3 of 5

Anonymous
Not applicable

Your solutions never disappoint.  

Thank you.

 

One more question if you don't mind.

Is there a way to create a rule in all of the sub-assemblies and paste data into it and save the rule?

0 Likes
Message 4 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

@Anonymous 

Here's an example on creating rules:

Dim oAsm As AssemblyDocument = ThisDoc.Document
For Each oRefDoc As Document In oAsm.ReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
		Try
			'Create the rule with empty text first, otherwise iLogic will run the rule immediatley after creation
			Dim oRule As iLogicRule = iLogicVb.Automation.AddRule(oRefDoc, "NewRule", "")
			'Set the rule text as a string. use doubble " ("") for " in the srring and vbCrlf for linebreak
			oRule.Text = "MsgBox(""messagebox on line 1"")" & vbCrLf & _
			"MsgBox(""messagebox on line 2"")"
		Catch
		End Try
	End If
Next

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

Worked 100%

 

Always to the point and effective solutions. 

 

Thank you.