请问 在vb.net下怎样实现块插入,有这方面的例子吗?
www.dimcax.com
请问 在vb.net下怎样实现块插入,有这方面的例子吗?
请问 在vb.net下怎样实现块插入,有这方面的例子吗?期待中!!
下面是一个c#的例子:
public class testinsert
{
[commandmethod("testinsert"

]
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 = "你想要的块名"