#include <iostream> #include <uf_modl.h> #include <uf_obj.h> #include <uf_part.h> #include <uf_disp.h>

// 定义属性结构体 struct Attribute { std::string title; std::string value; }

// 设置属性 void setAttribute(const char* tag, const Attribute& attribute) { UF_PART_set_attr_value(tag, attribute.value.c_str()); }

// 设置图层 void setLayer(const char* tag, const char* layer) { UF_DISP_set_layer(tag, layer); }

int main() { // 获取当前工作部件和实体的标签 tag_t partTag, entityTag; UF_PART_ask_display_part(&partTag); UF_OBJ_ask_null(&entityTag);

&#x2F;&#x2F; 创建属性
Attribute partName = {&#x22;部件名&#x22;, &#x22;Part1&#x22;};
Attribute designer = {&#x22;设计者&#x22;, &#x22;John&#x22;};
Attribute date = {&#x22;日期&#x22;, &#x22;2021-01-01&#x22;};
Attribute qq = {&#x22;QQ&#x22;, &#x22;123456&#x22;};

&#x2F;&#x2F; 设置属性
setAttribute(UF_PART_part_name, partName);
setAttribute(UF_OBJ_name, partName);  &#x2F;&#x2F; 给实体设置部件名属性
setAttribute(UF_PART_designer, designer);
setAttribute(UF_PART_date, date);
setAttribute(UF_PART_qq, qq);

&#x2F;&#x2F; 设置图层
setLayer(partTag, &#x22;PartLayer&#x22;);
setLayer(entityTag, &#x22;EntityLayer&#x22;);

&#x2F;&#x2F; 输出属性值
char value[UF_ATTR_MAX_STRING_LEN+1];
UF_PART_ask_attr_value(partTag, UF_PART_part_name, value);
std::cout &#x3C;&#x3C; &#x22;部件名: &#x22; &#x3C;&#x3C; value &#x3C;&#x3C; std::endl;

UF_PART_ask_attr_value(partTag, UF_PART_designer, value);
std::cout &#x3C;&#x3C; &#x22;设计者: &#x22; &#x3C;&#x3C; value &#x3C;&#x3C; std::endl;

UF_PART_ask_attr_value(partTag, UF_PART_date, value);
std::cout &#x3C;&#x3C; &#x22;日期: &#x22; &#x3C;&#x3C; value &#x3C;&#x3C; std::endl;

UF_PART_ask_attr_value(partTag, UF_PART_qq, value);
std::cout &#x3C;&#x3C; &#x22;QQ: &#x22; &#x3C;&#x3C; value &#x3C;&#x3C; std::endl;

return 0;

}


原文地址: https://www.cveoy.top/t/topic/p4NY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录