private BCOM.CellElement GroupGeoTagCell(string strCellName) { BCOM.CellElement oCel = null; try { AddInMain.ComApp.CadInputQueue.SendCommand("GROUP SELECTION"); //WS: can I use this .NET version of keyin instead of COM based as above? //Bentley.Internal.MicroStation.Session.Instance.Keyin("GROUP SELECTION"); BCOM.ElementEnumerator oEnum = AddInMain.ComApp.ActiveModelReference.GetSelectedElements(); while (oEnum.MoveNext()) { if (oEnum.Current.IsCellElement()) { oCel = oEnum.Current.AsCellElement(); break; } } oCel.Name = strCellName; oCel.Redraw(); oCel.Rewrite(); } catch { } return(oCel); }
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(); }
//WS: note: the drop command is uing MS built UI command, so always make sure element got selected first. private void btnDrop_Click(object sender, EventArgs e) { BCOM.CellElement oCel = null; BCOM.ElementEnumerator oEnum = AddInMain.ComApp.ActiveModelReference.GetSelectedElements(); BCOM.Element[] oEleSet = oEnum.BuildArrayFromContents(); if (oEleSet.Length != 1) { AddInMain.ComApp.CadInputQueue.SendCommand("CHOOSE NONE"); AddInMain.ComApp.CommandState.StartLocate(new DropTagCell()); } if (oEleSet.Length == 1) { if (oEleSet[0].IsCellElement()) { if (oEleSet[0].AsCellElement().Name == "Embankment" || oEleSet[0].AsCellElement().Name == "Dike" || oEleSet[0].AsCellElement().Name == "Pond" || oEleSet[0].AsCellElement().Name == "Road" || oEleSet[0].AsCellElement().Name == "OpenChannel" || oEleSet[0].AsCellElement().Name == "RetainWall") { oCel = oEleSet[0].AsCellElement(); oECAdaptor.DeleteInstancesOnElement(oCel, oCel.Name); //WS: delete the ECInstance first. //oECAdaptor.DeleteInstancesOnElement(oCel, "Tag"); BCOM.Point3d oPt = oCel.Origin; //WS: window pops up here AddInMain.ComApp.CadInputQueue.SendCommand("DROP ELEMENT"); AddInMain.ComApp.SetCExpressionValue("dropOptions.complex", -1, "DROP"); int iActiveViewNum = Commons.GetActiveViewIndex(); AddInMain.ComApp.CadInputQueue.SendDataPoint(ref oPt, iActiveViewNum); MessageBox.Show("Please re-select elements for old tag, and start Step 3."); btnSelect.Enabled = false; btnDrop.Enabled = false; btnEdit.Enabled = true; } else { AddInMain.ComApp.CadInputQueue.SendCommand("CHOOSE NONE"); AddInMain.ComApp.CommandState.StartLocate(new DropTagCell()); } } } }
private static void getSubElements_ <T>( BCOM.CellElement cell, List <T> coll) where T : BCOM.Element { BCOM.ElementEnumerator iter = cell.GetSubElements(); while (iter.MoveNext()) { if (iter.Current is T) { coll.Add((T)iter.Current); } else if (iter.Current.IsCellElement()) { getSubElements_ <T>(iter.Current.AsCellElement(), coll); } } }
//WS: click "Select" button private void btnSelect_Click(object sender, EventArgs e) { BCOM.ElementEnumerator oEnum = AddInMain.ComApp.ActiveModelReference.GetSelectedElements(); BCOM.Element[] oEleSet = oEnum.BuildArrayFromContents(); if (oEleSet.Length != 1) { AddInMain.ComApp.CadInputQueue.SendCommand("CHOOSE NONE"); AddInMain.ComApp.CommandState.StartLocate(new LocateEle()); } else //WS: check if a correct cell with tag is already selected. { if (oEleSet[0].IsCellElement()) { if (oEleSet[0].AsCellElement().Name == "Embankment" || oEleSet[0].AsCellElement().Name == "Dike" || oEleSet[0].AsCellElement().Name == "Pond" || oEleSet[0].AsCellElement().Name == "Road" || oEleSet[0].AsCellElement().Name == "OpenChannel" || oEleSet[0].AsCellElement().Name == "RetainWall") { BCOM.Element oEle = oEleSet[0]; ECInstanceList oECInstancelist = GeoTag.Tag.oECAdaptor.ReadInstancesFromElement(oEle, 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") { Commons.PopulateGeoTagForm(GeoTag.Tag.s_current, oEC); AddInMain.ComApp.ShowPrompt("Old Tag Data Retrived."); return; //Not necessary, but good practice. } } } else { AddInMain.ComApp.CadInputQueue.SendCommand("CHOOSE NONE"); AddInMain.ComApp.CommandState.StartLocate(new LocateEle()); } } } }
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); } }
private static void scanRecurse(BCOM.ModelReference model, BCOM.ElementScanCriteria criteria) { BCOM.ElementEnumerator iter = App.ActiveModelReference.Scan(criteria); var errorColl = new Dictionary <BCOM.Element, List <TagToDataGroupMapProperty> >(); var successList = new List <BCOM.Element>(); int summaryCount = 0; iter.Reset(); while (iter.MoveNext()) { IEnumerable <TagToDataGroupMapProperty> mapTags; if (!ScanElementHasMappingTags(iter.Current, out mapTags)) { continue; } ++summaryCount; var skippedProps = new List <TagToDataGroupMapProperty>(); foreach (TagToDataGroupMapProperty mapTag in mapTags) { bool res = DataGroupHelper.SetDataGroupPropertyValue(iter.Current, mapTag.DataGroupCatalogType, mapTag.DataGroupInstance, mapTag.DataGroupXPath, mapTag.TagName, mapTag.Value); if (!res) { skippedProps.Add(mapTag); } } if (skippedProps.Count == 0) { successList.Add(iter.Current); } else { errorColl.Add(iter.Current, skippedProps); } } string brief = $"Команда 'Экспорт свойств из Tags в DataGroup', успешно: {successList.Count()}/{summaryCount}"; var builder = new StringBuilder(); builder.AppendLine($"*** С ошибками: {errorColl.Count()} из {summaryCount}"); if (errorColl.Count() > 0) { foreach (var pair in errorColl) { var element = pair.Key; var errProps = pair.Value; builder.AppendLine(element.ID.ToString() + ":"); foreach (TagToDataGroupMapProperty prop in errProps) { builder.AppendLine(" -" + XmlSerializerEx.ToXml(prop)); } } } builder.Append("\n\n"); builder.AppendLine($"*** Успешно: {successList.Count()} из {summaryCount}"); if (successList.Count() > 0) { foreach (var element in successList) { builder.AppendLine(element.ID.ToString()); } } #if V8i App.MessageCenter.AddMessage(brief, builder.ToString(), BCOM.MsdMessageCenterPriority.Info, true); #elif CONNECT Bentley.MstnPlatformNET.MessageCenter.Instance.ShowMessage(MessageType.Info, brief, builder.ToString(), MessageAlert.Dialog); #endif // TODO ОБРАБОТКА РЕФЕРЕНСОВ //foreach (BCOM.Attachment attachment in model.Attachments) //{ // if (!attachment.IsActive || !attachment.IsMissingFile || !attachment.IsMissingModel) // return; // ModelReference modelRef = // App.MdlGetModelReferenceFromModelRefP(attachment.MdlModelRefP()); // scanRecurse(modelRef, criteria); //} }
private bool ApplyTagFromUI2Selection(string strFunctionCode) { bool retVal = false; try { GeoTagDataBase oGeoTagDataBase = null; string strClassName = Commons.MapFunctionCode2ClassName(strFunctionCode); if (strFunctionCode == "PND") { oGeoTagDataBase = new Pond(); } else if (strFunctionCode == "ROAD") { oGeoTagDataBase = new Road(); } else if (strFunctionCode == "CHN") { oGeoTagDataBase = new OpenChannel(); } else if (strFunctionCode == "EMB") { oGeoTagDataBase = new Embankment(); } else if (strFunctionCode == "DIKE") { oGeoTagDataBase = new Dike(); } else if (strFunctionCode == "RW") { oGeoTagDataBase = new RetainWall(); } oGeoTagDataBase.Tag_Number = this.lblTagValue.Text; oGeoTagDataBase.Tag_Status = this.cmbTagStatus.Text; oGeoTagDataBase.Location = this.txtLocation.Text; oGeoTagDataBase.Service_Description = this.txtSerDesc.Text; oGeoTagDataBase.Type = this.cmbType.Text; oGeoTagDataBase.Plot_Plan_Document_Number = this.txtPlotPlan.Text; oGeoTagDataBase.Detail_Drawing_Document_Number = this.txtDetailDwg.Text; oGeoTagDataBase.Construction_Month = this.dateTimePickerMon.Text; oGeoTagDataBase.Construction_Year = this.dateTimePickerYear.Text; oGeoTagDataBase.Originating_Contractor = this.txtOriContractor.Text; oGeoTagDataBase.Document_Number = this.txtDocNo.Text; oGeoTagDataBase.Material_Main = this.cmbMaterial.Text; oGeoTagDataBase.Procument_Package_Number = this.txtProcumentPkg.Text; oGeoTagDataBase.Contract_Package_Number = this.txtContractPkgNo.Text; oGeoTagDataBase.Construction_Contractor_Name = this.txtConstrContractor.Text; oGeoTagDataBase.Construction_Specification_Document_Number = this.txtConstrSpec.Text; if (oGeoTagDataBase is Pond) { (oGeoTagDataBase as Pond).Supplier_Name = this.txt17.Text; (oGeoTagDataBase as Pond).Design_Capacity = this.txt19.Text; (oGeoTagDataBase as Pond).Fluid_Description = this.txt16.Text; (oGeoTagDataBase as Pond).Max_Fluid_Level = this.txt20.Text; (oGeoTagDataBase as Pond).Supplier_Reference_Drawing_Doc_Number = this.txt18.Text; } if (oGeoTagDataBase is Road) { (oGeoTagDataBase as Road).Number_of_Lanes = this.txt16.Text; } if (oGeoTagDataBase is OpenChannel) { (oGeoTagDataBase as OpenChannel).Fluid_Description = this.txt16.Text; } BCOM.CellElement oCel = null; BCOM.ElementEnumerator oEnum = AddInMain.ComApp.ActiveModelReference.GetSelectedElements(); BCOM.Element[] oEleSet = oEnum.BuildArrayFromContents(); if (oEleSet.Length < 1) { return(false); } //WS: if a tagged celll is selected. if (oEleSet.Length == 1) { if (oEleSet[0].IsCellElement()) { if (oEleSet[0].AsCellElement().Name == "Embankment" || oEleSet[0].AsCellElement().Name == "RetainWall" || oEleSet[0].AsCellElement().Name == "Pond" || oEleSet[0].AsCellElement().Name == "Road" || oEleSet[0].AsCellElement().Name == "OpenChannel" || oEleSet[0].AsCellElement().Name == "Dike") { oCel = oEleSet[0].AsCellElement(); } } } else //WS: when more than 1 elements selected. { oCel = GroupGeoTagCell(strClassName); } if (oCel == null) { return(false); } AttachInstanceAndValues(oCel, strClassName, oGeoTagDataBase); retVal = true; } catch (Exception) { throw new Exception("Unexpected error: GeoTag.ApplyTagFromUI2Selection"); } return(retVal); }
public static void selectZons(ref BCOM.ElementEnumerator oEnum, ref DataZone oSelZone) { BCOM.Element oElem = default(BCOM.Element); List <BCOM.Element> MVFlyingStays = new List <BCOM.Element>(); //MVFlyingStay Program.MSApp.ActiveModelReference.UnselectAllElements(); while (oEnum.MoveNext()) { oElem = oEnum.Current; //Debug.Print CStr(oEnum.Current.ID.high) & CStr(oEnum.Current.ID.low) switch (oElem.Type) { case BCOM.MsdElementType.CellHeader: //Cells switch (oElem.AsCellElement().Name) { case "001": //LVStays oSelZone.LVStays.Add(oElem.ID, oElem); // (oElem, Convert.ToString(oElem.ID)); break; case "002": //LVStruts oSelZone.LVStruts.Add(oElem.ID, oElem); break; case "003": //MVStays oSelZone.MVStays.Add(oElem.ID, oElem); break; case "004": //MVStruts oSelZone.MVStruts.Add(oElem.ID, oElem); break; case "005": //TRFRCircles oSelZone.TRFRCircles.Add(oElem.ID, oElem); break; case "006": //TRFRNameplates" oSelZone.TRFRNameplates.Add(oElem.ID, oElem); break; case "009": //LVpoles" oSelZone.LVpoles.Add(oElem.ID, oElem); break; case "010": //MVpoles" oSelZone.MVpoles.Add(oElem.ID, oElem); break; case "011": //MVSharingPoles oSelZone.MVSharingPoles.Add(oElem.ID, oElem); break; case "012": //KickerPoles" oSelZone.KickerPoles.Add(oElem.ID, oElem); break; case "015": //LVFlyingStays" oSelZone.LVFlyingStays.Add(oElem.ID, oElem); break; case "016": //LVShortStays oSelZone.LVShortStays.Add(oElem.ID, oElem); break; case "017": //MVFlyingStays" oSelZone.MVFlyingStays.Add(oElem.ID, oElem); break; case "018": //MVShortStays oSelZone.MVShortStays.Add(oElem.ID, oElem); break; case "035": //MVFuseIsolators oSelZone.MVFuseIsolators.Add(oElem.ID, oElem); break; case "TXTCS": //TRFRs oSelZone.TRFRs.Add(oElem.ID, oElem); break; default: oSelZone.elseCellElements.Add(oElem.ID, oElem); break; } break; case BCOM.MsdElementType.Line: switch (oElem.Level.Name) { case "Level 18": // Airdac oSelZone.Airdac.Add(oElem.ID, oElem); break; //Debug.Print CStr(oEnum.Current.ID.high) & CStr(oEnum.Current.ID.low) case "Level 25": //LVConductor oSelZone.LVConductor.Add(oElem.ID, oElem); break; case "Level 29": //MVConductor oSelZone.MVConductor.Add(oElem.ID, oElem); break; default: oSelZone.elseLineElements.Add(oElem.ID, oElem); break; } break; case BCOM.MsdElementType.Shape: switch (oElem.Level.Name) { case "Level 11": //TrfrShapes oSelZone.TrfrShapes.Add(oElem.ID, oElem); break; default: oSelZone.elseShapeElements.Add(oElem.ID, oElem); break; } break; case (BCOM.MsdElementType.Text): switch (oElem.Level.Name) { case "Level 3": //houseText oSelZone.houseText.Add(oElem.ID, oElem); break; default: oSelZone.elseTextElements.Add(oElem.ID, oElem); break; } break; default: oSelZone.elseElements.Add(oElem.ID, oElem); break; } } Debug.Print(oSelZone.ToString()); Debug.Print(oSelZone.mergedMVPolesList().Count.ToString()); Debug.Print(oSelZone.printCoordinatesMVPoles()); Debug.Print(oSelZone.printCoordinatesMVLines()); }
public static void selectConductor(string conType) { BCOM.Element oElem; // = default(BCOM.Element); BCOM.Fence ofence; // = default(Fence); BCOM.ElementEnumerator oEnum = default(BCOM.ElementEnumerator); int color = 0; string levelName = null; bool stats = false; stats = false; switch (conType) { case "Service Cable": color = 0; levelName = "Level 18"; break; case "LV Lines": color = 2; levelName = "Level 25"; break; case "MV Lines": color = 3; levelName = "Level 29"; break; case "Stats": stats = true; break; default: MessageBox.Show("Invalid conductor"); break; } Program.MSApp.ActiveModelReference.UnselectAllElements(); ofence = Program.MSApp.ActiveDesignFile.Fence; oEnum = ofence.GetContents(); while (oEnum.MoveNext()) { oElem = oEnum.Current; if ((oElem.Type == BCOM.MsdElementType.Line | oElem.Type == BCOM.MsdElementType.LineString)) { if (!stats) { if ((oElem.Color == color & oElem.Level.Name == levelName)) { oElem.Redraw(BCOM.MsdDrawingMode.Hilite); Program.MSApp.ActiveModelReference.SelectElement(oElem); } } else { if ((oElem.Color == color & oElem.Level.Name == levelName)) { oElem.Redraw(BCOM.MsdDrawingMode.Hilite); Program.MSApp.ActiveModelReference.SelectElement(oElem); } } } } }