明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1802|回复: 1

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

[复制链接]
发表于 2009-6-10 16:59:00 | 显示全部楼层 |阅读模式

// ObjectARX defined commands
#include "StdAfx.h"
#include "StdArx.h"
#include <aced.h>
#include <string.h>
#include <adslib.h>
#include <dbents.h>
#include <stdio.h>
#include <math.h>
#include <dbgroup.h>
#include <dbid.h>
#include "dbmain.h"
#include "dbidar.h "
#include "dbapserv.h"
#include "gepnt3d.h "
#include  "rxregsvc.h"
#include  "acedads.h"
#include  "adscodes.h"
#include   <stdlib.h>
#include  "accmd.h"
#define Cpoint(d,s) {d[X]=s[X];d[Y]=s[Y];d[Z]=s[Z];}
#define Spoint(d,x,y,z){d[X]=(x);d[Y]=(y);d[Z]=(z);}
//#define ELEMENTS(array) {sizeof(array)/sizeof((array)[0])}
#define CommandB()  { struct resbuf rB_cmd,rB_usr; \
        acedGetVar("CMDECHO", &rB_cmd); \
        rB_usr.restype = RTSHORT; \
        rB_usr.resval.rint = (int) (0); \
        acedSetVar("CMDECHO", &rB_usr);                               
#define CommandE()  acedSetVar("CMDECHO", &rB_cmd); \
};
#define layer_do(mode,layer_name){\
 if(acedCommand(RTSTR,"LAYER",RTSTR,mode,RTSTR,layer_name,RTSTR,"",0)\
!=RTNORM) acdbFail("\n Layer opration error.");\}
#define  layer_edit(mode,value,layer_name){\
 if(acedCommand(RTSTR,"LAYER",RTSTR,mode,RTSTR,value,RTSTR,layer_name,\
    RTSTR,"",0)!=RTNORM) acdbFail("\n layer edit opration  error.");\
 }
static struct size_list{ //图幅尺寸的数据结构
                      char *name;//图幅名称
       int hor;//图纸水平长度
       int ver;//图纸纵向长度
       short a;//图框的图纸左边界距离
       short c;//图框到图纸上,下,右边界距离
}
size_list[]={
 {"A0",1189,841,25,10},//A0,A1...幅面边界的尺寸
 {"A1",841,594,25,10},
 {"A2",594,420,25,10},
 {"A3",420,297,25,5},
 {"A4",210,297,25,5},
 {"A5",210,148,25,5},
 
};

#define SIZE_L 6
//static int size=0;
static char style;//图纸布置方式,1=正常,0=转置
static char head ;//标题栏,1= 格式A,0=格式B

