Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
oransen
648 Views, 3 Replies

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

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

3 REPLIES 3
Message 2 of 4
oransen
in reply to: oransen

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?

 

Message 3 of 4
adam.nagy
in reply to: oransen

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
in reply to: adam.nagy

Ah, thanks. Easy when you know how!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report