How to insert components into an existing component after the fact

0 votes
asked Feb 10 in Question / help by anonymous

Let's say I create the following node with a single component

node "Node1" {
  [Component1]
}
But later, I want to modify the Node with another component (and let's say I want to do this programmatically), is it possible for me to modify Node1 outside of it's context?

Something like:
[Node1].add([Component2])
How close could I get to this level of functionality?
commented Feb 10 by Martin (2,440 points)

Here's a way to do the reverse (add components and then add the node)...

@startuml
!procedure addComponent($nodename, $component)
%set_variable_value($nodename, %get_variable_value($nodename) + $component + %newline()  )
!end procedure

!procedure addNode($nodename)
node "$nodename" {
  %get_variable_value($nodename)
}
!end procedure

addComponent("mynode", "[Component1]")
addComponent("mynode", "[Component2]")
addComponent("mynode", "[Component3]")
addNode("mynode")
@enduml

1 Answer

0 votes
answered Feb 10 by Martin (2,440 points)

You just repeat the node definition.  e.g.

@startuml
node mynode {
[Component1]
}

node mynode {
[Component2]
}
@enduml

...