Here is the problem: we want to filter all parts which have the part position (or "part mark") of "p/2".
How can we do this programmatically?
Check out this code snippet - it assumes you have set up your references and are ready to go!
this.model = new Model();
if (model.GetConnectionStatus())
{
# first filter on parts
BinaryFilterExpressionCollection filterCollection = new BinaryFilterExpressionCollection();
var filterParts = new BinaryFilterExpression(new ObjectFilterExpressions.Type(), NumericOperatorType.IS_EQUAL, new NumericConstantFilterExpression(TeklaStructuresDatabaseTypeEnum.PART));
filterCollection.Add(new BinaryFilterExpressionItem(filterParts, BinaryFilterOperatorType.BOOLEAN_AND));
# then filter on part position
BinaryFilterExpression filterPositionNumber = new BinaryFilterExpression(new PartFilterExpressions.PositionNumber(), StringOperatorType.IS_EQUAL, new StringConstantFilterExpression("p/2"));
filterCollection.Add(new BinaryFilterExpressionItem(filterPositionNumber, BinaryFilterOperatorType.BOOLEAN_AND));
ModelObjectEnumerator filteredObjects = model.GetModelObjectSelector().GetObjectsByFilter(filterCollection);
List<ModelObject> parts = new List<ModelObject>();
foreach (ModelObject obj in filteredObjects)
{
Part filteredPart = (Part)obj;
string partMark = filteredPart.GetPartMark();
Debug.WriteLine(partMark);
}
}
Unfortunately the documentation is poor, and the API is even worse!