Adding and deleting constraints after model states changed

Adding and deleting constraints after model states changed

stewart_sabadell
Participant Participant
95 Views
0 Replies
Message 1 of 1

Adding and deleting constraints after model states changed

stewart_sabadell
Participant
Participant

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

0 Likes
96 Views
0 Replies
Replies (0)