We value your input!
Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey

Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

AddOnCommand

poco2013
Mentor
I am trying to configure a AddOnCommad AddIn by following Tibors Publish Example. Unfortunately, Tibor only demo the transfer of Strings. I need to also transfer integer (int), boolean, number (double)

When I type code for a integer type in the function GetInputParametersSchema i get a APIERR_BADPARS error,
String work OK a in Tibor's example. What are the types for integer, boolean and double?

Below is the code which fails at the integer type def.
GS::Optional<GS::UniString>MyAddInCommand::GetInputParametersSchema() const
{
	//ACAPI_WriteReport("inside keynotecommand getinputparamschema", true);
	return GS::UniString::Printf(R"({
	"type": "object",
	"properties": {
		"%s": {
			"type": "string",
			"description": "The name of the Library Shape",
			"minLength": 1
		 }
		"%s": {
			"type": "integer",
			"description": "Text Pen Number.",
			"minLength": 1
		},
	},

	"additionalProperties": false,
	"required": [
		"%s"
	]
})", SymbolShapeParameterField, TextPenParameterField, SymbolShapeParameterField);  

// fails at "type" : "integer" ,

Also will need types for boolean & Double

Thanks
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
poco2013
Mentor
Thank for the reply Tibor. That's about what I thought but was confused when my code did not work. The problem in the above, which I did not see for the tenth time, is a misplaced comma.

A thousand apologizes!!

BTW -- I'm still trying to get my interface working -- so may have more dumb questions.
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

View solution in original post

4 REPLIES 4
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Gerry,

JSON Schema is not Graphisoft specific. JSON Schema is a proposed IETF standard. It is a grammar language for defining the structure, content, and (to some extent) semantics of JSON objects. It lets you specify metadata (data about data) about what an object's properties mean and what values are valid for those properties.

Here is the official specification of JSON Schema:
https://json-schema.org/understanding-json-schema/reference/type.html

JSON Schema defines the following basic types:
  • string
  • number
  • integer
  • object
  • array
  • boolean
  • null
These types have analogs in most programming languages, though they may go by different names.
JSON -> Python
string -> string
number -> int/float
object -> dict
array -> list
boolean -> bool
null -> None

So JSON does not have separate types for integer and floating-point. More details: https://json-schema.org/understanding-json-schema/reference/numeric.html
Solution
poco2013
Mentor
Thank for the reply Tibor. That's about what I thought but was confused when my code did not work. The problem in the above, which I did not see for the tenth time, is a misplaced comma.

A thousand apologizes!!

BTW -- I'm still trying to get my interface working -- so may have more dumb questions.
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
poco2013 wrote:
The problem in the above, which I did not see for the tenth time, is a misplaced comma.
I'm happy that you managed to solve the issue.

You can store your JSON schemas in separate JSON files if you like. That way the editor applications (IDE like Visual Studio Code) will warn you that there are mistakes in your JSON file and underline your code where the comma is missing.
To do that you have to make a JSON file like this (JSONSchemas.json):
{
    "MyInputParametersSchema": {
        "type": "object",
        "properties": {
            "shapeName": {
                "type": "string",
                "description": "The name of the Library Shape",
                "minLength": 1
            },
            "pen": {
                "type": "integer",
                "description": "Text Pen Number.",
                "minLength": 1
            }
        },
        "additionalProperties": false,
        "required": [
            "shapeName",
            "pen"
        ]
    },
    "MyResponseSchema": {
        "type": "object",
        "properties": {
            "error": {
                "$ref": "APITypes.json#/definitions/Error"
            }
        },
        "additionalProperties": false,
        "required": []
    }
}
Add it as a DATA resource into your GRC file:
'DATA' 1000 "JSON file containing the JSON schemas of commands" {
	"JSONSchemas.json"
}
Finally read the JSON resource from your C++ code:
GS::Optional<GS::UniString> MyJSONCommand::GetSchemaDefinitions () const
{
	GSHandle myJSONFileContent = RSLoadResource ('DATA', ACAPI_GetOwnResModule (), 1000);
	return GS::UniString (*myJSONFileContent);
}


GS::Optional<GS::UniString> MyJSONCommand::GetInputParametersSchema () const
{
	return GS::UniString (R"({
	"$ref": "#/MyInputParametersSchema"
})");
}


GS::Optional<GS::UniString> MyJSONCommand::GetResponseSchema () const
{
	return GS::UniString (R"({
	"$ref": "#/MyResponseSchema"
})");
}
poco2013
Mentor
Thanks Tibor - What a GREAT tip.

I have a Json editor and could have used it, if i understood what i was doing rather than just trying to follow a pattern.
At any rate, this simplifies things for the most complicated part of the Command handler.

Thanks again
Gerry

Windows 11 - Visual Studio 2022; ArchiCAD 27

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!