Пример #1
0
        private static void WriteMLine()
        {
            DxfDocument dxf = new DxfDocument();
            //MLineStyle style = MLineStyle.Default;
            //dxf.AddMLineStyle(style);

            List<Vector2> vertexes = new List<Vector2>
                                            {
                                                new Vector2(0, 0),
                                                new Vector2(0, 150),
                                                new Vector2(150, 150),
                                                new Vector2(150, 0)
                                            };

            MLine mline = new MLine(vertexes);
            mline.Scale = 20;
            mline.Justification = MLineJustification.Zero;
            //mline.IsClosed = true;

            MLineStyle style = new MLineStyle("MyStyle", "Personalized style.");
            style.Elements.Add(new MLineStyleElement(0.25));
            style.Elements.Add(new MLineStyleElement(-0.25));
            // if we add new elements directly to the list we need to sort the list,
            style.Elements.Sort();
            style.Flags = MLineStyleFlags.EndInnerArcsCap | MLineStyleFlags.EndRoundCap | MLineStyleFlags.StartInnerArcsCap | MLineStyleFlags.StartRoundCap;
            //style.StartAngle = 25.0;
            //style.EndAngle = 160.0;
            // AutoCad2000 dxf version does not support true colors for MLineStyle elements
            style.Elements[0].Color = new AciColor(180, 230, 147);
            mline.Style = style;
            // we have modified the multiline after setting its vertexes so we need to manually call this method.
            // also when manually editing the vertex distances
            mline.Update();

            // we can manually create cuts or gaps in the individual elements that made the multiline.
            // the cuts are defined as distances from the start point of the element along its direction.
            mline.Vertexes[0].Distances[0].Add(50);
            mline.Vertexes[0].Distances[0].Add(100);
            mline.Vertexes[0].Distances[mline.Style.Elements.Count-1].Add(50);
            mline.Vertexes[0].Distances[mline.Style.Elements.Count-1].Add(100);

            dxf.AddEntity(mline);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2004;
            dxf.Save("MLine.dxf");

            //dxf = DxfDocument.Load("Drawing1.dxf");
            //dxf.Save("Drawing1 copy.dxf");

            //dxf = DxfDocument.Load("Drawing3.dxf");
            //dxf.Save("Drawing3 copy.dxf");

            //dxf = DxfDocument.Load("Drawing2.dxf");
            //dxf.Save("Drawing2 copy.dxf");

            // empty mline
            //List<Vector2> vertexes2 = new List<Vector2>
            //                             {
            //                                 new Vector2(0, 0),
            //                                 new Vector2(100, 100),
            //                                 new Vector2(100, 100),
            //                                 new Vector2(200, 0)
            //                             };

            //MLine mline2 = new MLine(vertexes2){Scale = 20};
            //mline2.CalculateVertexesInfo();

            //DxfDocument dxf2 = new DxfDocument();
            //dxf2.AddEntity(mline2);
            ////dxf2.Save("void mline.dxf");

            //MLine mline3 = new MLine();
            //dxf2.AddEntity(mline3);
            ////dxf2.Save("void mline.dxf");

            //Polyline pol = new Polyline();
            //LwPolyline lwPol = new LwPolyline();
            //dxf2.AddEntity(pol);
            //dxf2.AddEntity(lwPol);
            //dxf2.Save("void mline.dxf");
            //dxf2 = DxfDocument.Load("void mline.dxf");
            
        }
