pengyh 发表于 2006-6-2 23:49:00

请教如何通过程序实现在类似AutoCAD中添加一中字体样式的功能?

<P>如题,我需要通过程序实现类似AutoCAD中添加一中字体样式的功能?这样我可以将这个字体样式一直保存,然后每次我添加文字的时候都可以用啦,望大虾们不吝赐教!</P>

jingelou 发表于 2006-6-14 00:41:00

<P><BR>AcDbObjectId CLjDwg::AddTextStyle(const char* strName,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char* strStype,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char* strBigName,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const double dHeight,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const double dFactor,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcDbDatabase* pDb)<BR>{<BR>&nbsp;AcDbObjectId idTextStyle=NULL;</P>
<P>&nbsp;AcDbTextStyleTable *pTable=NULL;&nbsp;<BR>&nbsp;AcDbTextStyleTableRecord *pTableRecord;&nbsp;<BR>&nbsp;if (pDb==NULL)<BR>&nbsp;&nbsp;pDb=acdbCurDwg();<BR>&nbsp;pDb-&gt;getTextStyleTable(pTable,AcDb::kForWrite);</P>
<P>&nbsp;if(pTable==NULL)<BR>&nbsp;{<BR>&nbsp;&nbsp;AfxMessageBox("Fonttable open wrong");<BR>&nbsp;&nbsp;return idTextStyle;<BR>&nbsp;}<BR>&nbsp;// 生成新的图层表记录&nbsp;<BR>&nbsp;Acad::ErrorStatus es;<BR>&nbsp;pTable-&gt;getAt(ACDB_MODEL_SPACE,pTableRecord,AcDb::kForWrite);<BR>&nbsp;if(pTable-&gt;has(strName))<BR>&nbsp;{<BR>&nbsp;&nbsp;pTable-&gt;getAt(strName,idTextStyle);<BR>&nbsp;}<BR>&nbsp;else<BR>&nbsp;{<BR>&nbsp;&nbsp;pTableRecord=new AcDbTextStyleTableRecord;&nbsp;&nbsp;<BR>&nbsp;&nbsp;es = pTableRecord-&gt;setName(strName);&nbsp;</P>
<P>&nbsp;&nbsp;if(CString(strStype).Find(_T(".shx")) != -1 <BR>&nbsp;&nbsp;&nbsp;|| CString(strStype).Find(_T(".SHX")) != -1)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;char szPath;<BR>&nbsp;&nbsp;&nbsp;if (ads_findfile(strStype,szPath) != RTNORM) <BR>&nbsp;&nbsp;&nbsp;{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;ads_printf("Could not find file %s.\n", strStype);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;es = pTableRecord-&gt;setFileName(strStype);<BR>&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;if(CString(strBigName) != _T(""))<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;char szPath;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (ads_findfile(strBigName,szPath) != RTNORM) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ads_printf("Could not find file %s.\n", strBigName);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;es = pTableRecord-&gt;setBigFontFileName(strBigName);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;else<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;es = pTableRecord-&gt;setFont(strStype,FALSE,FALSE,200,100);<BR>&nbsp;&nbsp;}</P>
<P>&nbsp;&nbsp;pTableRecord-&gt;setTextSize(dHeight);<BR>&nbsp;&nbsp;pTableRecord-&gt;setXScale(dFactor);&nbsp;&nbsp;<BR>&nbsp;&nbsp;es = pTable-&gt;add(idTextStyle,pTableRecord);&nbsp;<BR>&nbsp;&nbsp;pTableRecord-&gt;close();&nbsp;<BR>&nbsp;}&nbsp;</P>
<P>&nbsp;pTable-&gt;close();</P>
<P>&nbsp;return idTextStyle;<BR>}</P>
<P>&nbsp;</P>

wzz1968 发表于 2006-6-14 17:19:00

<P>上述代码有点太复杂啦</P>
<P>用acedCommand函数调用AUTOCAD的style命令就可以实现.</P>
<P>&nbsp;</P>

easypower 发表于 2006-6-17 10:06:00

wzz1968发表于2006-6-14 17:19:00static/image/common/back.gif
上述代码有点太复杂啦
用acedCommand函数调用AUTOCAD的style命令就可以实现.


就是要用复杂的代码,呵呵,用二楼的代码才是真正和cad的内核打交道,用acedCommand还不如用 lisp,不用编译,二楼的是正解<BR>

HuaiYu 发表于 2006-6-17 17:53:00

同意,既然是程序就要用编程的思想

wzz1968 发表于 2006-6-23 15:15:00

<P>初学编程的非常忌讳搞一对找不着边的代码,二楼的代码足以使初学者望而却步.</P>
<P>当然可以用LISP解决问题.</P>
<P>方式如下:</P>
<P>假设定义HS字型</P>
<P>1.用command函数</P>
<P>(if&nbsp; (= (tblsearch "style" "hs") nil)</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; (command&nbsp; "style" "hs" "txt,hs" "4" "0.5" "" "" "")</P>
<P>)</P>
<P>2.用tblobjname函数</P>
<P>(if&nbsp; (= (tblsearch "style" "hs") nil)</P>
<P>&nbsp;(progn&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp; (setq ent (tblobjname "style" "standard"))</P>
<P>&nbsp; &nbsp;&nbsp; (setq ent_list (entget ent))</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;(setq ent_list&nbsp;(subst (cons&nbsp;2 "hs") (assoc 2 ent_list))</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; (setq ent_list&nbsp;(subst (cons&nbsp;3 "txt") (assoc&nbsp;3 ent_list))</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; (setq ent_list&nbsp;(subst (cons&nbsp;4 "hs") (assoc&nbsp;4 ent_list))</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; (setq ent_list&nbsp;(subst (cons&nbsp;40&nbsp;&nbsp;&nbsp;4.0) (assoc 40 ent_list))</P>
<P>&nbsp;&nbsp;&nbsp; &nbsp;(setq ent_list&nbsp;(subst (cons&nbsp;41 &nbsp;0.5) (assoc 41 &nbsp;ent_list))</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; (entmake ent)</P>
<P>)</P>
<P>)</P>
<P>对于初学者,那段代码好理解是不言而语的.</P>
<P>&nbsp;</P>
<P>&nbsp;&nbsp;&nbsp;&nbsp; (command&nbsp; "style" "hs" "txt,hs" "4" "0.5" "" "" "")</P>
<P>)</P>

pglyxq 发表于 2006-6-23 17:36:00

wzz1968发表于2006-6-23 15:15:00static/image/common/back.gif
初学编程的非常忌讳搞一对找不着边的代码,二楼的代码足以使初学者望而却步.
当然可以用LISP解决问题.
方式如下:


<P>ARX任何方面的代码都足以使初学者望而却步,如果害怕,就不要去碰ARX。刚从LISP转ARX的人的最大安慰就是有acedCommand()函数,但那只是古老的ADS遗留下来的ADSRX,从面向对象的角度而言,要真正掌握ARX,就要彻底放弃LISP的思维方式。</P>
<P>所以这些LISP代码对于ARX而言没有任何价值!</P>




<P>//<BR></P>
页: [1]
查看完整版本: 请教如何通过程序实现在类似AutoCAD中添加一中字体样式的功能?