Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I Started work with Windonw Form. After create Hatch for a object. I begine make a form to seclect Hatch. However when i test code that has appear a message as picture below:
-moderator edit: corrected spelling errors in title.
So everyone can tell me how to fix that ?
Thank you !
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void B2_Click(object sender, EventArgs e)
{
this.Close();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void B3_Click(object sender, EventArgs e)
{
Document doc = AcAp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
string mh = B1.SelectedItem.ToString();
try
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
Polyline pl = new Polyline();
pl.SetDatabaseDefaults();
pl.AddVertexAt(0, new Point2d(2.0, 4.0), 0, 0, 0);
pl.AddVertexAt(1, new Point2d(4.0, 2.0), 0, 0, 0);
pl.AddVertexAt(2, new Point2d(6.0, 4.0), 0, 0, 0);
pl.Closed = true;
pl.ColorIndex = 6;
// Add the polyline to the database
ObjectId plineId = btr.AppendEntity(pl);
trans.AddNewlyCreatedDBObject(pl, true);
// Create the hatch object
Hatch ht = new Hatch();
ht.SetHatchPattern(HatchPatternType.PreDefined, "mh");
ht.ColorIndex = 54;
ht.BackgroundColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, 4);
// Add the hatch to the database
btr.AppendEntity(ht);
trans.AddNewlyCreatedDBObject(ht, true);
// Set the hatch boundary
ht.Associative = true;
ht.AppendLoop(HatchLoopTypes.Default, new ObjectIdCollection() { plineId });
ht.EvaluateHatch(true);
// Add dimention
AlignedDimension al = new AlignedDimension();
AlignedDimension al1 = new AlignedDimension();
AlignedDimension al2 = new AlignedDimension();
al.XLine1Point = new Point3d(2, 4, 0);
al.XLine2Point = new Point3d(4, 2, 0);
al.Dimscale = 0.5;
al.DimensionStyle = db.Dimstyle;
al1.XLine1Point = new Point3d(4, 2, 0);
al1.XLine2Point = new Point3d(6, 4, 0);
al1.Dimscale = 0.5;
al1.DimensionStyle = db.Dimstyle;
al2.XLine1Point = new Point3d(2, 4, 0);
al2.XLine2Point = new Point3d(6, 4, 0);
al2.Dimscale = 0.5;
al2.DimensionStyle = db.Dimstyle;
// Add the new object to Model space and the transaction
btr.AppendEntity(al);
trans.AddNewlyCreatedDBObject(al, true);
btr.AppendEntity(al1);
trans.AddNewlyCreatedDBObject(al1, true);
btr.AppendEntity(al2);
trans.AddNewlyCreatedDBObject(al2, true);
trans.Commit();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
AcAp.ShowAlertDialog("not create hatch from poplyline " + ex.Message);
}
}
private void B1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Solved! Go to Solution.