.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I use Mline Class to draw mline in dwg using C#?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
allentable
1177 Views, 4 Replies

How can I use Mline Class to draw mline in dwg using C#?

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

Tags (1)
4 REPLIES 4
Message 2 of 5
Hallex
in reply to: allentable

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);
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 5
allentable
in reply to: Hallex

hi                   ,

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

Message 4 of 5
Hallex
in reply to: allentable

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();
 
    }
 
}

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 5
allentable
in reply to: Hallex

@Hallex,

Thanks very much.

I get what I want.

 

Best regards,Smiley Happy

Allen

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost