static public void CreatePolyLine() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; HostApplicationServices hs = HostApplicationServices.Current; string outputPath = hs.FindFile(doc.Name, doc.Database, FindFileHint.Default); //get user input //select point input file ed.WriteMessage("Select the Excel file contains the door step points"); string excelPath = FileOps.SelectFile(); #region get Excel Sheet Name PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter Sheet Name: "); pStrOpts.AllowSpaces = true; PromptResult pStrRes = doc.Editor.GetString(pStrOpts); string shtName = pStrRes.StringResult; #endregion List <Point3d> doorStepPts = Excel.getAllpoint(doc, excelPath, shtName); CADops.CreatePolylineFromPoint(doc, doorStepPts); }
private static string DrawingPath() { Document doc = Application.DocumentManager.MdiActiveDocument; HostApplicationServices hs = HostApplicationServices.Current; string path = hs.FindFile(doc.Name, doc.Database, FindFileHint.Default); return(path); }
public DataBlok() { Doc = AcAp.DocumentManager.MdiActiveDocument; acDb = Doc.Database; HostApplicationServices hs = HostApplicationServices.Current; string path = hs.FindFile(Doc.Name, Doc.Database, FindFileHint.Default); infoFile = new FileInfo(path); ListBlokTabel = new Dictionary <string, ObjectId>(); ListBlokReference = new Dictionary <string, ObjectId>(); ListAtributReference = new Dictionary <string, ObjectId>(); }
private void AddEntityToModelSpace(Entity ent) { Database workingDatabase = HostApplicationServices.get_WorkingDatabase(); using (Transaction transaction = workingDatabase.get_TransactionManager().StartTransaction()) { BlockTable blockTable = (BlockTable)transaction.GetObject(workingDatabase.get_BlockTableId(), (OpenMode)0); ((BlockTableRecord)transaction.GetObject(((SymbolTable)blockTable).get_Item((string)BlockTableRecord.ModelSpace), (OpenMode)1)).AppendEntity(ent); transaction.AddNewlyCreatedDBObject((DBObject)ent, true); transaction.Commit(); } this.ed.UpdateScreen(); Thread.Sleep(this.delay); }
private void butSpecify_Click(object sender, EventArgs e) { if (rdoBlock.Checked) { m_refresher.FrameBlock = Functions.GetBlock(); if (m_refresher.FrameBlock != null) { m_refresher.BasePoints = Utils.GetCorners(); } if (m_refresher.FrameBlock != null && m_refresher.BasePoints != new Point3d[2]) { // Get Name || Filename || Path of block string p = m_refresher.FrameBlock.PathName; txtBlockName.Text = m_refresher.FrameBlock.Name; txtBlockFileName.Text = Path.GetFileName(p); if (txtBlockFileName.Text == "") { p = ""; rdoName.Checked = true; rdoFileName.Enabled = false; rdoPath.Enabled = false; } else { rdoFileName.Enabled = true; rdoPath.Enabled = true; if (!(Path.IsPathRooted(p))) { Document doc = Autodesk.AutoCAD.ApplicationServices. Application.DocumentManager.MdiActiveDocument; HostApplicationServices hs = HostApplicationServices.Current; string acPath = hs.FindFile( doc.Name, doc.Database, FindFileHint.Default); p = Path.Combine(acPath, p); p = Path.GetFullPath(p); } } txtBlockPath.Text = p; } } if (rdoRectangle.Checked) { } if (rdoLine.Checked) { } }
public void init(LayoutHelperDevice pDevice, Model gsModule, Database pDb /* OdDbCommandContext ctx*/) { m_pDevice = pDevice; m_pGsModel = gsModule; //pDb->addReactor(&m_cDbReactor); HostApplicationServices pAppSvcs = HostApplicationServices.Current; m_GRIPSIZE = pAppSvcs.GRIPSIZE; m_GRIPOBJLIMIT = pAppSvcs.GRIPOBJLIMIT; m_GRIPCOLOR = new EntityColor(ColorMethod.ByAci, pAppSvcs.GRIPCOLOR); m_GRIPHOVER = new EntityColor(ColorMethod.ByAci, pAppSvcs.GRIPHOVER); m_GRIPHOT = new EntityColor(ColorMethod.ByAci, pAppSvcs.GRIPHOT); //m_pGetSelectionSetPtr = pGetSSet; }
public void DrawingPath() { Document doc = Core.Application.DocumentManager.MdiActiveDocument; HostApplicationServices hs = HostApplicationServices.Current; string path = hs.FindFile( doc.Name, doc.Database, FindFileHint.Default ); doc.Editor.WriteMessage( "\nFile was found in: " + path ); }
/// <summary> /// Get charactericstic of block (Name || Filename || Path) /// </summary> /// <param name="btr"></param> /// <returns></returns> private string GetBlockChar(Document doc) { string n = null; BlockName nType = BlockName.Name; if (m_rdoFileName.Checked) { nType = BlockName.FileName; } if (m_rdoPath.Checked) { nType = BlockName.Path; } switch (nType) { case BlockName.Name: n = FrameBlock.Name; break; case BlockName.FileName: n = Path.GetFileName(FrameBlock.PathName); break; case BlockName.Path: string p = FrameBlock.PathName; if (!(Path.IsPathRooted(p))) { HostApplicationServices hs = HostApplicationServices.Current; string acPath = hs.FindFile( doc.Name, doc.Database, FindFileHint.Default); p = Path.Combine(acPath, p); n = Path.GetFullPath(p); } break; } return(n); }
static public void ListVertices() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; HostApplicationServices hs = HostApplicationServices.Current; string path = hs.FindFile(doc.Name, doc.Database, FindFileHint.Default); //ed.WriteMessage("\nTo List all the points in the 3D string, type command LISTVERTICES."); long adjustX = 0; long adjustY = 0; long scaler = 1; PromptEntityResult per = ed.GetEntity("Select polylines"); ObjectId oid = per.ObjectId; if (per.Status == PromptStatus.OK) { Transaction tr = db.TransactionManager.StartTransaction(); DBObject objPick = tr.GetObject(oid, OpenMode.ForRead); Entity objEnt = objPick as Entity; string sLayer = objEnt.Layer.ToString(); path += "_" + sLayer; ObjectIdCollection oDBO = CADops.SelectAllPolyline(sLayer); //Handle handseed = db.Handseed; try { using (tr) { long shtNo = 1; List <string> data = new List <string>(); foreach (ObjectId id in oDBO) { //DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead); DBObject obj = tr.GetObject(id, OpenMode.ForRead); Entity ent = obj as Entity; string layerName = ent.Layer.ToString(); //create list for storing x,y,z value of point string StrId = ""; // If a "lightweight" (or optimized) polyline Autodesk.AutoCAD.DatabaseServices.Polyline lwp = obj as Autodesk.AutoCAD.DatabaseServices.Polyline; if (lwp != null) { //StrId = lwp.ObjectId.ToString(); StrId = lwp.Handle.ToString(); ed.WriteMessage("\n" + StrId); // Use a for loop to get each vertex, one by one int vn = lwp.NumberOfVertices; for (int i = 0; i < vn; i++) { // Could also get the 3D point here Point2d pt = lwp.GetPoint2dAt(i); string temp = CADops.scaleNmove(pt.X, adjustX, scaler) + "," + CADops.scaleNmove(pt.Y, adjustY, scaler) + ", ," + StrId + "," + layerName; data.Add(temp); ed.WriteMessage("\n" + pt.ToString()); } } else { // If an old-style, 2D polyline Polyline2d p2d = obj as Polyline2d; if (p2d != null) { StrId = p2d.Handle.ToString(); ed.WriteMessage("\n" + StrId); // Use foreach to get each contained vertex foreach (ObjectId vId in p2d) { Vertex2d v2d = (Vertex2d)tr.GetObject(vId, OpenMode.ForRead); string temp = CADops.scaleNmove(v2d.Position.X, adjustX, scaler) + "," + CADops.scaleNmove(v2d.Position.Y, adjustY, scaler) + "," + v2d.Position.Z * scaler + "," + StrId + "," + layerName; data.Add(temp); ed.WriteMessage("\n" + v2d.Position.ToString()); } } else { // If an old-style, 3D polyline Polyline3d p3d = obj as Polyline3d; if (p3d != null) { StrId = p3d.Handle.ToString(); ed.WriteMessage("\n" + StrId); // Use foreach to get each contained vertex foreach (ObjectId vId in p3d) { PolylineVertex3d v3d = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead); string temp = CADops.scaleNmove(v3d.Position.X, adjustX, scaler) + "," + CADops.scaleNmove(v3d.Position.Y, adjustY, scaler) + "," + v3d.Position.Z * scaler + "," + StrId + "," + layerName; data.Add(temp); ed.WriteMessage("\n" + v3d.Position.ToString()); } } } } //create dataarray to populate in excel int no = data.Count; ed.WriteMessage("\n Number of Point:" + no); //createCSV(data, shtNo); shtNo += 1; } Excel.createCSV(data, path); // Committing is cheaper than aborting ed.WriteMessage("\ncsv file has been created under path " + path); ed.WriteMessage("\nData format: Easting, Northing, Elevation, String ID, Layer Name."); tr.Commit(); } } catch { } } }
//project to level 0 to find the intersect point static public void CheckElevationDifference() { string msg = string.Empty; double checkDistance = 0.55; Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; HostApplicationServices hs = HostApplicationServices.Current; string outputPath = hs.FindFile(doc.Name, doc.Database, FindFileHint.Default); string logPath = outputPath + "_log.log"; System.IO.File.WriteAllText(logPath, msg); //get user input //select point input file ed.WriteMessage("Select the Excel file contains the door step points"); string excelPath = FileOps.SelectFile(); #region get Excel Sheet Name PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter Sheet Name: "); pStrOpts.AllowSpaces = true; PromptResult pStrRes = doc.Editor.GetString(pStrOpts); string shtName = pStrRes.StringResult; #endregion List <Point3d> doorStepPts = Excel.getAllpoint(doc, excelPath, shtName); PromptEntityResult per = ed.GetEntity("Select polylines"); ObjectId oid = per.ObjectId; ObjectIdCollection oDBO = new ObjectIdCollection(); List <Polyline3d> poly3ds = new List <Polyline3d>(); List <Polyline3d> poly3ds0 = new List <Polyline3d>(); if (per.Status == PromptStatus.OK) { Transaction tr = db.TransactionManager.StartTransaction(); BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false); DBObject objPick = tr.GetObject(oid, OpenMode.ForRead); Entity objEnt = objPick as Entity; string sLayer = objEnt.Layer.ToString(); oDBO = CADops.SelectAllPolyline(sLayer); foreach (ObjectId id in oDBO) { Polyline3d pl = new Polyline3d(); System.IO.File.AppendAllText(logPath, $"{id}\n"); poly3ds0.Add(CADops.CreatePolylineOnXYPlane(doc, id, ref pl)); poly3ds.Add(pl); } } List <Point3d> output = new List <Point3d>(); List <string> data = new List <string>(); if (poly3ds.Count() > 0) { Transaction tr = db.TransactionManager.StartTransaction(); BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false); using (tr) { List <Vector3d> vectorsAlongPath = new List <Vector3d>(); List <Vector3d> vectors = CADops.getVectors(doorStepPts, doc, ref vectorsAlongPath); //foreach (Point3d pt in doorStepPts) for (int i = 0; i < doorStepPts.Count(); i++) { Point3d pt = doorStepPts[i]; Point3d pt0 = new Point3d(pt.X, pt.Y, 0); Vector3d v = vectors[i].GetNormal() * 5; Matrix3d mat = Matrix3d.Displacement(v); Point3d npt = pt0.TransformBy(mat); v = vectors[i].GetNormal() * -5; mat = Matrix3d.Displacement(v); Point3d npt2 = pt0.TransformBy(mat); //create a 2d line in XY plane Line ln = new Line(npt, npt2); btr.AppendEntity(ln); tr.AddNewlyCreatedDBObject(ln, true); msg = $"pt => {pt.X}, {pt.Y}, {pt.Z}\n"; #region get intersect point from point to polyline Point3d ptNearest = Point3d.Origin; for (int j = 0; j < poly3ds0.Count(); j++) { Polyline3d p3d0 = poly3ds0[j]; Polyline3d p3d = poly3ds[j]; Point3d ptTemp = new Point3d(); #region get the alignment object and find the nearest point to the nominated point Point3dCollection pts3D = new Point3dCollection(); p3d0.IntersectWith(ln, Intersect.OnBothOperands, pts3D, IntPtr.Zero, IntPtr.Zero); try { if (pts3D.Count > 0) { double para = p3d0.GetParameterAtPoint(pts3D[0]); //ed.WriteMessage($"{pts3D[0]}, {para}\n"); ptTemp = p3d.GetPointAtParameter(para); } } catch { } #region get the point with lower Z if (ptNearest == Point3d.Origin) { ptNearest = ptTemp; } else { if (ptNearest.Z > ptTemp.Z) { ptNearest = ptTemp; } } #endregion } #endregion #endregion msg += $"ptNearest: {ptNearest.X}, {ptNearest.Y}, {ptNearest.Z}\n"; try { double diff = ptNearest.Z - pt.Z; if (Math.Abs(diff) <= checkDistance) { Point3d newPt = new Point3d(pt.X, pt.Y, ptNearest.Z + checkDistance); output.Add(newPt); data.Add($"{newPt.X},{newPt.Y},{newPt.Z}, less, {diff}, {ptNearest.Z}"); msg += $", Z diff: {diff} => less than {checkDistance} => {newPt.X}, {newPt.Y}, {newPt.Z}\n\n"; } else { Point3d newPt = pt; output.Add(newPt); data.Add($"{newPt.X},{newPt.Y},{newPt.Z}, more, {diff}, {ptNearest.Z}"); msg += $", Z diff: {diff} => more than {checkDistance} => {newPt.X}, {newPt.Y}, {newPt.Z}\n\n"; } } catch { } System.IO.File.AppendAllText(logPath, msg); } tr.Commit(); } } Excel.createCSV(data, outputPath); ed.WriteMessage("\ncsv file has been created under path " + outputPath); }
public static Transaction StartTransaction() { return(HostApplicationServices.get_WorkingDatabase().get_TransactionManager().StartTransaction()); }
public void convertGivenListsToXML( List <Geometry.Polygon2D> originList, List <Geometry.Polygon2D> intermediateList, List <Geometry.Segment2D> gatheringLineList, List <Geometry.Polygon2D> destinationList, List <Geometry.Polygon2D> avoidanceList, List <Geometry.Segment2D> wallList, List <Geometry.Polygon2D> solidList, List <Geometry.Segment2D> graphList, Dictionary <String, List <Polygon2D> > taggedAreaList) { Document currentDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Editor editor = currentDocument.Editor; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; XmlWriter writer = null; HostApplicationServices hs = HostApplicationServices.Current; String drawingFilePath = ""; try { drawingFilePath = hs.FindFile(currentDocument.Name, currentDocument.Database, FindFileHint.Default); } catch (Exception) { drawingFilePath = currentDocument.Database.Filename; } String targetPath = drawingFilePath.Remove(drawingFilePath.Count() - 4) + "_pedSimScenario.xml"; SaveFileDialog fileDialog = new SaveFileDialog("Choose target folder:", targetPath, "xml", "XMLfileToLink", SaveFileDialog.SaveFileDialogFlags.DoNotTransferRemoteFiles); System.Windows.Forms.DialogResult result = fileDialog.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { editor.WriteMessage("\nWrong file format."); return; } targetPath = fileDialog.Filename; simulationName_Value = this.getFileName(targetPath); writer = XmlWriter.Create(@targetPath, settings); writer.WriteStartDocument(); writer.WriteStartElement(simulator_Node); writer.WriteAttributeString(version_Attribute, version_Value); writer.WriteAttributeString(simulationName_Attribute, simulationName_Value); writer.WriteStartElement(layouts_Node); writer.WriteStartElement(scenario_Node); writer.WriteAttributeString(id_Attribute, scenarioID.ToString()); writer.WriteAttributeString(name_Attribute, scenarioName_Value); double[] maxCoordinates = GeometryFactory.getMaximumCoordinates(); double[] minCoordinates = GeometryFactory.getMinimumCoordinates(); writer.WriteAttributeString(maxX_Attribute, Math.Round(maxCoordinates[0] + 1.0, decimalPlaces).ToString()); writer.WriteAttributeString(maxY_Attribute, Math.Round(maxCoordinates[1] + 1.0, decimalPlaces).ToString()); writer.WriteAttributeString(minX_Attribute, Math.Round(minCoordinates[0] - 1.0, decimalPlaces).ToString()); writer.WriteAttributeString(minY_Attribute, Math.Round(minCoordinates[1] - 1.0, decimalPlaces).ToString()); graphID = this.generateGraph(writer, graphList, graphType_Value, graphID); areaID = this.generatePolygon(writer, originList, area_Node, originArea_Value, areaID); areaID = this.generateIntermediates(writer, intermediateList, gatheringLineList, areaID); areaID = this.generatePolygon(writer, destinationList, area_Node, destinationArea_Value, areaID); areaID = this.generatePolygon(writer, avoidanceList, area_Node, avoidanceArea_Value, areaID); foreach (KeyValuePair <string, List <Polygon2D> > currentTaggedAreaList in taggedAreaList) { taggedAreaID = this.generatePolygon(writer, currentTaggedAreaList.Value, taggedArea_Node, currentTaggedAreaList.Key, taggedAreaID); } obstacleID = this.generateSegment(writer, wallList, obstacle_Node, wall_Value, obstacleID); obstacleID = this.generatePolygon(writer, solidList, obstacle_Node, solid_Value, obstacleID); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); editor.WriteMessage("\nXMLconversion successfull:" + "\n" + targetPath); }
public void WaitForFileToExist() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; HostApplicationServices ha = HostApplicationServices.Current; PromptResult pr = ed.GetString("Enter path to PCG: "); if (pr.Status != PromptStatus.OK) { return; } string pcgPath = pr.StringResult.Replace('/', '\\'); pr = ed.GetString("Enter path to LAS: "); if (pr.Status != PromptStatus.OK) { return; } string lasPath = pr.StringResult.Replace('/', '\\'); ed.WriteMessage( "\nWaiting for PCG creation to complete...\n" ); // Check the write time for the PCG file... // if it hasn't been written to for at least half a second, // then we try to use a file lock to see whether the file // is accessible or not const int ticks = 50; TimeSpan diff; bool cancelled = false; // First loop is to see when writing has stopped // (better than always throwing exceptions) while (true) { if (File.Exists(pcgPath)) { DateTime dt = File.GetLastWriteTime(pcgPath); diff = DateTime.Now - dt; if (diff.Ticks > ticks) { break; } } System.Windows.Forms.Application.DoEvents(); if (HostApplicationServices.Current.UserBreak()) { cancelled = true; break; } } // Second loop will wait until file is finally accessible // (by calling a function that requests an exclusive lock) if (!cancelled) { int inacc = 0; while (true) { if (IsFileAccessible(pcgPath)) { break; } else { inacc++; } System.Windows.Forms.Application.DoEvents(); if (HostApplicationServices.Current.UserBreak()) { cancelled = true; break; } } ed.WriteMessage("\nFile inaccessible {0} times.", inacc); try { CleanupTmpFiles(lasPath); } catch { } } }