Import file with different properties

0 votes
asked Mar 15 in Question / help by anonymous

Hi,  im trying to include the same file multiple times but have it change a few variables the second time its loaded.  Is that possible?   For example, if I do

---------- main.puml
@startuml
!$var1 = "x"
!$var2 = "y"
!include_many include.puml

!$var1 = "y"
!$var2 = "x"
!include_many include.puml


---------- include.puml
@startuml
!$var1 ?= "default1"
!$var2 ?= "default2"
'do some stuff below...
@enduml


It will read the variables properly on the first include and display them as "x" and "y", but on the second import it will not show them reversed. 
I also tried with having an intermediate file that did the reversing and also with a procedure that I called. But nothing seems to allow me to change it on the second include.  Is there a way to accomplish this?  Thanks!

1 Answer

0 votes
answered Mar 17 by kirchsth (7,140 points)

Hi,

I think the problem is that the includes are optimized and are loaded only once.
But you could
a) encapsulate the relevant part of the `include.puml` into a procedure
b1) include the  file at the beginning of main
b2) and instead of your current includes you could call the procedure.

main.puml:

@startuml

!include defintions.puml

!$var1 = "x"
!$var2 = "y"

AddPartsFromIncludePuml()

!$var1 = "y"
!$var2 = "x"

AddPartsFromIncludePuml()

@enduml

defintions.puml

!$var1 ?= "default1"
!$var2 ?= "default2"

!procedure AddPartsFromIncludePuml()
$var1 -> $var2
!end procedure

BR
Helmut







 

commented Mar 20 by anonymous

Awesome, thanks for the help!

FWIW, it was my fault that it wasnt working.  On the "include.puml" I had other variables that got configured off of the first ones and I defined them with "?=" so they weren't getting updated since they got defined on the first include. 

Your solution looks good as well  yes

...