How to get details of a constraint from a list of Assembly constraints? C++

How to get details of a constraint from a list of Assembly constraints? C++

oransen
Collaborator Collaborator
796 Views
3 Replies
Message 1 of 4

How to get details of a constraint from a list of Assembly constraints? C++

oransen
Collaborator
Collaborator

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...

0 Likes
Accepted solutions (1)
797 Views
3 Replies
Replies (3)
Message 2 of 4

oransen
Collaborator
Collaborator

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?

 

0 Likes
Message 3 of 4

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

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,



Adam Nagy
Autodesk Platform Services
Message 4 of 4

oransen
Collaborator
Collaborator
Ah, thanks. Easy when you know how!

0 Likes