中心点坐标移动
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
namespace AutoDemo8
{
public class Class1
{
[CommandMethod("PanTop")]
public static void PanTop()
{
//创建文档管理 获取当前文档
Document acDoc = Application.DocumentManager.MdiActiveDocument;
//声明数据库
Database acDB = acDoc.Database;
using (Transaction acTran = acDB.TransactionManager.StartTransaction())
{
//视图记录表
ViewTableRecord acView;
//获取当前视图
acView = acDoc.Editor.GetCurrentView();
//获取当前视图的中心点
Point2d Pc;
Pc = acView.CenterPoint;
//声明字符串
string str;
str = "原始图中心点:X:" + Pc.X.ToString() + "Y:" + Pc.Y.ToString()+"\n";
//autoCad 输出信息
acDoc.Editor.WriteMessage(str);
//声明一个新的中心点
Point2d newPC = new Point2d(500, 500);
//赋值
acView.CenterPoint = newPC;
//将新的中心点交于文档管理器
acDoc.Editor.SetCurrentView(acView);
//提交事务
acTran.Commit();
acDoc.Editor.WriteMessage("现视图中心点为:" + "X:" + acView.CenterPoint.X.ToString() + "Y:" + acView.CenterPoint.Y.ToString() + "\n");
}
}
}
}
|