Book a Demo

Author Topic: Code Generation create separate files  (Read 7616 times)

leon_lgrt

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Code Generation create separate files
« on: March 20, 2018, 01:35:17 am »
Hello community,
I am currently working with the code template editor exporting a custom designed language.
For testing I keep things simple. I only have 3 classes with max. 3 attributes.

My problem is:
I want to export multiple classes of the same type (e.g. materials) into one single file.
That means - separatefile.xyz should include the classes material1 (with attributes), material2 (with attributes), material3 (with attributes). All three classes are from the same type.

Currently EA creates a separate file for each class.
That means - material1.xyz, material2.xyz etc.

My macros on the top level "file" look like this:
%list="Class" @separator="\n" @indent=""% \n
%list="Attribute" @separator="\n" @indent=""% \n

Have you got some suggestions or can you provide some help?
Thank you
Leon


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Code Generation create separate files
« Reply #1 on: March 20, 2018, 02:02:41 am »
I don't understand what you mean by
"Classes of the same type".

I'm guessing that EA might have the same problem. I'm not even sure there's a way to group individual classes in a single file.
I can imagine that ALL classes, or all classes of a package might work though.

Geert

leon_lgrt

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Code Generation create separate files
« Reply #2 on: March 20, 2018, 02:11:57 am »
Hello Geert,
thank you for your reply.

Let me rephrase that point with the "type".
I am not meaning any special type of class here. So let us keep that beside for a moment.
I only want to export multiple classes into one single file.

Have you maybe got a workaround how to export a whole package (or all classes) into one file?

Thanks in advance,
Leon

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code Generation create separate files
« Reply #3 on: March 20, 2018, 08:53:26 am »
Set the filename for multiple classes to the same thing, then do a package generation.

Tschana

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Code Generation create separate files
« Reply #4 on: April 18, 2018, 09:11:11 pm »
Set the filename for multiple classes to the same thing, then do a package generation.

Hello all,

I'm currently trying to do this within the tab "Files" of the property window of some classes. I set the File Path to C:\...\test.h for three different classes. If I run the package generation and select "Auto Generate Files" the specified file path C:\...\test.h doesn't exist in the viewed list. The three classes get generated in three different files like Enable.h, Disable.h and GetMeasurements.h etc. (see https://imgur.com/a/NQ10tPs) Am I doing something wrong?

Furthermore is it possible to set the filepath and filename etc with code (or also with transform) templates? I did only find the commands like
Code: [Select]
%filePath%
Thanks in advance :)

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code Generation create separate files
« Reply #5 on: April 19, 2018, 09:28:52 am »
If you don't want EA to set filenames for you, don't check "Auto Generate Files". (http://www.sparxsystems.com/enterprise_architect_user_guide/13.5/model_domains/generateapackage.html)

Short of creating an MDG add-in, there's nowhere EA calls code you can write to request the filename. The easiest solution is to write a script that sets the filenames for all classes as needed.

Tschana

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Code Generation create separate files
« Reply #6 on: April 19, 2018, 04:28:16 pm »
If you don't want EA to set filenames for you, don't check "Auto Generate Files". (http://www.sparxsystems.com/enterprise_architect_user_guide/13.5/model_domains/generateapackage.html)


First of all thanks Simon for the fast answer.

I deselect the "Auto Generate Files" checkbox but nevertheless EA doesn't generate the code to my declared filepath ("C:\...\test.h"). The "Target File"tab in the "Generate" window is for each class empty. If I press the Generate button for each class within the package a "Save as..." window is showing up and asking me for a name and in with path the files should be generated. (see: https://imgur.com/a/Pe7wnA2)

Do you have any suggestion why EA doesn't recognize my defined filepaths? (FYI: I'm using EA Version 13.0.1306 with a System Engineering Edition)

Short of creating an MDG add-in, there's nowhere EA calls code you can write to request the filename. The easiest solution is to write a script that sets the filenames for all classes as needed.

If I get EA working to generate into the specified filepaths, I'll try to write a script for it. Thanks.
« Last Edit: April 19, 2018, 04:47:38 pm by Tschana »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code Generation create separate files
« Reply #7 on: April 20, 2018, 08:50:48 am »
Not sure I can comment further without more information.

I'd recommend sending in a support request. If you can, include images of where you have assigned the path and the package generation dialog.

Tschana

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Code Generation create separate files
« Reply #8 on: April 20, 2018, 05:53:05 pm »
Not sure I can comment further without more information.

I'd recommend sending in a support request. If you can, include images of where you have assigned the path and the package generation dialog.

I'll contact the support. Nevertheless thank you Simon for your help.