【UG\NX二次开发】NXOpen 表达式相关操作

//判断表达式类型
if (!strcmp(expression1->Type().getLocaleText(), "String"))
{
	uc1601("是字符串类型",1);
}

//获取表达式完整类型
UF_UI_write_listing_window((char*)express->Equation().getLocaleText());

//创建字符串类型的表达式
string equation = "a=\"ABCD\"";
Expression* new_Str_Exp = workPart->Expressions()->CreateExpression("String", equation);

//根据名称获取表达式Expression
Expression* get_exps(NXString& titles)
{
	if (!workPart) return 0;
	Expression* expression1 = NULL;
	try
	{
		expression1 = workPart->Expressions()->FindObject(titles);
	}
	catch (exception& ex)
	{
		//xt_msgtxt(titles.GetLocaleText());
		return 0;
	}
	return expression1;
}

void changeExp(NXString& title, NXString& exp)
{
	Expression* exp1 = get_exps(title);
	if (!exp1) return;

	char zii[256]; 
	sprintf_s(zii, 256, "%s", exp.getLocaleText());
	if (isUseUTF8Text(exp.GetUTF8Text()))
		sprintf_s(zii, 256, "%s", exp.GetUTF8Text());

	sprintf_s(ex_type, 256, "%s", exp1->Type().GetLocaleText());
	if (isUseUTF8Text(exp1->Type().GetUTF8Text()))
		sprintf_s(ex_type, 256, "%s", exp1->Type().GetUTF8Text());

	char* strs = strstr(zii, "!");
	if (strs) strs[0] = '\0';


	Unit* nullUnit(NULL);
	if (strstr(ex_type, "Number"))
	{
		bool isSame = 1;
		if (isNumber(zii))
		{
			if (exp1->Value() != atof(zii)) isSame = 0;
		}
		else
		{
			if (stricmp(exp1->RightHandSide().getLocaleText(), zii) != 0) isSame = 0;
		}

		if (!isSame)
		{
			string tmp_title = title.getLocaleText();
			string tmp_exp = tmp_title + "=" + zii;
			UF_MODL_edit_exp((char*)tmp_exp.c_str());
		}

	}
	else if (strstr(ex_type, "String"))
	{
		if (zii[0] != '"')
		{
			sprintf_s(ex_type, 256, "%s", zii);
			sprintf_s(zii, "\"%s\"", ex_type);
		}
		string old_expRhs = exp1->StringValue().getLocaleText();
		if (old_expRhs[0] != '"')
		{
			old_expRhs = "\"" + old_expRhs + "\"";
		}
		if (stricmp(old_expRhs.c_str(), zii) != 0)
		{
			//exp1->SetRightHandSide(zii);--不要采取这种方式,采取下面的方法
			workPart->Expressions()->Edit(exp1, zii);
		}

	}
}
//迭代器遍历所有表达式
{
	tag_t part_occ_tag = UF_PART_ask_part_tag(new_NULLPartPath);
	tag_t pre_work_tag = NULL_TAG;
	UF_ASSEM_set_work_part_quietly(part_occ_tag, &pre_work_tag);
	Session* theSession1 = Session::GetSession();
	ExpressionCollection* exp_collection = theSession1->Parts()->Work()->Expressions();
	vector< NXOpen::Expression*> tmpExpsVec;
	for (NXOpen::ExpressionCollection::iterator it = exp_collection->begin(); it != exp_collection->end(); it++)
	{
		NXOpen::Expression* exp_ = (*it);
		tmpExpsVec.push_back(exp_);
	}
	tag_t  pre_work_tag_ = NULL_TAG;
	UF_ASSEM_set_work_part_quietly(pre_work_tag, &pre_work_tag_);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

社恐猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值