access diagram name from preprocessor

+2 votes
asked Jun 3, 2020 in Question / help by ncasaux

Hello,

Is it possible to access to the diagram name from the pre-processor ? 

@startuml my_diagram_name

In my example, I would like to get the "my_diagram_name" value

Thanks !

1 Answer

0 votes
answered Jun 3, 2020 by plantuml (294,960 points)

It depends on which plugin you are using, but %filename() may work in some situation.

Tell us if it's working for you, and if it does not, tell us more about your config !

commented Jun 3, 2020 by ncasaux

I'm using it through VS Code, and the %filename() returns the actual filename of the .puml file. 

As we can have mutliple diagrams in a single file, it would be great to have access to the diagram name

commented Jun 3, 2020 by The-Lu (63,920 points)

Hello N. and Plantuml team,

Yes, a good example, adaped from:

will be perhaps a file named 'global_filename.pu' with 3 sections:

@startuml my_diagram_name
:filename: "%filename()";
:filenameNoExtension: "%filenameNoExtension()";
@enduml

@startuml BobAndAlice
Bob -> Alice : hello from "%filename()"
@enduml

@startuml JohnAndJane.svg
John -> Jane : hello from filename: "%filename()" and filenameNoExtension: "%filenameNoExtension()"
@enduml

And the result are 3 PNG files:

  • my_diagram_name.png with filename: "global_filename.pu"
  • BobAndAlice.png with filename: "global_filename.pu"
  • JohnAndJane.png with filename: "global_filename.pu"

Then:

  1. Also perhaps a new function, like "%filenameFromStartuml()" will be created for that (for retrieve the final filename [came from 'after the @startuml tag'])
  2. It seem also that the function "%filenameNoExtension()" seems to no longer exist.

Could you confirm @plantuml?

Thank @plantuml for your works,
If that can help,

Regards,
Th.

...