回答(2)
wustguangh 19级 2014-11-14 07:54:11
CATIBuildPath *piBuildPath = NULL; HRESULT rc = spTempObject->QueryInterface( IID_CATIBuildPath, (void**) &piBuildPath ); if ( SUCCEEDED(rc) ) { CATFrmEditor *pEditor = CATFrmEditor::GetCurrentEditor(); CATPathElement Context = pEditor->GetUIActiveObject(); CATPathElement *pPathElement = NULL ; rc = piBuildPath->ExtractPathElement(&Context,&pPathElement); }
可以试试这个获取全路径的方法
wustguangh 19级 2014-11-13 16:58:54
BOOL UCEGetPathElementFromSpecObject(CATPathElement* &pPathElement,const CATISpecObject_var spSpecObject,CATPathElement* pFatherPathElement) { pPathElement=NULL; if(spSpecObject==NULL_var) { return FALSE; } // ////////////////////////////////////////////////////////////////////////////////////////////// CATPathElement * pInputContext; if(pFatherPathElement==NULL) { //获得当前editor CATFrmEditor * editor = CATFrmEditor::GetCurrentEditor (); if (NULL == editor) { UCEErrorMsgBox(" error: failed to get current editor"); return FALSE; } CATPathElement FatherPathElement=editor->GetUIActiveObject(); if(FatherPathElement.GetSize()==0) { UCEErrorMsgBox(" error: failed to get current path"); return FALSE; } pInputContext = new CATPathElement(FatherPathElement); } else { pInputContext = new CATPathElement(*pFatherPathElement); } if (pInputContext==NULL) return FALSE; // CATIBuildPath_var spiBuildPathAccess = spSpecObject; if(spiBuildPathAccess==NULL_var) { UCEErrorMsgBox(" error: failed to get build path access"); return FALSE; } // HRESULT rs=spiBuildPathAccess -> ExtractPathElement (pInputContext, &pPathElement); pInputContext -> Release(); pInputContext = NULL; if(FAILED(rs)) { UCEErrorMsgBox(" error: 由于装配上下文变化,无法根据路径获取对象全路径!"); return FALSE; } // return TRUE; } BOOL UCEGetPathElementFromSpecObject(CATPathElement* &pPathElement,const CATISpecObject_var spSpecObject,CATIProduct_var spPrdInstance) { pPathElement=NULL; if(spSpecObject==NULL_var || spPrdInstance==NULL_var) { return FALSE; } if(SUCCEEDED(spPrdInstance->IsReference())) { UCEErrorMsgBox(" 错误:不是一个产品实例"); return FALSE; } // CATIProduct_var spRootProduct; if(UCEGetRootProduct(spRootProduct,TRUE)==FALSE) { return FALSE; } CATIBuildPath_var spiBuildPathAccess = spPrdInstance; if(spiBuildPathAccess==NULL_var) { UCEErrorMsgBox(" error: failed to get build path access"); return FALSE; } CATPathElement * pInputContext = new CATPathElement(); if (pInputContext==NULL) return FALSE; pInputContext -> AddChildElement (spRootProduct); CATPathElement* pFatherPathElement; HRESULT rs=spiBuildPathAccess -> ExtractPathElement (pInputContext, &pFatherPathElement); pInputContext -> Release(); pInputContext = NULL; if(FAILED(rs)) { return FALSE; } // BOOL bState=UCEGetPathElementFromSpecObject(pPathElement,spSpecObject,pFatherPathElement); // pFatherPathElement->Release(); pFatherPathElement=NULL; // return bState; }