#include <uf_defs.h>\n#include <uf_ui.h>\n#include <uf.h>\n#include <NXOpen/PartCollection.hxx>\n#include <NXOpen/Part.hxx>\n#include <NXOpen/PartLoadStatus.hxx>\n#include <NXOpen/AttributeManager.hxx>\n#include <NXOpen/AttributeProperties.hxx>\n#include <NXOpen/AttributePropertiesCollection.hxx>\n#include <NXOpen/Layer.hxx>\n#include <NXOpen/LayerCollection.hxx>\n\nusing namespace NXOpen;\n\nvoid SetPropertyValues(NXObject* object, const char* attributeName, const char* attributeValue)\n{\n AttributeManager* attributeManager = object->GetAttributeManager();\n \n if(attributeManager != NULL)\n {\n AttributePropertiesCollection* attributePropertiesCollection = attributeManager->GetAttributes();\n \n if(attributePropertiesCollection != NULL)\n {\n AttributeProperties* attributeProperties = attributePropertiesCollection->Get(attributeName);\n \n if(attributeProperties != NULL)\n {\n attributeProperties->SetValue(attributeValue);\n }\n \n delete attributePropertiesCollection;\n }\n \n delete attributeManager;\n }\n}\n\nvoid SetLayer(NXObject* object, const char* layerName)\n{\n Layer* layer = object->Layer;\n \n if(layer != NULL)\n {\n layer->SetName(layerName);\n }\n}\n\nint main(int argc, char* argv[])\n{\n UF_initialize();\n UF_UI_open_listing_window();\n \n PartCollection* partCollection = Session::GetSession()->Parts;\n Part* part = partCollection->NewDisplay("SamplePart", PartLoadStatus::New);\n \n // 创建工作部件属性\n SetPropertyValues(part, "部件名", "SamplePart");\n SetPropertyValues(part, "设计者", "John Doe");\n SetPropertyValues(part, "日期", "2021-01-01");\n SetPropertyValues(part, "QQ", "123456789");\n \n // 设置工作部件图层\n SetLayer(part, "工作部件图层");\n \n // 创建实体属性\n // 这里假设有一个名为"Body"的实体\n Body* body = dynamic_cast<Body*>(part->Bodies->FindObject("Body"));\n if(body != NULL)\n {\n SetPropertyValues(body, "部件名", "SamplePart Body");\n SetPropertyValues(body, "设计者", "John Doe");\n SetPropertyValues(body, "日期", "2021-01-01");\n SetPropertyValues(body, "QQ", "987654321");\n \n // 设置实体图层\n SetLayer(body, "实体图层");\n }\n \n part->SaveAs("SamplePart.prt");\n part->Close(NXOpen::BasePart::CloseWholeTree, true);\n \n UF_terminate();\n return 0;\n}


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

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