Insert an external graph block into the current graph (C # code)
Source: Internet
Author: User
In the process of using C # To develop AutoCAD tools, you need to transfer the externally defined DWG block file to the current file. On the internet, you have checked a lot of relevant materials, not many of which are involved, sort it as follows: 1 Public objectid insertblock (string filename)
2 {
3 objectid blockid;
4 // read external graph blocks from the Graphic Database
5 database blockdatabase = new database (false, true );
6 blockdatabase. readdwgfile (filename, system. Io. fileshare. Read, false, String. Empty );
7 blockdatabase. closeinput (true );
8
9 database DB = hostapplicationservices. workingdatabase;
10 using (transaction trans = dB. transactionmanager. starttransaction ())
11 {
12 blocktable bt = (blocktable) Trans. GetObject (db. blocktableid, openmode. forwrite );
13 string blockname = symbolutilityservices. getblocknamefrominsertpathname (filename );
14 // insert an external graph block into the current model space
15 blockid = dB. insert (blockname, blockdatabase, false );
16 TRANS. Commit ();
17}
18 return blockid;
19}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.