//用户代码
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/BasePart.hxx>
#include <NXOpen/Expression.hxx>
#include <NXOpen/ExpressionCollection.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Preferences_SessionModeling.hxx>
#include <NXOpen/Preferences_SessionPreferences.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Unit.hxx>
#include <NXOpen/UnitCollection.hxx>
#include <NXOpen/Update.hxx>
#include <NXOpen/ExpressionGroup.hxx>
#include <NXOpen/ExpressionGroupCollection.hxx>
void MyClass::do_it()
{
// TODO: add your code here
//用户代码
//遍历工作部件表达式
ExpressionCollection* Expressions = workPart->Expressions();
ExpressionCollection::iterator Exp_All;
char Char_Exp_Val_double[256];
for (Exp_All = Expressions->begin(); Exp_All != Expressions->end(); ++Exp_All)
{
Expression* Exp1 = dynamic_cast<Expression*> (* Exp_All);
NXString Exp_Name1 = Exp1->Name();//获取表达式名字
NXString Exp_Type = Exp1->Type();//获取表达式类型
theSession->ListingWindow()->Open();
//theSession->ListingWindow()->WriteLine(Exp_Name1 + "表达式类型:" + Exp_Type );
//std::vector<string> Exp_Sring1;
if (strcmp(Exp_Type.GetLocaleText(), "String") == 0)
{
theSession->ListingWindow()->WriteLine("字符串表达式:" + Exp_Name1 + " = " );
}
else if (strcmp(Exp_Type.GetLocaleText(), "Number") == 0)
{
double Exp_Val_double = Exp1->Value();
sprintf(Char_Exp_Val_double, "%.2f", Exp_Val_double);
theSession->ListingWindow()->WriteLine("数量表达式:" + Exp_Name1 + " = " + Char_Exp_Val_double);
}
}
}
标签:遍历,Val,double,NXOpen,Exp,include,Type,表达式 From: https://www.cnblogs.com/hqsalanhuang/p/17071566.html