Hello , few question regarding your Diagram Creation tool
Hello
Is there and easy way to read and write control module parameters inside diagram using excel vba? Right now i am reading the entire Diagram XML and reading control module parameter from the the XML and for writing i am modifying the existing diagram XML and writing it back to Diagram. On the other hand doing the same in Single Control Module is very easy.
Is there and easy way to read and write control module parameters inside diagram using excel vba? Right now i am reading the entire Diagram XML and reading control module parameter from the the XML and for writing i am modifying the existing diagram XML and writing it back to Diagram. On the other hand doing the same in Single Control Module is very easy.
Answers
Hello
I agree it is a bit confusing that CM connections are not defined directly at particular CM invocation but in the end of Diagram page.
There are CBOI methods for reading and writing CM connection. Unfortunately SetCMConnection doesn't work inside Diagrams.
I suggest to use magic power of regular expressions over Diagram XML code to find and to replace CM connections.
Lets assume value 55.2 is connected to PidCC_1.TrackValue that looks like:
<DataConnection Src="55.2" SrcDirect="true" Dest="PidCC_1.TrackValue" Id="91a07a7d-cb0c-4372-9c8b-dfee756868a7"/>
Use regular expression in VBA to modify value:
Dim myRegExp As New RegExp
DiagramXml = cb.GetDiagram("Application_1.Diagram2")
myRegExp.IgnoreCase = False
myRegExp.Global = True
myRegExp.MultiLine = True myRegExp.Pattern = "(<DataConnection Src=)""([^""]*)""([^/]*)( Dest=""PidCC_1.TrackValue"")([^/]*/>)"
If myRegExp.Test(DiagramXml) Then
DiagramXml = myRegExp.Replace(DiagramXml, "$1""23.456""$3$4$5")
End If
That regexp Replace function is looking for the whole DataConnection pattern and replacing just number after Src= .
Outgoing connection needs little modification in regexp pattern.
See how connection to PidCC.Out looks like
<DataConnection Src="PidCC_1.Out" Dest="PID1_OUT" DestDirect="true" Id="8059d105-9569-43bb-9cef-f7eee7616fc9"/>
try to use following code
myRegExp.Pattern = "(<DataConnection Src=""PidCC_1.Out"" Dest=)""([^""]*)"""
If myRegExp.Test(DiagramXml) Then
DiagramXml = myRegExp.Replace(DiagramXml, "$1""another_variable""")
End If
Hopefully it helps.
I agree it is a bit confusing that CM connections are not defined directly at particular CM invocation but in the end of Diagram page.
There are CBOI methods for reading and writing CM connection. Unfortunately SetCMConnection doesn't work inside Diagrams.
I suggest to use magic power of regular expressions over Diagram XML code to find and to replace CM connections.
Lets assume value 55.2 is connected to PidCC_1.TrackValue that looks like:
<DataConnection Src="55.2" SrcDirect="true" Dest="PidCC_1.TrackValue" Id="91a07a7d-cb0c-4372-9c8b-dfee756868a7"/>
Use regular expression in VBA to modify value:
Dim myRegExp As New RegExp
DiagramXml = cb.GetDiagram("Application_1.Diagram2")
myRegExp.IgnoreCase = False
myRegExp.Global = True
myRegExp.MultiLine = True myRegExp.Pattern = "(<DataConnection Src=)""([^""]*)""([^/]*)( Dest=""PidCC_1.TrackValue"")([^/]*/>)"
If myRegExp.Test(DiagramXml) Then
DiagramXml = myRegExp.Replace(DiagramXml, "$1""23.456""$3$4$5")
End If
That regexp Replace function is looking for the whole DataConnection pattern and replacing just number after Src= .
Outgoing connection needs little modification in regexp pattern.
See how connection to PidCC.Out looks like
<DataConnection Src="PidCC_1.Out" Dest="PID1_OUT" DestDirect="true" Id="8059d105-9569-43bb-9cef-f7eee7616fc9"/>
try to use following code
myRegExp.Pattern = "(<DataConnection Src=""PidCC_1.Out"" Dest=)""([^""]*)"""
If myRegExp.Test(DiagramXml) Then
DiagramXml = myRegExp.Replace(DiagramXml, "$1""another_variable""")
End If
Hopefully it helps.
Add new comment