C# NX二次开发:获取模型中所有表达式并且更新某个表达式的值

165 阅读1分钟

大家好,今天要讲的是关于NX中表达式的相关UFUN函数。

UF_MODL_ask_exps_of_part (view source)

​编辑

tag_tpart_tagInputTag of the part to be queried
int *number_of_expsOutputNumber of expressions returned
tag_t * *expsOutput to UF_freeAll the expressions in the part. Use UF_free to deallocate memory.

下面使用一个例子讲解一下:

      Dictionary<string, string> keys = new Dictionary<string, string>();
int expnumber = 0;
Tag[] tags;
theUfSession.Modl.AskExpsOfPart(workPart.Tag,out expnumber,out tags);
for (int i = 0; i < expnumber; i++)
{
string expname = "";
theUfSession.Modl.AskExpTagString(tags[i], out expname);
if(!keys.ContainsKey(expname))
{
keys.Add(expname, expname);
}
}

上面就是将所有的表达式获取出来以后存储在一个字典中。

下面介绍如何更改表达式的值:

UF_MODL_edit_exp (view source)

​编辑

char *expr_strInputReplacement expression.

下面还是用一个例子来讲解如何使用:

   if (keys[i].Contains("例子1"))
{
theUfSession.Modl.EditExp("例子1=" + string016.Value);
}

当然在这里更新完表达式的值以后,一定要使用theUfSession.Modl.Update();

UF_MODL_update (view source)
Defined in: uf_modl.h
Overview

Updates a part. You call this routine after you use UF_MODL_import_exp,
UF_MODL_edit_exp, and UF_MODL_move_feature. Imported and edited expressions
do not take effect until you update the part. After you move a feature, please
update the database.
Environment     Internal and External
Required License(s)    solid_modelingint UF_MODL_update(void)

今天要介绍的就是这么多,我们下篇文章再见。