明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2397|回复: 5

快速插入目录图档下图块

[复制链接]
发表于 2012-8-23 18:26:51 | 显示全部楼层 |阅读模式
快速插入目录图档下图块
发表于 2012-8-26 14:50:13 | 显示全部楼层
void insertblc(CString blcname,double x,double y,double z,double sf_x,double sf_y,double sf_z,double blcRotation)
{
if(blcname.Trim().GetLength()<1)return;//modified by yzh 20080901
//if(blcname==p[0][0])return;//modified by yzh 20090117

// TODO: Add your control notification handler code here
acDocManager->lockDocument(curDoc());
AcDbObjectId blockId;   //要插入的块的Id值
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
  ->getSymbolTable(pBlockTable,AcDb::kForRead);
//pBlockTable->getAt(blcname,blockId,AcDb::kForRead);//根据块名获得要插入的块的ID值

if ( pBlockTable->getAt(blcname,blockId,AcDb::kForRead) != Acad::eOk )
acutPrintf(L"\n块名%s不存在!",blcname);

AcDbBlockReference *pBlkRef=new AcDbBlockReference;//插入块实质是插入块的引用
pBlkRef->setBlockTableRecord(blockId);//指定所引用的图块表记录的对象ID
resbuf to,from;
from.restype=RTSHORT;//插入图块要进行用户坐标与世界坐标的转换
from.resval.rint=1;//UCS
to.restype=RTSHORT;
to.resval.rint=0;//WCS
AcGeVector3d normal(0.0,0.0,0.0);
acedTrans(&(normal.x),&from,&to,Adesk::kTrue,&(normal.x));//转换函数
AcGePoint3d basePoint(x,y,z);//指定的插入点(可以根据需要输入)
//acedGetPoint(NULL,"\\nEnter insertion point:",asDblArray(basePoint));
double sfx = pBlkRef->scaleFactors().sx;
double sfy = pBlkRef->scaleFactors().sy;
double sfz = pBlkRef->scaleFactors().sz;
pBlkRef->setScaleFactors(AcGeScale3d(sfx*sf_x, sfy*sf_y, sfz*sf_z));//后加改变块比例
pBlkRef->setPosition(basePoint);

double ro=blcRotation/180*3.1415926;
/*
  360度=2*3.1415926=6.2831852弧度了?   
  180度=1*3.1415926=3.1415926弧度了?   
  90度=1/2*3.1415926=1.5707963弧度了?   
*/
pBlkRef->setRotation(ro);
pBlkRef->setNormal(normal);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId newEntId;
pBlockTableRecord->appendAcDbEntity(newEntId,pBlkRef);
pBlockTableRecord->close();
pBlkRef->close();
acDocManager->lockDocument(curDoc());
}
 楼主| 发表于 2012-8-26 18:05:10 | 显示全部楼层



(defun c:KK ()   

     (setvar "cmdecho" 0) ;指令执行过程不响应

     (PRINC "\n【开心CAD外挂】---插入图块(目录下)功能")(PRINC)

(command "insert" "d:\\33.dwg" "0,0" "1" "" "")

;(command "insert" "E:\\33.dwg" "0,0" "1" "" "");此行可添加图档所在位置(也可加行)

(entdel(entlast))

  (setq a (getstring "\n输入块名:")

        a (strcat "*" a)

  )

(WHILE(setq p1 (getpoint "\n插入点:  "))

(command "insert" a p1 "" ""))

(princ)

)
像这种能否帮我改一下,直接插入单一图块,无需输入块名?
 楼主| 发表于 2012-9-5 21:58:41 | 显示全部楼层
无人能解?

点评

Ref: http://www.google.com/search?as_q=setq++%E5%BF%AB%E9%80%9F%E6%8F%92%E5%85%A5+%E5%9B%BE%E5%9D%97+&as_epq=%E7%9B%AE%E5%BD%95&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_si   发表于 2012-9-6 08:00
发表于 2012-9-6 08:02:14 | 显示全部楼层
 楼主| 发表于 2012-9-6 23:26:46 | 显示全部楼层
帮我改一下,直接插入单一图块,无需输入块名?我只有一个图框要这样插入。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-12-23 17:44 , Processed in 0.175099 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表