By Wayne Brill
This C++ sample uses the selection set and deletes constraints found in the selected occurrences and their suboccurrences. When manipulating entities in the SelectSet, keep in mind that any change in the database resets the set. To avoid problems store the entities you want to change. This example uses an ObjectCollection to store the selected entities.
Download Delete_Constraints_Test
Here is the code that stores the selected components:
CComPtr<ObjectCollection> ObjColl =
TransObj->CreateObjectCollection(vopt);
for (int index = 1; index <= count; index++)
{
// it could even be just a folder
try
{
//get the selected entity
CComPtr<IDispatch> SelectedEntity =
SelSet->GetItem(index);
ObjColl->Add(SelectedEntity);
} catch (...) {}
}
Here is the code that deletes the constraints:
void CTestDlg::deleteConstraints
(ComponentOccurrence* CompOcc,
bool AlsoInSubOccurrences)
{
CComPtr<ComponentOccurrencesEnumerator>
SubOccs = NULL;
CComPtr<AssemblyConstraintsEnumerator>
AssCons = CompOcc->GetConstraints();
long count = AssCons->GetCount();
while (count > 0)
{
CComPtr<AssemblyConstraint> AssCon =
AssCons->GetItem(CComVariant(count));
AssCon->Delete();
AssCons = CompOcc->GetConstraints();
count = AssCons->GetCount();
}
if (!AlsoInSubOccurrences)
return;
SubOccs = CompOcc->GetSubOccurrences();
count = SubOccs->GetCount();
for (long i = 1; i <= count; i++)
{
CComPtr<ComponentOccurrence>
SubOcc = SubOccs->GetItem(i);
deleteConstraints(SubOcc, true);
}
}