Assembly UCS to Part UCS constraint (C++)

Assembly UCS to Part UCS constraint (C++)

Anonymous
Not applicable
936 Views
3 Replies
Message 1 of 4

Assembly UCS to Part UCS constraint (C++)

Anonymous
Not applicable

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!

 

0 Likes
937 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

Hello again,

Can someone help on this ? I could not find any information in any blogs or samples. I remember also another post on this.

 

Just a few guidelines...

 

Thank you

Fabio

0 Likes
Message 3 of 4

philippe.leefsma
Alumni
Alumni

Hi Fabio,

 

Pay attention to the comments in the Help Files for AddMateConstraint method, UCS is not a supported entity:

 

Method that creates a new mate assembly constraint. The two input entities can be a combination of planar faces, linear edges, vertices, cylindrical faces, conical faces, spherical faces, revolved faces, work planes, work axes, and work points

 

You could use instead the UCS elements (Axis and Origin) which are supported to create a mate. For example constrain the origin work points and two axis...

 

Regards,

Philippe.

 

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 4 of 4

Anonymous
Not applicable

Thanks a lot Philippe

I was aware that UCS was not mentioned inside documentation for AddMateConstraint, but I coul dnot find any info or suggestions and so I gave it a try....

 

I have the hint now and I will make some test with UCS elements and post a solution (if I succeed...)

 

Regards

FAbio

0 Likes