public void ZeroOpacityCommand() { Document doc = Application.DocumentManager.MdiActiveDocument; Database database = doc.Database; if (!ZeroOpacityDwg(database)) { Application.ShowAlertDialog("Une erreur est survenue."); } }
public void CleanCommand() { Document doc = Application.DocumentManager.MdiActiveDocument; Database database = doc.Database; if (!CleanDwg(database)) { Application.ShowAlertDialog("An error occurred!"); } }
private static TileConfig VraagConfiguratie() { var tilesConfig = TilesConfig.Get(); var tileNames = tilesConfig.Select(t => t.Naam).ToArray(); var tileName = AutocadUtils.GetCommand("\nSelecteer de achtergrond: ", tileNames, tileNames.First()); Application.ShowAlertDialog(tileName); var tileConfig = tilesConfig.Single(t => t.Naam == tileName); return(tileConfig); }
public void TestTestMergePolyline() { var doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var ed = doc.Editor; var selRes = ed.Select("Выбери полилинии для объединения"); if (selRes.Count == 0) { return; } using (var t = db.TransactionManager.StartTransaction()) { var pls = new List <Polyline>(); foreach (var item in selRes) { if (!item.IsValidEx()) { continue; } var pl = item.GetObject(OpenMode.ForRead) as Polyline; if (pl != null) { pls.Add(pl); } } try { var plMerged = pls.Merge(); var cs = db.CurrentSpaceId.GetObject(OpenMode.ForWrite) as BlockTableRecord; cs.AppendEntity(plMerged); t.AddNewlyCreatedDBObject(plMerged, true); plMerged.ColorIndex = 5; } catch (System.Exception ex) { Application.ShowAlertDialog(ex.ToString()); } t.Commit(); } }
private static void GetSelectionWithFilter() { // 创建一个 TypedValue 数组,用于定义过滤条件 var filterTypes = new TypedValue[] { new TypedValue((int)DxfCode.Color, 5), new TypedValue((int)DxfCode.Start, "CIRCLE"), new TypedValue((int)DxfCode.LayerName, "0") }; /* * var pso = new PromptSelectionOptions(); * pso.Keywords.Add("NoFilter", "无(N)", "无(N)"); // */ /* * var filterType = new[] * { * new TypedValue((int) DxfCode.Start, "DIMENSION"), * // 将标注类型限制为转角标注与对齐标注 * new TypedValue((int) DxfCode.Operator, "<OR"), * new TypedValue(100, "AcDbAlignedDimension"), * new TypedValue(100, "AcDbRotatedDimension"), * new TypedValue((int) DxfCode.Operator, "OR>") * }; */ //获取当前文档编辑器 Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor; // 请求在图形区域选择对象 var res = acDocEd.GetSelection(new SelectionFilter(filterTypes)); // 如果提示状态OK,表示对象已选 if (res.Status == PromptStatus.OK) { var acSSet = res.Value; Application.ShowAlertDialog("Number of objects selected: " + acSSet.Count.ToString()); } else { Application.ShowAlertDialog("Number of objects selected: 0"); } }
public void PariAutoFill() { log.Info("PariAutoFill"); try { var filler = new AttributeFiller(); filler.Fill(); var doc = Application.DocumentManager.MdiActiveDocument; var editor = doc.Editor; editor.WriteMessage("\n\nFill beendet."); } catch (Exception ex) { log.Error(ex.Message, ex); Application.ShowAlertDialog(ex.Message); } }
public static void CreateViewport(Point3d centerPoint, double height, double width) { Database db = Acad.DocumentManager.MdiActiveDocument.Database; //start the transaction using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); //open the paper space for write BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite); try { CreateLayer("VPORT", 151, "Continuous", false); Viewport vp = new Viewport { Layer = "VPORT", CenterPoint = centerPoint, Height = height, Width = width }; //add the reference to the paper space btr.AppendEntity(vp); //tell the transaction about the newly added block tr.AddNewlyCreatedDBObject(vp, true); vp.On = true; //all ok, commit it tr.Commit(); } catch (Exception e) { //something didn't go right, displays the error message Acad.ShowAlertDialog(e.Message); } //dispose of transaction when we are done tr.Dispose(); } }
/// <summary> Execute a method for each given file </summary> /// <param name="method">Method to execute</param> /// <param name="files">List of file</param> /// <param name="save">Allow to save the database</param> public static void ExecuteForeach(Func <Database, bool> method, string[] files, bool save = true) { string currentDocName = Application.DocumentManager.MdiActiveDocument.Name; Database currentDatabase = Application.DocumentManager.MdiActiveDocument.Database; string log = ""; foreach (var file in files) { try { string fileName = Path.GetFileName(file); if (fileName == null || fileName[0] == '.') { continue; } Database database; if (file == currentDocName) { database = currentDatabase; } else { database = new Database(false, true); database.ReadDwgFile(file, FileShare.ReadWrite, false, ""); } method(database); if (save && GetRealPath(database) != Application.DocumentManager.MdiActiveDocument.Name) { database.SaveAs(GetRealPath(database), DwgVersion.Current); } } catch (Exception e) { log += Path.GetFileName(file) + ": " + e.Message + "\n"; } } if (!string.IsNullOrEmpty(log)) { Application.ShowAlertDialog(log); } }
public void DelPariProj() { log.Info("DelPariProj"); try { var doc = Application.DocumentManager.MdiActiveDocument; _AcEd.PromptIntegerOptions inOpts = new _AcEd.PromptIntegerOptions("\nId des Projekts, das gelöscht werden soll: "); inOpts.AllowNegative = false; inOpts.AllowNone = false; var intRes = doc.Editor.GetInteger(inOpts); if (intRes.Status != _AcEd.PromptStatus.OK) { return; } int projektId = intRes.Value; var factory = new Factory(); var database = factory.CreatePariDatabase(); int nrOfDeletedRows = database.DeleteProjekt(projektId); if (nrOfDeletedRows == 0) { var msg = string.Format(CultureInfo.CurrentCulture, "\nEs wurde kein Projekt mit der Id {0} gefunden.", projektId); log.Warn(msg); doc.Editor.WriteMessage(msg); } else { var msg = string.Format(CultureInfo.CurrentCulture, "Anzahl gelöschter Datensätze für ProjektId {1}: {0}", nrOfDeletedRows, projektId); log.Info(msg); doc.Editor.WriteMessage(msg); } } catch (Exception ex) { log.Error(ex.Message, ex); Application.ShowAlertDialog(ex.Message); } }
public void PariLog() { log.Info("PariLog"); try { var pariLogFileName = Path.Combine(Path.GetTempPath(), Globs.LogfileName); if (File.Exists(pariLogFileName)) { System.Diagnostics.Process.Start(pariLogFileName); } else { var doc = Application.DocumentManager.MdiActiveDocument; var editor = doc.Editor; editor.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nDatei '{0}' nicht gefunden!", pariLogFileName)); } } catch (Exception ex) { log.Error(ex.Message, ex); Application.ShowAlertDialog(ex.Message); } }
public static void ShowEnt(this ObjectId id, Extents3d ext, Document docOrig) { var curDoc = Application.DocumentManager.MdiActiveDocument; if (docOrig != curDoc) { Application.ShowAlertDialog($"Должен быть активен документ {docOrig.Name}"); } else { if (ext.Diagonal() > 1) { docOrig.Editor.Zoom(ext); id.FlickObjectHighlight(2, 100, 100); docOrig.Editor.SetImpliedSelection(new[] { id }); // docOrig.Editor.AddEntToImpliedSelection(id); } else { Application.ShowAlertDialog("Границы элемента не определены"); } } }
/*<summary> * ///Inserts a drawing as an external reference overlay * ///</summary> * ///<param name="DrawingPath">The path of the dwg file to be XReferenced</param> * <param name="blockname">The file name</param>*/ public static void AttachAsOverlay(Point3d refPoint, string drawingPath) { var blockname = Path.GetFileName(drawingPath); var db = Acad.DocumentManager.MdiActiveDocument.Database; //start the transaction using (var tr = db.TransactionManager.StartTransaction()) { var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); //open the paper space for write var btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite); try { var xrefId = db.OverlayXref(drawingPath, blockname); var br = new BlockReference(refPoint, xrefId); //add the reference to the paper space btr.AppendEntity(br); //tell the transaction about the newly added block tr.AddNewlyCreatedDBObject(br, true); //all ok, commit it tr.Commit(); } catch (Exception e) { //something didn't go right, displays the error message Acad.ShowAlertDialog(e.Message); } //dispose of transaction when we are done tr.Dispose(); } }
resolvePath(string JN) { int jn = int.Parse(JN.ToString(CultureInfo.InvariantCulture)); string path = string.Empty; if (jn <= 1649) { path = @"E:\"; } else if (jn <= 1749) { path = @"F:\"; } else if (jn <= 1849) { path = @"G:\"; } else if (jn <= 1949) { path = @"H:\"; } else if (jn <= 2049) { path = @"J:\"; } else if (jn <= 2149) { path = @"K:\"; } else if (jn <= 2499) { path = @"L:\"; } else if (jn <= 2599) { path = @"N:\"; } else if (jn <= 2699) { path = @"N:\2600-2699\"; } else if (jn <= 2799) { path = @"O:\2700-2699\"; } else if (jn <= 2899) { path = @"O:\2800-2899\"; } else if (jn <= 2999) { path = @"O:\2900-2999\"; } else if (jn <= 3099) { path = @"O:\3000-3099\"; } else if (jn <= 3199) { path = @"O:\3100-3199\"; } else if (jn <= 3299) { path = @"O:\3200-3299\"; } else if (jn <= 3399) { path = @"O:\3300-3399\"; } else if (jn <= 3499) { path = @"O:\3400-3499\"; } else { Application.ShowAlertDialog("Drawing File location not found"); path = ""; } return(path); }
processArc(Point3d pnt3dBeg, Point3d pnt3dEnd, Point3d pnt3dCen, Point3d pnt3dX, bool through, double radius, bool rh, ObjectId idEnt, double disX, ref double offset) { disX = pnt3dCen.getDistance(pnt3dX); double dirX = pnt3dCen.getDirection(pnt3dX); double dirB = pnt3dCen.getDirection(pnt3dBeg); double dirE = pnt3dCen.getDirection(pnt3dEnd); if (through) { offset = System.Math.Abs(disX - radius); } bool go = false; if (rh) { if (dirB > dirE) { double adj = 2 * System.Math.PI - dirB; if (dirX + adj >= 0 && dirX + adj <= dirE + adj) { go = true; if (disX < radius) { offset = -offset; } } } else { if (dirX >= dirB && dirX <= dirE) { go = true; if (disX < radius) { offset = -offset; } } } } else if (!rh) { if (dirB < dirE) { double adj = 2 * System.Math.PI - dirE; if (dirX + adj <= dirB + adj && dirX + adj <= 0) { go = true; if (disX > radius) { offset = -offset; } } } else { if (dirX >= dirE && dirX <= dirB) { go = true; if (disX > radius) { offset = -offset; } } } } if (!go) { idEnt.delete(); Application.ShowAlertDialog("Point selected is outside limits of procedure. Exiting..."); } return(go); }
public void ExcelPari() { log.Info("ExcelPari"); try { var fact = new Factory(); var excelExporter = fact.CreateVisualOutputHandler(); var database = fact.CreatePariDatabase(); var dwgPrefix = Application.GetSystemVariable("DwgPrefix").ToString(); var dwgName = Application.GetSystemVariable("DwgName").ToString(); int projektId = -1; var doc = Application.DocumentManager.MdiActiveDocument; _AcEd.PromptIntegerOptions inOpts = new _AcEd.PromptIntegerOptions("\nId des Projekts, für das eine Exceldatei erstellt werden soll <Return für aktuelles>: "); inOpts.AllowNegative = false; inOpts.AllowNone = true; var intRes = doc.Editor.GetInteger(inOpts); if (intRes.Status == _AcEd.PromptStatus.OK) { projektId = intRes.Value; var pi = database.ListProjInfos().FirstOrDefault(x => x.ProjektId == projektId); if (pi == null) { var msg = string.Format(CultureInfo.CurrentCulture, "Das Projekt mit Id {0} existiert nicht in der Datenbank!", projektId); log.Error(msg); Application.ShowAlertDialog(msg); return; } } else if (intRes.Status == _AcEd.PromptStatus.None) { var blockReader = new BlockReader(); blockReader.ReadBlocksFromModelspace(); var projektInfo = blockReader.ProjektInfo; if (projektInfo == null) { var msg = string.Format(CultureInfo.CurrentCulture, "Der ProjektInfo-Block existiert nicht in der Zeichnung!"); log.Error(msg); Application.ShowAlertDialog(msg); return; } projektInfo.DwgName = dwgName; projektInfo.DwgPrefix = dwgPrefix; projektId = database.GetProjektId(projektInfo); if (projektId < 0) { var msg = string.Format(CultureInfo.CurrentCulture, "Das Projekt wurde nicht gefunden in der Datenbank!"); log.Error(msg); Application.ShowAlertDialog(msg); return; } } doc.Editor.WriteMessage("\nExport wird gestartet..."); //var targetFile = Path.Combine(dwgPrefix, Path.GetFileNameWithoutExtension(dwgName) + "_NW" + ".xlsx"); excelExporter.ExportNW(database, null, projektId); excelExporter.ExportNF(database, null, projektId); doc.Editor.WriteMessage("\nExport fertiggestellt."); } catch (Exception ex) { log.Error(ex.Message, ex); Application.ShowAlertDialog(ex.Message); } }
//[CommandMethod("gi")] public static void GetIntersections() { var db = HostApplicationServices.WorkingDatabase; var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; using (var docLock = doc.LockDocument()) { using (var tr = db.TransactionManager.StartTransaction()) { try { var btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); var peo = new PromptEntityOptions("\nSelect a single polyline >>"); peo.SetRejectMessage("\nSelected object might be of type polyline only >>"); peo.AddAllowedClass(typeof(Polyline), false); PromptEntityResult res; res = ed.GetEntity(peo); if (res.Status != PromptStatus.OK) { return; } var ent = tr.GetObject(res.ObjectId, OpenMode.ForRead); if (ent == null) { return; } //Polyline poly = (Polyline)ent as Polyline; var curv = ent as Curve; var pcurves = new DBObjectCollection(); curv.Explode(pcurves); TypedValue[] values = { new TypedValue(0, "lwpolyline") //might be added layer name to select curve: //, new TypedValue(8, "mylayer") }; var filter = new SelectionFilter(values); var fence = new Point3dCollection(); var leng = curv.GetDistanceAtParameter(curv.EndParam) - curv.GetDistanceAtParameter(curv.StartParam); // number of divisions along polyline to create fence selection var step = leng / 256; // set number of steps to your suit var num = Convert.ToInt32(leng / step); var i = 0; for (i = 0; i < num; i++) { var pp = curv.GetPointAtDist(step * i); fence.Add(curv.GetClosestPointTo(pp, false)); } var selres = ed.SelectFence(fence, filter); if (selres.Status != PromptStatus.OK) { return; } var intpts = new Point3dCollection(); var qcurves = new DBObjectCollection(); foreach (SelectedObject selobj in selres.Value) { var obj = tr.GetObject(selobj.ObjectId, OpenMode.ForRead, false); if (selobj.ObjectId != curv.ObjectId) { var icurves = new DBObjectCollection(); var icurv = obj as Curve; icurv.Explode(icurves); foreach (DBObject dbo in icurves) { if (!qcurves.Contains(dbo)) { qcurves.Add(dbo); } } } } ed.WriteMessage("\n{0}", qcurves.Count); var j = 0; var polypts = new Point3dCollection(); for (i = 0; i < pcurves.Count; ++i) { for (j = 0; j < qcurves.Count; ++j) { var curve1 = pcurves[i] as Curve; var curve2 = qcurves[j] as Curve; var pts = new Point3dCollection(); curve1.IntersectWith(curve2, Intersect.OnBothOperands, pts, IntPtr.Zero, IntPtr.Zero); foreach (Point3d pt in pts) { if (!polypts.Contains(pt)) { polypts.Add(pt); } } } } Application.SetSystemVariable("osmode", 0); // optional // for debug only Application.ShowAlertDialog(string.Format("\nNumber of Intersections: {0}", polypts.Count)); // test for visulization only foreach (Point3d inspt in polypts) { var circ = new Circle(inspt, Vector3d.ZAxis, 10 * db.Dimtxt); circ.ColorIndex = 1; btr.AppendEntity(circ); tr.AddNewlyCreatedDBObject(circ, true); } tr.Commit(); } catch (Exception ex) { ed.WriteMessage("\n{0}\n{1}", ex.Message, ex.StackTrace); } } } }
/// <summary> /// Метод для отладки /// </summary> /// <param name="message"></param> public void MakeMessage(string message) { Application.ShowAlertDialog(message); }
// [CommandMethod("wblockclone", CommandFlags.Session)] //static public void wblockclone() //{ // Document doc = Application.DocumentManager.MdiActiveDocument; // Database db = doc.Database; // Editor ed = doc.Editor; // //PromptEntityOptions peo = new PromptEntityOptions("\nSelect entity to copy: "); // //PromptEntityResult per = ed.GetEntity(peo); // //if (per.Status != PromptStatus.OK) // // return; // Application. // using (DocumentLock doclock = doc.LockDocument()) // { // ObjectIdCollection ObjectcIds = new ObjectIdCollection(); // ObjectcIds.Add(per.ObjectId); // Database destDb = new Database(false, true); // destDb.ReadDwgFile(@"C:\Users\Daryl Banks\Downloads\doraltest\2014Doral\Doral-Closed-Polygons\Doral06.DWG", System.IO.FileShare.Read, true, ""); // using (Transaction Tx = destDb.TransactionManager.StartTransaction()) // { // BlockTable bt = Tx.GetObject( // destDb.BlockTableId, // OpenMode.ForRead) as BlockTable; // BlockTableRecord btr = Tx.GetObject( // bt[BlockTableRecord.ModelSpace], // OpenMode.ForWrite) as BlockTableRecord; // IdMapping oIdMap = new IdMapping(); // destDb.WblockCloneObjects( // ObjectcIds, // btr.ObjectId, // oIdMap, // DuplicateRecordCloning.Ignore, // false); // Tx.Commit(); // } // destDb.SaveAs(destDb.Filename, DwgVersion.Current); // } //} public static void GetComplexity() { var db = HostApplicationServices.WorkingDatabase; var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; using (doc.LockDocument()) { using (var tr = db.TransactionManager.StartTransaction()) { try { var btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); var peo = new PromptEntityOptions("\nSelect a single polyline >>"); peo.SetRejectMessage("\nSelected object might be of type polyline only >>"); peo.AddAllowedClass(typeof(Polyline), false); PromptEntityResult res; res = ed.GetEntity(peo); if (res.Status != PromptStatus.OK) { return; } var ent = tr.GetObject(res.ObjectId, OpenMode.ForRead); if (ent == null) { return; } //Polyline poly = (Polyline)ent as Polyline; var curv = ent as Curve; var pcurves = new DBObjectCollection(); if (curv != null) { curv.Explode(pcurves); TypedValue[] values = { new TypedValue(0, "lwpolyline") //might be added layer name to select curve: //, new TypedValue(8, "mylayer") }; var filter = new SelectionFilter(values); var fence = new Point3dCollection(); var leng = curv.GetDistanceAtParameter(curv.EndParam) - curv.GetDistanceAtParameter(curv.StartParam); // number of divisions along polyline to create fence selection //double step = leng / 256;// set number of steps to your suit var step = leng / pcurves.Count; Application.SetSystemVariable("osmode", 0); // optional // for debug only Application.ShowAlertDialog(string.Format("\nNumber of Steps: {0}", step)); } tr.Commit(); } catch (Exception ex) { ed.WriteMessage("\n{0}\n{1}", ex.Message, ex.StackTrace); } } } }
public void ExportPari() { log.Info("ExportPari"); try { var factory = new Factory(); IPariDatabase database = factory.CreatePariDatabase(); if (!CheckTableValidity(database)) { return; } var blockReader = new BlockReader(); blockReader.ReadBlocksFromModelspace(); var blockInfos = blockReader.BlockInfos; var wohnungInfos = blockReader.WohnungInfos; var projektInfo = blockReader.ProjektInfo; if (projektInfo == null) { var msg = string.Format(CultureInfo.CurrentCulture, "Der ProjektInfo-Block existiert nicht in der Zeichnung!"); log.Error(msg); Application.ShowAlertDialog(msg); return; } var dwgName = Application.GetSystemVariable("DwgName").ToString(); var dwgPrefix = Application.GetSystemVariable("DwgPrefix").ToString(); projektInfo.DwgName = dwgName; projektInfo.DwgPrefix = dwgPrefix; var projektId = database.GetProjektId(projektInfo); if (projektId >= 0) { var msg = string.Format(CultureInfo.CurrentCulture, "Das Projekt '{0}' existiert bereits! ProjektId = {1}.", projektInfo.Bauvorhaben, projektId); log.Error(msg); Application.ShowAlertDialog(msg); return; } var tableBuilder = new TableBuilder(); tableBuilder.Build(blockInfos, wohnungInfos); if (CheckInvalidCategoriesAskUser(tableBuilder)) { return; } var doc = Application.DocumentManager.MdiActiveDocument; var editor = doc.Editor; database.SaveToDatabase(tableBuilder, projektInfo); var raumWithoutTop = tableBuilder.RaumTable.Where(x => string.IsNullOrEmpty(x.Top)).ToList(); if (raumWithoutTop.Count > 0) { editor.WriteMessage("\nFolgende Räume haben keine TOP-Information: "); editor.WriteMessage("\n-----------------------------------------------------------------"); foreach (var ri in raumWithoutTop) { var msg = string.Format(CultureInfo.CurrentCulture, "\nRaum: {0}\tGeschoss: {1}\tNutzwert: {2}\tHandle: {3}", ri.Raum, ri.Lage, ri.RNW, ri.AcadHandle); log.Warn(msg); editor.WriteMessage(msg); } } editor.WriteMessage("\n\nExport beendet."); } catch (Exception ex) { log.Error(ex.Message, ex); Application.ShowAlertDialog(ex.Message); } }
convertDictionaryLinksToXData() { try { BaseObjs.sendCommand("VBAUNLOAD\rC:\\TSET\\VBA2015\\CIVIL3D2015.DVB\r"); //BaseObjs.sendCommand("(unloadCivil3d2015)\r"); } catch (System.Exception ex) { Application.ShowAlertDialog(string.Format("{0} Convert_App.cs: line: 31", ex.Message)); BaseObjs.writeDebug(string.Format("{0} Convert_App.cs: line: 31", ex.Message)); } int k = 0; bool exists = false; ObjectId idBlock = ObjectId.Null; ObjectId idLeader = ObjectId.Null; ObjectId idText = ObjectId.Null; ObjectId idPnt1 = ObjectId.Null; ObjectId idPnt2 = ObjectId.Null; ObjectId idAlign = ObjectId.Null; ObjectId idSurface = ObjectId.Null; ObjectId idPoly = ObjectId.Null; ObjectId idBubble = ObjectId.Null; ObjectId idCwpRef = ObjectId.Null; string topNum = string.Empty; string topTxt = string.Empty; string botNum = string.Empty; string botTxt = string.Empty; string nameCmd = string.Empty; string nameApp = string.Empty; string top = string.Empty; string bot = string.Empty; List <string> dicts = new List <string> { "GradeTagDict", "PtTagDict", "FlTagDict", "SEDTagDict", "MHTagDict", "XrGradeTagDict", "XrFlTagDict", "VBTagDict" }; List <ObjectId> idsCgPnts = null; ResultBuffer rb = null; TypedValue[] tvs = null; List <Object> errorCallouts = new List <object>(); foreach (string dict in dicts) { ObjectId idDict = Dict.getNamedDictionary(dict, out exists); List <DBDictionaryEntry> entries = idDict.getEntries(); foreach (DBDictionaryEntry entry in entries) { string shPnt1 = entry.Key; Handle hPnt1 = new Handle(Int64.Parse(shPnt1, NumberStyles.AllowHexSpecifier)); idPnt1 = hPnt1.getObjectId(); rb = Dict.getXRec(idDict, hPnt1.ToString()); if (rb == null) { continue; } tvs = rb.AsArray(); idBlock = tvs[0].Value.ToString().stringToHandle().getObjectId(); checkGroup(idBlock); idLeader = tvs[1].Value.ToString().stringToHandle().getObjectId(); //if (idBlock.IsEffectivelyErased || idBlock.IsErased) //{ if (idLeader.IsErased || idLeader.IsEffectivelyErased) { Dict.deleteXRec(idDict, hPnt1.ToString()); errorCallouts.Add(idPnt1.getCogoPntNumber()); continue; } //} idsCgPnts = new List <ObjectId> { idPnt1 }; Leader ldr = null; using (Transaction tr = BaseObjs.startTransactionDb()) { ldr = (Leader)tr.GetObject(idLeader, OpenMode.ForWrite); ldr.Annotative = AnnotativeStates.True; tr.Commit(); } idLeader.moveToTop(); topNum = Blocks.getBlockRefAttributeValue(idBlock, "TOPNUM"); topTxt = Blocks.getBlockRefAttributeValue(idBlock, "TOPTXT"); botNum = Blocks.getBlockRefAttributeValue(idBlock, "BOTNUM"); botTxt = Blocks.getBlockRefAttributeValue(idBlock, "BOTTXT"); switch (dict) { case "GradeTagDict": nameCmd = "cmdG"; nameApp = "lnkC0"; break; case "PtTagDict": nameCmd = "cmdPT"; nameApp = "lnkC0"; break; case "FlTagDict": nameCmd = "cmdFL"; nameApp = "lnkC0"; break; case "SEDTagDict": nameCmd = "cmdSDE"; nameApp = "lnkC0"; idAlign = tvs[2].Value.ToString().stringToHandle().getObjectId(); break; case "MHTagDict": nameCmd = "cmdMH"; nameApp = "lnkC0"; idAlign = tvs[2].Value.ToString().stringToHandle().getObjectId(); idSurface = tvs[3].Value.ToString().stringToHandle().getObjectId(); break; case "XrGradeTagDict": nameCmd = "cmdSDE"; nameApp = "lnkC0"; idAlign = tvs[2].Value.ToString().stringToHandle().getObjectId(); idSurface = tvs[3].Value.ToString().stringToHandle().getObjectId(); break; case "XrFlTagDict": nameCmd = "cmdSDE"; nameApp = "lnkC0"; idAlign = tvs[2].Value.ToString().stringToHandle().getObjectId(); idSurface = tvs[3].Value.ToString().stringToHandle().getObjectId(); break; case "VBTagDict": nameCmd = "cmdVB"; nameApp = "lnkC0"; idPoly = tvs[1].Value.ToString().stringToHandle().getObjectId(); idSurface = tvs[2].Value.ToString().stringToHandle().getObjectId(); idBubble = tvs[3].Value.ToString().stringToHandle().getObjectId(); idCwpRef = tvs[4].Value.ToString().stringToHandle().getObjectId(); break; } top = string.Format("{0}{1}", topNum, topTxt); bot = string.Format("{0}{1}", botNum, botTxt); idBlock.delete(); Dict.deleteXRec(idDict, hPnt1.ToString()); if (topNum.Contains("(") && topNum.Contains(")")) { nameCmd = string.Format("{0}X", nameCmd); } double dZ = 0.0; if (botNum != "") { if (botNum == "0\"") { nameCmd = "cmdCF0"; dZ = 0; } else { dZ = double.Parse(topNum.ToString()) - double.Parse(botNum.ToString()); } } Txt.addLdrText(nameCmd, nameApp, ldr.ObjectId, idsCgPnts, top, bot, "", dZ, useBackgroundFill: true); ++k; } } ObjectId idDictGS = Dict.getNamedDictionary("GSDict", out exists); List <DBDictionaryEntry> entriesGS = idDictGS.getEntries(); ResultBuffer rbGS = null; TypedValue[] tvsGS = null; foreach (DBDictionaryEntry entryGS in entriesGS) { ObjectId idEntryGS = ObjectId.Null; string shText = entryGS.Key; Handle hText = new Handle(Int64.Parse(shText, NumberStyles.AllowHexSpecifier)); idText = hText.getObjectId(); rbGS = Dict.getXRec(idDictGS, hText.ToString()); if (rbGS == null) { continue; } tvsGS = rbGS.AsArray(); idLeader = tvsGS[0].getObjectId(); using (Transaction tr = BaseObjs.startTransactionDb()) { DBText text = (DBText)tr.GetObject(idText, OpenMode.ForRead); top = text.TextString; bot = string.Empty; Leader ldr = (Leader)tr.GetObject(idLeader, OpenMode.ForWrite); ldr.Annotative = AnnotativeStates.True; tr.Commit(); } switch (top.Substring(0, 1)) { case "(": nameCmd = "cmdGSX"; break; case "R": nameCmd = "cmdGS"; break; case "S": nameCmd = "cmdSS"; break; default: if (top.Contains(".")) { nameCmd = "cmdGSS"; } else { nameCmd = "cmdGS0"; } break; } idsCgPnts = new List <ObjectId> { tvsGS[1].getObjectId(), tvsGS[2].getObjectId() }; nameApp = apps.lnkGS; Dict.deleteXRec(idDictGS, hText.ToString()); idText.delete(); Txt.addLdrText(nameCmd, nameApp, idLeader, idsCgPnts, top, bot, useBackgroundFill: true); ++k; Debug.Print(string.Format("k:{0}", k)); } tvs = new TypedValue[11]; tvs.SetValue(new TypedValue((int)DxfCode.Start, "INSERT"), 0); tvs.SetValue(new TypedValue((int)DxfCode.Operator, "<OR"), 1); tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "GradeTag"), 2); tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "XrGradeTag"), 3); tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "FlTag"), 4); tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "XrFlTag"), 5); tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "PlxTag"), 6); tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "TcTag"), 7); tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "PtTag"), 8); tvs.SetValue(new TypedValue((int)DxfCode.BlockName, "LabelTag"), 9); tvs.SetValue(new TypedValue((int)DxfCode.Operator, "OR>"), 10); SelectionSet ss = Select.buildSSet(tvs); if (ss != null && ss.Count > 0) { ObjectId[] ids = ss.GetObjectIds(); Point3d pnt3dIns; using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId id in ids) { BlockReference br = (BlockReference)tr.GetObject(id, OpenMode.ForRead); pnt3dIns = br.Position; List <ObjectId> idLdrs = Select.getEntityatPoint(pnt3dIns, typeof(Leader), "ARROW", 1.0); if (idLdrs == null || idLdrs.Count == 0) { Debug.Print(string.Format("No Leader: {0},{1}", pnt3dIns.X, pnt3dIns.Y)); continue; } Point3d pnt3dLdrBeg = idLdrs[0].getBegPnt(); List <ObjectId> idCgPnts = Select.getEntityatPoint(pnt3dLdrBeg, typeof(CogoPoint), "CPNT-ON"); if (idCgPnts == null || idCgPnts.Count == 0) { Debug.Print(string.Format("No CogoPnt: {0},{1}", pnt3dLdrBeg.X, pnt3dLdrBeg.Y)); } idLeader = idLdrs[0]; Leader ldr = (Leader)tr.GetObject(idLeader, OpenMode.ForWrite); ldr.Annotative = AnnotativeStates.True; idLeader.moveToTop(); string nameBlock = br.Name.ToUpper(); switch (nameBlock) { case "GRADETAG": case "XRGRADETAG": topNum = Blocks.getBlockRefAttributeValue(id, "TOPNUM"); topTxt = Blocks.getBlockRefAttributeValue(id, "TOPTXT"); botNum = Blocks.getBlockRefAttributeValue(id, "BOTNUM"); botTxt = Blocks.getBlockRefAttributeValue(id, "BOTTXT"); top = string.Format("{0}{1}", topNum, topTxt); bot = string.Format("{0}{1}", botNum, botTxt); nameCmd = "cmdG"; break; case "FLTAG": case "XRFLTAG": case "PLXTAG": top = Blocks.getBlockRefAttributeValue(id, "TOPNUM"); bot = Blocks.getBlockRefAttributeValue(id, "BOTTXT"); nameCmd = "cmdFL"; break; case "TCTAG": case "PTTAG": case "LABELTAG": top = Blocks.getBlockRefAttributeValue(id, "TOPLABEL"); bot = Blocks.getBlockRefAttributeValue(id, "BOTLABEL"); if (top == "DEEPEN") { nameCmd = "cmdDEP"; } if (bot == "RISERS") { nameCmd = "cmdRISER"; } break; } id.delete(); nameApp = apps.lnkCO; if (top.Contains("(") && top.Contains(")")) { nameCmd = string.Format("{0}X", nameCmd); } double dZ = 0.0; if (botNum != "") { if (botNum == "0\"") { nameCmd = "cmdCF0"; dZ = 0; } else { dZ = double.Parse(topNum.ToString()) - double.Parse(botNum.ToString()); } } Txt.addLdrText(nameCmd, nameApp, idLeader, idsCgPnts, top, bot, "", dZ, useBackgroundFill: true); ++k; } tr.Commit(); } } Application.ShowAlertDialog(string.Format("{0} Callouts converted. {1} Points with broken links", k.ToString(), errorCallouts.Count.ToString())); foreach (object pntNum in errorCallouts) { Debug.Print(pntNum.ToString()); } BaseObjs.sendCommand("-VBALOAD\rC:\\TSET\\VBA2015\\CIVIL3D2015.DVB\r"); }
executeCLKS(SelectionSet ss0 = null) { hLnkAdds = new List <Handle>(); hLnkFixs = new List <Handle>(); winResults wResults = FormHandler.fHandler.wResults; Application.ShowModelessWindow(wResults); ListBox lbxAdd = wResults.lbxAdd; lbxAdd.Items.Clear(); lbxAdd.Height = 220; ListBox lbxFix = wResults.lbxFix; lbxFix.Items.Clear(); lbxFix.Height = 220; wResults.Height = 565; bool exists; string nameDict = ""; ObjectId idDict = ObjectId.Null; ObjectId idPnt = ObjectId.Null; List <ObjectId> ids = getBlockRefs(); List <ObjectId> idsPnt = getPoints(); List <ObjectId> idsLdr = getLeaders(); Handle hPntX = new Handle(); if (ids != null && ids.Count > 0) { wResults.pBar1.Maximum = ids.Count; int i = 0; Point3d pnt3dIns; ObjectId idGradeTagDict = Dict.getNamedDictionary("GradeTagDict", out exists); List <DBDictionaryEntry> entriesGradeTagDict = idGradeTagDict.getEntries(); ObjectId idFlTagDict = Dict.getNamedDictionary("FlTagDict", out exists); List <DBDictionaryEntry> entriesFlTagDict = idFlTagDict.getEntries(); List <DBDictionaryEntry> entries = null; using (Transaction tr = BaseObjs.startTransactionDb()) { foreach (ObjectId idBlkRef in ids) { ++i; Debug.Print(i.ToString()); string nameBlkRef = Blocks.getBlockRefName(idBlkRef).ToUpper(); switch (nameBlkRef) { case "GRADETAG": entries = entriesGradeTagDict; nameDict = "GradeTagDict"; idDict = idGradeTagDict; break; case "FLTAG": entries = entriesFlTagDict; nameDict = "FlTagDict"; idDict = idFlTagDict; break; } bool fix; bool isValid = utility1.isValidObjInDictionary(idBlkRef, entries, nameDict, idDict, out fix, out hPntX); if (isValid) { if (fix) { hLnkFixs.Add(hPntX); } } else { using (BaseObjs._acadDoc.LockDocument()) { try { BlockReference br = (BlockReference)tr.GetObject(idBlkRef, OpenMode.ForRead); pnt3dIns = br.Position; //Debug.Print(string.Format("{0:F3},{1:F3},{2:F3}", pnt3dIns.X, pnt3dIns.Y, pnt3dIns.Z)); ObjectId idLdr = findLeader(pnt3dIns, idsLdr); if (idLdr == ObjectId.Null) { continue; } Point3d pnt3dLdrBeg = idLdr.getBegPnt(); Point3d pnt3dPnt = Point3d.Origin; bool found = false; try { foreach (ObjectId id in idsPnt) { pnt3dPnt = id.getCogoPntCoordinates(); if ((pnt3dPnt - pnt3dLdrBeg) == v3d0) { found = true; idPnt = id; break; } else if (System.Math.Round(pnt3dPnt.getDistance(pnt3dLdrBeg)) < .001) { found = true; idPnt = id; break; } } } catch (System.Exception ex) { Application.ShowAlertDialog(string.Format("{0} line 149", ex.Message)); } if (!found) { continue; } string desc = string.Empty; try { switch (nameBlkRef) { case "GRADETAG": desc = Blocks.getBlockRefAttributeValue(idBlkRef, "TOPTXT"); desc = desc.Replace(")", ""); desc = desc.Replace("(", ""); if (desc == "") { idBlkRef.delete(); continue; } switch (desc) { case "FF": utility1.checkFF(idBlkRef, pnt3dPnt); addOrphanToDicts("GradeTagDict", idPnt.getHandle(), idBlkRef.getHandle(), idLdr.getHandle()); //Debug.Print(idPnt.getHandle().ToString()); break; case "TC": utility1.checkTC(idBlkRef, pnt3dPnt); addOrphanToDicts("GradeTagDict", idPnt.getHandle(), idBlkRef.getHandle(), idLdr.getHandle()); //Debug.Print(idPnt.getHandle().ToString()); break; } break; case "FLTAG": desc = Blocks.getBlockRefAttributeValue(idBlkRef, "BOTTXT"); desc = desc.Replace(")", ""); desc = desc.Replace("(", ""); if (desc == "") { idBlkRef.delete(); continue; } utility1.checkFL(idBlkRef, pnt3dPnt); addOrphanToDicts("FlTagDict", idPnt.getHandle(), idBlkRef.getHandle(), idLdr.getHandle()); //Debug.Print(idPnt.getHandle().ToString()); break; } } catch (System.Exception ex) { Application.ShowAlertDialog(string.Format("{0} line 198", ex.Message)); } } catch (Autodesk.AutoCAD.Runtime.Exception ex5) { Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog(string.Format("{0} line 204", ex5.Message)); } } } wResults.pBar1.Value = i; } tr.Commit(); } } wResults.addControls(wResults, lbxAdd, hLnkAdds); wResults.addControls(wResults, lbxFix, hLnkFixs); using (BaseObjs._acadDoc.LockDocument()) { Dict.getNamedDictionary("CLKS", out exists); } wResults.pBar1.Value = 0; }