zoukankan      html  css  js  c++  java
  • cad.net创建浮动视口

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Runtime.InteropServices;

    using Autodesk.AutoCAD.Runtime;

    using Autodesk.AutoCAD.ApplicationServices;

    using Autodesk.AutoCAD.DatabaseServices;

    using Autodesk.AutoCAD.Geometry;

    using Autodesk.AutoCAD.EditorInput;

    using AcGi = Autodesk.AutoCAD.GraphicsInterface;

    namespace sample

    {

        public class paperViewport

        {

            //for 2013 cad

            [DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl,

            EntryPoint = "?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PEBVAcDbViewport@@@Z")]

            //[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl,

            // EntryPoint = "?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PBVAcDbViewport@@@Z")]

            extern static private int acedSetCurrentVPort(IntPtr AcDbVport);

            [CommandMethod("CreateFloatingViewport")]

            public static void CreateFloatingViewport()

            {

                // Get the current document and database, and start a transaction

                Document acDoc = Application.DocumentManager.MdiActiveDocument;

                Database acCurDb = acDoc.Database;

                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())

                {

                    // Open the Block table for read

                    BlockTable acBlkTbl;

                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,

                                                 OpenMode.ForRead) as BlockTable;

                    // Open the Block table record Paper space for write

                    BlockTableRecord acBlkTblRec;

                    acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.PaperSpace],

                                                    OpenMode.ForWrite) as BlockTableRecord;

                    // Switch to the previous Paper space layout

                    Application.SetSystemVariable("TILEMODE", 0);

                    acDoc.Editor.SwitchToPaperSpace();

                    // Create a Viewport

                    Viewport acVport = new Viewport();

                    acVport.CenterPoint = new Point3d(3.25, 3, 0);

                    acVport.Width = 6;

                    acVport.Height = 5;

                    // Add the new object to the block table record and the transaction

                    acBlkTblRec.AppendEntity(acVport);

                    acTrans.AddNewlyCreatedDBObject(acVport, true);

                    // Change the view direction

                    acVport.ViewDirection = new Vector3d(1, 1, 1);

                    // Enable the viewport

                    acVport.On = true;

                    // Activate model space in the viewport

                    acDoc.Editor.SwitchToModelSpace();

                    // Set the new viewport current via an imported ObjectARX function

                    acedSetCurrentVPort(acVport.UnmanagedObject);

                    // Save the new objects to the database

                    acTrans.Commit();

                }

            }

        }

  • 相关阅读:
    面向对象之设计模式大全
    JDK各版本新增的主要特性
    迷宫最短路径-货郎担问题的解决思路
    详细介绍Java垃圾回收机制
    并发编程与任务建模
    淘宝npm镜像使用方法
    Metrics-Java版的指标度量工具
    Velocity基本语法
    Git之”make sure you have the correct access…”
    Mysql的转义字符
  • 原文地址:https://www.cnblogs.com/swtool/p/3829003.html
Copyright © 2011-2022 走看看