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: 

EntityOne and EntityTwo in a FlushConstraint, C++

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

EntityOne and EntityTwo in a FlushConstraint, C++

I can use the following C++ code to loop over the constraints in an assembly:

 

 

    for (int i = 1 ; i <= pConstraintList->Count ; i++) {
        CComPtr<AssemblyConstraint> pConstraint = nullptr ;
        pConstraintList->get_Item (CComVariant(i),&pConstraint) ;
        TRACE ("Type is %d\n",pConstraint->GetType()) ;
        CComQIPtr<FlushConstraint> pFlush (pConstraint) ;
        if (nullptr != pFlush) {
            IDispatchPtr pEnt1 = pFlush->EntityOne  ;
            IDispatchPtr pEnt2 = pFlush->EntityTwo  ;
            TRACE (L"Two parts are %p %p\n",pEnt1,pEnt2) ;
            // The question is, how to convert to PartDocument pointers???
        }
    }

 

But how do I convert from EntityOne to (for example) a PartDocument. I've experimented with all sorts of casts and conversions, but cannot get a CComPtr<PartDocument> from an IDispatchPtr

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

Hi,

 

You cannot cast EntityOne to a PartDocument because it is a FaceProxy. Just wrote an article that should be of help:
http://adndevblog.typepad.com/manufacturing/2013/10/discover-object-model.html 

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 4
oransen
in reply to: adam.nagy

Ok, thanks for the link, now I undestand better. The 2 entities can also be WorkPlaneProxy not just FaceProxy.

 

I've changed my sources and can now get to the document,file, part etc like this:

 

    for (int i = 1 ; i <= pConstraintList->Count ; i++) {
        CComPtr<AssemblyConstraint> pConstraint = nullptr ;
        pConstraintList->get_Item (CComVariant(i),&pConstraint) ;
        TRACE ("Type is %d\n",pConstraint->GetType()) ;
        CComQIPtr<MateConstraint> pMate (pConstraint) ;
        if (nullptr != pMate) {
            IDispatchPtr pEnt1 = pMate->EntityOne  ;
            IDispatchPtr pEnt2 = pMate->EntityTwo  ;
            CComQIPtr<FaceProxy> pFace1 = CComQIPtr<FaceProxy>(pEnt1);
            CComQIPtr<WorkPlaneProxy> pWP1 = CComQIPtr<WorkPlaneProxy>(pEnt1);
            if (pFace1 != nullptr) {
                TRACE (L"  Ent1 is a face proxy...\n") ;
            
            } else if (pWP1 != nullptr) {
                TRACE (L"  Ent1 is a workplane proxy...\n") ;
                CComPtr<ComponentOccurrence> pContOcc = pWP1->ContainingOccurrence ;
                if (pContOcc != nullptr) {
                    CComPtr<ReferencedFileDescriptor> pFileDesc = nullptr ;
                    pContOcc->get_ReferencedFileDescriptor (&pFileDesc) ;
                    if (pFileDesc != nullptr) {
                        CComBSTR bstrFullFileName ;
                        pFileDesc->get_FullFileName (&bstrFullFileName) ;
                        TRACE (L"  Ent1 full file name is %s\n",bstrFullFileName) ;
                    }
                }

            } else {
                TRACE (L"  Ent1 This is neither a face or workplane proxy\n") ;
            }
        }
    }

 

Can the entities be anything else, apart from Face or WorkPlane proxies?

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

Hi,

 

Yes, I forgot about WorkPlane's.

Well, it would need to be something with a plane, so I think it's only face and workplane.

 

But if you go down the other route: Constraint > AffectedOccurrenceOne >... then it does not even matter what EntityOne is.

 

Cheers,



Adam Nagy
Autodesk Platform Services

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

Post to forums  

Autodesk Design & Make Report