This very simple macro acts as a mixer for which Port 2 is optional. This is the top-level view:
And this is the inside view:
I put some “smart” Comp 46s inside them macro. They know whether to turn on or off as-needed — if Port 2 is connected, they’re OFF; if Port 2 is NOT connected, they’re ON.
This is shown in the model “Macro with optional port.ebs” on my Ebsilon Tips OneDrive.
Here’s the trick
Each Comp 46’s FFU has a mini-EbsScript that traverses the topology to check if port 2 is used.
Here’s the code
In the Comp 46, right-click FFU… Expression Editor. Then copy / paste the following code, then Save & OK.
function ():integer
var
i : integer ;
pipe : ebspipe ;
mac : ebsmacro ;
begin
// Get pipe this Comp 46 is sitting on
pipe := $.PipeAtPort(1) ;
// Within this context, get the macro port number the pipe is attached to.
// Do this by looping around all the ports, checking if the pipe at the port is THIS pipe.
for i := 1 to macrointerface.portcount do
begin
if pipe = macrointerface.pipeAtPort(i) then break
end ;
// OK. We have the port number, i
mac := macrointerface.dualmacro ; // the macro as it is known at the upper level
// Get the pipe at that outer-level port
pipe := mac.pipeAtPort(i) ;
// If there isn't a pipe, turn this Comp 46 on.
if isnull(pipe) then
result := 1
else
result := 0
;
end ()
This model runs!
This model “Macro with optional port.ebs” on my Ebsilon Tips OneDrive has two identical copies of the macro. It runs whether or not Port 2 is used.
Final Thoughts
The Compo 46s could be turned on and off by a pre-run EbsScript in the MacroInterface definition, doing the same topology traversing as in the code I showed above. However, I like the “Smart Comp 46” approach because it’s very visible to the user.
It’s also easily modified by users. For example, if a user modifies the interior of the macro, and something else will be setting pressure, they can just delete the red Comp 46, rather than editing EbsScript code.
“Clarity is Key” is one of my fundamental beliefs.
I edited this post with a link to the model.
Neat trick.