几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(VB.NET/C#)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


 
 
主题工具 搜索本主题 显示模式
旧 2009-04-22, 01:23 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】请问 在vb.net下怎样实现块插入,有这方面的例子吗?

请问 在vb.net下怎样实现块插入,有这方面的例子吗?
www.dimcax.com
请问 在vb.net下怎样实现块插入,有这方面的例子吗?
请问 在vb.net下怎样实现块插入,有这方面的例子吗?期待中!!
下面是一个c#的例子:
public class testinsert
{
[commandmethod("testinsert&quot]
static public void doit()
{
document doc = application.documentmanager.mdiactivedocument;
editor ed = doc.editor;
promptresult res = ed.getstring("give me a file to insert"
if (res.status != promptstatus.ok)
return;
string fname = res.stringresult;
if (!file.exists(fname))
fname = hostapplicationservices.current.findfile(fname, doc.database, findfilehint.default);
using (database db = new database(false, false))
{
//read drawing
db.readdwgfile(fname, fileshare.read, true, null);
using (transaction t = doc.transactionmanager.starttransaction())
{
//insert it as a new block
objectid idbtr = doc.database.insert("test", db, false);
//create a ref to the block
blocktable bt = (blocktable)t.getobject(doc.database.blocktableid, openmode.forread);
blocktablerecord btr = (blocktablerecord)t.getobject(bt[blocktablerecord.modelspace], openmode.forwrite);
using (blockreference bref = new blockreference(point3d.origin, idbtr))
{
btr.appendentity(bref);
t.addnewlycreateddbobject(bref, true);
}
t.commit();
}
}
}
}
好的,我参考以下,哈!
能不能将一个dwg文件当成一个块插入到当前图中。dwg图纸名称就是当前图中的块名。上面的代码老出错。
cad开发爱好者
这是vb。net的例子
<commandmethod("insertblockdwg")> _
public function insertblockdwg() as objectid
dim sourcefilename as string = "e:\equa3.dwg"
dim newblockname as string = "dd"
dim po as point3d = new point3d(0, 0, 0)
dim db as database = hostapplicationservices.workingdatabase()
dim trans as transaction = db.transactionmanager.starttransaction()
dim bt as blocktable = trans.getobject(db.blocktableid, openmode.forwrite)
dim btr as blocktablerecord = trans.getobject(bt(blocktablerecord.modelspace), openmode.forwrite)
try
dim sourcedatabase as database = getdatabasefromfile(sourcefilename)
'把源数据库模型空间中的实体插入到当前数据库的一个新的块表记录中
dim bobj as objectid = hostapplicationservices.workingdatabase.insert(newblockname, sourcedatabase, true)
dim bref as blockreference = new blockreference(po, bobj)
dim blockobj as objectid = btr.appendentity(bref)
dim empbtr as blocktablerecord = trans.getobject(bt(newblockname), openmode.forread)
dim id as objectid
for each id in empbtr
dim ent as entity = trans.getobject(id, openmode.forread, true)
if typeof ent is attributedefinition then
dim attref as attributereference = new attributereference
dim attdef as attributedefinition = ctype(ent, attributedefinition)
attref.setpropertiesfrom(attdef)
attref.position = new point3d(bref.position.x + attdef.position.x, bref.position.y + attdef.position.y, bref.position.z + attdef.position.z)
attref.height = attdef.height
attref.rotation = attdef.rotation
attref.tag = attdef.tag
attref.textstring = attdef.textstring
bref.attributecollection.appendattribute(attref)
trans.addnewlycreateddbobject(attref, true)
end if
next
trans.addnewlycreateddbobject(bref, true)
trans.commit()
trans.dispose()
return blockobj
catch e as system.exception
application.showalertdialog(e.message)
end try
end function
我引用 的是这些,
imports autodesk.autocad.applicationservices
imports autodesk.autocad.editorinput
imports autodesk.autocad.runtime
imports autodesk.autocad.databaseservices
imports autodesk.autocad.geometry
imports autodesk.autocad.colors
第四行dim newblockname as string = "你想要的块名"
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
 


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 02:12 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多