Message 1 of 15
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
First sorry for the poor Title. Anyway I'm making a Form for AutoCAD in C# So at the beginning I got error by creating polyline in case using Form
Application does not support Windows Forms just-in-time (JIT)
So I looked in the form and I found that I should lock the Document and it solved the problem
using (DocumentLock acLckDoc = acDoc.LockDocument())
But after that I had to use ed.Command to perform fillet like this .
acDoc.Database.Filletrad = 5.0;
ed.Command("_.fillet", "Polyline", acPoly.ObjectId);
And I got this error again but locking the Document didn't help this time
Application does not support Windows Forms just-in-time (JIT)
help me plz and thx in advance
Nader.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
namespace AutoNader.Data.Creator
{
public class PolyLineClass
{
public static void PolyLineCreate()
{
// Get the current document and database
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
var ed = acDoc.Editor;
Polyline acPoly = new Polyline();
// Lock the new document
using (DocumentLock acLckDoc = acDoc.LockDocument())
{
// Start a transaction
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForWrite) as BlockTableRecord;
// Create a polyline with two segments (3 points)
acPoly.SetDatabaseDefaults();
acPoly.AddVertexAt(0, new Point2d(0, 0), 0, 0, 0);
acPoly.AddVertexAt(1, new Point2d(300, 0), 0, 0, 0);
acPoly.AddVertexAt(2, new Point2d(300, 300), 0, 0, 0);
acPoly.AddVertexAt(3, new Point2d(0, 300), 0, 0, 0);
acPoly.AddVertexAt(4, new Point2d(0, 0), 0, 0, 0);
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPoly);
acTrans.AddNewlyCreatedDBObject(acPoly, true);
// Save the new object to the database
acTrans.Commit();
acDoc.Database.Filletrad = 5.0;
ed.Command("_.fillet", "Polyline", acPoly.ObjectId);
}
}
}
}
}
private void Button1_Click(object sender, EventArgs e)
{
PolyLineClass.PolyLineCreate();
}
public class MainClass
{
[CommandMethod("AN")]
public void Main()
{
Form1 F1 = new Form1();
F1.Show();
// PolyLineClass.PolyLineCreate();
}
}
Solved! Go to Solution.