当前位置: 首页>>代码示例>>C#>>正文


C# Layout.Clone方法代码示例

本文整理汇总了C#中Layout.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Layout.Clone方法的具体用法?C# Layout.Clone怎么用?C# Layout.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Layout的用法示例。


在下文中一共展示了Layout.Clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PaperSpace


//.........这里部分代码省略.........
            Layout layout1 = new Layout("Layout1");

            // When the layout is added to the list, a new PaperSpace block will be created automatically
            dxf.Layouts.Add(layout1);
            // Set this new Layout as the active one. All entities will now be added to this layout.
            dxf.ActiveLayout = layout1.Name;

            // Create a viewport, this is the window to the ModelSpace
            Viewport viewport1 = new Viewport
                {
                    Width = 100,
                    Height = 100,
                    Center = new Vector3(50, 50, 0),
                };

            // Add it to the "Layout1" since this is the active one
            dxf.AddEntity(viewport1);
            // Also add a circle
            Circle circle = new Circle(new Vector2(150), 25);
            dxf.AddEntity(circle);

            // Create a second Layout, add it to the list, and set it as the active one.
            Layout layout2 = new Layout("Layout2");
            dxf.Layouts.Add(layout2);
            dxf.ActiveLayout = layout2.Name;

            // viewports might have a non rectangular boundary, in this case we will use an ellipse.
            Ellipse ellipse = new Ellipse(new Vector2(100), 200, 150);
            Viewport viewport2 = new Viewport
            {
                ClippingBoundary = ellipse,
            };

            // Add the viewport to the document. This will also add the ellipse to the document.
            dxf.AddEntity(viewport2);

            Layout layout3 = new Layout("AnyName");
            dxf.Layouts.Add(layout3);
            //layout can also be renamed
            layout3.Name = "Layout3";
            
            //dxf.Layouts.Remove(layout2.Name);

            ShowDxfDocumentInformation(dxf);

            // Save the document as always.
            dxf.Save("PaperSpace.dxf");

#region CAUTION - This is subject to change in the future, use it with care

            // You cannot directly remove the ellipse from the document since it has been attached to a viewport
            bool ok = dxf.RemoveEntity(ellipse); // OK = false

            // If an entity has been attached to another, its reactor will point to its owner
            // This information is subject to change in the future to become a list, an entity can be attached to multiple objects;
            // but at the moment only the viewport clipping boundary make use of this.
            // This is the way AutoCad also handles hatch and dimension associativity, that I might implement in the future
            DxfObject reactor = ellipse.Reactors[0]; // in this case reactor points to viewport2

            // You need to delete the viewport instead. This deletes the viewport and the ellipse
            //dxf.RemoveEntity(viewport2);

            // another way of deleting the ellipse, is first to assign another clipping boundary to the viewport or just set it to null
            viewport2.ClippingBoundary = null;
            // now it will be possible to delete the ellipse. This will not delete the viewport.
            ok = dxf.RemoveEntity(ellipse); // OK = true

            // Save the document if you want to test the changes
            dxf.Save("PaperSpace.dxf");

#endregion

            DxfDocument dxfLoad = DxfDocument.Load("PaperSpace.dxf");

            // For every entity you can check its layout
            // The entity Owner will return the block to which it belongs, it can be a *Model_Space, *Paper_Space, ... or a common block if the entity is part of its geometry.
            // The block record stores information about the block and one of them is the layout, this mimics the way the dxf stores this information.
            // Remember only the internal blocks *Model_Space, *Paper_Space, *Paper_Space0, *Paper_Space1, ... have an associated layout,
            // all other blocks will return null is asked for block.Record.Layout
            Layout associatedLayout = dxfLoad.Lines[0].Owner.Record.Layout;

            // or you can get the complete list of entities of a layout
            foreach (Layout layout in dxfLoad.Layouts)
            {
                List<DxfObject> entities = dxfLoad.Layouts.GetReferences(layout.Name); 
            }

            // You can also remove any layout from the list, except the "Model".
            // Remember all entities that has been added to this layout will also be removed.
            // This mimics the behavior in AutoCad, when a layout is deleted all entities in it will also be deleted.
            dxfLoad.Layouts.Remove(layout1.Name);

            Layout layout4 = (Layout) layout2.Clone("Layout4");
            dxfLoad.Layouts.Add(layout4);

            ShowDxfDocumentInformation(dxfLoad);

            dxfLoad.Save("PaperSpace removed.dxf");

        }
开发者ID:DaishiNakase,项目名称:WaveguideDesigner,代码行数:101,代码来源:Program.cs


注:本文中的Layout.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。