From c229fd991bdd3aadfe6a38c96ae4cccb713d06a7 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Mon, 7 Apr 2025 12:23:47 +0200 Subject: [PATCH 1/5] Cpp: rewriten constructor example --- website/docs/dev_api_cpp.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/website/docs/dev_api_cpp.md b/website/docs/dev_api_cpp.md index 3bf87c84..6675a347 100644 --- a/website/docs/dev_api_cpp.md +++ b/website/docs/dev_api_cpp.md @@ -55,12 +55,18 @@ and repeat them inside `ext` folder in your project folder. #include "AyonCppApi.h" int main (){ - AyonApi con = AyonApi(); + AyonApi con = AyonApi( + "path/to/log_file.txt", + "your_api_key", // AYON API key + "http://your.server", // AYON server url + "project_name", + "site-id" // e.g. military-mouse-of-jest + ); return 0; } ``` -```shell title="CMakelists.txt" +```shell title="CMakeLists.txt" cmake_minimum_required(VERSION "3.28.1") set(CMAKE_CXX_STANDARD 17) @@ -92,11 +98,6 @@ you'd need to set few environment variables. otherwise, it won't work. ```shell -set AYON_SERVER_URL= -set AYON_API_KEY= -set AYON_PROJECT_NAME= -set AYON_SITE_ID= # e.g. military-mouse-of-jest - build\Debug\main.exe ``` From 1028339add84a8b3b7e981ca4bdc9183e92f4b53 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Mon, 7 Apr 2025 13:45:09 +0200 Subject: [PATCH 2/5] Changed example to match the current implementation --- website/docs/dev_api_cpp.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/website/docs/dev_api_cpp.md b/website/docs/dev_api_cpp.md index 6675a347..1903124a 100644 --- a/website/docs/dev_api_cpp.md +++ b/website/docs/dev_api_cpp.md @@ -54,9 +54,9 @@ and repeat them inside `ext` folder in your project folder. // AYON CPP API Test #include "AyonCppApi.h" -int main (){ +int main () { AyonApi con = AyonApi( - "path/to/log_file.txt", + "path/to/log_file.json", "your_api_key", // AYON API key "http://your.server", // AYON server url "project_name", @@ -85,33 +85,33 @@ target_link_libraries(${PROJECT_NAME} AyonCppApi) #### Build the project -> I'm using `VS studio` (devenv.exe) on my side. - ```shell cmake -S . -B build -DJTRACE=0 -devenv build/main.sln /Build +cmake --build build --config Debug -j12 ``` #### Test Run -you'd need to set few environment variables. -otherwise, it won't work. - ```shell build\Debug\main.exe ``` -Expected Output +#### Expected Output + ```shell my_cpp_project> build\Debug\main.exe -[2024-09-20 15:59:31.541] [info] Loaded AYON_API_KEY and AYON_SERVER_URL -[2024-09-20 15:59:31.542] [info] Found SideId +[2025-04-07 13:24:47.985] [info] Failed to determine the OpenSSL directory. Falling back to the default certificate file path. +[2025-04-07 13:24:48.368] [info] Connected to the Ayon server : 200 ``` -:::tip `AYON_SITE_ID` fallback -When skipping setting `AYON_SITE_ID` env variable, the lib will default to file named `site_id` *without an extension*. -located at `%AppData%/Roaming/AYON/site_id` on windows. -::: +> If you don't see any output in the terminal, the logs may be written only to the `log_file.json` specified in the constructor. + +Example contents of `log_file.json`: + +```json +{"timestamp":"2025-04-07 13:24:47.985","level":"info","Thread Id":"5832","Process Id":"13732","message":"Failed to determine the OpenSSL directory. Falling back to the default certificate file path."} +{"timestamp":"2025-04-07 13:24:48.368","level":"info","Thread Id":"5832","Process Id":"13732","message":"Connected to the Ayon server : 200"} +``` From 9eef5769b4b660f61718f3b967f09940d7e55ea2 Mon Sep 17 00:00:00 2001 From: Tadeas Hejnic Date: Mon, 7 Apr 2025 16:43:45 +0200 Subject: [PATCH 3/5] Edit of the new example --- website/docs/dev_api_cpp.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/website/docs/dev_api_cpp.md b/website/docs/dev_api_cpp.md index 1903124a..8c09c20e 100644 --- a/website/docs/dev_api_cpp.md +++ b/website/docs/dev_api_cpp.md @@ -56,7 +56,7 @@ and repeat them inside `ext` folder in your project folder. int main () { AyonApi con = AyonApi( - "path/to/log_file.json", + "path/to/log_file.json", // extension will be always changed to json "your_api_key", // AYON API key "http://your.server", // AYON server url "project_name", @@ -90,6 +90,13 @@ cmake -S . -B build -DJTRACE=0 cmake --build build --config Debug -j12 ``` +or + +```shell +cmake -S . -B build -DJTRACE=0 +devenv build/main.sln /Build +``` + #### Test Run ```shell From 0eb32b258daf5a24740a4f94d34167ca4ec389a4 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Fri, 18 Jul 2025 18:52:04 +0300 Subject: [PATCH 4/5] update cpp example in cpp doc --- website/docs/dev_api_cpp.md | 153 +++++++++++++++++++----------------- 1 file changed, 80 insertions(+), 73 deletions(-) diff --git a/website/docs/dev_api_cpp.md b/website/docs/dev_api_cpp.md index 8c09c20e..f75b75ee 100644 --- a/website/docs/dev_api_cpp.md +++ b/website/docs/dev_api_cpp.md @@ -6,67 +6,73 @@ description: Information about AYON C++ API toc_max_heading_level: 5 --- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ## About AYON C++ API -The AYON CPP API allows communication with the AYON server. +The AYON CPP API is a static lib. It allows communication with the AYON server. Implementation is mainly focused on [AYON USD Resolver](dev_api_usd_resolver.md) to communicate with the server resolve endpoint. -## Get Started - :::tip Development Environment -We assume you already have setup your c++ dev environment as well as cmake. +We assume you already have setup your C++ dev environment as well as cmake. +You need to use at least C++17 in CMake ::: -### Fetch and Build The library -AYON CPP API is a static lib. - -You need to build it first. We've prepared python script to do the hard lifting for you. -```shell -git clone --recurse-submodules https://github.com/ynput/ayon-cpp-api.git -cd ayon-cpp-api -python AyonBuild.py setup -python AyonBuild.py runStageGRP CleanBuild -``` +## C++ Example Project -### Include it in your cmake projects +Once built, you can then start including it in your cpp projects. -Once you include it and build your cpp project you'll no longer need the library. + + -
A CPP Example - -Here's an example cpp project structure ``` . ├─ ext/ayon-cpp-api ├─ CMakelists.txt └─ main.cpp ``` + + -#### Fetch Dependencies - -Please refer to [Fetch and Build The library](#fetch-and-build-the-library) section above for the instructions -and repeat them inside `ext` folder in your project folder. - -#### CPP Project Files - -```cpp title="main.cpp" +```cpp // AYON CPP API Test +#include #include "AyonCppApi.h" -int main () { +int main (){ + std::string project_name = "" ; + std::cout << "Enter a project: "; + std::cin >> project_name; + AyonApi con = AyonApi( - "path/to/log_file.json", // extension will be always changed to json - "your_api_key", // AYON API key - "http://your.server", // AYON server url - "project_name", - "site-id" // e.g. military-mouse-of-jest + "log/log.json", // extension will be always changed to json + "your_access_token", // This is a Bearer access token not AYON_API_KEY + "https://your.server", // with No trailing or forward slash at the end. + project_name, + "your-site-id" // Your site id e.g. military-mouse-of-jest ); + + std::string uri = "" ; + std::cout << "Enter a uri to resolve: "; + std::cin >> uri; + + std::pair resolvedAsset = con.resolvePath(uri); + std::cout << "The resolved path: " << resolvedAsset.second << std::endl; return 0; } ``` +:::caution + +The auth key used in the cpp example is an [Authentication Token](https://community.ynput.io/t/ayon-rest-api-guide/1268#get-authentication-token-6) which is not an `AYON_API_KEY`. +Also, don't add a trailing forward slash to your AYON server URL. +::: + + + -```shell title="CMakeLists.txt" +```shell cmake_minimum_required(VERSION "3.28.1") set(CMAKE_CXX_STANDARD 17) @@ -77,50 +83,51 @@ project(main) # Include AyonCppApi add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/ext/ayon-cpp-api") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/ext/ayon-cpp-api") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/ext/ayon-cpp-api/ext/ayon-cpp-dev-tools/src/") add_executable(${PROJECT_NAME} main.cpp) target_link_libraries(${PROJECT_NAME} AyonCppApi) ``` - -#### Build the project - -```shell -cmake -S . -B build -DJTRACE=0 -cmake --build build --config Debug -j12 -``` - -or - -```shell -cmake -S . -B build -DJTRACE=0 -devenv build/main.sln /Build -``` - -#### Test Run - -```shell -build\Debug\main.exe -``` - -#### Expected Output - -```shell -my_cpp_project> build\Debug\main.exe -[2025-04-07 13:24:47.985] [info] Failed to determine the OpenSSL directory. Falling back to the default certificate file path. -[2025-04-07 13:24:48.368] [info] Connected to the Ayon server : 200 -``` - -> If you don't see any output in the terminal, the logs may be written only to the `log_file.json` specified in the constructor. - -Example contents of `log_file.json`: - -```json -{"timestamp":"2025-04-07 13:24:47.985","level":"info","Thread Id":"5832","Process Id":"13732","message":"Failed to determine the OpenSSL directory. Falling back to the default certificate file path."} -{"timestamp":"2025-04-07 13:24:48.368","level":"info","Thread Id":"5832","Process Id":"13732","message":"Connected to the Ayon server : 200"} -``` - -
+
+
+ +*This example is brought from: [test_cpp_api](https://github.com/MustafaJafar/ayon-recipes/tree/main/test_cpp_api).* + + +### Build And Run Commands + +- **Build CPP** + `ayon-cpp-api` repo provides python script to do the hard lifting for you. + ``` + git submodule update --init --recursive + cd ext\ayon-cpp-api + python AyonBuild.py --setup + python AyonBuild.py --runStageGRP CleanBuild + ``` +- **Build CPP Example** + ``` + rmdir /s /q build + cmake -S . -B build -DJTRACE=0 + cmake --build ./build --config Debug -j12 + ``` +- **Run CPP Example** + ``` + build\Debug\main.exe + ``` +- **Example Output** + ``` + Enter a project: Animal_Logic_ALab + Enter a uri to resolve: ayon+entity://Animal_Logic_ALab/assets/book_encyclopedia01?product=usdAsset&version=v002&representation=usd + The resolved path: H:\AYON\projects\Animal_Logic_ALab\assets\book_encyclopedia01\publish\usd\usdAsset\v002\ALA_book_encyclopedia01_usdAsset_v002.usd + ``` +- **Example contents of `log.json`** + ```json + {"timestamp":"2025-04-07 13:24:48.368","level":"info","Thread Id":"5832","Process Id":"13732","message":"Connected to the Ayon server : 200"} + {"timestamp":"2025-07-18 18:14:56.645","level":"warning","Thread Id":"34840","Process Id":"40096","message":"asset identification cant be generated {"entities":[],"error":"Invalid scheme: h","uri":"H:\\AYON\\projects\\Animal_Logic_ALab\\assets\\book_encyclopedia01\\publish\\usd\\usdAsset\\v002\\ALA_book_encyclopedia01_usdAsset_v002.usd"}"} + {"timestamp":"2025-07-18 18:16:17.522","level":"warning","Thread Id":"564","Process Id":"37400","message":"asset identification cant be generated {"entities":[{}],"uri":"ayon+entity://Animal_Logic_ALab/assets/book_encyclopedia01?product=usdAsset"}"} + {"timestamp":"2025-07-18 18:16:48.017","level":"warning","Thread Id":"33948","Process Id":"38436","message":"asset identification cant be generated {"entities":[],"error":"Invalid scheme: ","uri":"{root[work]}/Animal_Logic_ALab/assets/book_encyclopedia01/work/lookdev/ALA_book_encyclopedia01_lookdev_v001.hip"}"} + ``` ## Learn More From 1cf0408632de0b3a77e8e6f0b4482f4c2bd930a1 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Thu, 24 Jul 2025 11:03:28 +0300 Subject: [PATCH 5/5] cpp docs: update build and run section --- website/docs/dev_api_cpp.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/website/docs/dev_api_cpp.md b/website/docs/dev_api_cpp.md index f75b75ee..018cf0c5 100644 --- a/website/docs/dev_api_cpp.md +++ b/website/docs/dev_api_cpp.md @@ -97,10 +97,14 @@ target_link_libraries(${PROJECT_NAME} AyonCppApi) ### Build And Run Commands -- **Build CPP** +- **Fetch AYON CPP Repo** + ``` + cd ext + git clone https://github.com/ynput/ayon-cpp-api.git --recurse-submodules + ``` +- **Build CPP**
`ayon-cpp-api` repo provides python script to do the hard lifting for you. ``` - git submodule update --init --recursive cd ext\ayon-cpp-api python AyonBuild.py --setup python AyonBuild.py --runStageGRP CleanBuild