- 积分
- 81
- 明经币
- 个
- 注册时间
- 2011-11-3
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2011-11-5 09:39:12
|
显示全部楼层
本帖最后由 zzrxt 于 2011-11-5 09:49 编辑
我在建坐标系时也出现相同问题,请各位帮帮忙啊 ,刚学二次开发:
1.以wcs为基准,新建ucs1
2.以ucs1为基准,新建ucs2
3.相同代码,ucs1位置正确了,但ucs2就不对了,它的圆心位置仍然是以wcs为准了,而我想以ucs1为基准。
public static void DrawingLayout(double[] orgPt, double length, double width, double height)
{
//初始化绝对坐标系
IniLayout.TCS("ABS", new double[3] { 0, 0, 0 });
CAD.CreateCircle(new double[4] { 0, 0, 0, 50 });
//初始化坐标系ucs1:
IniLayout.TCS("ucs1", orgPt);
CAD.CreateCircle(new double[4] { 0, 0, 0, 50 });
//初始化坐标系ucs2:
double[] p = new double[3];
p[0] = 1000 + length / 2;
p[1] = 1000 + width / 2;
p[2] = 0;
IniLayout.TCS("ucs2", p);
CAD.CreateCircle(new double[4] { 0, 0, 0, 50 });
}
/// <summary>
/// 给定原点,创建坐标系
/// </summary>
public static void TCS(String ucsName, double[] p)
{
using (DocumentLock docLock = CAD.CurrentDocument.LockDocument()) //注意此句,如果自定义对话框与CAD交互,一定要锁定文档
{
//获得当前文档和数据库,并启动一个事务,开始事务处理
using (Transaction acTrans = CAD.CurrentDatabase.TransactionManager.StartTransaction())
{
//以读的方式打开UCS表
UcsTable acUCSTbl;
acUCSTbl = acTrans.GetObject(CAD.CurrentDatabase.UcsTableId, OpenMode.ForRead) as UcsTable;
//检查看0cs用户坐标系表记录是否存在
try
{
UcsTableRecord acUCSTblRec;
if (acUCSTbl.Has(ucsName) == false)
{
acUCSTblRec = new UcsTableRecord();
acUCSTblRec.Name = ucsName;
acUCSTbl.UpgradeOpen();
//添加新的 UCS 表记录
acUCSTbl.Add(acUCSTblRec);
acTrans.AddNewlyCreatedDBObject(acUCSTblRec, true);
}
else
{
acUCSTblRec = acTrans.GetObject(acUCSTbl[ucsName], OpenMode.ForWrite) as UcsTableRecord;
}
CAD.CurrentEditor.WriteMessage(p[0].ToString() + ">" + p[1].ToString() + "\n");
acUCSTblRec.Origin = new Point3d(p[0], p[1], p[2]);
acUCSTblRec.XAxis = new Vector3d(1, 0, 0);
acUCSTblRec.YAxis = new Vector3d(0, 1, 0);
// 以只读方式打开视口表
ViewportTable acVportTbl;
acVportTbl = acTrans.GetObject(CAD.CurrentDatabase.ViewportTableId,
OpenMode.ForRead) as ViewportTable;
// 以写的方式打开视图表
acVportTbl.UpgradeOpen();
// 遍历符号表的每一个对象
foreach (ObjectId acObjId in acVportTbl)
{
//以写方式打开对象
ViewportTableRecord acVportTblRec;
acVportTblRec = acTrans.GetObject(acObjId, OpenMode.ForWrite) as ViewportTableRecord;
// 判断是否是活动窗口
if (acVportTblRec.Name == "*Active")
{
acVportTblRec.IconAtOrigin = true;
acVportTblRec.IconEnabled = true;
acVportTblRec.SetUcs(acUCSTblRec.ObjectId);
CAD.CurrentDocument.Editor.UpdateTiledViewportsFromDatabase();
UcsTableRecord acUCSTblRecActive;
acUCSTblRecActive = acTrans.GetObject(acVportTblRec.UcsName,
OpenMode.ForRead) as UcsTableRecord;
CAD.CurrentEditor.WriteMessage("\n当前坐标系为: " + acUCSTblRecActive.Name);
// 保存新对象到数据库中
acTrans.Commit();
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|