-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathViewportTools.cs
More file actions
60 lines (57 loc) · 2.07 KB
/
Copy pathViewportTools.cs
File metadata and controls
60 lines (57 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
namespace DotNetARX
{
/// <summary>
/// 视口操作类
/// </summary>
public static class ViewportTools
{
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@PBVAcDbViewport@@@Z")]
extern static private int acedSetCurrentVPort(IntPtr AcDbVport);
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?acedSetCurrentVPort@@YA?AW4ErrorStatus@Acad@@H@Z")]
extern static private int acedSetCurrentVPort(int vpnumber);
/// <summary>
/// 将视口置为当前
/// </summary>
/// <param name="editor">命令行对象</param>
/// <param name="vport">视口对象</param>
public static void SetCurrentVPort(this Editor editor, Viewport vport)
{
acedSetCurrentVPort(vport.UnmanagedObject);
}
/// <summary>
/// 将视口置为当前
/// </summary>
/// <param name="editor">命令行对象</param>
/// <param name="vportNumber">视口编号</param>
public static void SetCurrentVPort(this Editor editor, int vportNumber)
{
acedSetCurrentVPort(vportNumber);
}
/// <summary>
/// 获取当前活动视口
/// </summary>
/// <param name="db">数据库对象</param>
/// <returns>返回当前活动视口的Id</returns>
public static ObjectId CurrentViewportTableRecordId(this Database db)
{
ObjectId vtrId=ObjectId.Null;
ViewportTable vt=(ViewportTable)db.ViewportTableId.GetObject(OpenMode.ForRead);
foreach (ObjectId id in vt)
{
if (!id.IsErased)
{
vtrId = id;
break;
}
}
return vtrId;
}
}
}