Previously hosted on CodePlex.
AutoCAD Code Pack
is a powerful library that helps you to develop AutoCAD plugins using the AutoCAD .NET API. It re-encapsulates the over-designed and old-fashioned classes and methods into easy-to-use static modules and functions. It also brings modern C# syntax like LINQ and lambdas (functional programming) to AutoCAD development. With all the features it provides, you can save over half the lines of your code.
The library was originally developed for AutoCAD R18 (2010, 2011, 2012) and .NET 3.5. We recently updated it to target AutoCAD R23 (2019) and .NET 4.7.1, thanks to the contribution from @lavantgarde. You can target other versions with the source files and build yourself.
View Test.cs for API usage examples.
The library consists of the following modules:
Draw
to directly draw entities (with AutoCAD-command-like functions)NoDraw
to create in-memory entitiesModify
to edit entities (with AutoCAD-command-like functions)Annotation
to draw annotationsDbHelper
to manipulate the DWG databaseQuickSelection
to simplify entity manipulation with LINQ style coding experience (like jQuery, if you know some Web)Interaction
to handle user interactionsAlgorithms
to offer some mathematical helpersMultiDoc
to process cross-document scenariosCustomDictionary
to help you attach data to entitiesSymbolPack
to help you draw symbols like arrows, etc.IronPython
to allow you use IronPython in AutoCADYou may write this elegant code with the code pack:
/// <summary>
/// Eliminate zero-length polylines
/// </summary>
[CommandMethod("PolyClean0", CommandFlags.UsePickSet)]
public static void PolyClean0()
{
var ids = Interaction.GetSelection("\nSelect polyline", "LWPOLYLINE");
int n = 0;
ids.QForEach<Polyline>(poly =>
{
if (poly.Length == 0)
{
poly.Erase();
n++;
}
});
Interaction.WriteLine("{0} eliminated.", n);
}
instead of the verbose version using original API:
[CommandMethod("PolyClean0_Old", CommandFlags.UsePickSet)]
public static void PolyClean0_Old()
{
string message = "\nSelect polyline";
string allowedType = "LWPOLYLINE";
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionOptions opt = new PromptSelectionOptions { MessageForAdding = message };
ed.WriteMessage(message);
SelectionFilter filter = new SelectionFilter(new TypedValue[] { new TypedValue(0, allowedType) });
PromptSelectionResult res = ed.GetSelection(opt, filter);
if (res.Status != PromptStatus.OK)
{
return;
}
ObjectId[] ids = res.Value.GetObjectIds();
int n = 0;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
foreach (ObjectId id in ids)
{
Polyline poly = trans.GetObject(id, OpenMode.ForWrite) as Polyline;
if (poly.Length == 0)
{
poly.Erase();
n++;
}
}
trans.Commit();
}
ed.WriteMessage("{0} eliminated.", n);
}
View Test.cs for detailed API usage examples.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。