目录
一、 给定半径和圆心 绘制圆 Circle
类 Circle 构造函数有两个:
public Circle();
public Circle(Point3d center,Vector3d normal,double radius);
1、代码记录
写入CircleTest.cs文件里
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yztest4
{
public class CircleTest
{
[CommandMethod("Circletest")]
public void Circletest()
{
//类 Circle 圆
//两个构造函数
//public Circle();
//public Circle(Point3d center, Vector3d normal, double radius);
Circle c1 = new Circle();
c1.Center = new Point3d(50, 50, 0);
c1.Radius = 50;
Circle c2 = new Circle(new Point3d(100, 100, 0), new Vector3d(0, 0, 1), 50);
Database db = HostApplicationServices.WorkingDatabase;
db.AddEntityToModelSpace(c1, c2);
}
}
}
2、封装函数
写入AddEntityTool.cs文件里
/// <summary>
/// 绘制圆
/// </summary>
/// <param name="db">图形数据库</param>
/// <param name="center">圆心</param>
/// <param name="radius">半径</param>
/// <returns>ObjectId</returns>
public static ObjectId AddCircleToModelSpace(this Database db,Point3d center,Point3d radius)
{
return db.AddEntityToModelSpace(new Circle(center, new Vector3d(0, 0, 1), radius);
}
写完封装函数后,就可以把CircleTest.cs文件里的代码改写了
Database db = HostApplicationServices.WorkingDatabase;
db.AddCircleToModelSpace(new Point3d(100, 100, 0), 100);
二、给定两点绘制圆
1、代码记录
写入CircleTest.cs文件中