关于偏移GetOffset的使用方法,点哪边则偏移哪边(偏移方向)!
using System;using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
namespace qian2014531
{
class qian2014531a
{
public void qianpp()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityResult ent = ed.GetEntity("选择实体");
Entity entity = null;
using (Transaction transaction = db.TransactionManager.StartTransaction())
{
entity = (Entity)transaction.GetObject(ent.ObjectId, OpenMode.ForRead, true);
transaction.Commit();
}
// 拾取点,指定偏移的方向“点 ”
PromptPointResult pPtRes;
PromptPointOptions pPtOpts = new PromptPointOptions("");
pPtOpts.Message = "\nEnter the start point of the line: ";
pPtRes = doc.Editor.GetPoint(pPtOpts);
Point3d DirectOffsetPt = pPtRes.Value;
double offsetDist = 10;
Curve mycurve = entity as Curve;
Point3d offPtNew = new Point3d(DirectOffsetPt.X, DirectOffsetPt.Y, 0);
//这里开始判断偏移的方向
Point3d pt1 = mycurve.GetClosestPointTo(offPtNew, false);
pt1 = new Point3d(pt1.X, pt1.Y, 0);
Vector3d vec1 = offPtNew - pt1;
Vector3d vec2 = mycurve.GetFirstDerivative(pt1);
Vector3d vec3 = vec1.CrossProduct(vec2);
if (vec3.Z < 0)
{
offsetDist = -offsetDist;
}
if (mycurve.GetType() == typeof(Line))
{
offsetDist = -offsetDist;
}
//结束,这里开始判断偏移的方向
using (Transaction acTrans = db.TransactionManager.StartTransaction())
{
// 以读模式打开Block 表
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
// 以写模式打开块表记录模型空间
BlockTableRecord acBlkTblRec;
acBlkTblRec =acTrans.GetObject(acBlkTbl,OpenMode.ForWrite) as BlockTableRecord;
DBObjectCollection objCol = new DBObjectCollection();
objCol = mycurve.GetOffsetCurves(offsetDist);
// 遍历得到的新对象
foreach (Curve acEnt in objCol)
{
// 添加每个对象
acBlkTblRec.AppendEntity(acEnt);
acTrans.AddNewlyCreatedDBObject(acEnt, true);
}
acTrans.Commit();
}
}
}
}
试了一下,挺好
VBAActiveX APICOM 下如何完成呢? Student 发表于 2014-6-3 09:54 static/image/common/back.gif
试了一下,挺好
抛砖引玉,大家可以都来讨论 Student 发表于 2014-6-3 09:54 static/image/common/back.gif
试了一下,挺好
同理用叉积方法,即可, 感谢 jiikoo 的提示-----“同理用叉积方法,即可”!!
能否给出VBAActiveX APICOM 下的 多段线“点哪边则偏移哪边(偏移方向)” 代码呢!? 谢谢!
页:
[1]