Chuyển đến nội dung
Diễn đàn CADViet
Đăng nhập để thực hiện theo  
thich_minh_hue

trợ giúp về autocad.net help.help

Các bài được khuyến nghị

138932_2_1.jpgthưa các bác.e có 1 đoạn code của autocad.net e làm trên visual basic 8.......e muốn tạo hatch vào trong ô vuông mà code e tạo ra. có bác nào giúp e với ạ.e chân thành cảm ơn 

Public Class Class1
    <CommandMethod("vehinhvuong")> Public Sub Ve_hinh_vuong()
        add_line(0, 0, 0, 10)
        add_line(0, 10, 10, 10)
        add_line(10, 10, 10, 0)
        add_line(10, 0, 0, 0)
 
    End Sub
    Sub add_line(ByVal x1, ByVal y1, ByVal x2, ByVal y2)
 
        '' Get the current document and database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
 
        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
 
            '' Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, DatabaseServices.OpenMode.ForRead)
 
            '' Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                            DatabaseServices.OpenMode.ForWrite)
 
            '' Create a line that starts at 5,5 and ends at 12,3
            Dim acLine As Line = New Line(New Point3d(x1, y1, 0), _
                                  New Point3d(x2, y2, 0))
 
            acLine.SetDatabaseDefaults()
 
            '' Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(acLine)
            acTrans.AddNewlyCreatedDBObject(acLine, True)
 
            '' Save the new object to the database
            acTrans.Commit()
 
        End Using
    End Sub
 
 
Public Class Class1
    <CommandMethod("vehinhvuong")> Public Sub Ve_hinh_vuong()
        add_line(0, 0, 0, 10)
        add_line(0, 10, 10, 10)
        add_line(10, 10, 10, 0)
        add_line(10, 0, 0, 0)
 
    End Sub
    Sub add_line(ByVal x1, ByVal y1, ByVal x2, ByVal y2)
 
        '' Get the current document and database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
 
        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
 
            '' Open the Block table for read
            Dim acBlkTbl As BlockTable
            acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, DatabaseServices.OpenMode.ForRead)
 
            '' Open the Block table record Model space for write
            Dim acBlkTblRec As BlockTableRecord
            acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                            DatabaseServices.OpenMode.ForWrite)
 
            '' Create a line that starts at 5,5 and ends at 12,3
            Dim acLine As Line = New Line(New Point3d(x1, y1, 0), _
                                  New Point3d(x2, y2, 0))
 
            acLine.SetDatabaseDefaults()
 
            '' Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(acLine)
            acTrans.AddNewlyCreatedDBObject(acLine, True)
 
            '' Save the new object to the database
            acTrans.Commit()
 
        End Using
    End Sub
 
End Class

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

e gửi cả ảnh đây ạ

Gửi ảnh lên để .. đánh đố thiên hạ à?

Đùng bắt mọi người phải gõ lại code chứ!

 

Tham khảo code C#: Vẽ RecTang (hình chữ nhật) qua 2 điểm sau đó tạo Hatch cho Rectang đó.

       [CommandMethod("DrawPL")]
        public void DrawPL()
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            PromptPointOptions ppo = new PromptPointOptions("\nChọn điểm đầu: ");
            PromptPointResult ppr = ed.GetPoint(ppo);
            if (ppr.Status != PromptStatus.OK) return;
            Point3d pt1 = ppr.Value;

            ppr = ed.GetCorner("\nChọn điểm đối diện: ", pt1);
            if (ppr.Status != PromptStatus.OK) return;
            Point3d pt2 = ppr.Value;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blk = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord btr = tr.GetObject(blk[blockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                // add Polyline
                Polyline pl = new Polyline();
                btr.AppendEntity(pl);
                tr.AddNewlyCreatedDBObject(pl, true);
                pl.AddVertexAt(0, new Point2d(pt1.X, pt1.Y), 0, 0, 0);
                pl.AddVertexAt(1, new Point2d(pt2.X, pt1.Y), 0, 0, 0);
                pl.AddVertexAt(2, new Point2d(pt2.X, pt2.Y), 0, 0, 0);
                pl.AddVertexAt(3, new Point2d(pt1.X, pt2.Y), 0, 0, 0);
                pl.Closed = true;                
                // add Hatch
                Hatch hat = new Hatch();
                btr.AppendEntity(hat);
                tr.AddNewlyCreatedDBObject(hat, true);
                hat.SetHatchPattern(HatchPatternType.PreDefined, "ANSI31");
                hat.Associative = true;
                hat.AppendLoop(HatchLoopTypes.Outermost, new ObjectIdCollection() { pl.ObjectId });
                hat.EvaluateHatch(true);                

                tr.Commit();
            }
        }
Chỉnh sửa theo gia_bach
  • Vote tăng 1

Chia sẻ bài đăng này


Liên kết tới bài đăng
Chia sẻ trên các trang web khác

Tạo một tài khoản hoặc đăng nhập để nhận xét

Bạn cần phải là một thành viên để lại một bình luận

Tạo tài khoản

Đăng ký một tài khoản mới trong cộng đồng của chúng tôi. Điều đó dễ mà.

Đăng ký tài khoản mới

Đăng nhập

Bạn có sẵn sàng để tạo một tài khoản ? Đăng nhập tại đây.

Đăng nhập ngay
Đăng nhập để thực hiện theo  

×