Creating an AutoCAD linetype programmatically using .NET
Happy New Year, everyone!
I had a very relaxing break over the holiday period: during the better part of two weeks I managed to stay away from my PC and even my BlackBerry, which I admit I'm generally not very good at ignoring. So now I'm easing back into the swing of things, remembering how to type and open modelspaces, among other things. :-)
To save my brain from unnecessary stress during the first few weeks of 2008, I've decided to take inspiration from the ADN website. Today's post is based on this DevNote, which shows how to create a custom linetype using ObjectARX.
Here's some equivalent code in C#:
public class Commands
public void CreateLinetype()
Document doc =
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction tr =
// Get the linetype table from the drawing
LinetypeTable lt =
// Create our new linetype table record...
LinetypeTableRecord ltr =
// ... and set its properties
ltr.AsciiDescription = "T E S T -";
ltr.PatternLength = 0.75;
ltr.NumDashes = 2;
ltr.Name = "TESTLINTEYPE";
// Add the new linetype to the linetype table
ObjectId ltId = lt.Add(ltr);
// Create a test line with this linetype
BlockTable bt =
BlockTableRecord btr =
Line ln =
new Point3d(0, 0, 0),
new Point3d(10, 10, 0)
ln.LinetypeId = ltId;
Once you've run the CL command, Zoom Extents to see a line that has been created with our new custom linetype.