Adding a flush constraint using workplanes |
Top Previous Next |
Here is an example, which shows that you must use geometrical proxies, assuming you have a CComQIPtr<AssemblyDocument> pAsmDoc to start off with.
/* * Get the assembly definition which contains the actual "stuff"... */ CComPtr<AssemblyComponentDefinition> pAssemblyCompDef = nullptr ; hRes = pAsmDoc->get_ComponentDefinition(&pAssemblyCompDef);
/* * Get the list of occurrences so that you can add two cyliders to it... */ CComPtr<ComponentOccurrences> pOccurrencesList=nullptr; hRes = pAssemblyCompDef->get_Occurrences (&pOccurrencesList) ;
/* * Create some geometries to place the parts in space... */ CComPtr<TransientGeometry> pTransGeom = nullptr ; pInvApp->get_TransientGeometry(&pTransGeom); CComPtr<Matrix> pPosMatrix = nullptr ; hRes = pTransGeom->CreateMatrix(&pPosMatrix); // Defaults to 0 0 0
CComPtr<ComponentOccurrence> pCyl1Occ = nullptr; hRes = pOccurrencesList->Add (CComBSTR(L"C:\\TEST\\Cyl1.ipt"),pPosMatrix,&pCyl1Occ) ;
CComQIPtr<PartComponentDefinition> pCyl1CompDef = CComQIPtr<PartComponentDefinition>(pCyl1Occ->Definition); CComPtr<WorkPlane> pWorkPlane1=nullptr ; hRes = pCyl1CompDef->WorkPlanes->get_Item(CComVariant(L"XY Plane"),&pWorkPlane1);
CComPtr<WorkPlaneProxy> pWPProxy1 ; pCyl1Occ->CreateGeometryProxy (pWorkPlane1,(IDispatch**)&pWPProxy1) ;
CComPtr<ComponentOccurrence> pCyl2Occ = nullptr; hRes = pOccurrencesList->Add (CComBSTR(L"C:\\TEST\\Cyl2.ipt"),pPosMatrix,&pCyl2Occ) ; CComQIPtr<PartComponentDefinition> pCyl2CompDef = CComQIPtr<PartComponentDefinition>(pCyl2Occ->Definition); CComPtr<WorkPlane> pWorkPlane2 ; hRes = pCyl2CompDef->WorkPlanes->get_Item(CComVariant(L"YZ Plane"),&pWorkPlane2); CComPtr<WorkPlaneProxy> pWPProxy2 ; pCyl2Occ->CreateGeometryProxy (pWorkPlane2,(IDispatch**)&pWPProxy2) ;
// Get the list of constraints of the assembly so you can add a new one CComPtr<AssemblyConstraints> pConstraintList = nullptr ; hRes = pAssemblyCompDef->get_Constraints(&pConstraintList) ;
CComVariant varEmpty, varReal(0.0); CComPtr<FlushConstraint> pFC = nullptr ; hRes = pConstraintList->AddFlushConstraint (pWPProxy1,pWPProxy2, varEmpty, varEmpty, varEmpty,&pFC);
|
Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)