zoukankan      html  css  js  c++  java
  • 【NX二次开发】属性操作总结

    内容包括:
    1.属相创建
    2.判断属性是否存在
    3.读取属性值
    4.时间属性转换成字符串
    5.统计属性的数量
    6.删除指定属性
    7.删除全部属性

    源码:

      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <uf.h>
      4 #include <uf_attr.h>
      5 #include <uf_cfi.h>
      6 #include <uf_curve.h>
      7 
      8 #define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
      9 static int report(char *file, int line, char *call, int irc)
     10 {
     11     if (irc)
     12     {
     13         char    messg[133];
     14         printf("%s, line %d:  %s
    ", file, line, call);
     15         (UF_get_fail_message(irc, messg)) ?
     16             printf("    returned a %d
    ", irc) :
     17             printf("    returned error %d:  %s
    ", irc, messg);
     18     }
     19     return(irc);
     20 }
     21 static void do_ugopen_api(void)
     22 {
     23     //声明变量
     24     tag_t       pnt;
     25     double    zero[3] = { 0,0,0 };
     26     UF_ATTR_value_t value;
     27     //创建一个点来分配属性
     28     UF_CALL(UF_CURVE_create_point(zero, &pnt));
     29     //分配一个“整型”属性给对象
     30     value.type = UF_ATTR_integer;
     31     value.value.integer = 1;
     32     UF_CALL(UF_ATTR_assign(pnt, "INTEGER_ATTRIBUTE", value));
     33     //分配一个“数字”属性给对象
     34     value.type = UF_ATTR_real;
     35     value.value.real = 1.5;
     36     UF_CALL(UF_ATTR_assign(pnt, "REAL_ATTRIBUTE", value));
     37     //分配一个“日期”属性给对象
     38     value.type = UF_ATTR_time;
     39     //初始化到当前日期和时间
     40     //uc4583 将字符串转换为NX能读取的日期格式
     41     //第一个参数:输入日期字符串,如果为空则为当前日期(样式有多种)
     42     //第二个参数:输入时间字符串,如果为空则为当前日期(样式有多种)
     43     UF_CALL(uc4583("", "", value.value.time));
     44     UF_CALL(UF_ATTR_assign(pnt, "DATE_AND_TIME_ATTRIBUTE", value));
     45     //分配一个“空”属性给对象
     46     value.type = UF_ATTR_null;
     47     UF_CALL(UF_ATTR_assign(pnt, "NULL_ATTRIBUTE", value));
     48     //分配一个“字符串”属性给对象
     49     value.type = UF_ATTR_string;
     50     value.value.string = "这是个字符串";
     51     UF_CALL(UF_ATTR_assign(pnt, "STRING_ATTRIBUTE", value));
     52     //分配一个“布尔”属性给对象
     53     value.type = UF_ATTR_bool;
     54     value.value.string = "这是个布尔";
     55     UF_CALL(UF_ATTR_assign(pnt, "BOOL_ATTRIBUTE", value));
     56 
     57     //读取属性值 判断属性是否存在
     58     UF_ATTR_value_t valueTemp;
     59     int iAttrType = UF_ATTR_any;
     60     UF_CALL(UF_ATTR_read_value(pnt, "STRING_ATTRIBUTE", iAttrType, &valueTemp));
     61     if (valueTemp.type == 0)
     62     {
     63         //此属性不存在
     64     }
     65     
     66     //valueTemp.type 5
     67     //valueTemp.value.string 字符串值abc
     68     UF_free(valueTemp.value.string);
     69     
     70     //读取属性值
     71     UF_ATTR_value_t valueTemp2;
     72     UF_CALL(UF_ATTR_read_value(pnt, "DATE_AND_TIME_ATTRIBUTE", iAttrType, &valueTemp2));
     73     char cDate[20] = "";
     74     char cTime[20] = "";
     75     //uc4582 将NX的日期格式转换为字符串
     76     //第一个参数输入{-1,-1}则为当前日期时间
     77     //第二个参数为日期样式
     78     UF_CALL(uc4582(valueTemp2.value.time, 1, cDate, cTime));
     79     //cDate 08/04/20
     80     //cTime 15:48
     81 
     82     //按类型统计属性的数量
     83     int iAttrCount = 0;
     84     UF_CALL(UF_ATTR_count_attributes(pnt, UF_ATTR_any, &iAttrCount));
     85     
     86     return;
     87     //删除指定属性
     88     UF_CALL(UF_ATTR_delete(pnt, iAttrType, "STRING_ATTRIBUTE"));
     89 
     90     //删除所有属性
     91     UF_CALL(UF_ATTR_delete_all(pnt, iAttrType));
     92     return;
     93 }
     94 
     95 void ufusr(char *param, int *retcode, int param_len)
     96 {
     97     if (!UF_CALL(UF_initialize()))
     98     {
     99         do_ugopen_api();
    100         UF_CALL(UF_terminate());
    101     }
    102 }
    103 int ufusr_ask_unload(void)
    104 {
    105     return (UF_UNLOAD_IMMEDIATELY);
    106 }

    效果:

  • 相关阅读:
    数据结构-包含min函数的栈
    数据结构-顺时针打印矩阵
    数据结构-二叉树的镜像
    数据结构-树的子结构
    数据结构-合并两个排序的链表
    数据结构-反转链表
    数据结构-链表中倒数第K个节点
    数据结构-调整数组顺序使奇数位于偶数前面
    数据结构-在O(1)时间删除链表节点
    数据结构-打印1到最大的n位数
  • 原文地址:https://www.cnblogs.com/KMould/p/13433836.html
Copyright © 2011-2022 走看看