Hello, i am trying to create a pattern of code able to automatically include an image into a diagram only based on the image name and compatible with the include mechanism.
For information, i use a local installation of plantuml (.jar file on windows).
To introduce my questions (below), i propose the following situation:
- 2 files are in the same folder :
- parent.plantuml
- child.plantuml
- Facts
- parent.plantuml includes child.plantuml
- child.plantuml contains an image named "foo.png"
- "foo.png" is located in a subfolder called "inc_child.plantuml" (normative name for automation)
- Compilation command should stay independant of the content of the files (no use of -Dfoo="<PATH>" for flexibility reasons.
# Code of "child.plantuml":
@startuml
' image file are inside a sub folder called "inc_<filename>" (normative name for automation)
!$dPath = "inc_"+%filename()
:<img:$dPath/foo.png{scale=0.2}>;
:"DEBUG child" {
"version" : %version()
"dirpath" : %dirpath()
"filename" : %filename()
"dPath" : $dPath
};
@enduml
Result when compiled:
[Image is present]
"DEBUG child" {
"version": 1.2023.5
"dirpath":
"filename": child.plantuml
"dPath": inc_child.plantuml
}
# Code of "parent.plantuml"
@startuml
!include child.plantuml
:"DEBUG parent" {
"version" : %version()
"dirpath" : %dirpath()
"filename" : %filename()
"dPath" : $dPath
}
@enduml
Resul when compiled:
(Cannot decode) [Image is NOT present]
DEBUG child" {
"version": 1.2023.5
"dirpath":
"filename": parent.plantuml
"dPath": inc_parent.plantuml}
"DEBUG parent" {
"version": 1.2023.5
"dirpath":
"filename": parent.plantuml
"dPath": inc_parent.plantuml
}
# My questions:
- how to get the current filename and not the one of the parent file ?
The result of "parent.plantuml" shows that "DEBUG child" is equal to "DEBUG parent". It means that %filename() is only setted by the first compiled file. - how to get the absolute path of the current file (for image hyperlink automation) ?
Then the code could be (image inclusion + hyperlink):
!$dPathFull = %dirpath()+"/inc_"+%filename()
:[[$dPathFull/foo.png <img:$dPath/foo.png{scale=0.2}>]]; - how to get the current file title (means filename without the extension) ?
f(parent.plantuml) -> parent
For flexibility reasons, i cannot customize -Dfoo="<hard coded absolute path>" args in the compilation command line.
I hope to be clear and understandable.
Thank you
Regards.