C# Create LineTypeStyle in code with symbol SHX autocad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How to create a line style in the c # code by using Shape (shp) from the *.shx file. Kean Walmsley Creating a complex AutoCAD linetype containing text using .NET shows how to make a line style with text. I care about the line style with the shp symbol.
In the *.lin file it is saved by:
*ZIG,Zig zag
A,0,[Zig,Shapes.shx,X=0,Y=0.15],-2.5,
Example by Kean for line style with text
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
namespace Linetype
{
public class Commands
{
[CommandMethod("CCL")]
public void CreateComplexLinetype()
{
Document doc =
Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction tr =
db.TransactionManager.StartTransaction();
using (tr)
{
// We'll use the textstyle table to access
// the "Standard" textstyle for our text
// segment
TextStyleTable tt =
(TextStyleTable)tr.GetObject(
db.TextStyleTableId,
OpenMode.ForRead
);
// Get the linetype table from the drawing
LinetypeTable lt =
(LinetypeTable)tr.GetObject(
db.LinetypeTableId,
OpenMode.ForWrite
);
// Create our new linetype table record...
LinetypeTableRecord ltr =
new LinetypeTableRecord();
// ... and set its properties
ltr.Name = "COLD_WATER_SUPPLY";
ltr.AsciiDescription =
"Cold water supply ---- CW ---- CW ---- CW ----";
ltr.PatternLength = 0.9;
ltr.NumDashes = 3;
// Dash #1
ltr.SetDashLengthAt(0, 0.5);
// Dash #2
ltr.SetDashLengthAt(1, -0.2);
ltr.SetShapeStyleAt(1, tt["Standard"]);
ltr.SetShapeNumberAt(1, 0);
ltr.SetShapeOffsetAt(1, new Vector2d(-0.1,-0.05));
ltr.SetShapeScaleAt(1, 0.1);
ltr.SetShapeIsUcsOrientedAt(1, false);
ltr.SetShapeRotationAt(1, 0);
ltr.SetTextAt(1, "CW");
// Dash #3
ltr.SetDashLengthAt(2, -0.2);
// Add the new linetype to the linetype table
ObjectId ltId = lt.Add(ltr);
tr.AddNewlyCreatedDBObject(ltr, true);
// Create a test line with this linetype
BlockTable bt =
(BlockTable)tr.GetObject(
db.BlockTableId,
OpenMode.ForRead
);
BlockTableRecord btr =
(BlockTableRecord)tr.GetObject(
bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite
);
Line ln =
new Line(
new Point3d(0, 0, 0),
new Point3d(10, 10, 0)
);
ln.SetDatabaseDefaults(db);
ln.LinetypeId = ltId;
btr.AppendEntity(ln);
tr.AddNewlyCreatedDBObject(ln, true);
tr.Commit();
}
}
}
}
How to add shp from shx file instead of text?
Please help!