UG二次开发导出工程图尺寸

   网上有作者介绍UF_DRF_ask_draft_aid_text_info这个函数,能够得到尺寸的尺寸值及公差,就想到既然如此能否用它导出图纸的尺寸。于是随意画了个工程图上,又标了几个尺寸。结果发现,这个函数的确可以获取到尺寸的尺寸值、公差、前后附加文本,但是它不是按期待的那样:以 (前附加文本+尺寸值+公差+后附加文本)的顺序排列,比如尺寸6-60±0.1X45°±4°通过循环得到的结果并不是6-60<T+0.1!-0.1>X45<$s><$t>4<$s>,而是6-<$t>4<$s>60<T+0.1!-0.1>45<$s>X。那么问题来了,怎样才能让它以理想的顺序排列并导出呢?因为刚刚入手UG二次开发,对于函数了解的不多,所以只能以已知的几个函数来解决这个问题,采用的笨办法就是先输出原始排列的结果,然后根据情况重新编排正确的输出顺序。一番操作之后,对于图示中的尺寸都能够导出想要的结果(应该没有囊括所有的标注)。而且如果网友们有更好的解决方法,希望得到指教。代码附后。

下面的图是随意画的,尺寸也是随意标注的,只是用来测试代码。暂且不考虑标注的合理性。图中气泡是按上篇文章的代码运行得到的。气泡的位置可能不是想要的,可以通过更改代码值或鼠标移动气泡到合理的位置。

运行代码导出的TXT文件如下,因为篇幅,图像没有截取全

// 遍历尺寸,获取TAG值
tag_t object_tag = NULL_TAG;       //尺寸object_tag初始化
UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_dimension_type, &object_tag);     // 遍历尺寸,获取TAG值	
//打开文件
int fwl_file = uc4504("C:\\Users\\xiao'fan\\Desktop\\d.txt", 4, 79);