char tbuf[80];//全局性的自由变量
int draw_size(ads_point pt_temp1,int hor,int ver,short a,short c,char style,char head,ads_real scale)
{
// 传递参数依次为:左下角点坐标,水平长度,纵向长度,至左边界距离,到其他三边的距离,图纸布置方式,标题栏格式,绘图比例 
 ads_point  pt0,pt1,pt2,pt3;
 int intl;
 char head_name[12];
 ads_name ss,e0,e1;//选择集和实体名称
 
 if(style!='1'){//图纸转置90°
               intl=hor;
      hor=ver;
      ver=intl;}
if(head=='1') strcpy(head_name,"head_a.dwg");//标题栏格式A
else strcpy(head_name,"head_b.dwg");//标题栏格式B
if (acedFindFile(head_name,tbuf)!=RTNORM){//在盘上查找标题栏图块
                                         sprintf(tbuf,"file<%s> not existed.",head_name);
           acedAlert(tbuf);
           return RTERROR;}
Cpoint(pt0,pt_temp1);//对图幅外边界四角点x,y,z坐标赋值
Spoint(pt1,pt0[X]+hor,pt0[Y],0);
Spoint(pt2,pt0[X]+hor,pt0[Y]+ver,0);
Spoint(pt3,pt0[X],pt0[Y]+ver,0);
acedCommand(RTSTR,"COLOR",RTSTR,"YELLOW",0);
acedCommand(RTSTR,"LINE",RTPOINT,pt0,RTPOINT,pt1,0);//画外边界
// acdbEntNext(NULL,ss);
acdbEntLast(e0);//为后续生成ss选择集而保存第一个实体的名称
acedCommand(RTPOINT,pt2,RTPOINT,pt3,RTSTR,"C",0);
Spoint(pt0,pt0[X]+a,pt0[Y]+c,0);
Spoint(pt1,pt1[X]-c,pt1[Y]+c,0);
Spoint(pt2,pt2[X]-c,pt2[Y]-c,0);
Spoint(pt3,pt3[X]+a,pt3[Y]-c,0);
acedCommand(RTSTR,"COLOR",RTSTR,"WHITE",0);
acedCommand(RTSTR,"LINE",RTPOINT,pt0,RTPOINT,pt1,RTPOINT,pt2,RTPOINT,pt3,RTSTR,"C",0);//绘图框线
acedCommand(RTSTR,"LINE",RTPOINT,pt3,RTSTR,"@40<0",RTSTR,"@12<-90",RTSTR,"@40<-180",RTSTR,"@12<90",RTSTR,"",0);//绘图号区
acedCommand(RTSTR,"INSERT",RTSTR,head_name,RT3DPOINT,pt1,RTSTR,"",RTSTR,"",RTSTR,"",0);//插入标题栏图块
acedCommand(RTSTR,"COLOR",RTSTR,"BYLAYER",0);
acedSSAdd(NULL,NULL,ss);//构造的新的选择集ss
do {//生成包含所有新实体的(标题栏,图框等)的选择集,送ss中
 acedSSAdd(e0,ss,ss);
 acdbNameSet(e0,e1);
} while(acdbEntNext(e1,e0)==RTNORM);
acedCommand(RTSTR,"SCALE",RTPICKS,ss,RTSTR,"",RTPOINT,pt_temp1,RTREAL,1.0/scale,0);//对图框和标题栏进行反比例缩放
acedSSFree(ss);//释放选择集ss
return RTNORM;
}
// This is command 'SETSIZE'
void arxarxsetsize()
{
 int i,size;
 struct resbuf rb,rb1,rb2;//供存取AutoCAD系统变量之用
 ads_real lx,ly,//图形的真实宽度和高度
          real1,real2,//图形的有效绘图区域x,y
    head_ht=40.0,//标题栏高度
    no_ht=12.0,//左上角的图号区的高度
    scale;//绘图比例
 ads_point pt_temp1;
 style='1';//在后置设定过程中,图纸布置方式只考虑正常方式
 head='1';//标题栏只考虑用格式A
 acedGetVar("userr1",&rb);//从系统变量userr1获取当前使用的比例值
 scale=rb.resval.rreal;
 if(scale==0.0) scale=1.0;
 CommandB();
 acedCommand(RTSTR,"ZOOM",RTSTR,"ALL",0);
 CommandE();
 acedGetVar("EXTMAX",&rb1);//获取当前图形的右上角点坐标
 acedGetVar("EXTMIN",&rb2);//获取当前图形的左下角点坐标
 lx=rb1.resval.rpoint[X]-rb2.resval.rpoint[X];//图形水平长度
    ly=rb1.resval.rpoint[Y]-rb2.resval.rpoint[Y];//图形纵向长度
 for(i=5;i>=0;i--) { //查找能包含此图形的最小图幅
                  real1=(size_list.hor-size_list.a-size_list.c)/scale;
      real2=(size_list.ver-size_list.c*2-head_ht-no_ht)/scale;
      if((lx<real1)&&(ly<real2)){ //找到合适的图幅
       size=i;
       break;
      }
 }
 if(i==-1) {
         acedAlert("找不到合适的标准图幅");
       return;
 }
 real1=real1-lx;
 real2=real2-ly;
 Spoint(pt_temp1,rb2.resval.rpoint[X]-real1/2.0,rb2.resval.rpoint[Y]-real2/2.0,0.0);//pt_temp1,图纸左下角点
 pt_temp1[X]-=size_list[size].a/scale;
 pt_temp1[Y]-=(head_ht+size_list[size].c)/scale;
 CommandB();//关CMDECHO命令回显,然后调用draw_size()绘图框标题栏等
 if(draw_size(pt_temp1,size_list[size].hor,size_list[size].ver,size_list[size].a,size_list[size].c,style,head,scale)!=RTERROR)
 acedCommand(RTSTR,"ZOOM",RTSTR,"ALL",0);
 CommandE();//打开CMDECHO命令回显
 acedRetVoid();
 return;// TODO: Implement the command// TODO: Implement the command

}

 楼主| 发表于 2009-6-11 10:22:00 | 显示全部楼层

 没有高手帮我看一看吗?

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-25 14:29 , Processed in 0.167384 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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