快捷导航 上传作品

[snap] grip 调 uf 选择一个面或边缘返回实体

[复制链接]
梅雷工具箱发表于 2015-6-25 10:26:15 | 显示全部楼层 |阅读模式


选择一个面或边缘返回实体

$$  
$$ api 调用grip     【grip选择对象面,返回参数api】
$$ api 再次调用grip 【mm6(1)==1 时 grip把对象实体染蓝色】
$$

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$             grip代码 - 文件名:m_face_body.grs             $$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

gripsw / declrv       $$必须声明变量
entity / obj(1),ln
string / strga(132)
number / resp,mm6(4)
number / p(6),dx,dy,dz
number / xmin,ymin,zmin,xmax,ymax,zmax



strga='梅雷33038219920103'

ufargs / strga,mm6,obj $$api 向 grip传递参数
if/strga<>'。',jump/apiend:

ifthen/mm6(1)==1
&color(obj(1))=211 $$染蓝色
p=solbox/obj(1)
xmin=minf(p(1),p(4))
xmax=maxf(p(1),p(4))
ymin=minf(p(2),p(5))
ymax=maxf(p(2),p(5))
zmin=minf(p(3),p(6))
zmax=maxf(p(3),p(6))
dx=xmax-xmin
dy=ymax-ymin
dz=zmax-zmin

$$对象最大外形 dx,dy,dz
$$对象最小坐标 xmin,ymin,zmin
$$对象最大坐标 xmax,ymax,zmax

&decpl=2       $$小数位数
print/dx
print/dy
print/dz


halt
endif


ifthen/&actprt==1
messg/'梅雷提示!请打开一个部件。'
halt
endif


l10:
    mask/71,72
     ident/'梅雷提示!请选择目标面或边缘。',obj(1),resp
    jump/l10:,end:,,,resp


