Constraints for all objects

Technical discussions
Post Reply
Grassimo
Posts: 4
Joined: Fri Jul 26, 2013 8:35 am

Constraints for all objects

Post by Grassimo »

Hi
I decided to test a model with several objects (Light.glm) in C# Modal view sample.

It loaded adequately and with the "Modify" mode (rbModify)
checked:

1- If "Highlight Current Object" (checkHighLight) is checked, clicking an object make it highlighted, as expected.
2- If "Enable Constraint" (checkContraint) is checked, all the options of the translation and rotation constraints apply
ONLY to the Box, which was set as the "current object" of the model.The other objects are not constrained at all.

I have tried unsuccessfully to modify the code, particularly the line 532 (m_iSection = iModel.GetSection(0);).
As a non-programmer, even observing the source codes of other samples who deal with several objects, I was not able to solve
this issue; so I am looking for some tips on how to make the constraints apply to ALL the objects of the model.

Thanks a lot

gerard12
Posts: 21
Joined: Fri Jul 26, 2013 8:34 am

Re: Constraints for all objects

Post by gerard12 »

Hello Grassimo



The problem is that the constraint is enabled (in checkContraint_CheckedChanged method) and applied in the program to a fixed (hard coded) section (object) number 0. Because m_iSection was obtained as object 0 in Form1_Load.



The simplest way to apply a constraint to several objects is to make all other objects children of the first one. So they will form a group and will be moved together as a solid object. After that Modal sample will work as you expect.



To do the above open Model Explorer: Right click > Advanced > Model Explorer. Click on the top object in the tree. Press “Set current” button. Than select the second object in the tree and in the menu of the Explorer select Action > Join. The second object will appear under the top one. Repeat the same for all other objects and save.



You can do the same programmatically like in Object Array sample or in Modeling Studio.



Another method to apply a constraint to the object, which just has been clicked on, needs slightly more work. It uses IModel2 interface and is demonstrated in Morph sample. You would need to change m_iSection and the constraint in response to change in the currently selected object.

Gerard

Grassimo
Posts: 4
Joined: Fri Jul 26, 2013 8:35 am

Re: Constraints for all objects

Post by Grassimo »

Thank you very much. I got it working
Grassimo

Post Reply