请教下VBA如何创建动态块?
如题,请教下VBA如何创建动态块?有可以参考的代码可以分享吗?
非常感谢! 会了吗 老哥
官方已明确:动态块可VBA编辑属性、 可参数控制变形;但不可VBA/Vlisp创建。
创建动态块得 .net或Objarx
下面这段.net 试试看
using System;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
namespace Sample
{
class AddBlock
{
///
/// 把块定义变为块参照插入
///
public void AddBk()
{
Database db = HostApplicationServices.WorkingDatabase;
ObjectId blkid;
//创建块定义
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord blk = new BlockTableRecord();
blk.Name = "BLK";
Line L = new Line(Point3d.Origin, new Point3d(1000, 1000, 0));
Circle C = new Circle(Point3d.Origin, Vector3d.ZAxis, 500);
blk.AppendEntity(L);
blk.AppendEntity(C);
blkid = bt.Add(blk);
trans.AddNewlyCreatedDBObject(blk, true);
trans.Commit();
}
//把块参照添加到块表记录
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt, OpenMode.ForWrite) as BlockTableRecord;
BlockReference br = new BlockReference(new Point3d(0,0, 0), blkid); // 通过块定义创建块参照
btr.AppendEntity(br);
tr.AddNewlyCreatedDBObject(br, true); // 通过事务添加块参照到数据库
tr.Commit();
}
}
}
}
好的我试试
好像是没有对应的动态块创建命令,我一般都是手动设置动态块的属性和范围后,VBA可调用已存在的对应块定义,插入块参照,设置指定的参数属性。
页:
[1]