Externalize Property with a defined value #1852
-
Hello Bonsai community! I've been working on some workflows for different applications, and there is a feature that would be quite useful, but I don't know how to implement it or if it is even possible. I understand that when we externalize a property of a node within a Group Workflow, it becomes available to be edited as a property of that group. However, is it possible to have a variable dependent on another one, with its value also externalized? For example, I want a variable named "time on" that depends on the frequency and the duty cycle of a wave, both parameters that you can choose. The "time on" variable would be calculated automatically and shown in the properties, but it should not accept inputs. In other words, I would like to display the results of some calculation graphically, but any externalized property that I attribute a value to, automatically calculated, will not be shown in the Group Workflow property section. If anyone has already done something similar, I would love to hear your ideas. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Not sure if this is what you want, but you can just calculate the value from values stored elsewhere, for instance, subjects. Workflow (Copy+Paste me)<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions"
xmlns="https://bonsai-rx.org/2018/workflow">
<Workflow>
<Nodes>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="Frequency" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="FloatProperty">
<Value>1</Value>
</Combinator>
</Expression>
<Expression xsi:type="rx:BehaviorSubject">
<Name>Frequency</Name>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" DisplayName="DutyCycle" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="FloatProperty">
<Value>0</Value>
</Combinator>
</Expression>
<Expression xsi:type="rx:BehaviorSubject">
<Name>DutyCycle</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>Frequency</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>DutyCycle</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Zip" />
</Expression>
<Expression xsi:type="scr:ExpressionTransform">
<scr:Name>DoSomeMath</scr:Name>
<scr:Expression>1.0 / Item1 * Item2</scr:Expression>
</Expression>
<Expression xsi:type="rx:BehaviorSubject">
<Name>Result</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>Result</Name>
</Expression>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Value" />
</PropertyMappings>
</Expression>
<Expression xsi:type="GroupWorkflow">
<Name>UseTheResultHere</Name>
<Workflow>
<Nodes>
<Expression xsi:type="ExternalizedMapping">
<Property Name="Value" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="FloatProperty">
<Value>0</Value>
</Combinator>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="2" Label="Source1" />
</Edges>
</Workflow>
</Expression>
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="2" Label="Source1" />
<Edge From="3" To="4" Label="Source1" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="6" To="8" Label="Source1" />
<Edge From="7" To="8" Label="Source2" />
<Edge From="8" To="9" Label="Source1" />
<Edge From="9" To="10" Label="Source1" />
<Edge From="11" To="12" Label="Source1" />
<Edge From="12" To="13" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>
|
Beta Was this translation helpful? Give feedback.
You can externalize the property twice:
or use the new Bonsai.Gui package (https://bonsai-rx.org/gui/) and PropertyGrid operator. This will probably require you to periodically hit the refresh property.
This package is still in its early stages so complete documentation might take a while. Play around a bit and ask questions :)
Workflow (Copy+Paste me)