Пример #2
0
        public static void ModifyingMLineStyles()
        {
            DxfDocument doc = new DxfDocument(DxfVersion.AutoCad2010);
            doc.DrawingVariables.LtScale = 10;

            List<Vector2> vertexes = new List<Vector2>
                                            {
                                                new Vector2(0, 0),
                                                new Vector2(0, 150),
                                                new Vector2(150, 150),
                                                new Vector2(150, 0)
                                            };

            MLine mline = new MLine(vertexes);
            mline.Scale = 20;
            mline.Justification = MLineJustification.Zero;

            MLineStyle style = new MLineStyle("MyStyle", "Personalized style.");
            style.Elements.Add(new MLineStyleElement(0.25));
            style.Elements.Add(new MLineStyleElement(-0.25));
         
            // if we add new elements directly to the list we need to sort the list,
            style.Elements.Sort();           
            style.Flags = MLineStyleFlags.EndInnerArcsCap | MLineStyleFlags.EndRoundCap | MLineStyleFlags.StartInnerArcsCap | MLineStyleFlags.StartRoundCap;

            // AutoCad2000 dxf version does not support true colors for MLineStyle elements
            style.Elements[0].Color = new AciColor(180, 230, 147);
           
            doc.AddEntity(mline);

            // change the multi line style after it has been added to the document
            mline.Style = style;
            Debug.Assert(ReferenceEquals(mline.Style, doc.MlineStyles[mline.Style.Name]), "Reference not equals.");

            // VERY IMPORTANT: We have modified the MLine after setting its vertexes so we need to manually call this method.
            // It is also necessary when manually editing the vertex distances.
            mline.Update();
            
            // the line type will be automatically added to the document
            foreach (MLineStyleElement e in style.Elements)
            {
                // making changes after the MLineStyle has been added to the document
                e.LineType = LineType.Dashed;
                Debug.Assert(ReferenceEquals(e.LineType, doc.LineTypes[e.LineType.Name]), "Reference not equals.");
            }

            MLine copy = (MLine) mline.Clone();
            copy.Scale = 100;
            doc.AddEntity(copy);
            // once the entity has been added to the document, changing its style requires that the new style is also present in the document.
            copy.Style = doc.MlineStyles["standard"];
            // VERY IMPORTANT: We have modified the MLine after setting its vertexes so we need to manually call this method.
            // It is also necessary when manually editing the vertex distances.
            copy.Update();

            doc.Save("ModifyingMLineStyle.dxf");
            Test("ModifyingMLineStyle.dxf");
        }
Пример #3
0
        private static void MLineStyleUsesAndRemove()
        {
            DxfDocument dxf = new DxfDocument();
            //MLineStyle style = MLineStyle.Default;
            //dxf.AddMLineStyle(style);

            List<Vector2> vertexes = new List<Vector2>
                                            {
                                                new Vector2(0, 0),
                                                new Vector2(0, 150),
                                                new Vector2(150, 150),
                                                new Vector2(150, 0)
                                            };

            MLine mline = new MLine(vertexes);
            mline.Scale = 20;
            mline.Justification = MLineJustification.Zero;
            //mline.IsClosed = true;

            MLineStyle style = new MLineStyle("MyStyle", "Personalized style.");
            style.Elements.Add(new MLineStyleElement(0.25));
            style.Elements.Add(new MLineStyleElement(-0.25));
            // if we add new elements directly to the list we need to sort the list,
            style.Elements.Sort();
            style.Flags = MLineStyleFlags.EndInnerArcsCap | MLineStyleFlags.EndRoundCap | MLineStyleFlags.StartInnerArcsCap | MLineStyleFlags.StartRoundCap;
            //style.StartAngle = 25.0;
            //style.EndAngle = 160.0;
            // AutoCad2000 dxf version does not support true colors for MLineStyle elements
            style.Elements[0].Color = new AciColor(180, 230, 147);
            mline.Style = style;
            // we have modified the mline after setting its vertexes so we need to manually call this method.
            // also when manually editting the vertex distances
            mline.Update();

            // we can manually create cuts or gaps in the individual elements that made the multiline.
            // the cuts are defined as distances from the start point of the element along its direction.
            mline.Vertexes[0].Distances[0].Add(50);
            mline.Vertexes[0].Distances[0].Add(100);
            mline.Vertexes[0].Distances[mline.Style.Elements.Count - 1].Add(50);
            mline.Vertexes[0].Distances[mline.Style.Elements.Count - 1].Add(100);
            dxf.AddEntity(mline);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2004;
            dxf.Save("MLine.dxf");

            DxfDocument dxf2 = DxfDocument.Load("MLine.dxf");

            // "MyStyle" is used only once
            List<DxfObject> uses;
            uses = dxf.MlineStyles.GetReferences(mline.Style.Name);

            // if we try to get the LineTypeUses, we will find out that "MyStyle" appears several times,
            // this is due to that each MLineStyleElement of a MLineStyle has an associated LineType
            uses = dxf.LineTypes.GetReferences(LineType.ByLayerName);

            bool ok;
            ok = dxf.RemoveEntity(mline);

            // "MyStyle" is not used its reference has been deleted
            uses = dxf.MlineStyles.GetReferences(mline.Style.Name);
            // we can safely remove it
            dxf.MlineStyles.Remove(mline.Style.Name);

            dxf.Save("MLine2.dxf");

            dxf.Layers.Clear();

            dxf.Save("MLine2.dxf");
        }