!startsub inside !procedure

0 votes
asked Jun 2, 2023 in Question / help by bruno963852 (120 points)
Hello,

I`m trying to create a procedure that, among other things, create a subpart of the diagram to be importer later, for instance:

!procedure example($name)

!startsub %upper($name)

state $name

!endsub

!endprocedure

Is there any way to make something like this?

1 Answer

0 votes
answered Jun 7, 2023 by The-Lu (64,760 points)

Hi B, and all,

It is not yet possible, because the preproc. turns only one time, and directly interprets the !startsub command

See:

But a tricky workaround is to use first the prepoc to create the source file and then run plantuml, with this code:

@startuml mainfile
!procedure $example($name)
%newline()!startsub %upper($name)
state $name
%newline()!endsub
!endprocedure

$example(foo)
$example(bar)
@enduml

[You can also use `%chr`, or `%string`, ...]

Then run:

java -jar plantuml.jar -preproc code.puml

We obtain:

@startuml mainfile

!startsub FOO
state foo

!endsub

!startsub BAR
state bar

!endsub
@enduml

Then run:

java -jar plantuml.jar mainfile.preproc

Enjoy,
Regards,
Th.

...