/// <summary> /// 生成表单 /// </summary> public static void AddCarTable() { Database db = HostApplicationServices.WorkingDatabase; using (var tr = db.TransactionManager.StartTransaction()) { //选择车 var cars = db.GetSelectionOfBlockRefs("\n选择车", false, carBlockName); if (cars.Count != 0) { //车类型、数量字典 var gCar = cars.GroupBy(d => d.ObjectId.GetDynBlockValue("类型")) .ToDictionary(d => d.Key, d => d.Count()); //文字样式 var tsId = db.AddTextStyle("index", "sceic.shx", "sceic.shx", 0.7); //设置表样式 var tableStyleId = db.AddTableStyle("Summary", "index", 350, CellAlignment.BottomCenter, 100); //表单 Table table = new Table(); table.TableStyle = tableStyleId; //表单大小 table.SetSize(2 + gCar.Count, 2); //设置列宽 foreach (var col in table.Columns) { col.Width = 2000; } //表头行 int row = 0; table.Cells[row, 0].Value = "车位统计"; //标题行 row++; table.Cells[row, 0].Value = "名称"; table.Cells[row, 1].Value = "数量"; //表单内容 for (int i = row + 1; i <= gCar.Count + row; i++) { var gc = gCar.ElementAt(i); table.Cells[i, 0].Value = gc.Key; table.Cells[i, 1].Value = gc.Value; } Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; //插入点 var ppr = ed.GetPoint(new PromptPointOptions("\n指定点")); //添加表单 if (ppr.Status == PromptStatus.OK) { table.Position = ppr.Value; db.AddToCurrentSpace(table); } } else { AcadApp.ShowAlertDialog("选中数量为0"); } tr.Commit(); } }
private Microsoft.Win32.RegistryKey GetAcadAppKey(bool forWrite) { string User = Environment.UserDomainName + "\\" + Environment.UserName; string RootKey = Autodesk.AutoCAD.DatabaseServices.HostApplicationServices.Current.UserRegistryProductRootKey; Microsoft.Win32.RegistryKey AcadKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(RootKey); RegistryAccessRule Role = new RegistryAccessRule(User, RegistryRights.WriteKey | RegistryRights.Delete | RegistryRights.ReadKey, AccessControlType.Allow); RegistrySecurity Rs = new RegistrySecurity(); Rs.AddAccessRule(Role); Microsoft.Win32.RegistryKey AppKey = AcadKey.OpenSubKey("Applications", forWrite); if (AppKey == null) { try { Microsoft.Win32.RegistryKey Key = AcadKey.CreateSubKey("Applications", RegistryKeyPermissionCheck.ReadWriteSubTree, Rs); return(Key); } catch (System.Exception Ex) { AcadApp.ShowAlertDialog(Ex.Message + "注册失败。详情请查看软件的帮助文档"); return(AppKey); } } else { return(AppKey); } }
private void frmGridLabelEdit_Load(object sender, System.EventArgs e) { Point3d pnt3dPick = Pub.pnt3dO; try { Entity ent = Base_Tools45.Select.selectEntity(typeof(Line), "Select Grid Line for Label Edit:", "", out pnt3dPick); if (ent == null) { return; } idLine = ent.ObjectId; } catch { Application.ShowAlertDialog("Retry and make sure to elect the Grid Line not the text"); return; } ResultBuffer rb = idLine.getXData("GRID"); TypedValue[] tvs = rb.AsArray(); tv = tvs; this.lblGridLabel.Text = tvs[1].Value.ToString(); }
//create an tabpage private bool CreateDWGThumnailCollection(ref TabPage Page) { string PathStr = Page.Tag as string; FlowLayoutPanel FlowPanel = new FlowLayoutPanel(); if (Directory.Exists(PathStr)) { List <string> DwgFiles = Directory.GetFiles(PathStr, "*.dwg", SearchOption.AllDirectories).ToList(); BlockingCollection <DwgThumnail> DwgItemList = new BlockingCollection <DwgThumnail>(); FlowPanel.Dock = DockStyle.Fill; FlowPanel.BackColor = System.Drawing.SystemColors.ButtonHighlight; FlowPanel.AutoScroll = true; int type = 0; if (Regex.Match(PathStr, @"StdBlock").Success) { type = 0; } else { type = 1; } Parallel.ForEach(DwgFiles, item => { DwgThumnail DwgItem = new DwgThumnail(item, type); DwgItemList.Add(DwgItem); }); if (DwgItemList.Count == 0) { Label lb = new Label(); lb.Text = "该路径下不包含任何DWG文件"; lb.Dock = DockStyle.Top; lb.AutoSize = true; FlowPanel.Padding = new Padding(30); FlowPanel.Controls.Add(lb); Page.Controls.Add(FlowPanel); return(false); } else { FlowPanel.SuspendLayout(); List <DwgThumnail> DwgList = DwgItemList.ToList(); DwgList.Sort(); FlowPanel.Controls.AddRange(DwgList.ToArray()); FlowPanel.ResumeLayout(); Page.Controls.Add(FlowPanel); return(true); } } else { AcadApp.ShowAlertDialog(string.Format("路径:{0} 不存在", PathStr)); return(false); } }
public void Execute() { // Get the current document var acDocument = Application.DocumentManager.MdiActiveDocument; // Get the PickFirst selection set PromptSelectionResult acSSPrompt; acSSPrompt = acDocument.Editor.SelectImplied(); SelectionSet acSSet; // If the prompt status is OK, objects were selected before // the command was started if (acSSPrompt.Status == PromptStatus.OK) { acSSet = acSSPrompt.Value; // Get the current document and database, and start a transaction Database acCurDb = acDocument.Database; double totalArea = default; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { int nCnt = 0; // Step through each object in Model space and // display the type of object found foreach (var acObjId in acSSet.GetObjectIds()) { var pline = acTrans.GetObject(acObjId, OpenMode.ForRead) as Polyline; if (!(pline is null)) { totalArea += pline.Area; nCnt++; } } string userInfoContetnt = $"\nSummed polylines: {nCnt}" + $"\nTotal Area: {totalArea}" + $"\nTotal area is copied to clipboard." + $"\nUse Paste command (Ctrl+V) to place vale."; Application.ShowAlertDialog(userInfoContetnt); acDocument.Editor.WriteMessage(userInfoContetnt); System.Windows.Clipboard.SetText(totalArea.ToString(CultureInfo.InvariantCulture)); } } else { Application.ShowAlertDialog("Select polylines first"); } }
public void openHelpFolder() { try { System.Diagnostics.Process.Start(HelpFile); }catch (System.Exception ex) { AcadApp.ShowAlertDialog(ex.Message); } }
public void ListAttributes() { var dlg = new AttributeSyncForm(); dlg.BlockName = "Old"; if (AcAp.ShowModalDialog(dlg) == DialogResult.OK) { AcAp.ShowAlertDialog(dlg.BlockName); } }
private void UnRegisterPlugin(string dname) { Microsoft.Win32.RegistryKey AcadPluginKey = GetAcadAppKey(true); if (AcadPluginKey != null) { AcadPluginKey.DeleteSubKey(AppName); AcadPluginKey.Close(); AcadApp.ShowAlertDialog("注册表删除成功"); } else { AcadApp.ShowAlertDialog("注册表删除失败"); } }
/// <summary> /// 添加车位块 /// </summary> /// <param name="filePath">文件路径</param> /// <param name="carType">车位类型</param> /// <param name="angle">角度</param> public static void AddCarBlock(string filePath, string carType, double angle) { if (!File.Exists(filePath)) { AcadApp.ShowAlertDialog($"{filePath} 文件不存在。"); return; } //导入图形 Database db = HostApplicationServices.WorkingDatabase; using (var tr = db.TransactionManager.StartTransaction()) { bool success = db.ImportBlockFromDwg(filePath, carBlockName, DuplicateRecordCloning.Replace); if (!success) { return; } //设置图层 db.AddLayer(carLayer, "车位图层"); db.SetLayerColor(carLayer, carColorIndex); tr.Commit(); } Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; //插入点 var ppr = ed.GetPoint(new PromptPointOptions("\n指定点")); while (ppr.Status == PromptStatus.OK) { var pt = ppr.Value; using (var tr = db.TransactionManager.StartTransaction()) { //插入图形 var id = db.CurrentSpaceId.InsertBlockReference(carLayer, carBlockName, pt, new Scale3d(1), angle); //设置车位类型 if (id != ObjectId.Null) { id.SetDynBlockValue("类型", carType); tr.Commit(); ppr = ed.GetPoint(new PromptPointOptions("\n指定点")); } else { break; } } } }
private void btnIronrectpipe_Click(object sender, EventArgs e) { FtLgScForm ftlgscfrm = new FtLgScForm();; //ftlgscfrm.Show(); var result = AcAp.ShowModalDialog(ftlgscfrm); if (result == DialogResult.OK) { AcAp.ShowAlertDialog("Pickup point"); } else { AcAp.ShowModalDialog(ftlgscfrm); } }
private void RegeisterPlugin() { Microsoft.Win32.RegistryKey AcadPluginKey = this.GetAcadAppKey(true); if (AcadPluginKey != null) { Microsoft.Win32.RegistryKey AcadPluginInspectorKey = AcadPluginKey.CreateSubKey(AppName); AcadPluginInspectorKey.SetValue("DESCRIPTION", "CSCECDEC DWG Library", Microsoft.Win32.RegistryValueKind.String); AcadPluginInspectorKey.SetValue("LOADCTRLS", 2, Microsoft.Win32.RegistryValueKind.DWord); AcadPluginInspectorKey.SetValue("LOADER", PluginPath, Microsoft.Win32.RegistryValueKind.String); AcadPluginInspectorKey.SetValue("MANAGED", 1, Microsoft.Win32.RegistryValueKind.DWord); AcadPluginKey.Close(); AcadApp.ShowAlertDialog("写入注册表成功,之后插件将在CAD每次重启时自动加载"); } else { AcadApp.ShowAlertDialog("写入注册表失败"); AcadPluginKey.Close(); } }
public void Register() { try { System.Version Ver = Autodesk.AutoCAD.ApplicationServices.Application.Version; //版本低于2007的软件 if (Ver.Major < 17) { AcadApp.ShowAlertDialog("插件不适合当前CAD版本,请安装2008及以上版本的AutoCAD软件"); } else { this.RegeisterPlugin(); } } catch (Autodesk.AutoCAD.Runtime.Exception Ex) { AcadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("注册失败:" + Ex.Message); } }
public void DwgStdSystem() { string _Path = Properties.Settings.Default.StdSysPath; /* * string Code = GetMd5Hash(MD5.Create(), EncryString); * if (Properties.Settings.Default.verifycode != Code) * { * AcadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage("未注册软件,请注册后使用"); * return; * } */ if (Directory.Exists(_Path)) { LibaryDialog Diag = new LibaryDialog(_Path, "中建深装-标准节点图库", LibType.SysLib); AcadApp.ShowModelessDialog(Diag); } else { AcadApp.ShowAlertDialog(string.Format("路径:{0}不存在,请先设置正确的图库加载路径", _Path)); } }
private void cmdSelectGrid_Click(System.Object eventSender, System.EventArgs eventArgs) { BaseObjs.acadActivate(); bool escape; string xRefPath = ""; Entity obj = xRef.getEntity("Select feature to stake:", out escape, out xRefPath); ObjectId idGuideline = ObjectId.Null; if (obj.GetType().Name != "Line") { Application.ShowAlertDialog("Grid Lines need to be simple Acad Lines, not Polylines, etc. - exiting..."); return; } else { idGuideline = Stake_GetGuidelines.getGuidelines(obj); string strLayerName = idGuideline.getLayer(); int intPos = strLayerName.IndexOf("|"); strLayerName = strLayerName.Substring(intPos + 1); if (!Stake_Main.testClass("BLDG", strLayerName)) { return; } Stake_Forms.sForms.fStake.NameStakeObject = strLayerName; } Stake_GetNestedObjects.copyGRID((Stake_Forms.sForms.fStake.XRefDbModelSpace));//XrefDbModelSpace is source of grid selected idGuideline.delete(); Stake_Forms.sForms.fStake.Hide(); Application.ShowModelessDialog(Application.MainWindow.Handle, Stake_Forms.sForms.fGrid, false); }
getLimits(int intInterval) { SelectionSet objSSet = EW_Utility1.buildSSetGradingLim(); if (objSSet.Count == 0) { Application.ShowAlertDialog("Grading Limit not found - should be on layer GRADING LIMIT - exiting...."); return(null); } else if (objSSet.Count > 1) { Application.ShowAlertDialog("More than one Project Boundary found - exiting...."); return(null); } ObjectId[] ids = objSSet.GetObjectIds(); Polyline objPlineBndry = (Polyline)ids[0].getEnt(); Extents3d ext3d = (Extents3d)objPlineBndry.Bounds; Point3d pnt3dMin = new Point3d(ext3d.MinPoint.X - 100, ext3d.MinPoint.Y - 100, 0.0); Point3d pnt3dMax = new Point3d(ext3d.MaxPoint.X + 100, ext3d.MaxPoint.Y + 100, 0.0); double dblDeltaX = pnt3dMax.X - pnt3dMin.X; double dblDeltaY = pnt3dMax.Y - pnt3dMin.Y; int iMax = (int)System.Math.Truncate(dblDeltaX / intInterval); int jMax = (int)System.Math.Truncate(dblDeltaY / intInterval); object[] varLimits = new object[4]; varLimits[0] = pnt3dMin.X; varLimits[1] = pnt3dMin.Y; varLimits[2] = iMax; varLimits[3] = jMax; return(varLimits); }
getNestedEntity(string prompt, out bool escape, out Object xRefPathX, out PromptStatus ps, out List <Point3d> pnts3dEntX, out FullSubentityPath path, out Point3d pnt3dPick, out bool isClosed) { xRefPathX = null; escape = true; pnt3dPick = Pub.pnt3dO; isClosed = false; Entity entX = null; Editor ED = BaseObjs._editor; PromptEntityOptions PEO = new PromptEntityOptions(prompt); PEO.AllowNone = true; PromptEntityResult PER = ED.GetEntity(PEO); ps = PER.Status; pnts3dEntX = new List <Point3d>(); pnt3dPick = PER.PickedPoint; path = new FullSubentityPath(); switch (ps) { case PromptStatus.OK: escape = false; break; case PromptStatus.None: escape = false; return(entX); default: return(entX); } ObjectId objId = PER.ObjectId; try { using (Transaction tr = BaseObjs.startTransactionDb()) { isClosed = false; Entity ent0 = (Entity)objId.GetObject(OpenMode.ForRead); if (ent0 is BlockReference) { BlockReference BR = (BlockReference)objId.GetObject(OpenMode.ForRead); if (BR != null) { ObjectId idBtr = BR.BlockTableRecord; BlockTableRecord Btr = (BlockTableRecord)idBtr.GetObject(OpenMode.ForRead); if (Btr != null) { if (Btr.IsFromExternalReference || Btr.IsFromOverlayReference) { entX = getNestedEntityAndHighlight(PER.PickedPoint, BR, out path, out isClosed); xRefPathX = getXRefFileName(BR.ObjectId); } else { entX = (Entity)objId.GetObject(OpenMode.ForRead); } if (entX is Line) { Line line = (Line)entX; pnts3dEntX.Add(line.StartPoint); pnts3dEntX.Add(line.EndPoint); } else if (entX is Polyline) { Polyline poly = (Polyline)entX; pnts3dEntX = Conv.polyX_listPnts3d(entX.ObjectId); isClosed = poly.Closed; } else if (entX is Polyline3d) { Polyline3d poly3d = (Polyline3d)entX; pnts3dEntX = Conv.polyX_listPnts3d(entX.ObjectId); isClosed = poly3d.Closed; } } } } else { Application.ShowAlertDialog("Selected Entity was not from a xref. Exiting..."); } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " xRef.cs: line: 600"); } return(entX); }
BD(double B1Width, double B1Slope, double B2Width, double B2Slope, double gradeSlope, int interval, string surfTAR, string surfDES, int side = 0, double elev = 0.0, Polyline3d poly3d = null) { Boolean success = false; Boolean exists = false; Boolean doB1 = fSG.boolB1; Boolean doB2 = fSG.boolB1; List <Point3d> pnts3d = new List <Point3d>(); List <Point3d> pnts3dB1 = new List <Point3d>(); List <Point3d> pnts3dB2 = new List <Point3d>(); List <Point3d> pnts3dDL = new List <Point3d>(); List <Point3d> pnts3dRF = new List <Point3d>(); Vector3d v3d = Vector3d.XAxis; Point3d pnt3dB; BaseObjs.acadActivate(); ObjectId idPoly3dOrg = ObjectId.Null; ObjectId idPoly3d = ObjectId.Null; ObjectId idPoly = ObjectId.Null; if (poly3d == null) { idPoly3dOrg = Select.getBrkLine("\nSelect 3D Polyline Reference: "); } else { idPoly3dOrg = poly3d.ObjectId; } if (idPoly3dOrg == ObjectId.Null) { return(false); } ResultBuffer rb = idPoly3dOrg.getXData(apps.lnkBrks); if (rb == null) { return(false); } TypedValue[] tvs = rb.AsArray(); List <ObjectId> idsCgPntRF = tvs.getObjectIdList(); List <ObjectId> idsCgPntM = null; ObjectId idCgPnt = ObjectId.Null; bool isClosed = idPoly3dOrg.checkIfClosed3d(false); if (!isClosed) { Application.ShowAlertDialog("Design reference Breakline is not closed. Exiting..."); return(false); } Point3d pnt3dB1_Mb = Pub.pnt3dO, pnt3dB2_Mb = Pub.pnt3dO, pnt3dDL_Mb = Pub.pnt3dO, pnt3dRF_Mb = Pub.pnt3dO; Point3d pnt3dB1_Me = Pub.pnt3dO, pnt3dB2_Me = Pub.pnt3dO, pnt3dDL_Me = Pub.pnt3dO, pnt3dRF_Me = Pub.pnt3dO; Point3d pnt3dX = Pub.pnt3dO, pnt3dXA = Pub.pnt3dO, pnt3dXB = Pub.pnt3dO; uint pntNum = 0; int s = 0; double angle = 0.0, deflc = 0.0, delta = 0.0, slopeChk = 0.0; List <ANG_PT_PROP> angPtProps = new List <ANG_PT_PROP>(); ANG_PT_PROP angPtProp = null; try { using (BaseObjs._acadDoc.LockDocument()) { pnts3d = idPoly3dOrg.getCoordinates3dList(); if (side == 0) { side = Geom.getSide(pnts3d); } angPtProps = pnts3d.getPoly3dAngPtProps(); int k = angPtProps.Count; for (int i = 0; i < k; i++) { angPtProp = angPtProps[i]; pnt3dB = angPtProp.BEG; //last point = first point deflc = angPtProp.ANG_DEFLC; if (i == 0) { pnts3dRF.Add(pnt3dB); //add begin point } angle = getMidDeltaDirection(side, deflc, angPtProp.DIR_SEG1, angPtProp.DIR_SEG2, out s); if (s == 0) { if (surfTAR == "") { pnt3dDL_Mb = getTargetElevation(elev, pnt3dB, angle, gradeSlope); } else { v3d = new Vector3d(sMath.Cos(angle), sMath.Sin(angle), -gradeSlope); pnt3dDL_Mb = getSlopeIntercept(surfTAR, pnt3dB, gradeSlope, v3d); } pnts3dDL.Add(pnt3dDL_Mb); idCgPnt = pnt3dDL_Mb.setPoint(out pntNum); BaseObjs.updateGraphics(); idsCgPntM = new List <ObjectId> { idsCgPntRF[i], idCgPnt }; idPoly3d = BrkLine.makeBreakline(apps.lnkSLP, "cmdBD", out idPoly, idsCgPntM); BaseObjs.updateGraphics(); } else if (s == -2 || s == 4) { getToeIntercept(side, angPtProp, surfTAR, elev, gradeSlope, doB1, B1Width, B1Slope, doB2, B2Width, B2Slope, ref pnt3dDL_Mb, ref pnt3dXA, ref pnt3dXB); if (i == 0) { pnt3dDL_Me = pnt3dXB; } else { pnts3dRF.Add(pnt3dXB); pnt3dXB.setPoint(out pntNum, "CPNT-ON"); BaseObjs.updateGraphics(); } slopeChk = pnt3dDL_Mb.getSlope(pnt3dXB); Debug.Print(slopeChk.ToString("0.0000")); pnts3dRF.Add(pnt3dB); //add RF Angle point pnts3dRF.Add(pnt3dXA); pnt3dXA.setPoint(out pntNum, "CPNT-ON"); BaseObjs.updateGraphics(); slopeChk = pnt3dDL_Mb.getSlope(pnt3dXA); Debug.Print(slopeChk.ToString("0.0000")); idCgPnt = pnt3dDL_Mb.setPoint(out pntNum, "CPNT-ON"); BaseObjs.updateGraphics(); idsCgPntM = new List <ObjectId> { idsCgPntRF[i], idCgPnt }; pnts3dDL.Add(pnt3dDL_Mb); idPoly3d = BrkLine.makeBreakline(apps.lnkSLP, "cmdBD", out idPoly, idsCgPntM); BaseObjs.updateGraphics(); } else if (s == 2 || s == -4) { pnts3dRF.Add(pnt3dB); double anglePerp1 = angPtProp.DIR_SEG1 + PI / 2 * -side; double anglePerp2 = angPtProp.DIR_SEG2 + PI / 2 * -side; Vector2d v2d1 = new Vector2d(sMath.Cos(anglePerp1), sMath.Sin(anglePerp1)); Vector2d v2d2 = new Vector2d(sMath.Cos(anglePerp2), sMath.Sin(anglePerp2)); delta = v2d1.GetAngleTo(v2d2); List <double> angles = new List <double>(); angles.Add(anglePerp1); double angleX = anglePerp1 + delta / 4 * side; angles.Add(angleX); angles.Add(angle); angleX = angle + delta / 4 * side; angles.Add(angleX); angles.Add(anglePerp2); foreach (double ang in angles) { angle = ang; if (surfTAR != "") { v3d = new Vector3d(sMath.Cos(angle), sMath.Sin(angle), -gradeSlope); pnt3dDL_Mb = getSlopeIntercept(surfTAR, pnt3dB, gradeSlope, v3d); } else { pnt3dDL_Mb = getTargetElevation(elev, pnt3dB, angle, gradeSlope); } pnts3dDL.Add(pnt3dDL_Mb); idCgPnt = pnt3dDL_Mb.setPoint(out pntNum, "CPNT-ON"); BaseObjs.updateGraphics(); idsCgPntM = new List <ObjectId> { idsCgPntRF[i], idCgPnt }; idPoly3d = BrkLine.makeBreakline(apps.lnkSLP, "cmdBD", out idPoly, idsCgPntM); BaseObjs.updateGraphics(); } } } pnts3dDL.Add(pnts3dDL[0]); //complete point list with first point - for closure if (pnt3dRF_Me != Pub.pnt3dO) { pnts3dRF.Add(pnt3dRF_Me); //point on RF opposite DL back - first mid delta pnt3dRF_Me.setPoint(out pntNum, "CPNT-ON"); BaseObjs.updateGraphics(); } pnts3dRF.Add(pnts3dRF[0]); //complete point list with first point - for closure } } catch (SystemException ex) { BaseObjs.writeDebug(ex.Message + " cmdBD.cs: line: 244"); success = false; } ObjectId idPoly3dX = ObjectId.Null; ObjectIdCollection idsPoly3dX = new ObjectIdCollection(); tvs = new TypedValue[13]; tvs.SetValue(new TypedValue(1001, "lnkSLP"), 0); using (BaseObjs._acadDoc.LockDocument()) { try { idPoly3dOrg.handOverPoly3d2(pnts3dRF); Handle hB1; if (pnts3dB1.Count > 0) { idPoly3dX = pnts3dB1.addPoly3d("CPNT-BRKLINE"); //Lower Bench idsPoly3dX.Add(idPoly3dX); hB1 = idPoly3dX.getHandle(); } else { B1Width = 0.0; B1Slope = 0.0; hB1 = "0".stringToHandle(); } tvs.SetValue(new TypedValue(1000, B1Width), 1); tvs.SetValue(new TypedValue(1000, B1Slope), 2); tvs.SetValue(new TypedValue(1005, hB1), 3); Handle hB2; if (pnts3dB2.Count > 0) { idPoly3dX = pnts3dB2.addPoly3d("CPNT-BRKLINE"); //Top of Slope/Upper Bench idsPoly3dX.Add(idPoly3dX); hB2 = idPoly3dX.getHandle(); } else { B2Width = 0.0; B2Slope = 0.0; hB2 = "0".stringToHandle(); } tvs.SetValue(new TypedValue(1000, B2Width), 4); tvs.SetValue(new TypedValue(1000, B2Slope), 5); tvs.SetValue(new TypedValue(1005, hB2), 6); Handle hDL; idPoly3dX = pnts3dDL.addPoly3d("CPNT-BRKLINE"); //Top of Slope/Daylight (if no upper bench) idsPoly3dX.Add(idPoly3dX); hDL = idPoly3dX.getHandle(); tvs.SetValue(new TypedValue(1000, gradeSlope), 7); tvs.SetValue(new TypedValue(1070, side), 8); tvs.SetValue(new TypedValue(1000, interval), 9); tvs.SetValue(new TypedValue(1005, hDL), 10); tvs.SetValue(new TypedValue(1000, surfTAR), 11); tvs.SetValue(new TypedValue(1000, surfDES), 12); idPoly3dOrg.setXData(tvs, apps.lnkSLP); } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " cmdBD.cs: line: 307"); } } if (idPoly3dX != ObjectId.Null) { DialogResult result; result = MessageBox.Show(string.Format("Add Slope Breaklines to Design Surface? \nYes to add to surface: {0}\nNo to keep Breaklines, but not add to surface.\nCancel to dispose of Breaklines.", surfDES), "Slope Breaklines", System.Windows.Forms.MessageBoxButtons.YesNoCancel); switch (result) { case DialogResult.Yes: TinSurface surf = Surf.getTinSurface(surfDES, out exists); surf.BreaklinesDefinition.AddStandardBreaklines(idsPoly3dX, 1.0, 1.0, 0.0, 0.0); success = true; break; case DialogResult.No: success = true; break; case DialogResult.Cancel: success = false; break; } } else { success = false; } return(success); }
ABC(string nameCmd) { Arc arc0 = null; Point3d pnt3dBeg = Pub.pnt3dO, pnt3dEnd = Pub.pnt3dO, pnt3dX = Pub.pnt3dO; ObjectId idCgPntEnd = ObjectId.Null; ObjectId idPoly = ObjectId.Null; List <Point3d> pnts3d = null, pnts3dEntX = null; bool escape = true; Object xRefPathX = null; PromptStatus ps; FullSubentityPath path; Point3d pnt3dPick; bool isClosed = false; double grd = 0.0; Entity ent = xRef.getNestedEntity("\nSelect ARC: ", out escape, out xRefPathX, out ps, out pnts3dEntX, out path, out pnt3dPick, out isClosed); if (ent.GetType().ToString() != "Autodesk.AutoCAD.DatabaseServices.Arc") { Application.ShowAlertDialog(string.Format("Selected object was type of: {0} - Exiting...", ent.GetType().ToString())); return; } else { arc0 = (Arc)ent; } pnt3dX = UserInput.getPoint("\nPick point Back of Curb adjacent to arc segment", arc0.StartPoint, out escape, out ps, osMode: 8); double distX = arc0.Center.getDistance(pnt3dX); if (distX == arc0.Radius) { Application.ShowAlertDialog("Selected point is on arc. Select point away from street side: "); pnt3dX = UserInput.getPoint("\nPick point Back of Curb adjacent to arc segment", pnt3dBeg, out escape, out ps, osMode: 8); distX = arc0.Center.getDistance(pnt3dX); if (distX == arc0.Radius) { return; } } int side = -1; int n = (arc0.Normal.Z > 0) ? 1 : -1; switch (n) { case 1: //right hand direction if (distX > arc0.Radius) { side = 1; } break; case -1: //left hand direction if (distX < arc0.Radius) { side = 1; } break; } string elev = "", prompt = "\nSelect Cogo Point for begin elevation at beginning of curve (as indicated by guideline): "; ObjectId idCgPntBeg = getEndPoint(pnt3dBeg, out elev, prompt); if (elev == "") { return; } List <ObjectId> idsCgPnt = new List <ObjectId>(); idsCgPnt.Add(idCgPntBeg); pnt3dBeg = idCgPntBeg.getCogoPntCoordinates(); BaseObjs.write(string.Format("\nBegin Elevation = {0:F2}", elev)); if (arc0.EndPoint.isEqual(pnt3dBeg, 0.1)) { Curve curve = arc0; curve.ReverseCurve(); //***************************************************************************** } else if (arc0.StartPoint.isEqual(pnt3dBeg, 0.1)) { } else { Application.ShowAlertDialog("Selected Begin point is not at either end of the arc. Revise and retry..."); return; } uint pntNum = 0; ObjectId idCgPntX = ObjectId.Null; List <double> userInput = null; userInput = cmdBC.getUserInput(nameCmd); if (userInput == null) { return; } double offH1 = 0.5 * 1.25 * side; double offV1 = userInput[0] + 0.0208; double offH2 = userInput[1] * side; double offV2 = userInput[2] * userInput[1]; double offH3 = 0; double offV3 = 0; List <double> offHs = new List <double> { 0.0, offH1, offH2 }; List <double> offVs = new List <double> { 0.0, offV1, offV2 }; List <Arc> arcs = new List <Arc>(); arcs.Add(arc0); DBObjectCollection dbObjs = arc0.GetOffsetCurves(offH1); Arc arc1 = (Arc)dbObjs[0]; arcs.Add(arc1); dbObjs = arc1.GetOffsetCurves(offH2); Arc arc2 = (Arc)dbObjs[0]; arcs.Add(arc2); Arc arc3 = null; if (nameCmd == "cmdABG") { offH3 = (userInput[3] * side * -1) - offH1 - offH2; //offset from bench offV3 = userInput[4] - offV1 - offV2; //offset from bench offHs.Add(offH3); offVs.Add(offV3); dbObjs = arc0.GetOffsetCurves(userInput[3] * side * -1); arc3 = (Arc)dbObjs[0]; arcs.Add(arc3); } string cmdDefault = "R"; prompt = string.Format("\nStraight grade(two or more points)/slope Intercept/Vertical curve/Plane method/Modified plane method/Reinhard plane method: S/I/V/P/M/R <{0}> [S/I/V/P/M/R]:", cmdDefault); escape = UserInput.getUserInputKeyword(cmdDefault, out cmdDefault, prompt, "S I V P M R"); if (escape) { return; } Vector3d v3dBeg = new Vector3d(0, 0, 0); Vector3d v3dEnd = new Vector3d(0, 0, 0); List <arcInfo> arcInfos = new List <arcInfo>(); arcInfo aInfo = getArcInfo(pnt3dBeg, arc0, nameCmd, offHs, offVs, idCgPntBeg); arcInfos.Add(aInfo); Point3d pnt3d = pnt3dBeg; switch (cmdDefault) { #region "S" case "S": // Assuming points are set at both ends, with optional points set at intermediate locations on arc bool Done = false; do { prompt = "\nSelect Cogo Point on Arc (Arc endpoint or intermediate point) ENTER when done: "; idCgPntEnd = getEndPoint(pnt3d, out elev, prompt); if (elev == "") { Done = true; } else { pnt3d = idCgPntEnd.getCogoPntCoordinates(); idsCgPnt.Add(idCgPntEnd); aInfo = getArcInfo(pnt3d, arc0, nameCmd, offHs, offVs, idCgPntEnd); arcInfos.Add(aInfo); } }while (!Done); var sortByLen = from a in arcInfos orderby a.distFromBeg ascending select a; int i = -1; foreach (var b in sortByLen) { arcInfos[++i] = b; } processArcInfo(ref arcInfos); switch (idsCgPnt.Count) { case 1: return; default: processArcs(arcs, arcInfos, arc0, idsCgPnt, nameCmd, offHs, offVs); break; } break; #endregion "S" #region "I" case "I": double m1 = Pub.slp1; double m2 = Pub.slp2; prompt = "\nSelect Cogo Point for end elevation: "; idCgPntEnd = getEndPoint(pnt3dBeg, out elev, prompt); if (elev == "") { return; } pnt3dEnd = idCgPntEnd.getCogoPntCoordinates(); idsCgPnt.Add(idCgPntEnd); grd = (pnt3dEnd.Z - pnt3dBeg.Z) / arc0.Length; BaseObjs.write(string.Format("\nSlope along curve is: {0:P2}", grd)); m1 = Pub.slp1; m2 = Pub.slp2; UserInput.getUserInput("\nEnter slope from FIRST POINT: ", out m1, m1); if (m1 == -99.99) { return; } UserInput.getUserInput("\nEnter slope from SECOND POINT: ", out m2, m2); if (m2 == -99.99) { return; } Pub.slp1 = m1; Pub.slp2 = m2; double elev1 = pnt3dBeg.Z; double elev2 = pnt3dEnd.Z; distX = cmdSSP.getSlopeInterceptArc(arc0.Length, elev1, elev2, m1, -m2); if (distX == 0) { return; } Point3d pnt3dInt = arc0.GetPointAtDist(distX); pnt3dInt = new Point3d(pnt3dInt.X, pnt3dInt.Y, elev1 + distX * m1); ObjectId idCgPntInt = pnt3dInt.setPoint(out pntNum); idsCgPnt.Add(idCgPntInt); Application.ShowAlertDialog(string.Format("The elevation of the slope\nintercept is {0:F2}", pnt3dInt.Z)); aInfo = getArcInfo(pnt3dInt, arc0, nameCmd, offHs, offVs, idCgPntInt); arcInfos.Add(aInfo); aInfo = getArcInfo(pnt3dEnd, arc0, nameCmd, offHs, offVs, idCgPntEnd); arcInfos.Add(aInfo); processArcInfo(ref arcInfos); processArcs(arcs, arcInfos, arc0, idsCgPnt, nameCmd, offHs, offVs); break; #endregion "I" #region "V" case "V": prompt = "\nSelect Cogo Point for end elevation: "; idCgPntEnd = getEndPoint(pnt3dBeg, out elev, prompt); if (elev == "") { return; } pnt3dEnd = idCgPntEnd.getCogoPntCoordinates(); idsCgPnt.Add(idCgPntEnd); grd = (pnt3dEnd.Z - pnt3dBeg.Z) / arc0.Length; BaseObjs.write(string.Format("\nSlope along curve is: {0:P2}", grd)); m1 = Pub.slp1; m2 = Pub.slp2; UserInput.getUserInput("\nEnter slope from FIRST POINT: ", out m1, m1); if (m1 == -99.99) { return; } UserInput.getUserInput("\nEnter slope from SECOND POINT: ", out m2, m2); if (m2 == -99.99) { return; } string lenVC = "20"; escape = UserInput.getUserInputDoubleAsString("\nEnter length of vertical curve: ", out lenVC, lenVC); if (escape) { return; } Pub.slp1 = m1; Pub.slp2 = m2; elev1 = pnt3dBeg.Z; elev2 = pnt3dEnd.Z; distX = cmdSSP.getSlopeInterceptArc(arc0.Length, elev1, elev2, m1, -m2); if (distX == 0) { return; } pnt3dInt = arc0.GetPointAtDist(distX); pnt3dInt = new Point3d(pnt3dInt.X, pnt3dInt.Y, elev1 + distX * m1); Application.ShowAlertDialog(string.Format("The elevation of the slope\nintercept is {0:F2}", pnt3dInt.Z)); double lVC = double.Parse(lenVC); if ((distX - lVC / 2) < 0 || (distX + lVC / 2) > arc0.Length) { double lenMax = distX * 2; if ((arc0.Length - distX) < lenMax / 2) { lenMax = (arc0.Length - distX) * 2; Application.ShowAlertDialog(string.Format("Maximum length of Vertical Curve length with current inputs is {0:F2}", lenMax)); } } pnts3d = arc0.traverse(m1, -m2, distX, lVC, pnt3dBeg); BrkLine.makeBreakline(apps.lnkBrks, nameCmd, out idPoly, idsCgPnt, pnts3dL: pnts3d); break; #endregion "V" #region "M" case "M": prompt = "\nSelect Begin Curve backsight Cogo Point for grade and direction: "; Point3d pnt3dBegBS = UserInput.getPoint(prompt, pnt3dBeg, out escape, out ps, osMode: 8); if (pnt3dBegBS == Pub.pnt3dO) { return; } prompt = "\nSelect Cogo Point for end elevation: "; idCgPntEnd = getEndPoint(pnt3dBeg, out elev, prompt); if (elev == "") { return; } pnt3dEnd = idCgPntEnd.getCogoPntCoordinates(); grd = (pnt3dEnd.Z - pnt3dBeg.Z) / arc0.Length; BaseObjs.write(string.Format("\nSlope along curve is: {0:P2}", grd)); prompt = "\nSelect End Curve backsight Cogo Point for grade and direction: "; Point3d pnt3dEndBS = UserInput.getPoint(prompt, pnt3dEnd, out escape, out ps, osMode: 8); if (pnt3dEndBS == Pub.pnt3dO) { return; } Point3d pnt3dPI = Geom.getPntInt(pnt3dBegBS, pnt3dBeg, pnt3dEndBS, pnt3dEnd, true, extend.both); double g1 = pnt3dBegBS.getSlope(pnt3dBeg); double g2 = pnt3dEnd.getSlope(pnt3dEndBS); double el1 = pnt3dBeg.Z + g1 * pnt3dBeg.getDistance(pnt3dPI); double el2 = pnt3dEnd.Z - g2 * pnt3dEnd.getDistance(pnt3dPI); double ratio = 0; double aDiff = g1 - g2; double el = 0; if (g1 < 0 && g2 < 0) { ratio = g1 / (g1 + g2); if (g1 <= g2) { //g1 controls if (el1 < el2) { el = el1 + (el2 - el1) * ratio; } else if (el1 > el2) { el = el1 - (el1 - el2) * ratio; } } else if (g2 < g1) { //g2 controls if (el2 < el1) { el = el2 + (el1 - el2) * (1 - ratio); } else if (el2 > el1) { el = el2 - (el2 - el1) * (1 - ratio); } } } else if (g1 > 0 && g2 > 0) { ratio = g1 / (g1 + g2); if (g1 >= g2) { //g1 controls if (el1 < el2) { el = el1 + (el2 - el1) * ratio; } else if (el1 > el2) { el = el1 - (el1 - el2) * ratio; } } else if (g2 > g1) { //g2 controls if (el2 < el1) { el = el2 + (el1 - el2) * (1 - ratio); } else if (el2 > el1) { el = el2 - (el2 - el1) * (1 - ratio); } } } else { ratio = g1 / aDiff; if (ratio >= (1 - ratio)) { //g1 controls if (el1 < el2) { el = el1 + (el2 - el1) * ratio; } else if (el1 > el2) { el = el1 - (el1 - el2) * ratio; } } else if ((1 - ratio) > ratio) { //g2 controls if (el2 < el1) { el = el2 + (el1 - el2) * (1 - ratio); } else if (el2 > el1) { el = el2 - (el2 - el1) * (1 - ratio); } } } pnt3dPI = new Point3d(pnt3dPI.X, pnt3dPI.Y, el); pnt3dPI.setPoint(out pntNum); BaseObjs.updateGraphics(); double g1Mod = pnt3dBeg.getSlope(pnt3dPI); double g2Mod = pnt3dPI.getSlope(pnt3dEnd); g1 = (g1 + g1Mod) / 2; g2 = (g2 + g2Mod) / 2; Point3d pnt3dChordMid = pnt3dBeg.getMidPoint3d(pnt3dEnd); Vector3d v3dM = pnt3dPI - pnt3dChordMid; pnts3d = arc0.planeMethodModified(pnt3dBeg, pnt3dEnd, pnt3dPI, v3dM, g1, g2, ref idsCgPnt); idsCgPnt.Add(idCgPntEnd); arcInfos = new List <arcInfo>(); for (int s = 0; s < pnts3d.Count; s++) { pnt3dX = pnts3d[s]; aInfo = getArcInfo(pnt3dX, arc0, nameCmd, offHs, offVs, idsCgPnt[s]); arcInfos.Add(aInfo); } processArcInfo(ref arcInfos); processArcs(arcs, arcInfos, arc0, idsCgPnt, nameCmd, offHs, offVs); break; #endregion "M" #region "R" case "R": prompt = "\nSelect Begin Curve backsight Cogo Point for grade and direction: "; pnt3dBegBS = UserInput.getPoint(prompt, pnt3dBeg, out escape, out ps, osMode: 8); if (pnt3dBegBS == Pub.pnt3dO) { return; } prompt = "\nSelect Cogo Point for end elevation: "; idCgPntEnd = getEndPoint(pnt3dBeg, out elev, prompt); if (elev == "") { return; } pnt3dEnd = idCgPntEnd.getCogoPntCoordinates(); grd = (pnt3dEnd.Z - pnt3dBeg.Z) / arc0.Length; BaseObjs.write(string.Format("\nSlope along curve is: {0:P2}", grd)); prompt = "\nSelect End Curve backsight Cogo Point for grade and direction: "; pnt3dEndBS = UserInput.getPoint(prompt, pnt3dEnd, out escape, out ps, osMode: 8); if (pnt3dEndBS == Pub.pnt3dO) { return; } pnt3dPI = Geom.getPntInt(pnt3dBegBS, pnt3dBeg, pnt3dEndBS, pnt3dEnd, true, extend.both); g1 = pnt3dBegBS.getSlope(pnt3dBeg); g2 = pnt3dEnd.getSlope(pnt3dEndBS); string resOut = ""; prompt = string.Format("\nUse g1={0:P2} or g2={1:P2}?: [1/2]", g1, g2); escape = UserInput.getUserInputKeyword("1", out resOut, prompt, "1 2"); if (escape) { return; } el = 0; switch (resOut) { case "1": el = pnt3dBeg.Z + g1 * pnt3dBeg.getDistance(pnt3dPI); break; case "2": el = pnt3dEnd.Z - g2 * pnt3dEnd.getDistance(pnt3dPI); break; } pnt3dPI = new Point3d(pnt3dPI.X, pnt3dPI.Y, el); pnt3dPI.setPoint(out pntNum); BaseObjs.updateGraphics(); pnts3d = arc0.planeMethodReinhard(pnt3dBeg, pnt3dEnd, pnt3dPI, ref idsCgPnt); idsCgPnt.Add(idCgPntEnd); arcInfos = new List <arcInfo>(); for (int s = 0; s < pnts3d.Count; s++) { pnt3dX = pnts3d[s]; aInfo = getArcInfo(pnt3dX, arc0, nameCmd, offHs, offVs, idsCgPnt[s]); arcInfos.Add(aInfo); } processArcInfo(ref arcInfos); processArcs(arcs, arcInfos, arc0, idsCgPnt, nameCmd, offHs, offVs); break; #endregion "R" #region "P" case "P": prompt = "S\nelect Begin Curve backsight Cogo Point for grade and direction: "; pnt3dBegBS = UserInput.getPoint(prompt, pnt3dBeg, out escape, out ps, osMode: 8); if (pnt3dBegBS == Pub.pnt3dO) { return; } prompt = "\nSelect Cogo Point for end elevation: "; idCgPntEnd = getEndPoint(pnt3dBeg, out elev, prompt); if (elev == "") { return; } pnt3dEnd = idCgPntEnd.getCogoPntCoordinates(); grd = (pnt3dEnd.Z - pnt3dBeg.Z) / arc0.Length; BaseObjs.write(string.Format("\nSlope along curve is: {0:P2}", grd)); prompt = "\nSelect End Curve backsight Cogo Point for grade and direction: "; pnt3dEndBS = UserInput.getPoint(prompt, pnt3dEnd, out escape, out ps, osMode: 8); if (pnt3dEndBS == Pub.pnt3dO) { return; } pnt3dPI = Geom.getPntInt(pnt3dBegBS, pnt3dBeg, pnt3dEndBS, pnt3dEnd, true, extend.both); g1 = pnt3dBegBS.getSlope(pnt3dBeg); g2 = pnt3dEndBS.getSlope(pnt3dEnd); el1 = pnt3dBeg.Z + g1 * pnt3dBeg.getDistance(pnt3dPI); el2 = pnt3dEnd.Z + g2 * pnt3dEnd.getDistance(pnt3dPI); el = (el1 + el2) / 2; pnt3dPI = new Point3d(pnt3dPI.X, pnt3dPI.Y, el); pnt3dChordMid = pnt3dBeg.getMidPoint3d(pnt3dEnd); v3dM = pnt3dPI - pnt3dChordMid; pnts3d = arc0.planeMethod(pnt3dBeg, pnt3dEnd, pnt3dPI, v3dM, ref idsCgPnt, nameCmd); idsCgPnt.Add(idCgPntEnd); arcInfos = new List <arcInfo>(); for (int s = 0; s < pnts3d.Count; s++) { pnt3dX = pnts3d[s]; aInfo = getArcInfo(pnt3dX, arc0, nameCmd, offHs, offVs, idsCgPnt[s]); arcInfos.Add(aInfo); } processArcInfo(ref arcInfos); processArcs(arcs, arcInfos, arc0, idsCgPnt, nameCmd, offHs, offVs); break; #endregion "P" } }
/// <summary> /// 车位排序 /// </summary> /// <param name="isUpToDown">从上到下</param> public static void OrderCarBlock(bool isUpToDown = true) { Database db = HostApplicationServices.WorkingDatabase; using (var tr = db.TransactionManager.StartTransaction()) { //选择车和索引 var blocks = db.GetSelectionOfBlockRefs("\n选择车或索引", false, carBlockName, indexBlockName); //删除原索引 var indexs = blocks.Where(d => d.GetBlockName() == indexBlockName).ToList(); if (indexs.Count > 0) { foreach (var index in indexs) { index.UpgradeOpen(); index.Erase(); } } //选择的车 var cars = blocks.Where(d => d.GetBlockName() == carBlockName).ToList(); if (cars.Count != 0) { //添加块定义 if (AddIndexBtr()) { //从上到下 if (isUpToDown) { cars = cars.OrderBy(car => car.Position.X) .ThenByDescending(d => d.Position.Y).ToList(); } //从下到上 else { cars = cars.OrderBy(car => car.Position.X) .ThenBy(d => d.Position.Y).ToList(); } for (int i = 0; i < cars.Count; i++) { BlockReference car = cars[i]; Dictionary <string, string> atts = new Dictionary <string, string> { { "编号", $"{i + 1:D2}" } }; //车位图形中点 var pt = new LineSegment3d(car.GeometricExtents.MinPoint, car.GeometricExtents.MaxPoint).MidPoint; var scale = new Scale3d(100); //添加索引块 db.CurrentSpaceId.InsertBlockReference("0", indexBlockName, pt, scale, 0, atts); } } } else { AcadApp.ShowAlertDialog("选中数量为0"); } tr.Commit(); } }
public void KojtoCAD_3D_Get_Glass_Conturs_Centroid() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Matrix3d old = ed.CurrentUserCoordinateSystem; ed.CurrentUserCoordinateSystem = Matrix3d.Identity; try { PromptKeywordOptions pop = new PromptKeywordOptions(""); pop.AppendKeywordsToMessage = true; pop.AllowNone = false; pop.Keywords.Add("Run"); pop.Keywords.Add("Help"); pop.Keywords.Default = "Run"; PromptResult res = ed.GetKeywords(pop); //_AcAp.Application.ShowAlertDialog(res.ToString()); if (res.Status == PromptStatus.OK) { switch (res.StringResult) { case "Run": if ((container != null) && (container.Bends.Count > 0) && (container.Nodes.Count > 0) && (container.Triangles.Count > 0)) { double area = 0.0; quaternion cen = new quaternion(); foreach (WorkClasses.Triangle TR in container.Triangles) { Triplet <quaternion, quaternion, quaternion> pr = container.GetInnererTriangle(TR.Numer, true); double ar = Math.Abs(GlobalFunctions.GetArea(pr)); area += ar; quaternion centroid = new quaternion(); centroid = (pr.First + pr.Second) / 2.0; centroid = centroid - pr.Third; centroid *= (2.0 / 3.0); centroid = pr.Third + centroid; centroid *= ar; cen += centroid; } if (area > 0.0) { cen /= area; string title = "\nTeoretical Mesh Glass Conturs center of gravity\n------------------\n\n"; string mess = string.Format("{0} total area: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, area, cen.GetX(), cen.GetY(), cen.GetZ()); ed.WriteMessage(mess); MessageBox.Show(mess, "Glass Conturs - teoretical mesh center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; case "Help": GlobalFunctions.OpenHelpHTML("http://3dsoft.blob.core.windows.net/kojtocad/html/SPOTS_CENTROID.htm"); break; } } } catch (System.Exception ex) { Application.ShowAlertDialog( string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace)); } finally { ed.CurrentUserCoordinateSystem = old; } }
public void KojtoCAD_3D_Get_Teoretical_Bends_Centroid() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Matrix3d old = ed.CurrentUserCoordinateSystem; ed.CurrentUserCoordinateSystem = Matrix3d.Identity; try { PromptKeywordOptions pop = new PromptKeywordOptions(""); pop.AppendKeywordsToMessage = true; pop.AllowNone = false; pop.Keywords.Add("Run"); pop.Keywords.Add("Help"); pop.Keywords.Default = "Run"; PromptResult res = ed.GetKeywords(pop); //_AcAp.Application.ShowAlertDialog(res.ToString()); if (res.Status == PromptStatus.OK) { switch (res.StringResult) { case "Run": if ((container != null) && (container.Bends.Count > 0)) { quaternion qSum_Bends_Teor = new quaternion(); double mass = 0.0; foreach (WorkClasses.Bend bend in container.Bends) { if (!bend.IsFictive()) { qSum_Bends_Teor += (bend.MidPoint * bend.Length); mass += bend.Length; } } if (mass > 0) { qSum_Bends_Teor /= mass; //UtilityClasses.GlobalFunctions.DrawLine(new Point3d(1000, 1000, 0), (Point3d)qSum_Bends_Real, 3); string title = "\nTeoretical Mesh Bends center of gravity\n------------------\n\n"; string mess = string.Format("{0} total length: {1} \n Coordinate: {2:f5},{3:f5},{4:f5}", title, mass, qSum_Bends_Teor.GetX(), qSum_Bends_Teor.GetY(), qSum_Bends_Teor.GetZ()); ed.WriteMessage(mess); MessageBox.Show(mess, "Bends - teoretical mesh center of gravity", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("\nData Base Empty !\n\nMissing Bends !", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; case "Help": GlobalFunctions.OpenHelpHTML("http://3dsoft.blob.core.windows.net/kojtocad/html/MESH_CENTROID.htm"); break; } } } catch (System.Exception ex) { Application.ShowAlertDialog( string.Format("\nError: {0}\nStackTrace: {1}", ex.Message, ex.StackTrace)); } finally { ed.CurrentUserCoordinateSystem = old; } }
private void button_OK_Click(object sender, EventArgs e) { double s = 0, R = 0, k = 0; try { s = Double.Parse(textBox_S.Text); R = Double.Parse(textBox_R.Text); k = Double.Parse(textBox_KFactor.Text); if (radioButtonAirBending.Checked == true) { pos = 0; } else if (radioButtonBA.Checked == true) { pos = 1; } else { pos = 2; } if ((s > 0) && (R > 0) && (k >= 0.0)) { if ((k > 1) && (radioButtonAirBending.Checked == true)) { throw new FormatException(); } m_S = s; m_R = R; m_kF = k; if (radioButtonBD.Checked == true) { double ba = 2 * (R + s) - k; if ((ba > (Math.PI / 2.0) * (R + s)) || (ba < (Math.PI / 2.0) * R)) { Application.ShowAlertDialog("BD Out of Range !"); textBox_KFactor.Text = ""; textBox_KFactor.Focus(); throw new FormatException(); } else { m_kF = ((ba / (Math.PI / 2.0)) - R) / s; MessageBox.Show(m_kF.ToString()); } } DialogResult = DialogResult.OK; } else { throw new FormatException(); } } catch (FormatException) { if (s <= 0) { MessageBox.Show("S <= 0 !", "ERROR"); textBox_S.Text = ""; textBox_S.Focus(); } if (R <= 0) { MessageBox.Show("R <= 0 !", "ERROR"); textBox_R.Text = ""; textBox_R.Focus(); } if (((k < 0) || (k > 1)) && (radioButtonAirBending.Checked == true)) { MessageBox.Show("K - Factor = ? ( between 0 and 1 ) !", "ERROR"); textBox_KFactor.Text = ""; textBox_KFactor.Focus(); } if ((k < 0) && (radioButtonBA.Checked == true)) { MessageBox.Show("Bend Allowance Value = ? (BA > 0) !", "ERROR"); textBox_KFactor.Text = ""; textBox_KFactor.Focus(); } if ((k < 0) && (radioButtonBD.Checked == true)) { MessageBox.Show("Bend Deduction Value = ? (BD > 0) !", "ERROR"); textBox_KFactor.Text = ""; textBox_KFactor.Focus(); } } }
private void OKBtn_Click(object sender, EventArgs e) { this.IsChange = false; Properties.Settings.Default.Save(); AcadApp.ShowAlertDialog("保存成功"); }
private void buttonPlot_Click(object sender, EventArgs e) { #region check textBoxSourcePath // Check for all the inputs... if (!Directory.Exists(this.textBoxSourcePath.Text)) { // Show error message and return... Application.ShowAlertDialog("Specify the DWG/DXF source directory."); this.textBoxSourcePath.Focus(); return; } #endregion #region check textBoxSavePath // Setting the focus based on the check box selection (if not set) if (checkBoxDWF.Checked || checkBoxPDF.Checked) { if (textBoxSavePath.Text.Length == 0) { // Show error message and return... Application.ShowAlertDialog( "Please specify destination directory."); textBoxSavePath.Focus(); return; } if (!Directory.Exists(this.textBoxSavePath.Text)) { // Show error message and return... Application.ShowAlertDialog( "Specified directory " + this.textBoxSavePath.Text + " not present."); textBoxSavePath.Focus(); return; } } #endregion #region check PDF device if (checkBoxPDF.Checked) { if (cmbPlotDevicePDF.Text.Length < 4) { cmbPlotDevicePDF.Text = "Select PDF device!"; cmbPlotDevicePDF.Focus(); } } #endregion #region check DWF device if (checkBoxPDF.Checked) { if (cmbPlotDevicePDF.Text.Length < 4) { cmbPlotDeviceDWF.Text = "Select DWF device!"; cmbPlotDeviceDWF.Focus(); } } #endregion if (textBoxDynamicBlockFrameName.Text.Length < 1) { MessageBox.Show( "Provide dynamic block frame name.", "No dynamic block frame name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (checkBoxPrint.Checked) { if ( MessageBox.Show( "Are you shure you want to REALLY PRINT all these DWGs ? If otherwise click NO, unckeck 'Print' option and try again.", "Real print confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } if (checkBoxMultiSheet.Checked && (cmbPaperSizePDF.Text.Equals("Auto", StringComparison.CurrentCultureIgnoreCase) || cmbPaperSizeDWF.Text.Equals("Auto", StringComparison.CurrentCultureIgnoreCase))) { DialogResult warning = MessageBox.Show( "Multi sheet PDF with different frame format is not allowed. If your drawings have different frames press Cancel and separate them by frame.", "KojtoCADPlotter", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (warning == DialogResult.Cancel) { cmbPlotDevicePDF.Focus(); return; } //return; } _publish = true; this.DialogResult = DialogResult.OK; // Save the current inputs to the Winforms properties SaveSettings(); }
makeBaseline() { Layer.manageLayers("GRADING LIMIT"); Layer.manageLayers("SECTIONS"); SelectionSet objSSet = EW_Utility1.buildSSetGradingLim(); Entity ent = objSSet.GetObjectIds()[0].getEnt(); ObjectId idLim = ent.ObjectId; double dblStationBase = 0; bool boolUseBase; Alignment objAlignBASE = null; Alignment objAlign = Align.getAlignment("BASE"); if (objAlign != null) { DialogResult varResponse = MessageBox.Show("Use existing BASE alignment for sections?", "", MessageBoxButtons.YesNo); if (varResponse == DialogResult.Yes) { objAlignBASE = objAlign; dblStationBase = objAlignBASE.StartingStation; objAlign = null; boolUseBase = true; } else { boolUseBase = false; objAlign.Name = "BASE_old"; } } else { boolUseBase = false; } List <Point3d> varPntInts = new List <Point3d>(); ObjectId idLWPline = ObjectId.Null, idLine = ObjectId.Null; double dblAng = 0; bool exists; Point3d pnt3dCEN = Pub.pnt3dO, pnt3dTAR = Pub.pnt3dO, dPntBeg = Pub.pnt3dO, dPntEnd = Pub.pnt3dO; if (!boolUseBase) { ObjectId idDictGRADEDOCK = Dict.getNamedDictionary("GRADEDOCK", out exists); if (!exists) { Application.ShowAlertDialog("GRADEDOCK Dictionary missing. Create alignment BASE and try again."); return; } else { ResultBuffer rb = Dict.getXRec(idDictGRADEDOCK, "CENTROID"); TypedValue[] tvs = rb.AsArray(); pnt3dCEN = new Point3d(double.Parse(tvs[0].Value.ToString()), double.Parse(tvs[1].Value.ToString()), double.Parse(tvs[2].Value.ToString())); rb = Dict.getXRec(idDictGRADEDOCK, "TARGET"); tvs = rb.AsArray(); pnt3dTAR = new Point3d(double.Parse(tvs[0].Value.ToString()), double.Parse(tvs[1].Value.ToString()), double.Parse(tvs[2].Value.ToString())); } idLine = Draw.addLine(pnt3dCEN, pnt3dTAR); varPntInts = idLine.intersectWith(idLim, extend.source); idLine.delete(); dPntBeg = varPntInts[0]; dPntEnd = varPntInts[1]; dblAng = dPntBeg.getDirection(dPntEnd); if (dblAng > pi / 2 & dblAng <= 3 * pi / 2) { varPntInts.Reverse(); dPntBeg = varPntInts[0]; dPntEnd = varPntInts[1]; dblAng = Measure.getAzRadians(dPntBeg, dPntEnd); } idLWPline = Draw.addPoly(varPntInts); dblStationBase = 0; } Point3d pnt3dB = dPntBeg.traverse(dblAng, 10); Point3d pnt3dE = dPntEnd.traverse(dblAng, 10); Point3d pnt3dM = pnt3dB.getMidPoint3d(pnt3dE); if ((objAlignBASE == null)) { objAlignBASE = Align.addAlignmentFromPoly("BASE", "SECTIONS", idLWPline, "Standard", "Standard", true, true); } AlignmentEntityCollection ents = objAlignBASE.Entities; AlignmentEntity objAlignEnt = ents[0]; if (objAlignEnt.EntityType == AlignmentEntityType.Line) { AlignmentLine objAlignEntTan = (AlignmentLine)objAlignEnt; Point2d pnt2dBeg = objAlignEntTan.StartPoint; Point2d pnt2dEnd = objAlignEntTan.EndPoint; dblAng = pnt2dBeg.getDirection(pnt2dEnd); } int j = -1; double easting = 0, northing = 0; double dblOffR = 0, dblOffL = 0; while (dblStationBase < objAlignBASE.Length) { j = j + 1; dblStationBase = dblStationBase + j * 50; objAlignBASE.PointLocation(dblStationBase, 0.0, ref easting, ref northing); Point3d pnt3dX = new Point3d(easting, northing, 0); Point3d varPntPolar = pnt3dX.traverse(dblAng + pi / 2, 100.0); idLine = Draw.addLine(pnt3dX, varPntPolar); varPntInts = idLine.intersectWith(idLim, extend.source); idLine.delete(); StaOff sOff = new StaOff(); sOff.Sta = dblStationBase; double dblStation = 0, dblOffset = 0; for (int k = 0; k < varPntInts.Count; k++) { objAlignBASE.StationOffset(varPntInts[k].X, varPntInts[k].Y, ref dblStation, ref dblOffset); if (dblOffset >= 0) { sOff.R = dblOffset; } else { sOff.L = System.Math.Abs(dblOffset); } if (sOff.R > dblOffR) { dblOffR = sOff.R; } if (sOff.L > dblOffL) { dblOffL = sOff.L; } if (k == 3) { break; } } } double dblRem = dblOffL % 10; if (dblRem < 5) { dblOffL = System.Math.Round(dblOffL / 10, 0) * 10 + 10; } else { dblOffL = System.Math.Round(dblOffL / 10, 0) * 10; } dblRem = dblOffR % 10; if (dblRem < 5) { dblOffR = System.Math.Round(dblOffR / 10, 0) * 10 + 10; } else { dblOffR = System.Math.Round(dblOffR / 10, 0) * 10; } EW_CmdSections.cmdSections(objAlignBASE.ObjectId, dblOffR, dblOffL); }
ARCG() { Arc arc = null; Point3d pnt3dBeg = Pub.pnt3dO, pnt3dEnd = Pub.pnt3dO, pnt3dX = Pub.pnt3dO; ObjectId idCgPntEnd = ObjectId.Null; ObjectId idPoly = ObjectId.Null; List <Point3d> pnts3d = null; PromptStatus ps; bool escape = true; Point3d pnt3dPick; string nameLayer; FullSubentityPath path = new FullSubentityPath(); Entity ent = xRef.getNestedEntity("\nSelect ARC: ", out escape, out pnt3dPick, out nameLayer, out path); if (escape) { return; } if (ent.GetType().ToString() != "Autodesk.AutoCAD.DatabaseServices.Arc") { Application.ShowAlertDialog(string.Format("Selected object was type of: {0} - Exiting...", ent.GetType().ToString())); return; } else { arc = (Arc)ent; } string elev = "", prompt = "Select Cogo Point for begin elevation: "; ObjectId idCgPntBeg = cmdABC.getEndPoint(pnt3dBeg, out elev, prompt); if (elev == "") { return; } List <ObjectId> idsCgPnt = new List <ObjectId>(); idsCgPnt.Add(idCgPntBeg); pnt3dBeg = idCgPntBeg.getCogoPntCoordinates(); BaseObjs.write(string.Format("\nBegin Elevation = {0:F2}", elev)); int n = (arc.Normal.Z > 0) ? 1 : -1; //right hand direction if (arc.EndPoint.isEqual(pnt3dBeg, 0.1)) { arc.ReverseCurve(); //***************************************************************************** } string cmdOpts = "M"; prompt = string.Format("\nDistance/End of curve/Single point/Multiple points <{0}> [D/E/S/M]:", cmdOpts); escape = UserInput.getUserInputKeyword(cmdOpts, out cmdOpts, prompt, "D E S M"); if (escape) { return; } double dist = 0.0, elv = 0.0, deltaZ = 0.0, grade = 0.0; uint pntNum = 0; resultsRL resultsRL = new resultsRL(); ObjectId idCgPntX = ObjectId.Null; switch (cmdOpts) { #region "D" case "D": escape = UserInput.getUserInput("\nEnter arc distance from selected begin point: ", out dist); if (escape) { return; } pnt3dX = arc.GetPointAtDist(dist); cmdRL.getRLpromptresults(out resultsRL, out escape); if (escape) { return; } switch (resultsRL.opt) { case "R": grade = resultsRL.val; elv = pnt3dBeg.Z + dist * grade; break; case "Z": deltaZ = resultsRL.val; elv = pnt3dBeg.Z + deltaZ; break; } pnt3dX = new Point3d(pnt3dX.X, pnt3dX.Y, elv); idCgPntX = pnt3dX.setPoint(out pntNum); //*********** new point ******************* break; #endregion "D" #region "E" case "E": cmdRL.getRLpromptresults(out resultsRL, out escape); if (escape) { return; } switch (resultsRL.opt) { case "R": grade = resultsRL.val; elv = pnt3dBeg.Z + arc.Length * grade; break; case "Z": deltaZ = resultsRL.val; grade = deltaZ / arc.Length; break; } pnts3d = arc.traverse(grade, pnt3dBeg); idCgPntEnd = pnts3d[pnts3d.Count - 1].setPoint(out pntNum); //*********** new point ******************* idsCgPnt.Add(idCgPntEnd); BrkLine.makeBreakline(apps.lnkBrks, "cmdARCG", out idPoly, idsCgPnt, pnts3dL: pnts3d); break; #endregion "E" #region "S" case "S": pnt3dX = UserInput.getPoint("\nSelect target point on arc: ", out ps, osMode: 512); if (pnt3dX == Pub.pnt3dO) { return; } dist = arc.GetDistAtPoint(pnt3dX); resultsRL = new resultsRL(); cmdRL.getRLpromptresults(out resultsRL, out escape); if (escape) { return; } switch (resultsRL.opt) { case "R": grade = resultsRL.val; elv = pnt3dBeg.Z + dist * grade; break; case "Z": deltaZ = resultsRL.val; elv = pnt3dBeg.Z + deltaZ; break; } pnt3dX = new Point3d(pnt3dX.X, pnt3dX.Y, elv); idCgPntX = pnt3dX.setPoint(out pntNum); //*********** new point ******************* break; #endregion "S" #region "M" case "M": string res = "N"; prompt = string.Format("\nSelect Method: <Interval distance/Number of points per segment> <{0}> [I N]: ", res); escape = UserInput.getUserInputKeyword(res, out res, prompt, "I N"); int numPnts = 5; switch (res) { case "I": dist = 10; escape = UserInput.getUserInput(string.Format("\nEnter distance between points <{0}>:", dist), out dist, dist, false); if (escape) { return; } numPnts = (int)System.Math.Truncate(arc.Length / dist); break; case "N": ps = UserInput.getUserInputInt(string.Format("\nNumber of Points <{0}>:", numPnts), false, true, false, false, true, numPnts, out numPnts); if (ps != PromptStatus.OK) { return; } dist = arc.Length / numPnts; break; } resultsRL = new resultsRL(); cmdRL.getRLpromptresults(out resultsRL, out escape); if (escape) { return; } switch (resultsRL.opt) { case "R": grade = resultsRL.val; break; case "Z": deltaZ = resultsRL.val; grade = deltaZ / arc.Length; break; } pnt3dX = new Point3d(pnt3dX.X, pnt3dX.Y, elv); idCgPntX = pnt3dX.setPoint(out pntNum); //*********** new point ******************* double sta = 0.0; for (int i = 1; i < numPnts; i++) { sta = i * dist; if (sta <= (arc.Length - dist / 2)) { pnt3dX = arc.GetPointAtDist(sta); pnt3dX = new Point3d(pnt3dX.X, pnt3dX.Y, pnt3dBeg.Z + sta * grade); idCgPntX = pnt3dX.setPoint(out pntNum); idsCgPnt.Add(idCgPntX); } } elv = pnt3dBeg.Z + arc.Length * grade; pnt3dX = new Point3d(pnt3dX.X, pnt3dX.Y, elv); idCgPntX = pnt3dX.setPoint(out pntNum); idsCgPnt.Add(idCgPntX); //*********** new point - end point ******************* break; #endregion "M" } }