├── CAA RenameObject ├── Readme.txt ├── RenameObjectSetup.exe └── Ryd重命名特征.wmv ├── CAA实用代码片段.cpp ├── CAA帮助的使用.doc ├── CAA获取属性.txt ├── README.md └── 小结.txt /CAA RenameObject/Readme.txt: -------------------------------------------------------------------------------- 1 | Copyright©RYD_XXP 批量重命名特征 2 | 命名示例: 3 | RYDRename@34&Suffix 4 | 解释:由34开始编号,后缀为Suffix。 5 | 无起始编号:RYDRename 6 | 无须后缀:RYDRename@34 7 | 8 | 注:安装时需选择路径为已安装的CATIA路径。 9 | -------------------------------------------------------------------------------- /CAA RenameObject/RenameObjectSetup.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaopinglp/CAA-Learn/06252a8edc7b048d177c9b8c2847e0167fa131c9/CAA RenameObject/RenameObjectSetup.exe -------------------------------------------------------------------------------- /CAA RenameObject/Ryd重命名特征.wmv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaopinglp/CAA-Learn/06252a8edc7b048d177c9b8c2847e0167fa131c9/CAA RenameObject/Ryd重命名特征.wmv -------------------------------------------------------------------------------- /CAA实用代码片段.cpp: -------------------------------------------------------------------------------- 1 | /*常见编译错误: 2 | fatal error C1189: #error :WINDOWS.H already included. 3 | 解决方法:最顶端定义预编译的宏*/ 4 | #ifdef _WINDOWS_ 5 | #undef _WINDOWS_ #include 6 | #endif 7 | 8 | CAA常用代码构件 9 | #include 10 | AfcMessageBox(_T("hello!Point Command")); 11 | 12 | //变量和表达式转换成字符串 13 | //使用字符串运算符来实现转换输出定义 14 | #define PR(x) cout<<#x"="<SetText(NotifyText); 23 | _OpenNotify->SetVisibility(CATDlgShow); 24 | 25 | //2、MessageBox CATUnicodeString -->LPSTR 利用CString afxstr; 26 | CATUnicodeString InstanceName; 27 | spProduct->GetPrdInstanceName(InstanceName); 28 | CString name=InstanceName.ConvertToChar(); 29 | MessageBox(NULL,name,L"OK",MB_OK | MB_SYSTEMMODAL); 30 | MessageBox(NULL,L"Hello World!",L"成功",MB_OK | MB_SYSTEMMODAL); 31 | 32 | //二、获取CATIA环境变量: 33 | CATUnicodeString oPreviewFileName,TmpDir,File; 34 | char *slash_tmp = NULL; 35 | if (CATGetEnvValue("CATInstallPath", &slash_tmp) == CATLibSuccess) 36 | oPreviewFileName = slash_tmp; 37 | if (slash_tmp) free(slash_tmp); slash_tmp=NULL; 38 | #ifndef _WINDOWS_SOURCE 39 | oPreviewFileName.Append("\\"); 40 | #else 41 | oPreviewFileName.Append("/"); 42 | #endif 43 | oPreviewFileName.Append("CAAxPDMPreview.jpg"); 44 | 45 | // get System environment variable 46 | char *pathvar; 47 | pathvar = getenv("PATH"); 48 | cout << pathvar << endl 49 | 50 | /*CATIA CAA 32位和64位编译 51 | 修改环境变量: 52 | _MkmkOS_BitMode = 32 // Win32位编译 53 | _MkmkOS_BitMode = 64 // Win64位编译 54 | */ 55 | 56 | //三、元素隐藏与显示 57 | /** 58 | * 隐藏元素 59 | * @param ipListElemObj 60 | * 元素列表 61 | */ 62 | void HideElements(CATLISTV(CATISpecObject_var) ipListElemObj) 63 | { 64 | for(int i=1;iQueryInterface(IID_CATIVisProperties,(void**) &pPropONElem ); 68 | if (NULL != pPropONElem) 69 | { 70 | CATIVisPropertiesValues PropValue; 71 | CATIVisPropertyType PropTypeOnPtObj = CATVPShow; 72 | CATVisGeomType GeomTypeOnPtObj = CATVPGlobalType; 73 | PropValue.SetShowAttr(CATNOShowAttr); 74 | rc = pPropONElem -> SetPropertiesAttr(PropValue, 75 | PropTypeOnPtObj, 76 | GeomTypeOnPtObj); 77 | pPropONElem ->Release(); 78 | pPropONElem = NULL; 79 | } 80 | } 81 | } 82 | 83 | /** 84 | * 检测元素显示状态 85 | */ 86 | bool CheckIsShow(CATIVisProperties_var spPropOnTreeNode) 87 | { 88 | // 5/18 add 89 | bool IsShow = false; 90 | 91 | CATShowAttribut oShow ; 92 | if ( NULL_var != spPropOnTreeNode ) 93 | { 94 | if ( SUCCEEDED(GetShow(spPropOnTreeNode,oShow,2))) 95 | { 96 | // model show flag 97 | if (oShow == CATShowAttr) 98 | { 99 | IsShow = true; 100 | } 101 | } 102 | }//--- 5/18 add 103 | 104 | return IsShow; 105 | } 106 | 107 | /** 108 | * 取得元素显示标识 Show Flag 109 | */ 110 | HRESULT GetShow(CATIVisProperties_var spProp, CATShowAttribut &oShow ,int Mode ) 111 | { 112 | if ( spProp == NULL_var) 113 | return E_FAIL; 114 | CATVisPropertiesValues MyPropertyOnFace; 115 | CATVisPropertyType PropTypeOnFace = CATVPShow; 116 | CATVisGeomType GeomTypeOnFace; 117 | if ( Mode == 1 ) 118 | GeomTypeOnFace = CATVPMesh; 119 | else 120 | GeomTypeOnFace = CATVPGlobalType ; 121 | HRESULT rc = spProp->GetPropertiesAtt(MyPropertyOnFace,PropTypeOnFace,GeomTypeOnFace); 122 | if ( SUCCEEDED(rc) ) 123 | { 124 | HRESULT HR = MyPropertyOnFace.GetShowAttr(oShow); 125 | if ( FAILED(HR)) 126 | return E_FAIL; 127 | } 128 | return S_OK; 129 | } 130 | 131 | //四、元素隐藏与显示 132 | /** 133 | * 高亮特征 134 | * @param spSpec 135 | * 高亮特征 136 | */ 137 | HRESULT HighLightSpecObject (CATISpecObject_var spSpec, CATBoolean boolClearHistory) 138 | { 139 | HRESULT rc = E_FAIL; 140 | CATFrmEditor * pEditor = CATFrmEditor::GetCurrentEditor(); 141 | if(NULL == pEditor ) 142 | return rc; 143 | CATHSO * pHSO = pEditor->GetHSO(); 144 | if(NULL == pHSO ) 145 | return rc; 146 | 147 | //为1时,清楚所有已有的高亮 148 | if(boolClearHistory) 149 | pHSO->Empty(); 150 | CATPathElement pContext = pEditor->GetUIActiveObject(); 151 | CATIBuildPath * piBuildPath = NULL; 152 | rc =spSpec->QueryInterface(IID_CATIBuildPath, (void **)&piBuildPath); 153 | if(SUCCEEDED(rc) && piBuildPath != NULL) 154 | { 155 | CATPathElement * pPathElement = NULL; 156 | rc = piBuildPath->ExtractPathElement(&pContext, &pPathElement); 157 | if (pPathElement != NULL) 158 | { 159 | pHSO->AddElement(pPathElement); 160 | pPathElement->Release(); 161 | pPathElement = NULL; 162 | } 163 | piBuildPath->Release(); 164 | piBuildPath = NULL; 165 | } 166 | return S_OK; 167 | } 168 | 169 | //五、属性获取 170 | CATIAttributesDescription *piAttrDesc = NULL; 171 | rc = spRootProduct->QueryInterface(IID_CATIAttributesDescription, (void **) &piAttrDesc); 172 | if (FAILED(rc) || (NULL == piAttrDesc)) 173 | { 174 | cout << "QueryInterface CATIAttributesDescription error" << endl; 175 | return 4; 176 | } 177 | CATIInstance *piInstance = NULL; 178 | rc = spRootProduct->QueryInterface(IID_CATIInstance, (void **) &piInstance); 179 | if (FAILED(rc) || (NULL == piInstance)) 180 | { 181 | cout << "QueryInterface CATIInstance error" << endl; 182 | return 4; 183 | } 184 | CATListValCATAttributeInfos attrInfoList; 185 | piAttrDesc->List(&attrInfoList); 186 | for (int i = 1; i <= attrInfoList.Size(); i++) 187 | { 188 | CATAttributeInfos attrInfo = attrInfoList[i]; 189 | const CATUnicodeString& propertyName = attrInfo.Name(); //属性名 190 | const CATUnicodeString& valueType = attrInfo.Type()->Name(); //属性类型 191 | CATIValue *pValue = piInstance->GetValue(propertyName); //获得对应属性名的属性值 192 | CATUnicodeString value = ""; 193 | pValue->AsString(value); 194 | cout << propertyName << "-" << valueType << "-" << value << endl; 195 | if (pValue) 196 | { 197 | pValue->Release(); 198 | pValue = NULL; 199 | } 200 | } 201 | 202 | //六、CATSystemInfo 主机信息获取 203 | /*全局方法CATGetSystemInfo,获得一个CATSystemInfo结构体,包含主机名字、主机系统名字、系统版本等主机信息。*/ 204 | CATSystemInfo host; 205 | ::CATGetSystemInfo(&host); 206 | 207 | cout << "HostName:" << host.HostName << endl; 208 | cout << "OSName:" << host.OSName << endl; 209 | cout << "OSVersion:" << host.OSVersion << endl; 210 | cout << "OSType:" << host.OSType << endl; 211 | cout << "MinorVersion:" << host.MinorVersion << endl; 212 | cout << "MajorVersion:" << host.MajorVersion << endl; 213 | 214 | 215 | CATTime 216 | CATTime timeNow = CATTime::GetCurrentLocalTime(); 217 | CATUnicodeString timeStr = timeNow.ConvertToString("%Y/%m/%d-%H:%M:%S"); 218 | std::cout << "Current Time:" << timeStr.ConvertToChar() << std::endl; 219 | 220 | //七、C# C++ 字符集转换 字节流 221 | string str="客服端是用c#写的,服务端是c++"; 222 | send(str); 223 | public void send(msg) 224 | { 225 | string hexstr=StringToHexString(str) 226 | char[] chars= hexstr.ToCharArray(); 227 | byte[] byteData = Encoding.Default.GetBytes(chars); 228 | socket.write(byteData ,0,byteData.length); 229 | } 230 | //字符串转为16进制 231 | public string StringToHexString(string message) 232 | { 233 | //按照指定编码将string编程字节数组 234 | byte[] b = Encoding.UTF8.GetBytes(message); 235 | string result = string.Empty; 236 | for (int i = 0; i < b.Length; i++) 237 | { 238 | result += Convert.ToString(b[i], 16); 239 | } 240 | return result.ToUpper(); 241 | } 242 | 243 | 244 | //八、调用exe文件 245 | ShellExecute(0,(LPCWSTR)L"open",(LPCWSTR)L"D:\\Bin_x64\\SuperMapDemo.exe",(LPCWSTR)L"",(LPCWSTR)L"",SW_SHOWNORMAL); 246 | SHELLEXECUTEINFO ShellInfo; 247 | memset(&ShellInfo,0,sizeof(ShellInfo)); 248 | ShellInfo.cbSize=sizeof(ShellInfo); 249 | ShellInfo.hwnd=NULL; 250 | ShellInfo.lpVerb=_T("open"); 251 | //ShellInfo.lpFile=_T("..\\..\\..\\SuperMapDemo\\SuperMapDemo.exe"); 252 | ShellInfo.lpFile=_T("E:\\supermap\\Bin_x64\\SuperMapDemo.exe"); 253 | ShellInfo.lpParameters= name; 254 | ShellInfo.nShow=SW_HIDE;//SW_SHOWNORMAL 255 | ShellInfo.fMask=SEE_MASK_NOCLOSEPROCESS; 256 | BOOL bResult=ShellExecuteEx(&ShellInfo); 257 | if (!bResult) 258 | { 259 | return false; 260 | } 261 | 262 | 行号 参数 含义 263 | 1 SW_HIDE 隐藏这个窗体,并激活其他窗体。 264 | 2 SW_MAXIMIZE 最大化指定的窗体。 265 | 3 SW_MINIMIZE 最小化指定的窗体,并按顺序激活最上层的窗体。 266 | 4 SW_RESTORE 激活并显示窗体。如果窗体为最小化或者最大化,窗体恢复到原始大小和位置。应用程序当恢复一个最小化的窗体时将指定标记。 267 | 5 SW_SHOW 以当前的大小和位置激活并显示窗体。 268 | 6 SW_SHOWDEFAULT 269 | 7 SW_SHOWMAXIMIZED 激活并最大化显示窗体。 270 | 8 SW_SHOWMINIMIZED 激活并最小化现实窗体。 271 | 9 SW_SHOWMINNOACTIVE 最小化窗体,保持其激活状态。 272 | 10 SW_SHOWNA 以当前状态显示窗体,保持其激活状态。 273 | 11 SW_SHOWNOACTIVATE 以当前的大小和位置显示窗体,并保持其激活状态。 274 | 12 SW_SHOWNORMAL 激活并显示一个窗体。如果窗体为最大化或者最小化,窗体恢复到原始的大小和位置。当窗体第一次显示的时候,应用程序记录标记。 275 | 276 | 277 | //九、批处理模式获得文件的rootProduct 278 | HRESULT GetCurrentDoc_TopProduct( CATIProduct_var & spTopProd) 279 | { 280 | //-------------------------------------------------------------------- 281 | // 1. Prologue 282 | //-------------------------------------------------------------------- 283 | cout << endl << flush; 284 | cout << endl << flush; 285 | cout << "----------------------------------------------------------------" << endl << flush; 286 | cout << endl << flush; 287 | 288 | // --- Creating the Session: A session must always be created in a batch 289 | char *sessionName = "CAA_EhiFilter_Session"; 290 | CATSession *pSession = NULL; 291 | HRESULT rc = ::Create_Session(sessionName,pSession); 292 | if ((SUCCEEDED(rc)) && (NULL != pSession)) 293 | { 294 | cout << "> session created : " << sessionName < open document :"<< argv[1] << argv[2] << endl << flush; 309 | rc = CATDocumentServices::OpenDocument(CATUnicodeString(argv[1])+CATUnicodeString(argv[2]), pDoc); 310 | 311 | CATLockDocument(*pDoc); 312 | 313 | if (SUCCEEDED(rc) && (NULL != pDoc)) 314 | { 315 | cout << "> document opened " << endl << flush; 316 | } 317 | else 318 | { 319 | cout << "ERROR in opening document" << endl << flush; 320 | return 2; 321 | } 322 | 323 | // --- Retrieving root product of the opened document 324 | CATIProduct* piRootProduct = NULL; // piRootProduct is a handle to document root product 325 | // 326 | CATIDocRoots * piDocRoots = NULL; 327 | rc = pDoc->QueryInterface(IID_CATIDocRoots,(void**) &piDocRoots); 328 | if ( FAILED(rc) || (NULL==piDocRoots) ) 329 | { 330 | cout << "ERROR : Failed to query CATIDocRoots" << endl; 331 | return 3; 332 | } 333 | CATListValCATBaseUnknown_var* pListRootProduct = piDocRoots->GiveDocRoots(); 334 | piDocRoots->Release(); 335 | piDocRoots=NULL; 336 | 337 | if ( pListRootProduct && pListRootProduct->Size() ) 338 | { 339 | CATBaseUnknown_var hUnk = (*pListRootProduct)[1]; 340 | 341 | if (NULL_var != hUnk) 342 | rc = hUnk->QueryInterface(IID_CATIProduct,(void**) &piRootProduct ); 343 | if (pListRootProduct) 344 | delete pListRootProduct; 345 | pListRootProduct = NULL; 346 | // 347 | if (SUCCEEDED(rc) && (NULL != piRootProduct)) 348 | { 349 | cout << "> root product found in document " << endl << flush; 350 | spTopProd = piProductOnRoot; 351 | CATUnicodeString partNumber = piProductOnRoot->GetPartNumber(); 352 | cout << "Working with '" << partNumber.ConvertToChar() << "'" << endl; 353 | return S_OK; 354 | } 355 | else 356 | { 357 | cout << "ERROR : Root product not found in document " << endl << flush; 358 | return 3; 359 | } 360 | } 361 | 362 | //-------------------------------------------------------------------- 363 | //创建草图 364 | CATInit *piInitOnDoc = NULL; 365 | rc = pDoc -> QueryInterface (IID_CATInit,(void**) &piInitOnDoc); 366 | if(SUCCEEDED(rc) && NULL != piInitOnDoc) 367 | { 368 | //获取Container 369 | const CATIdent idCATIContainer = "CATIPrtContainer"; 370 | CATIPrtContainer *piRootContainer = NULL; 371 | piRootContainer = (CATIPrtContainer*) 372 | piInitOnDoc -> GetRootContainer(idCATIContainer); 373 | if(NULL != piRootContainer) 374 | { 375 | CATIPrtPart_var spPart = piRootContainer->GetPart(); 376 | CATIBasicTool_var spTool= spPart->GetCurrentTool(); 377 | 378 | CATIDescendants_var spDesTool = spPart; 379 | CATListValCATISpecObject_var oLst ; 380 | spDesTool->GetAllChildren("CATIMechanicalTool",oLst); 381 | CATISpecObject_var spMainBody = oLst[1]; 382 | CATIAlias_var spAlias = spMainBody; 383 | cout << spAlias->GetAlias() << endl << flush; 384 | 385 | CATISketchFactory_var spSketchFactory(piRootContainer); 386 | if(NULL_var != spSketchFactory) 387 | { 388 | CATISpecObject_var spSketchSpec=spSketchFactory->CreateSketch(); 389 | CATISketch_var spSketch=spSketchSpec; 390 | if(NULL_var != spSketch) 391 | { 392 | spSketch->OpenEdition(); 393 | CATI2DWFFactory_var sketch2DFactory(spSketch); 394 | if(NULL_var != sketch2DFactory) 395 | { 396 | double Origin[2]={0.,0.}; 397 | double Radius=10; 398 | CATISpecObject_var spSpecCircle= 399 | sketch2DFactory->CreateCircle(Origin,Radius); 400 | if(NULL_var != spSpecCircle) 401 | { 402 | cout<<"草图中创建圆成功!"<CloseEdition(); 405 | 406 | spPart->SetCurrentFeature(spMainBody); 407 | 408 | 409 | //创建凸台 410 | CATIPrtFactory * piPrtFact=NULL; 411 | rc=piRootContainer->QueryInterface(IID_CATIPrtFactory, 412 | (void **)&piPrtFact); 413 | if(SUCCEEDED(rc) && NULL != piPrtFact) 414 | { 415 | CATISpecObject_var spPad=piPrtFact->CreatePad(spSketch); 416 | if(NULL_var != spPad) 417 | { 418 | CATIPad_var spPadPad=spPad; 419 | if(NULL_var != spPadPad) 420 | { 421 | spPadPad->ModifyEndType(catOffsetLimit); 422 | spPadPad->ModifyEndOffset(20.); 423 | } 424 | 425 | spPad->Update(); 426 | cout<<"创建凸台成功!"<Release(); 429 | piPrtFact=NULL; 430 | 431 | CATISpecObject_var spPart = piRootContainer->GetPart(); 432 | spPart->Update(); 433 | } 434 | } 435 | } 436 | } 437 | 438 | CATISpecObject_var spParentForTool = spMainBody; 439 | CATIMechanicalRootFactory_var spMechRoot = piRootContainer; 440 | CATISpecObject_var spSpecGS1 = NULL_var; 441 | rc = spMechRoot -> CreateGeometricalSet("新增几何图形集1",spParentForTool,spSpecGS1); 442 | } 443 | 444 | piInitOnDoc->Release(); 445 | piInitOnDoc=NULL; 446 | } 447 | -------------------------------------------------------------------------------- /CAA帮助的使用.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaopinglp/CAA-Learn/06252a8edc7b048d177c9b8c2847e0167fa131c9/CAA帮助的使用.doc -------------------------------------------------------------------------------- /CAA获取属性.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaopinglp/CAA-Learn/06252a8edc7b048d177c9b8c2847e0167fa131c9/CAA获取属性.txt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # myRepository 2 | CATIA CAA Secondary development 3 | 4 | CAA V5 Encyclopedia: 5 | http://www.maruf.ca/files/caadoc/CAACenV5Default.htm 6 | -------------------------------------------------------------------------------- /小结.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaopinglp/CAA-Learn/06252a8edc7b048d177c9b8c2847e0167fa131c9/小结.txt --------------------------------------------------------------------------------