while (object_tag != NULL_TAG)
		{
		//查询尺寸信息,获取尺寸类型dim_subtype值,用来判断尺寸是否是半径等(以确定是否在尺寸前添加“R”等符号)
		char msgtype[256];
		int dim_subtype = 0;    //尺寸类型
		double dim_origin[3];    //尺寸坐标点
		UF_DRF_dim_info_p_t    dimInfo;
		UF_DRF_ask_dim_info(object_tag, &dim_subtype, dim_origin, &dimInfo);   //查询尺寸信息,获取尺寸类型dim_subtype值
   
        //获取尺寸的附加文本 ,判断附加文本的前后位置
		int num_text1 = 0;                                                
		char msg2[256];
		UF_DRF_appended_text_p_t  appended_text;    //附加文本数量变量 
		UF_DRF_ask_appended_text(object_tag, &num_text1, &appended_text);
		sprintf(msg2,"%d",num_text1);
		
		//获得尺寸文本信息,包括前后附加文本、前缀、公差等
		 char msg[256];
		 int num_text;
		 UF_DRF_draft_aid_text_info_t *text_info;
		 UF_DRF_ask_draft_aid_text_info(object_tag,&num_text,&text_info);   //获得尺寸文本信息


	if (num_text1)   //如果存在附加文本,
      {
	   UF_DRF_appended_text_location_t   loca = appended_text->location;        //获得附加文本类型
    
      if(num_text == 3)//如果有三个文本,且有附加文本,存在两种情况
	    {  
		  if(loca ==UF_DRF_APPENDED_TEXT_BEFORE) //如果附加文本在前,文本的排列顺序

	           { 
			       sprintf(msg,"%s%s%s", text_info[0].text->string, text_info[2].text->string,text_info[1].text->string);
	               uc4524(fwl_file,msg);//尺寸文本写入TXT文件
		       }
		  else if(loca ==UF_DRF_APPENDED_TEXT_AFTER)//如果附加文本在后,文本的排列顺序
	           { 
			       sprintf(msg,"%s%s%s", text_info[2].text->string, text_info[0].text->string,text_info[1].text->string);
	               uc4524(fwl_file,msg);
		       }
	      }
          else if(num_text == 4)
	         { //非倒角标注情况
		       if((dim_subtype == 9)||(dim_subtype == 10)||(dim_subtype == 11))   //直径类标注时
	 	     {  
			      sprintf(msg,"%s%s% s%s", text_info[0].text->string, text_info[3].text->string,text_info[1].text->string,text_info[2].text->string);
	               uc4524(fwl_file,msg);
		      }

			 else //倒角标注情况
		     { //if(dim_subtype == 6)||(dim_subtype == 7))
			   if  (loca ==UF_DRF_APPENDED_TEXT_BEFORE) //如果附加文本在前,文本的排列顺序
                  { sprintf(msg,"%s%s%s%s", text_info[0].text->string, text_info[1].text->string,text_info[3].text->string,text_info[2].text->string);
	               uc4524(fwl_file,msg);
		         }
	           else 
				   {//if(loca ==UF_DRF_APPENDED_TEXT_AFTER)//如果附加文本在后,文本的排列顺序
		           sprintf(msg,"%s%s%s%s", text_info[1].text->string, text_info[3].text->string,text_info[2].text->string,text_info[0].text->string);
	               uc4524(fwl_file,msg);
		            }
			   }
		  
		   }

	         else if(num_text == 5)
	           {    //if((dim_subtype == 6)||(dim_subtype == 7)) 
			if  (loca ==UF_DRF_APPENDED_TEXT_BEFORE) //如果附加文本在前,文本的排列顺序
			    {if (num_text1==2)
					{sprintf( msg,"%s%s%s%s%s", text_info[0].text->string, text_info[2].text->string,text_info[4].text->string,text_info[3].text->string,text_info[1].text->string);
	            uc4524(fwl_file,msg);//写入尺寸值
	                 }  
			      else
				     {sprintf( msg,"%s%s%s%s%s", text_info[0].text->string, text_info[1].text->string,text_info[2].text->string,text_info[4].text->string,text_info[3].text->string);
	                 uc4524(fwl_file,msg);//写入尺寸值
	                 }
     
			      }


				else 
				{//if(loca ==UF_DRF_APPENDED_TEXT_AFTER)//如果附加文本在后,文本的排列顺序
			      sprintf( msg,"%s%s%s%s%s", text_info[1].text->string, text_info[2].text->string,text_info[4].text->string,text_info[3].text->string,text_info[0].text->string);
	             uc4524(fwl_file,msg);//写入尺寸值
	            }
			}
		 else if(num_text == 6)
	       {//if((dim_subtype == 6)||(dim_subtype == 7)) 
	 	   sprintf( msg,"%s%s%s%s%s%s", text_info[0].text->string, text_info[2].text->string,text_info[3].text->string,text_info[5].text->string, text_info[4].text->string,text_info[1].text->string);
	       uc4524(fwl_file,msg);//写入尺寸值
	        }
		 else if(num_text == 2)
	       {//if((dim_subtype == 6)||(dim_subtype == 7)) 
			
	 	   sprintf( msg,"%s%s", text_info[0].text->string, text_info[1].text->string);
	       uc4524(fwl_file,msg);//写入尺寸值
	        }

         }


	else     //如果没有附加文本,文本的排列顺序
      {
	 if (num_text== 1)
	    {	
		sprintf(msg,"%s", text_info[0].text->string);//文本信息只有一个时
		uc4524(fwl_file,msg);//写入尺寸值
	      }
	 else if(num_text == 2)
	   {  
		if((dim_subtype == 9)||(dim_subtype == 10)||(dim_subtype == 11)||(dim_subtype == 4)) 
	 	     {  
			     sprintf(msg,"%s%s", text_info[1].text->string,text_info[0].text->string);//文本信息有2个时,且有前缀时
	              uc4524(fwl_file,msg);//写入为前缀及尺寸值类型
		      }
	    else{  
		         sprintf(msg,"%s%s", text_info[0].text->string,text_info[1].text->string);//将文本信息有2个时,没有前缀时
	              uc4524(fwl_file,msg);//写入为尺寸及公差类型
		     }
	    }
      else if(num_text == 3)//如果没有附加文本,且文本数有三个
	    {  
	        if((dim_subtype == 9)||(dim_subtype == 10)||(dim_subtype == 11)) 
		     { 
	           sprintf(msg,"%s%s%s", text_info[2].text->string, text_info[0].text->string,text_info[1].text->string);
	           uc4524(fwl_file,msg);
		      }
	        else
			  {   //如果为倒角标注
		       sprintf(msg,"%s%s%s", text_info[0].text->string, text_info[2].text->string,text_info[1].text->string);//将文本信息有2个时,没有前缀时
	            uc4524(fwl_file,msg);//写入为尺寸及公差类型
		      }
	     }


	   else if(num_text == 4)//如果没有附加文本,且文本数有4个,倒角类型
	        {  
	        //if((dim_subtype == 6)||(dim_subtype == 7)) 
	          sprintf(msg,"%s%s%s%s", text_info[0].text->string, text_info[1].text->string,text_info[3].text->string,  text_info[2].text->string);
	          uc4524(fwl_file,msg);
		      }
  }

    UF_DRF_free_text(num_text, &text_info);//释放
	UF_OBJ_cycle_objs_in_part(UF_PART_ask_display_part(), UF_dimension_type, &object_tag);  //再次遍历,获取TAG值
	 
  }
  uc4540(fwl_file,0);//关闭文件

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值