hello,
I want to draw mline in the dwg automatically. Here is some codes, and what should I do next?
C# codes by VS2010,FOR AUTOCAD 2010.
Line dashdot = new Line();
dashdot.Linetype = "DashDot";
MlineStyleElement off1100 = new MlineStyleElement(3720/2,Autodesk.AutoCAD.Colors.Color.FromRgb (0,0,0),dashdot .LinetypeId );
MlineStyle mlineStyle = new MlineStyle();
mlineStyle.Elements.Add(off1100,false );
Mline mline = new Mline();
mline.Style = mlineStyle.ObjectId;//HOW CAN I DEFINE THE MLINE? it should contain lines and I don't know
// how to add lines(may be points) into it.
The code may be wrong.
Please give me some help and advice.
Thanks in advance.
Allen
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
Solved by Hallex. Go to Solution.
Just a quick shot sorry,
without explanations
see docs for more
[CommandMethod ("mil")] public void MLINECREATE() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = HostApplicationServices.WorkingDatabase; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); Mline ml = new Mline(); ml.Style = db.CmlstyleID; ml.Normal = Vector3d.ZAxis; ml.Justification = MlineJustification.Zero; ml.AppendSegment(new Point3d (0,0,0)); ml.AppendSegment(new Point3d(100, 0, 0)); ml.AppendSegment(new Point3d(100, 80, 0)); ml.AppendSegment(new Point3d(0, 80, 0)); ml.IsClosed = true; btr.AppendEntity(ml); tr.AddNewlyCreatedDBObject(ml, true); tr.Commit(); } doc.SendStringToExecute("_ZOOM _Ob _L ",true,false,false); }
hi Hallex, ,
Thank you for your so quick answer.
Your codes works well.
But can you give more codes about custom MlineStyle, my codes belows are wrong.
Line dashdot = new Line();
dashdot.Linetype = "Dash";
MlineStyleElement off1100 = new MlineStyleElement(3720 / 2, Autodesk.AutoCAD.Colors.Color.FromRgb(0, 0, 0), dashdot.LinetypeId);
MlineStyle mlineStyle = new MlineStyle();
mlineStyle.Elements.Add(off1100, false);
Mline ml = new Mline();
ml.Style = mlineStyle.ObjectId;
How can I use MlineStyle?
Thanks,
Allen
Found this code somewhere on forums
no tested, see if this helps
[CommandMethod("createmlinestyle")] public void createmlinestyle() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor editor = doc.Editor; Database db = doc.Database; using (Transaction Tx = db.TransactionManager.StartTransaction()) { DBDictionary mlineDic = (DBDictionary)Tx.GetObject(db.MLStyleDictionaryId, OpenMode.ForRead); if (!mlineDic.Contains("TEST")) { mlineDic.UpgradeOpen(); MlineStyle mlineStyle = new MlineStyle(); mlineDic.SetAt("TEST", mlineStyle); Tx.AddNewlyCreatedDBObject(mlineStyle, true); mlineStyle.EndAngle = 3.14159 * 0.5; mlineStyle.StartAngle = 3.14159 * 0.5; mlineStyle.Name = "TEST"; Autodesk.AutoCAD.Colors.Color Color; Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0); MlineStyleElement element = new MlineStyleElement(0.25, Color, db.Celtype); mlineStyle.Elements.Add(element, true); element = new MlineStyleElement(-0.25, Color, db.Celtype); mlineStyle.Elements.Add(element, false); } Tx.Commit(); } }
Can't find what you're looking for? Ask the community or share your knowledge.