public static void Run() { BCOM.ElementScanCriteria scanCriteria = new BCOM.ElementScanCriteriaClass(); scanCriteria.ExcludeAllTypes(); scanCriteria.ExcludeNonGraphical(); scanCriteria.IncludeType(BCOM.MsdElementType.CellHeader); scanRecurse(App.ActiveModelReference, scanCriteria); }
public static void ExportToCsv() { BCOM.ModelReference model = App.ActiveModelReference; BCOM.ElementScanCriteria criteria = new BCOM.ElementScanCriteriaClass(); criteria.ExcludeAllTypes(); criteria.ExcludeNonGraphical(); criteria.IncludeType(BCOM.MsdElementType.CellHeader); BCOM.ElementEnumerator iter = App.ActiveModelReference.Scan(criteria); var builder = new StringBuilder(); string dltr = ";"; while (iter.MoveNext()) { BCOM.Element element = iter.Current; XDocument xDoc = ElementHelper.getSp3dXDocument(element.ToElement()); var dgPropColl = new Dictionary <Sp3dToDataGroupMapProperty, string>(); Sp3dToDGMapping.Instance.LoadValuesFromXDoc(xDoc, dgPropColl, true); if (builder.Length == 0) { // строка заголовков: builder.Append("ElementId"); foreach (var pair in dgPropColl) { builder.Append(dltr + pair.Key.TargetName); } builder.AppendLine(); } builder.Append(element.ID); foreach (var pair in dgPropColl) { builder.Append(dltr + pair.Value); } builder.AppendLine(); } string path = Path.ChangeExtension(App.ActiveDesignFile.FullName, ".csv"); File.WriteAllText(path, builder.ToString()); if (File.Exists(path)) { System.Diagnostics.Process.Start(path); App.MessageCenter.AddMessage($"SUCCESS: экспорт '{path}'", "", BCOM.MsdMessageCenterPriority.None, false); } else { App.MessageCenter.AddMessage($"FAILED: экспорт '{path}'", "", BCOM.MsdMessageCenterPriority.Warning, false); } }
//WS: keyin Command public static void ListTags(string unparsed) { GeoTagList oListForm = new GeoTagList(); BCOM.ElementScanCriteria oScanCriteria = new BCOM.ElementScanCriteriaClass(); oScanCriteria.ExcludeAllTypes(); oScanCriteria.IncludeType(BCOM.MsdElementType.CellHeader); BCOM.ElementEnumerator oEnum = AddInMain.ComApp.ActiveModelReference.Scan(oScanCriteria); while (oEnum.MoveNext()) { BCOM.CellElement oCel = null; if (oEnum.Current.IsCellElement()) { if (oEnum.Current.AsCellElement().Name == "Embankment" || oEnum.Current.AsCellElement().Name == "RetainWall" || oEnum.Current.AsCellElement().Name == "Pond" || oEnum.Current.AsCellElement().Name == "Road" || oEnum.Current.AsCellElement().Name == "OpenChannel" || oEnum.Current.AsCellElement().Name == "Dike") { oCel = oEnum.Current.AsCellElement(); ECInstanceList oECInstancelist = GeoTagList.oECAdaptor.ReadInstancesFromElement(oCel, false); foreach (ECInstance oEC in oECInstancelist) { if (oEC.ClassDefinition.Name == "Embankment" || oEC.ClassDefinition.Name == "RetainWall" || oEC.ClassDefinition.Name == "Pond" || oEC.ClassDefinition.Name == "Road" || oEC.ClassDefinition.Name == "OpenChannel" || oEC.ClassDefinition.Name == "Dike") { //WS: loop through each class instance, get properties enumerator. IEnumerator <IECProperty> pFields = oEC.ClassDefinition.GetEnumerator(true); //WS: get properties values enumberator.. IEnumerator <IECPropertyValue> pVals = oEC.GetEnumerator(true); while (pFields.MoveNext()) { pVals.MoveNext(); if (pFields.Current.Name == "Tag_Number") { oListForm.WriteLine("Tag: " + pVals.Current.XmlStringValue + "; ElementId: " + oCel.ID.ToString()); } } } } } } } oListForm.ShowDialog(); }
//public static BCOM.Level getLevel(string name) //{ // BCOM.Levels levels = App.ActiveDesignFile.Levels; // var activeModel = App.ActiveModelReference; // activeModel.Levels.IncludeHidden = true; // try // { // return activeModel.Levels[name]; // } // catch (Exception) {} // не найден // BCOM.Level activeLevel = App.ActiveSettings.Level; // try // { // Addin.Instance.sendKeyin( // string.Format("level set active {0}", name)); // activeModel.Levels.IncludeHidden = true; // return activeModel.Levels[name]; // } // catch (Exception) // { // return null; // } // finally // { // App.ActiveSettings.Level = activeLevel; // } //} //public static BCOM.Level getLevelOrActive(string name) //{ // return getLevel(name) ?? App.ActiveSettings.Level; //} /// <summary> /// Поиск пересечений с элементами по диапазону заданного элемента в /// в пространстве заданной модели /// </summary> public static IEnumerable <BCOM.Element> scanIntersectsInElementRange( this BCOM.Element element, BCOM.ModelReference model = null) { model = model ?? App.ActiveModelReference; BCOM.ElementScanCriteria criteria = new BCOM.ElementScanCriteriaClass(); criteria.ExcludeAllTypes(); criteria.ExcludeNonGraphical(); criteria.IncludeType(BCOM.MsdElementType.CellHeader); BCOM.Range3d scanRange = getElementScanRange(element, model); criteria.IncludeOnlyWithinRange(scanRange); return(model.Scan(criteria).BuildArrayFromContents()); }
public static void ScanBSplineSurface() { BCOM.Application app = Program.COM_App; BCOM.ElementScanCriteria sc = new BCOM.ElementScanCriteriaClass(); sc.ExcludeAllTypes(); sc.IncludeType(BCOM.MsdElementType.BsplineSurface); var ee = app.ActiveModelReference.Scan(sc); //var firstcurrent = ee.Current; var bsplinesurface = new List <BCOM.BsplineSurface>(); while (ee.MoveNext()) { bsplinesurface.Add(ee.Current.AsBsplineSurfaceElement().ExtractBsplineSurface()); } //foreach (var surface in bsplinesurface) //{ // //var surfacehandler = app.CreatePropertyHandler(surface); // //string s= surfacehandler.GetDisplayString(); //} BCOM.Point3d p1 = app.Point3dFromXYZ(200, 110, 100); BCOM.Ray3d ray1 = new Bentley.Interop.MicroStationDGN.Ray3d() { Origin = app.Point3dFromXYZ(200, 110, 100), Direction = app.Point3dFromXYZ(0, 0, -200) }; BCOM.Point3d insertpoint = app.Point3dZero(); BCOM.Point2d uv = app.Point2dZero(); foreach (var bsp in bsplinesurface) { if (bsp.IntersectRay3d(ref insertpoint, ref uv, ref ray1)) { string s = insertpoint.ToString(); string s2 = uv.ToString(); } } }
private void scanInfoPerModel(BCOM.ModelReference model) { BCOM.CellElement cell = getTaskCell(); if (cell == null) { return; } //BCOM.ModelReference activeModel = App.ActiveModelReference; BCOM.ElementScanCriteria criteria = new BCOM.ElementScanCriteriaClass(); criteria.ExcludeAllTypes(); criteria.ExcludeNonGraphical(); criteria.IncludeType(BCOM.MsdElementType.CellHeader); BCOM.Range3d scanRange = cell.Range; #if CONNECT // корректировака для версии CONNECT if (cell.ModelReference.IsAttachmentOf(model)) // TODO ПРОВЕРИТЬ { // здесь есть различия с V8i: double k = model.UORsPerStorageUnit / cell.ModelReference.UORsPerStorageUnit; scanRange.High = App.Point3dScale(scanRange.High, k); scanRange.Low = App.Point3dScale(scanRange.Low, k); } #endif criteria.IncludeOnlyWithinRange(scanRange); BCOM.ElementEnumerator res = model.Scan(criteria); foreach (BCOM.Element current in res?.BuildArrayFromContents()) { TFCOM.TFElementList tfList = AppTF.CreateTFElement(); tfList.InitFromElement(current); if (tfList.AsTFElement == null) { continue; } int tfType = tfList.AsTFElement.GetApplicationType(); if (tfList.AsTFElement.GetIsCompoundCellType()) { CompoundsIntersected.Add(tfList); } else if (tfList.AsTFElement.GetIsFormType()) { bool coorrectType = isAvaliableTFFromType(tfType); if (isAvaliableTFFromType(tfType)) { TFFormsIntersected.Add(tfList); } } } projectLocationPointOnTFForm(TFFormsIntersected); }
private void findFlanges() { BCOM.CellElement cell = getTaskCell(); if (cell == null) { return; } BCOM.ModelReference taskModel = // TODO App.MdlGetModelReferenceFromModelRefP(modelRefP); BCOM.ModelReference activeModel = App.ActiveModelReference; FlangesGeom.Clear(); // Поиск фланцев BCOM.ElementScanCriteria criteria = new BCOM.ElementScanCriteriaClass(); //criteria.IncludeOnlyVisible(); criteria.ExcludeAllTypes(); criteria.ExcludeNonGraphical(); criteria.IncludeType(BCOM.MsdElementType.CellHeader); BCOM.Range3d scanRange = cell.Range; // App.Range3dScaleAboutCenter(cell.Range, 1.01); if (taskModel.IsAttachment) { double k = taskModel.UORsPerStorageUnit / activeModel.UORsPerStorageUnit; scanRange.High = App.Point3dScale(scanRange.High, k); scanRange.Low = App.Point3dScale(scanRange.Low, k); } criteria.IncludeOnlyWithinRange(scanRange); BCOM.ElementEnumerator res = taskModel.Scan(criteria); foreach (BCOM.Element current in res?.BuildArrayFromContents()) { // todo использовать только один тип точек PenetrTaskFlange flangeTask = null; //Element curEl = Element.FromElementID((ulong)current.ID, // (IntPtr)current.ModelReference.MdlModelRefP()); if (PenetrTaskFlange.getFromElement(current, out flangeTask)) { BCOM.Range3d range = current.Range; if (flangeTask.Oid.Equals(Oid)) { FlangesGeom.Add(flangeTask); } } } //BCOM.Transform3d tran = App.Transform3dInverse( // App.Transform3dFromMatrix3d(Rotation)); //cell.Transform(tran); // TODO проверить корректность transform отн. rawLocation_ transformToBase(cell, rawLocation_); if (FlangesCount != FlangesGeom.Count) { Warnings.Add(string.Format("Несоответствие количества фланцев, " + "указанных в атрибутах - {0} и заданных геометрически - {1}", FlangesCount, FlangesGeom.Count)); } if (FlangesCount == 1 && FlangesGeom.Count > 0) { BCOM.Element flangeEl = taskModel.GetElementByID(FlangesGeom[0].elemId); //flangeEl.Transform(tran); // TODO проверить корректность transform отн. rawLocation_ transformToBase(flangeEl, rawLocation_); SingleFlangeSide = App.Vector3dSubtractPoint3dPoint3d( ElementHelper.getCenter(flangeEl), ElementHelper.getCenter(cell)); } else { SingleFlangeSide = App.Vector3dFromXYZ(0, 0, -1); } }