Assembly UCS to Part UCS constraint (C++)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
My need is to assembly parts into an assembly by a known position in the assembly. The part has a UCS and I create UCS on the assembly programmatically. What I cannot do is to constrain the two UCS.
I tried this (Inventor 2013 x64 on W7/W8 64, c++ 2010 by the way DEBUG mode is not working from the IDE):
-
CAssemblyComponentDefinition compDef = doc.get_ComponentDefinition();
// MOdules UCS
CUserCoordinateSystems coords = compDef.get_UserCoordinateSystems();
CTransientGeometry geom = m_InventorApp.get_TransientGeometry();
CMatrix matrix = geom.CreateMatrix();
CComponentOccurrences assOcc = compDef.get_Occurrences();
matrix.SetTranslation(geom.CreateVector(x, y, z,FALSE);
// ADD Part
// aggiunge la parte
CComponentOccurrence cmpOcc = assOcc.Add(parteName, matrix);
// GET UCS FROM PART
CPartDocument part = docs.Open(parteName,TRUE);
CPartComponentDefinition partDef = part.get_ComponentDefinition();
// Part UCSs
CUserCoordinateSystems coords = partDef.get_UserCoordinateSystems();
CUserCoordinateSystem partUCS = coords.get_Item(COleVariant(_T("UCS1")));
CUserCoordinateSystemProxy newPrxUCS ;
cmpOcc.CreateGeometryProxy(partUCS, &newPrxUCS.m_lpDispatch );
// Create a new UCS in assembly, work good
CUserCoordinateSystem newUCS ;
newUCS = AddUCS(NewModuleName, CPointPosition, CPointRotation,newUCS);
//' Create the insert constraint between the parts.
CAssemblyConstraints vincs = compDef.get_Constraints();
COleVariant vtNull( DISP_E_PARAMNOTFOUND, VT_ERROR);
THIS BREAK INVENTOR
CMateConstraint mate = vincs.AddMateConstraint(newUCS, newPrxUCS, COleVariant(short(0)),kNoInference ,kNoInference ,vtNull,vtNull);
Thanks for any help!