Adding and deleting constraints after model states changed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I am learning how to add and delete objects in an assembly when multiple model states are present. Our specific situation has to do with deleting and adding constraints.
The code below works for an assembly (with sub-assemblies) where there is just one model state throughout, or, if the model state has not been changed within this session.
// Incoming objects
InsertConstraint ic1; // existing constraint obtained from the assembly
ComponentOccurrence selOcc; // from a selected object in the assembly
Edge newEdge1; // obtained from ic1.EntityOne.Faces through additional logic
AssemblyComponentDefinition parentForConstraint = ic1.Parent;
object oEdge2_ic1 = ic1.EntityTwo;
ic1.Delete();
selOcc.CreateGeometryProxy(newEdge1, out object oEdge1);
ic1 = parentForConstraint.Constraints.AddInsertConstraint(oEdge1, oEdge2_ic1, true, 0);
However, when multiple model states are present, and may be different in sub-assemblies, and/or the model state of one sub assembly has changed, this code will fail. The first failure comes from the call to ic1.Delete(). I have some code I use that looks at ic1.Parent.IsModelStateMember, and if so, gets the FactoryDocument.ComponentDefinition and looks up the constraint by name, then deletes that instance. This seems to work, to delete the constraint.
It then fails on the call to AddInsertConstraint().
Someone I am working with believes that the objects must all be in the correct "context" when working with model states. How can I accomplish that here?
Thanks.
Stew Sabadell