I'm attempting to scan a DGN model using the DgnPlatformNet. I'm using the ScanCriteria Class. When I scan with no filters, everything works and I see all the elements in the DGN model.
When I set an element type filter using SetElementTypeTest I see problems. Here's how I'm setting the type mask...
public static ScanCriteria AddElementTypes(this ScanCriteria criteria, params MSElementType[] types) { var bitMask = new BitMask(false); foreach (var type in types) bitMask.SetBit((uint)type - 1, true); StringBuilder s = new StringBuilder(); s.AppendFormat("AddElementTypes MSElementType {0} bit mask {1}...", types[0], bitMask.ToString (0)); ElementScanner.ShowMessage(s.ToString()); criteria.SetElementTypeTest(bitMask); return criteria; }
The message tells you what one would expect: that is, the appropriate bit of the mask is set. We scan like this...
public UInt32 Scan(MSElementType[] types) { nElements_ = 0; ScanCriteria criteria = new ScanCriteria(); criteria.SetDrawnElements(); criteria.SetModelRef(model_); criteria.AddElementTypes (types); criteria.Scan(ElementProcessor); return nElements_; }
public StatusInt ElementProcessor(Element el, DgnModelRef modelRef){ ++nElements_; StringBuilder s = new StringBuilder(); s.AppendFormat("Element [{0}] ID {1} type {2}", nElements_, el.ElementId, el.ElementType); ElementScanner.ShowMessage(s.ToString()); return StatusInt.Success; }
This works for elements such as line and shape. It doesn't work for elements of higher value MSElementType such as Arc, Ellipse or Tag. What am I doing wrong?
Please give the following code a try to see if it helps:
class ElementProcessor { public StatusInt ProcessElement(Element el, DgnModelRef model) { // Process elements here StringBuilder s = new StringBuilder(); s.AppendFormat("Element: {0}[{1}], ElementID: {2}", el.ToString(), el.ElementType, el.ElementId); System.Diagnostics.Trace.WriteLine("Element Details - " + s); return StatusInt.Success; } } private static void Test() { // Set element types to process MSElementType[] elTypes = new MSElementType[] { MSElementType.Line, MSElementType.Shape }; foreach (DGN.MSElementType elType in elTypes) { // Create bitmask for each element type to be scanned/enumerated DGN.BitMask bmType = new DGN.BitMask(false); bmType.Set((uint)elType - 1); uint bmSize = 1 + (uint)elType; bmSize = (bmSize + 7) / 8; bmSize = (bmSize * 16) - 15; bmType.EnsureCapacity(bmSize + 1); // Set bitmask size // Set model and scanner criteria DgnModelRef model = Session.Instance.GetActiveDgnModel(); DGN.ScanCriteria sc = new DGN.ScanCriteria(); sc.SetElementTypeTest(bmType); sc.SetModelRef(model); sc.SetModelSections(DGN.DgnModelSections.GraphicElements); // Create a ScanDelegate to allow each element to be processed ElementProcessor ep = new ElementProcessor(); ScanDelegate scanDelegate = new ScanDelegate(ep.ProcessElement); sc.Scan(scanDelegate); } }HTH,
Bob
Answer Verified By: Jon Summers
Thanks, Bob. I hadn't spotted that the Bitmask is a Bentley.DgnPlatformNET class, nor that it requires its capacity to be calculated.
Regards, Jon Summers LA Solutions