Below AutoCAD.NET command shows the procedure to reload the line type in AutoCAD using .NET API. The command runs in “Session” mode so that “SendCommand” can work synchronously. Also, code uses AutoCAD ActiveX API using late binding technique to avoid adding reference to AutoCAD ActiveX interops.
[CommandMethod("relaodLinetype", CommandFlags.Session)]
public void relaodLinetype()
{
DocumentCollection docManager =
Application.DocumentManager;
Database db =
docManager.MdiActiveDocument.Database;
Transaction trans =
db.TransactionManager.StartTransaction();
bool bReload = false;
using (trans)
{
LinetypeTable table =
trans.GetObject(
db.LinetypeTableId,
OpenMode.ForRead) as LinetypeTable;
if (table.Has("CENTER"))
bReload = true;
}
System.Int16 fileDia = (System.Int16)
Application.GetSystemVariable("FILEDIA");
Application.SetSystemVariable("FILEDIA", 0);
//reload using linetype command...
Object acadObject = Application.AcadApplication;
object ActiveDocument =
acadObject.GetType().InvokeMember(
"ActiveDocument",
System.Reflection.BindingFlags.GetProperty,
null,
acadObject,
null);
object[] dataArry = new object[1];
if (bReload)
{
dataArry[0] =
"-linetype Load CENTER\nacad.lin\nYes\n ";
}
else
{
dataArry[0] =
"-linetype Load CENTER\nacad.lin\n ";
}
ActiveDocument.GetType().InvokeMember(
"SendCommand",
System.Reflection.BindingFlags.InvokeMethod,
null,
ActiveDocument,
dataArry);
Application.SetSystemVariable("FILEDIA", fileDia);
}