コード例 #1
0
		public static void testLine ()
		{

			List<point> points = new List<point> ();

			points.Add (new point (0, 0));
			points.Add (new point (0, 10));
			points.Add (new point (10, 10));
			points.Add (new point (10, 0));

			Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.CurrentDocument; 
			Database acCurDb = acDoc.Database;


			using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction ()) {
				
				// Отваряне на блок таблицата за четене
				BlockTable acBlkTbl;
				acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

				// Отваряне на модела на блок таблицата за писсане
				BlockTableRecord acBlkTblRec;
				acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;


				foreach (point _p in points) {
					// Създаване на линия с координати
					Line acLine = new Line(new Point3d(_p.x, _p.y, 0), new Point3d(0, 0, 0));
					acLine.SetDatabaseDefaults();
	
					// Добавяне на линията
					acBlkTblRec.AppendEntity(acLine);
					acTrans.AddNewlyCreatedDBObject(acLine, true);

				}

//				// Създаване на линия с координати
//				Line acLine = new Line(new Point3d(5, 5, 0), new Point3d(12, 3, 0));
//				acLine.SetDatabaseDefaults();
//
//				// Добавяне на линията
//				acBlkTblRec.AppendEntity(acLine);
//				acTrans.AddNewlyCreatedDBObject(acLine, true);

				// Запазване на прмените
				acTrans.Commit();
			}

		}
コード例 #2
0
ファイル: CreateExtension.cs プロジェクト: samuto/Grevit
        public static DBObject Create(this Grevit.Types.Line l, Transaction tr)
        {
            LayerTable lt = (LayerTable)tr.GetObject(Command.Database.LayerTableId, OpenMode.ForRead);

            try
            {
                Line line = new Line(l.from.ToPoint3d(), l.to.ToPoint3d());


                line.SetDatabaseDefaults(Command.Database);

                BlockTable bt = (BlockTable)tr.GetObject(Command.Database.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                
                if (lt.Has(l.TypeOrLayer)) line.LayerId = lt[l.TypeOrLayer];
                ms.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                return line;
            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {

            }

            return null;

        }
コード例 #3
0
ファイル: CreateExtension.cs プロジェクト: bbrangeo/Grevit
        public static void Create(Grevit.Types.Line l)
        {
            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
            Transaction tr = db.TransactionManager.StartTransaction();
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);

            try
            {
                Line line = new Line(GrevitPtoPoint3d(l.from), GrevitPtoPoint3d(l.to));

                line.SetDatabaseDefaults(db);

                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                AddXData(l, line);
                if (lt.Has(l.TypeOrLayer)) line.LayerId = lt[l.TypeOrLayer];
                ms.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);

                writeProperties(line, l.parameters, tr);
                storeID(l, line.Id);
                tr.Commit();

            }

            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                ed.WriteMessage(e.Message);
                tr.Abort();
            }

            finally
            {
                tr.Dispose();
            }
        }