|
17 | 17 | /////////////////////////////////////////////////////////////////////////////////////////////////
|
18 | 18 |
|
19 | 19 | #include "AEHelper.h"
|
| 20 | +#include <iostream> |
| 21 | +#include "StringHelper.h" |
20 | 22 | #include "platform/PlatformHelper.h"
|
21 |
| - |
22 | 23 | namespace AEHelper {
|
23 | 24 |
|
24 | 25 | AEGP_PluginID PluginID = 0L;
|
25 | 26 | std::shared_ptr<AEGP_SuiteHandler> Suites = nullptr;
|
26 | 27 | std::string DocumentsFolderPath = "";
|
27 | 28 | std::string AeVersion = "";
|
28 | 29 |
|
| 30 | +int32_t MAJORVERSION = 23; |
| 31 | + |
29 | 32 | void SetSuitesAndPluginID(SPBasicSuite* basicSuite, AEGP_PluginID id) {
|
30 | 33 | Suites = std::make_shared<AEGP_SuiteHandler>(basicSuite);
|
31 | 34 | PluginID = id;
|
@@ -114,4 +117,141 @@ void RunScriptPreWarm() {
|
114 | 117 | }
|
115 | 118 | }
|
116 | 119 |
|
| 120 | +bool CheckAeVersion() { |
| 121 | + int32_t majorVersion = 0; |
| 122 | + if (AeVersion.empty()) { |
| 123 | + return false; |
| 124 | + } |
| 125 | + try { |
| 126 | + size_t dotPos = AeVersion.find('.'); |
| 127 | + if (dotPos == std::string::npos) { |
| 128 | + std::cerr << "Invalid version format" << std::endl; |
| 129 | + return false; |
| 130 | + } |
| 131 | + std::string versionStr = AeVersion.substr(0, dotPos); |
| 132 | + majorVersion = std::stoi(versionStr); |
| 133 | + } catch (const std::invalid_argument& e) { |
| 134 | + std::cerr << "Invalid argument: " << e.what() << std::endl; |
| 135 | + return false; |
| 136 | + } catch (const std::out_of_range& e) { |
| 137 | + std::cerr << "Out of range: " << e.what() << std::endl; |
| 138 | + return false; |
| 139 | + } |
| 140 | + if (majorVersion >= MAJORVERSION) { |
| 141 | + return true; |
| 142 | + } |
| 143 | + return false; |
| 144 | +} |
| 145 | + |
| 146 | +std::string GetItemName(const AEGP_ItemH& itemH) { |
| 147 | + std::string itemName; |
| 148 | + if (itemH == nullptr) { |
| 149 | + return itemName; |
| 150 | + } |
| 151 | + const auto& suites = GetSuites(); |
| 152 | + auto pluginID = GetPluginID(); |
| 153 | + AEGP_MemHandle nameMemory = nullptr; |
| 154 | + suites->ItemSuite8()->AEGP_GetItemName(pluginID, itemH, &nameMemory); |
| 155 | + if (!nameMemory) { |
| 156 | + return itemName; |
| 157 | + } |
| 158 | + itemName = StringHelper::AeMemoryHandleToString(nameMemory); |
| 159 | + suites->MemorySuite1()->AEGP_FreeMemHandle(nameMemory); |
| 160 | + |
| 161 | + itemName = StringHelper::DeleteLastSpace(itemName); |
| 162 | + return itemName; |
| 163 | +} |
| 164 | + |
| 165 | +std::string GetLayerName(const AEGP_LayerH& layerH) { |
| 166 | + std::string layerName; |
| 167 | + if (layerH == nullptr) { |
| 168 | + return layerName; |
| 169 | + } |
| 170 | + const auto& suites = GetSuites(); |
| 171 | + auto pluginID = GetPluginID(); |
| 172 | + AEGP_MemHandle layerNameHandle = nullptr; |
| 173 | + AEGP_MemHandle sourceNameHandle = nullptr; |
| 174 | + suites->LayerSuite6()->AEGP_GetLayerName(pluginID, layerH, &layerNameHandle, &sourceNameHandle); |
| 175 | + if (!layerNameHandle || !sourceNameHandle) { |
| 176 | + return layerName; |
| 177 | + } |
| 178 | + layerName = StringHelper::AeMemoryHandleToString(layerNameHandle); |
| 179 | + if (layerName.empty()) { |
| 180 | + layerName = StringHelper::AeMemoryHandleToString(sourceNameHandle); |
| 181 | + } |
| 182 | + suites->MemorySuite1()->AEGP_FreeMemHandle(layerNameHandle); |
| 183 | + suites->MemorySuite1()->AEGP_FreeMemHandle(sourceNameHandle); |
| 184 | + |
| 185 | + layerName = StringHelper::DeleteLastSpace(layerName); |
| 186 | + return layerName; |
| 187 | +} |
| 188 | + |
| 189 | +AEGP_ItemH GetItemFromComp(const AEGP_CompH& compH) { |
| 190 | + const auto& suites = GetSuites(); |
| 191 | + AEGP_ItemH itemH = nullptr; |
| 192 | + if (compH != nullptr) { |
| 193 | + suites->CompSuite6()->AEGP_GetItemFromComp(compH, &itemH); |
| 194 | + } |
| 195 | + return itemH; |
| 196 | +} |
| 197 | + |
| 198 | +std::string GetCompName(const AEGP_CompH& compH) { |
| 199 | + if (compH == nullptr) { |
| 200 | + return ""; |
| 201 | + } |
| 202 | + auto itemH = GetItemFromComp(compH); |
| 203 | + return GetItemName(itemH); |
| 204 | +} |
| 205 | + |
| 206 | +void SelectItem(const AEGP_ItemH& itemH) { |
| 207 | + const auto& suites = GetSuites(); |
| 208 | + if (itemH != nullptr) { |
| 209 | + suites->ItemSuite6()->AEGP_SelectItem(itemH, true, true); |
| 210 | + suites->CommandSuite1()->AEGP_DoCommand( |
| 211 | + 3061); // 3061: Open selection, ignoring any modifier keys. |
| 212 | + } |
| 213 | +} |
| 214 | + |
| 215 | +void SelectItem(const AEGP_ItemH& itemH, const AEGP_LayerH& layerH) { |
| 216 | + const auto& suites = GetSuites(); |
| 217 | + auto pluginID = GetPluginID(); |
| 218 | + if (itemH == nullptr) { |
| 219 | + return; |
| 220 | + } |
| 221 | + bool hasLayer = (layerH != nullptr); |
| 222 | + AEGP_CollectionItemV2 collectionItem; |
| 223 | + AEGP_StreamRefH streamH; |
| 224 | + if (hasLayer) { |
| 225 | + suites->DynamicStreamSuite4()->AEGP_GetNewStreamRefForLayer(pluginID, layerH, &streamH); |
| 226 | + collectionItem.type = AEGP_CollectionItemType_LAYER; |
| 227 | + collectionItem.u.layer.layerH = layerH; |
| 228 | + collectionItem.stream_refH = streamH; |
| 229 | + } |
| 230 | + |
| 231 | + suites->ItemSuite6()->AEGP_SelectItem(itemH, true, true); |
| 232 | + if (!hasLayer) { |
| 233 | + suites->CommandSuite1()->AEGP_DoCommand( |
| 234 | + 3061); // 3061: Open selection, ignoring any modifier keys. |
| 235 | + return; |
| 236 | + } |
| 237 | + |
| 238 | + auto compH = GetCompFromItem(itemH); |
| 239 | + AEGP_Collection2H collectionH = nullptr; |
| 240 | + suites->CollectionSuite2()->AEGP_NewCollection(pluginID, &collectionH); |
| 241 | + suites->CollectionSuite2()->AEGP_CollectionPushBack(collectionH, &collectionItem); |
| 242 | + suites->CompSuite6()->AEGP_SetSelection(compH, collectionH); |
| 243 | + suites->CommandSuite1()->AEGP_DoCommand( |
| 244 | + 3061); // 3061: Open selection, ignoring any modifier keys. |
| 245 | + suites->CollectionSuite2()->AEGP_DisposeCollection(collectionH); |
| 246 | +} |
| 247 | + |
| 248 | +AEGP_CompH GetCompFromItem(const AEGP_ItemH& itemH) { |
| 249 | + const auto& suites = GetSuites(); |
| 250 | + AEGP_CompH compH = nullptr; |
| 251 | + if (itemH != nullptr) { |
| 252 | + suites->CompSuite6()->AEGP_GetCompFromItem(itemH, &compH); |
| 253 | + } |
| 254 | + return compH; |
| 255 | +} |
| 256 | + |
117 | 257 | } // namespace AEHelper
|
0 commit comments