.NET

Reply
Active Member
allentable
Posts: 10
Registered: ‎05-24-2013
Message 1 of 7 (342 Views)

MlineStyle

342 Views, 6 Replies
05-27-2013 12:18 AM

Hello,

I want to use MlineStyle to custom mLine.

Here are my own codes and it does't work.

 

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 in advance.

 

Allen

Active Member
allentable
Posts: 10
Registered: ‎05-24-2013
Message 2 of 7 (321 Views)

Re: MlineStyle

05-27-2013 06:27 PM in reply to: allentable
       [CommandMethod ("mil")]
        public void MLINECREATE()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {

                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                DBDictionary mlineDic =(DBDictionary)tr.GetObject(db.MLStyleDictionaryId,OpenMode.ForRead);

                if (!mlineDic.Contains("TEST"))
                {

                    mlineDic.UpgradeOpen();

                    MlineStyle mlineStyle = new MlineStyle();

                    mlineDic.SetAt("TEST", mlineStyle);

                    tr.AddNewlyCreatedDBObject(mlineStyle, true);

                    mlineStyle.EndAngle = 3.14159 * 0.5;

                    mlineStyle.StartAngle = 3.14159 * 0.5;

                    mlineStyle.Name = "TEST";

                    MlineStyleElement off1100 = new MlineStyleElement(10 / 2, Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0), db.Celtype);
                    mlineStyle.Elements.Add(off1100, true );
                     
                    MlineStyleElement off0 = new MlineStyleElement(0, Autodesk.AutoCAD.Colors.Color.FromRgb(255, 255,255), db.Celtype);
                    mlineStyle.Elements.Add(off0, true );
                    
                    MlineStyleElement off1100n = new MlineStyleElement(-10 / 2, Autodesk.AutoCAD.Colors.Color.FromRgb(255,255, 0), db.Celtype);
                    mlineStyle.Elements.Add(off1100n, true );

                    mlineStyle.ShowMiters = false;
                   


                    Mline ml = new Mline();

                    ml.Style =mlineStyle .ObjectId;
                    //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 =false ;
                    btr.AppendEntity(ml);
                    tr.AddNewlyCreatedDBObject(ml, true);
                }
                tr.Commit();

            }
            doc.SendStringToExecute("_ZOOM _Ob _L  ",true,false,false);
        }

 

The code  (mainly supplied by Hallex, Thanks again) can work , but when I open the menu [options]-[mlinestyle]  and CLICK the "TEST" in the STYLE list,the autocad application occurs an error and closed. I don't know the reason.

 

Any help will be appreciated.

 

Allen

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 7 (302 Views)

Re: MlineStyle

05-28-2013 06:56 AM in reply to: allentable
Try remove this line from code:
doc.SendStringToExecute("_ZOOM _Ob _L ",true,false,false);
_____________________________________
C6309D9E0751D165D0934D0621DFF27919
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 7 (296 Views)

Re: MlineStyle

05-28-2013 07:46 AM in reply to: allentable

I've added small changes, this code working on my A2010,

