grasshorse 发表于 2009-6-10 16:59:00

[求助]我自己编写的图幅及标题栏后置设定程序怎么不能运行?

<p>// ObjectARX defined commands<br/>#include "StdAfx.h"<br/>#include "StdArx.h"<br/>#include &lt;aced.h&gt; <br/>#include &lt;string.h&gt; <br/>#include &lt;adslib.h&gt; <br/>#include &lt;dbents.h&gt; <br/>#include &lt;stdio.h&gt; <br/>#include &lt;math.h&gt; <br/>#include &lt;dbgroup.h&gt;<br/>#include &lt;dbid.h&gt;<br/>#include "dbmain.h"<br/>#include "dbidar.h "<br/>#include "dbapserv.h"<br/>#include "gepnt3d.h "<br/>#include&nbsp; "rxregsvc.h"<br/>#include&nbsp; "acedads.h"<br/>#include&nbsp; "adscodes.h"<br/>#include&nbsp;&nbsp; &lt;stdlib.h&gt;<br/>#include&nbsp; "accmd.h"<br/>#define Cpoint(d,s) {d=s;d=s;d=s;}<br/>#define Spoint(d,x,y,z){d=(x);d=(y);d=(z);}<br/>//#define ELEMENTS(array) {sizeof(array)/sizeof((array))}<br/>#define CommandB()&nbsp; { struct resbuf rB_cmd,rB_usr; \<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acedGetVar("CMDECHO", &amp;rB_cmd); \<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rB_usr.restype = RTSHORT; \<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rB_usr.resval.rint = (int) (0); \<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acedSetVar("CMDECHO", &amp;rB_usr);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>#define CommandE()&nbsp; acedSetVar("CMDECHO", &amp;rB_cmd); \<br/>};<br/>#define layer_do(mode,layer_name){\<br/>&nbsp;if(acedCommand(RTSTR,"LAYER",RTSTR,mode,RTSTR,layer_name,RTSTR,"",0)\<br/>!=RTNORM) acdbFail("\n Layer opration error.");\}<br/>#define&nbsp; layer_edit(mode,value,layer_name){\<br/>&nbsp;if(acedCommand(RTSTR,"LAYER",RTSTR,mode,RTSTR,value,RTSTR,layer_name,\<br/>&nbsp;&nbsp;&nbsp; RTSTR,"",0)!=RTNORM) acdbFail("\n layer edit opration&nbsp; error.");\<br/>&nbsp;}<br/>static struct size_list{ //图幅尺寸的数据结构<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char *name;//图幅名称<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int hor;//图纸水平长度<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int ver;//图纸纵向长度<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; short a;//图框的图纸左边界距离<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; short c;//图框到图纸上,下,右边界距离<br/>}<br/>size_list[]={<br/>&nbsp;{"A0",1189,841,25,10},//A0,A1...幅面边界的尺寸<br/>&nbsp;{"A1",841,594,25,10},<br/>&nbsp;{"A2",594,420,25,10},<br/>&nbsp;{"A3",420,297,25,5},<br/>&nbsp;{"A4",210,297,25,5},<br/>&nbsp;{"A5",210,148,25,5},<br/>&nbsp;<br/>};</p><p>#define SIZE_L 6<br/>//static int size=0;<br/>static char style;//图纸布置方式,1=正常,0=转置<br/>static char head ;//标题栏,1= 格式A,0=格式B</p><p>char tbuf;//全局性的自由变量<br/>int draw_size(ads_point pt_temp1,int hor,int ver,short a,short c,char style,char head,ads_real scale)<br/>{<br/>// 传递参数依次为:左下角点坐标,水平长度,纵向长度,至左边界距离,到其他三边的距离,图纸布置方式,标题栏格式,绘图比例&nbsp;<br/>&nbsp;ads_point&nbsp; pt0,pt1,pt2,pt3;<br/>&nbsp;int intl;<br/>&nbsp;char head_name;<br/>&nbsp;ads_name ss,e0,e1;//选择集和实体名称<br/>&nbsp;<br/>&nbsp;if(style!='1'){//图纸转置90°<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; intl=hor;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hor=ver;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ver=intl;}<br/>if(head=='1') strcpy(head_name,"head_a.dwg");//标题栏格式A<br/>else strcpy(head_name,"head_b.dwg");//标题栏格式B<br/>if (acedFindFile(head_name,tbuf)!=RTNORM){//在盘上查找标题栏图块<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf(tbuf,"file&lt;%s&gt; not existed.",head_name);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;acedAlert(tbuf);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return RTERROR;}<br/>Cpoint(pt0,pt_temp1);//对图幅外边界四角点x,y,z坐标赋值<br/>Spoint(pt1,pt0+hor,pt0,0);<br/>Spoint(pt2,pt0+hor,pt0+ver,0);<br/>Spoint(pt3,pt0,pt0+ver,0);<br/>acedCommand(RTSTR,"COLOR",RTSTR,"YELLOW",0);<br/>acedCommand(RTSTR,"LINE",RTPOINT,pt0,RTPOINT,pt1,0);//画外边界<br/>// acdbEntNext(NULL,ss);<br/>acdbEntLast(e0);//为后续生成ss选择集而保存第一个实体的名称<br/>acedCommand(RTPOINT,pt2,RTPOINT,pt3,RTSTR,"C",0);<br/>Spoint(pt0,pt0+a,pt0+c,0);<br/>Spoint(pt1,pt1-c,pt1+c,0);<br/>Spoint(pt2,pt2-c,pt2-c,0);<br/>Spoint(pt3,pt3+a,pt3-c,0);<br/>acedCommand(RTSTR,"COLOR",RTSTR,"WHITE",0);<br/>acedCommand(RTSTR,"LINE",RTPOINT,pt0,RTPOINT,pt1,RTPOINT,pt2,RTPOINT,pt3,RTSTR,"C",0);//绘图框线<br/>acedCommand(RTSTR,"LINE",RTPOINT,pt3,RTSTR,"@40&lt;0",RTSTR,"@12&lt;-90",RTSTR,"@40&lt;-180",RTSTR,"@12&lt;90",RTSTR,"",0);//绘图号区<br/>acedCommand(RTSTR,"INSERT",RTSTR,head_name,RT3DPOINT,pt1,RTSTR,"",RTSTR,"",RTSTR,"",0);//插入标题栏图块<br/>acedCommand(RTSTR,"COLOR",RTSTR,"BYLAYER",0);<br/>acedSSAdd(NULL,NULL,ss);//构造的新的选择集ss<br/>do {//生成包含所有新实体的(标题栏,图框等)的选择集,送ss中<br/>&nbsp;acedSSAdd(e0,ss,ss);<br/>&nbsp;acdbNameSet(e0,e1);<br/>} while(acdbEntNext(e1,e0)==RTNORM); <br/>acedCommand(RTSTR,"SCALE",RTPICKS,ss,RTSTR,"",RTPOINT,pt_temp1,RTREAL,1.0/scale,0);//对图框和标题栏进行反比例缩放<br/>acedSSFree(ss);//释放选择集ss<br/>return RTNORM;<br/>}<br/>// This is command 'SETSIZE'<br/>void arxarxsetsize()<br/>{<br/>&nbsp;int i,size;<br/>&nbsp;struct resbuf rb,rb1,rb2;//供存取AutoCAD系统变量之用<br/>&nbsp;ads_real lx,ly,//图形的真实宽度和高度<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; real1,real2,//图形的有效绘图区域x,y<br/>&nbsp;&nbsp;&nbsp; head_ht=40.0,//标题栏高度<br/>&nbsp;&nbsp;&nbsp; no_ht=12.0,//左上角的图号区的高度<br/>&nbsp;&nbsp;&nbsp; scale;//绘图比例<br/>&nbsp;ads_point pt_temp1;<br/>&nbsp;style='1';//在后置设定过程中,图纸布置方式只考虑正常方式<br/>&nbsp;head='1';//标题栏只考虑用格式A<br/>&nbsp;acedGetVar("userr1",&amp;rb);//从系统变量userr1获取当前使用的比例值<br/>&nbsp;scale=rb.resval.rreal;<br/>&nbsp;if(scale==0.0) scale=1.0;<br/>&nbsp;CommandB();<br/>&nbsp;acedCommand(RTSTR,"ZOOM",RTSTR,"ALL",0);<br/>&nbsp;CommandE();<br/>&nbsp;acedGetVar("EXTMAX",&amp;rb1);//获取当前图形的右上角点坐标<br/>&nbsp;acedGetVar("EXTMIN",&amp;rb2);//获取当前图形的左下角点坐标<br/>&nbsp;lx=rb1.resval.rpoint-rb2.resval.rpoint;//图形水平长度<br/>&nbsp;&nbsp;&nbsp; ly=rb1.resval.rpoint-rb2.resval.rpoint;//图形纵向长度<br/>&nbsp;for(i=5;i&gt;=0;i--) { //查找能包含此图形的最小图幅<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; real1=(size_list.hor-size_list.a-size_list.c)/scale;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;real2=(size_list.ver-size_list.c*2-head_ht-no_ht)/scale;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if((lx&lt;real1)&amp;&amp;(ly&lt;real2)){ //找到合适的图幅<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size=i;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;}<br/>&nbsp;if(i==-1) {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acedAlert("找不到合适的标准图幅");<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br/>&nbsp;}<br/>&nbsp;real1=real1-lx;<br/>&nbsp;real2=real2-ly;<br/>&nbsp;Spoint(pt_temp1,rb2.resval.rpoint-real1/2.0,rb2.resval.rpoint-real2/2.0,0.0);//pt_temp1,图纸左下角点 <br/>&nbsp;pt_temp1-=size_list.a/scale;<br/>&nbsp;pt_temp1-=(head_ht+size_list.c)/scale;<br/>&nbsp;CommandB();//关CMDECHO命令回显,然后调用draw_size()绘图框标题栏等<br/>&nbsp;if(draw_size(pt_temp1,size_list.hor,size_list.ver,size_list.a,size_list.c,style,head,scale)!=RTERROR)<br/>&nbsp;acedCommand(RTSTR,"ZOOM",RTSTR,"ALL",0);<br/>&nbsp;CommandE();//打开CMDECHO命令回显<br/>&nbsp;acedRetVoid();<br/>&nbsp;return;// TODO: Implement the command// TODO: Implement the command</p><p>}</p><p></p>

grasshorse 发表于 2009-6-11 10:22:00

<p>&nbsp;没有高手帮我看一看吗?</p>
页: [1]
查看完整版本: [求助]我自己编写的图幅及标题栏后置设定程序怎么不能运行?