First B4X layout created by AI

Erel

B4X founder
Staff member
Licensed User
Longtime User
Using LayoutUtils + LayoutGenerator:

1794901768988.png


Nothing fancy, but still exciting.
 

Attachments

 
1. Download and unzip LayoutGenerator: https://www.b4x.com/android/forum/t...-with-layoututils-and-layoutgenerator.172576/
2. Run from command line: java -jar LayoutGenerator.jar describe template.bal > instructions.txt
3. Upload instructions.txt and ask the AI to generate a json template for "sign in screen".
4. Convert the json template to layout with: java -jar LayoutGenerator.jar process <json file> <new output file.bal>
 
2. Run from command line: java -jar LayoutGenerator.jar describe template.bal > instructions.txt
Do we need to add the > character before instructions.txt ?

The tutorial command is:
Bash: Copy
java -jar LayoutGenerator.jar describe <layout file>
 
1. Download and unzip LayoutGenerator: https://www.b4x.com/android/forum/t...-with-layoututils-and-layoutgenerator.172576/
2. Run from command line: java -jar LayoutGenerator.jar describe template.bal > instructions.txt
3. Upload instructions.txt and ask the AI to generate a json template for "sign in screen".
4. Convert the json template to layout with: java -jar LayoutGenerator.jar process <json file> <new output file.bal>
That is the process I follow "manually".
  • I create a layout using the designer.
  • When I save the project, a macro triggers `JsonLayouts.jar`, which exports the layout into JSON format.
  • I provide the JSON file to ChatGPT and ask it to make modifications.
  • ChatGPT returns the updated JSON file, which I then place into the "JsonLayouts" folder.
  • I save the project and the JAR file reconstructs the binary file.

The issue is that ChatGPT (and other AIs) do not know how the JSON should be structured, including its overall format, the numerous properties of the views (especially custom views), and the `VARIANT` elements.
 
That is the process I follow "manually".
  • I create a layout using the designer.
  • When I save the project, a macro triggers `JsonLayouts.jar`, which exports the layout into JSON format.
  • I provide the JSON file to ChatGPT and ask it to make modifications.
  • ChatGPT returns the updated JSON file, which I then place into the "JsonLayouts" folder.
  • I save the project and the JAR file reconstructs the binary file.

The issue is that ChatGPT (and other AIs) do not know how the JSON should be structured, including its overall format, the numerous properties of the views (especially custom views), and the `VARIANT` elements.
You need to create a sample of correct layout and let the LLM learn the correct structure of the json file in a prompt. After 1 attempt, my AI agent able to understand how it works.
 
It works for you because you use James Bond as your agent, while I use ChatGPT 🤣

Jokes aside, I need to try generating that Instruction.txt file; perhaps that’s the solution.
That's the point if it was not obvious.
You are using the wrong tool and method.
Create a new question so other members can answer you.
 
Jokes aside, I need to try generating that Instruction.txt file; perhaps that’s the solution.
Tried and failed.

I must point out that I tested this with a B4J layout, not a B4A one.

C:\Users\sg>cd C:\LAYOUT_TEST

C:\LAYOUT_TEST> java -jar LayoutGenerator.jar process GPT.json GPT.bjl
LayoutGenerator v0.9
blview._setextra (java line: 385)
java.lang.RuntimeException: Invalid property: visible
at anywheresoftware.b4a.keywords.Common.ThrowException(Common.java:682)
at b4j.example.blview._setextra(blview.java:385)
at b4j.example.jsontemplate._applymodifications(jsontemplate.java:42)
at b4j.example.jsontemplate._process(jsontemplate.java:191)
at b4j.example.main._appstart(main.java:77)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(Dire
ctMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:117)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:104)
at b4j.example.main.main(main.java:28)


C:\LAYOUT_TEST>


GPT.json is the file created by ChatGPT, after I have passed to it the Instruction.txt file generated by LayoutGenerator.jar.
 
Attached is a B4J json file generated by ChatGPT and the Template layout file that it is based on. Give it to the AI as an example.

And LayoutGenerator v0.91 is also attached. It adds support to the "visible" property which was handled differently.
 

Attachments

Attached is a B4J json file generated by ChatGPT and the Template layout file that it is based on. Give it to the AI as an example.

And LayoutGenerator v0.91 is also attached. It adds support to the "visible" property which was handled differently.
If Json file was created by ChatGPT's Prompt, please send us your Prompt Script, don't you?
And then we covert Json file to be layout file
(. bjl)with LayoutGenerator.jar , it is correct, isn't it?
 
please send us your Prompt Script, don't you?
Prompt is what's in your mind or something you want to accomplish in English or your own language.
Something as simple as:
Add 2 buttons, submit and cancel to the bottom right of a panel, side by side horizontally.
At the end of day, you need to give your own prompt, to create what you want, not what others want, so you need to learn by practicing your own.
 
Prompt is what's in your mind or something you want to accomplish in English or your own language.
Something as simple as:
Add 2 buttons, submit and cancel to the bottom right of a panel, side by side horizontally.
At the end of day, you need to give your own prompt, to create what you want, not what others want, so you need to learn by practicing your own.
I recently asked about creating an `Instructions.txt` file. Gemini suggested creating `base_views.bal` and `xui_views.bal` separately, then using the command `java -jar LayoutGenerator.jar describe base_views.bal xui_views.bal > Instructions.txt` to generate and save the file. Afterward, you can use a set of AI prompts—along with the `Instructions.txt` file—to generate a JSON file, which can then be converted into a layout file.
 
This is my Prompt script for creating Json file, only we add/Edit thePrompt.Don't forget to add Instructions.txt file in ChatGPT
Code: Copy
You are an expert in B4X application development and creating layout files using the `LayoutGenerator` tool.

Your task is to:
Read the structural guidelines and the list of available view prototypes from the attached `instructions.txt` file, then generate a JSON file that can be processed into a `.bal` file using the command `java -jar LayoutGenerator.jar process`.

### Details of the screen to be created:
- **Screen Purpose:** [Specify, e.g., Sign-in screen / Data entry screen / List display screen]
- **Required Elements:**
  1. [Specify, e.g., A header displaying the text "Sign In"]
  2. [Specify, e.g., Input fields for "Username" and "Password"]
  3. [Specify, e.g., A blue "Sign In" button]
  4. [Specify, e.g., Links at the bottom: "Forgot Password?" and "Register New Account"]
- **Color Scheme and Style:** [Specify, e.g., Clean white background, dark gray text, primary button color #1E88E5]

### Strict Rules for JSON Creation (Must be followed):
1. **Output only 100% valid JSON code.** Do not include any introductory or concluding text, and **never include comments (`//` or `/* */`)** within the JSON.
2. **Adhere strictly to the structure defined in**  `instructions.txt`:** Ensure that template `alias` names, source View names (`source`), and property paths within `modifications` strictly match those provided in the documentation; do not invent your own property names.
3. **Declaration Order in `views`:** Any View serving as a `parent` or referenced as a template source must be declared before its child or dependent Views (ordered from top to bottom).
4. **Positioning and Sizing:** Define these using `horizontal` / `vertical` structures or via `script` (Designer Script) using raw numerical values only (do not include units like `dip`). **Never** include position or size values within `modifications`.
5. **Modifying Properties (`modifications`):** Use dot-notation paths (e.g., `text`, `drawable.color`) and specify color values exclusively in Hex format (`#RRGGBB` or `#AARRGGBB`).
 
Last edited:
Back
Top