$$ 根据边缘类型,判断对象是面还是边缘
mm6(2)=1 $$选择的是面
mm6(3)=&edgtyp(obj(1),iferr,label $$ 取边缘类型
mm6(2)=0 $$选择的是边缘
label:

mm6(1)=1
grargs / strga,mm6,obj $$grip 把参数返回给 api



end:
halt



apiend:
messg/'梅雷提示!无效的调用方式。'
halt



///////////////////////////////////////////////////////////////
//                        api代码                            //
///////////////////////////////////////////////////////////////


前提【设置c++6.0与ug二次开发环境】


打开c++6.0
文件 --> 新建 --> Unigraphics AppWizard V1 --> 输入:位置 工程名 --> 完成 --> 确定
双击 【工程名 classes】 -->双击 Globals --> 双击 ufsta( char *param, int *returnCode, int rlen )

输入以下源代码:
编译生成UG可以调用的 dll
如:工程名 m_face_body 会生成  m_face_body.dll


//////////////////////////////////////////////////////////////////////////////
//
//  m_face_body.cpp
//
//  Description:
//      Contains Unigraphics entry points for the application.
//
//////////////////////////////////////////////////////////////////////////////

//  Include files
#include <uf.h>
#include <uf_exit.h>
#include <uf_ui.h>
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
#        include <strstream>
#   include <iostream>
        using std:strstream;
        using std::endl;       
        using std::ends;
        using std::cerr;
#else
#        include <strstream.h>
#   include <iostream.h>
#endif
#include "m_face_body.h"

#include <uf_modl.h>
#include <string>


//----------------------------------------------------------------------------
//  Activation Methods
//----------------------------------------------------------------------------

//  Unigraphics Startup
//      This entry point activates the application at Unigraphics startup
extern "C" DllExport void ufsta( char *param, int *returnCode, int rlen )
{
    /* Initialize the API environment */
    int errorCode = UF_initialize();

    if ( 0 == errorCode )
    {
        /* TODO: Add your application code here */





          //调用grip  
                  //传递的数据 只能是 【字符串、数组 与 实体数组】
          int grip_arg_count  = 3;   //参数个数
                  char *grip_exe      =  "C:\\GRS-GRX\\zdj\\grip\\m_zdj.grx";
          char pick_xx[132]   = "。"; //字符串
          double pick_m6[4];    //数组
          pick_m6[0]=0;
                  tag_t   obj[2];       //实体数组


                  UF_args_t grip_arg_list[3];
                  grip_arg_list[0].type    = UF_TYPE_CHAR;        //字符串类型
          grip_arg_list[0].length  = 0;   
                  grip_arg_list[0].address = pick_xx;
                  grip_arg_list[1].type   = UF_TYPE_DOUBLE_ARRAY; //数组类型
          grip_arg_list[1].length = 4;                    
                  grip_arg_list[1].address = pick_m6;
                  grip_arg_list[2].type   = UF_TYPE_TAG_T_ARRAY;  //实体类型
          grip_arg_list[2].length = 1;                  
              grip_arg_list[2].address = obj;

          // 调用GRIP
                  int status_a;
          status_a = UF_call_grip (grip_exe, grip_arg_count,grip_arg_list);   
      
          if (pick_m6[0]==1)
                {
            //头文件 #include <uf_modl.h>
                        //面获取实体的函数   UF_MODL_ask_face_body(对象的面,返回的实体) //返回的实体对象前 加 &
                        //如:tag_t obj[2];  UF_MODL_ask_face_body(obj[0],&obj[1]);      //对象的面为obj[0] ,返回的实体对为obj[1]
                        //边缘获取实体函数   UF_MODL_ask_edge_body(对象边缘,返回的实体) //返回的实体对象前 加 &
                        //如:tag_t obj[2];  UF_MODL_ask_edge_body(obj[0],&obj[1]);      //对象边缘为obj[0] ,返回的实体对为obj[1]
            if (pick_m6[1]==1) //判断 obj[0]对象是实体面还是实体边缘
                        {
                           UF_MODL_ask_face_body(obj[0],&obj[1]); // 根据对象的面来得到该对象 //点、线、面、体... 都属于 实体
                        }
                     else
                        {
                       UF_MODL_ask_edge_body(obj[0],&obj[1]); // 根据对象缘获来得到该对象
                        }

    // 直接返回obj[1]是不正确的
    uf_list_p_t body_list;                         // 变量body_list为 对象列表
    UF_MODL_create_list(&body_list);               // 必须写上不然下一条代码不成立   
    UF_MODL_put_list_item(body_list, obj[1]);      // object_tag对象加入到body_list对象列表尾部

          grip_arg_list[2].type   = UF_TYPE_TAG_T_ARRAY;  //实体类型
          grip_arg_list[2].length = 1;                  
              grip_arg_list[2].address =  body_list;

            // 调用GRIP
            int status_b;
            status_b = UF_call_grip (grip_exe, grip_arg_count,grip_arg_list);   
                }
       
      
           HALT:;
             
   
       





        /* Terminate the API environment */
        errorCode = UF_terminate();
    }

    /* Print out any error messages */
    PrintErrorMessage( errorCode );
}

//----------------------------------------------------------------------------
//  Utilities
//----------------------------------------------------------------------------

// Unload Handler
//     This function specifies when to unload your application from Unigraphics.
//     If your application registers a callback (from a MenuScript item or a
//     User Defined Object for example), this function MUST return
//     "UF_UNLOAD_UG_TERMINATE".
extern "C" int ufusr_ask_unload( void )
{
        /* 设置UF程序运行以后立刻从内存中卸除,即当重新修改、编译成新的DLL文件时,UG无须关闭重启动,就可调用此新的*.DLL文件 */
        return (UF_UNLOAD_IMMEDIATELY);
}


/* PrintErrorMessage
**
**     Prints error messages to standard error and the Unigraphics status
**     line. */
static void PrintErrorMessage( int errorCode )
{
    if ( 0 != errorCode )
    {
        /* Retrieve the associated error message */
        char message[133];
        UF_get_fail_message( errorCode, message );

        /* Print out the message */
        UF_UI_set_status( message );

        // Construct a buffer to hold the text.
        ostrstream error_message;

        // Initialize the buffer with the required text.
        error_message << endl
                      << "Error:" << endl
                      << message
                      << endl << endl << ends;

            // Write the message to standard error
        cerr << error_message.str();
    }
}

_____________________________________________________________________________ _

中磊UG二次开发教程 梅雷著 qq1821117007
学UG就上UG网 http://www.9sug.com/
就上UG网淘宝直营店
回复

使用道具 评分 举报

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

本版积分规则