Given the list of AssemblyConstraints how do I list them textually? For example
// error checking removed for brevity CComPtr<AssemblyConstraints> pConstraintList; pAssDef->get_Constraints(&pConstraintList) ; _tprintf_s (_T("The assembly has %d constraints\n"),pConstraintList->Count); const int ikNum = pConstraintList->Count ; for (int iConstraint = 0 ; iConstraint < ikNum ; i++) { CComPtr<AssemblyConstraint> pConstraint; hr = pConstraintList->... what to put here? ... how to print out more data here...? }
How do I get each constraint from the list? And if there is some example of printing out the data that would be good too. I'd need a C++ solution...
Solved! Go to Solution.
Solved by adam.nagy. Go to Solution.
I've managed to get halfway there:
const int ikNumConstraints = pConstraintList->Count ; for (int j = 1 ; j <= ikNumConstraints ; j++) { CComPtr<AssemblyConstraint> pConstraint; hRes = pConstraintList->get_Item(CComVariant(j),&pConstraint) ; if (FAILED(hRes)) { _tprintf_s (_T("Could not get the constraint %d of the assembly, hr=%X\n"),j,hRes); return ; } _tprintf_s (_T("Got constraint %d\n"),j); // details???? }
but how to get textual descriptions of the contraints?
Hi,
Different constraints have different properties. So once you have the specific constraint then you can collect the information from them. E.g.:
HRESULT hRes; CComQIPtr<AssemblyDocument> pDoc = pInvApp->ActiveDocument; CComPtr<AssemblyConstraints> pConstraintList = pDoc->ComponentDefinition->Constraints; const int ikNumConstraints = pConstraintList->Count ; for (int j = 1 ; j <= ikNumConstraints ; j++) { CComPtr pConstraint; hRes = pConstraintList->get_Item(CComVariant(j),&pConstraint) ; if (FAILED(hRes)) { _tprintf_s (_T("Could not get the constraint %d of the assembly, hr=%X\n"),j,hRes); return NOERROR; } _tprintf_s (_T("Got constraint %d\n"), j); _tprintf_s (_T("Name = %s\n"), (LPCTSTR)pConstraint->Name); CComQIPtr<MateConstraint> pMate = pConstraint; if (pMate != NULL) { // print info } CComQIPtr<AngleConstraint> pAngle = pConstraint; if (pAngle != NULL) { // print info _tprintf_s (_T("Angle = %s\n"), (LPCTSTR)pAngle->Angle->Expression); } }
I hope this helps.
Cheers,