see if this helps

        [CommandMethod("mil")]
        public void MLINECREATE()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                doc.TransactionManager.EnableGraphicsFlush(true);
                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                DBDictionary mlineDic = (DBDictionary)tr.GetObject(db.MLStyleDictionaryId, OpenMode.ForRead);

                if (!mlineDic.Contains("TEST"))
                {

                    mlineDic.UpgradeOpen();

                    MlineStyle mlineStyle = new MlineStyle();

                    mlineDic.SetAt("TEST", mlineStyle);

                    tr.AddNewlyCreatedDBObject(mlineStyle, true);

                    mlineStyle.EndAngle = 3.14159 * 0.5;

                    mlineStyle.StartAngle = 3.14159 * 0.5;

                    mlineStyle.Name = "TEST";

                    MlineStyleElement off1100 = new MlineStyleElement(10 / 2, Autodesk.AutoCAD.Colors.Color.FromRgb(255, 0, 0), db.Celtype);
                    mlineStyle.Elements.Add(off1100, true);
                   
                    MlineStyleElement off0 = new MlineStyleElement(0, Autodesk.AutoCAD.Colors.Color.FromRgb(255, 255, 255), db.Celtype);
                    mlineStyle.Elements.Add(off0, true);

                    MlineStyleElement off1100n = new MlineStyleElement(-10 / 2, Autodesk.AutoCAD.Colors.Color.FromRgb(255, 255, 0), db.Celtype);
                    mlineStyle.Elements.Add(off1100n, true);
                    mlineStyle.EndInnerArcs = false;
                    mlineStyle.EndSquareCap=false;
                    mlineStyle.EndRoundCap = false;
                    mlineStyle.ShowMiters = false;
                    db.CmlstyleID = mlineStyle.ObjectId;
                    tr.TransactionManager.QueueForGraphicsFlush();
                    

                    Mline ml = new Mline();

                    ml.Style = mlineStyle.ObjectId;
                    //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.TransactionManager.QueueForGraphicsFlush();
                }
                doc.TransactionManager.FlushGraphics();
                tr.Commit();

            }
           // doc.SendStringToExecute("_ZOOM _Ob _L  ", true, false, false);
        }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Member
allentable
Posts: 10
Registered: ‎05-24-2013
Message 5 of 7 (283 Views)

Re: MlineStyle

05-29-2013 05:43 AM in reply to: Hallex

Thanks, Hallex,

The codes really works, but when I open the menu [options]-[mlinestyle] to see the details.

The application shows errors again,

 

System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
   在 Autodesk.AutoCAD.DatabaseServices.DBObject.DeleteUnmanagedObject()
   在 Autodesk.AutoCAD.Runtime.DisposableWrapper.!DisposableWrapper()
   在 Autodesk.AutoCAD.Runtime.DisposableWrapper.Dispose(Boolean )
   在 Autodesk.AutoCAD.DatabaseServices.DBObject.Dispose(Boolean )
   在 Autodesk.AutoCAD.Runtime.DisposableWrapper.Dispose()
   在 Autodesk.AutoCAD.AcMultiLineUi.MlineStylePreviewControl.set_PreviewStyle(MlineStyle value)
   在 Autodesk.AutoCAD.AcMultiLineUi.MlineStyleForm.UpdateSelected()
   在 Autodesk.AutoCAD.AcMultiLineUi.MlineStyleForm.MlineStyleForm_Load(Object sender, EventArgs e)
   在 System.EventHandler.Invoke(Object sender, EventArgs e)
   在 System.Windows.Forms.Form.OnLoad(EventArgs e)
   在 System.Windows.Forms.Form.OnCreateControl()
   在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   在 System.Windows.Forms.Control.CreateControl()
   在 System.Windows.Forms.Control.WmShowWindow(Message& m)
   在 System.Windows.Forms.Control.WndProc(Message& m)
   在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
   在 System.Windows.Forms.Form.WmShowWindow(Message& m)
   在 System.Windows.Forms.Form.WndProc(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

 

translate into English:

 

attempt to read from or write into protected memory,this usually indicates other memory is broken.

 

 

Maybe something is wrong with my application.

If I didn't try to open it, this can be the whole solution.

 

Thanks again.

 

Best regards.

 

Allen

ADN Support Specialist
Balaji_Ram
Posts: 700
Registered: ‎03-21-2011
Message 6 of 7 (260 Views)

Re: MlineStyle

06-07-2013 02:33 AM in reply to: allentable

Hi Allen,

 

I could reproduce the crash in AutoCAD 2013.

 

Please try including this line of code :

 

mlineStyle.Description = String.Empty;

 

It seems AutoCAD 2013 is more particular about setting this empty when there is no description text for the style.

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Active Member
allentable
Posts: 10
Registered: ‎05-24-2013
Message 7 of 7 (235 Views)

Re: MlineStyle

06-12-2013 07:26 AM in reply to: Balaji_Ram

Hi Balaji_Ram,

 

This mlineStyle.Description = String.Empty; really solve the problem.

 

Thanks

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.