多次调用后提示 执行引擎异常
各位大侠,帮忙看下这段代码有什么问题,开始几次可以实现功能,多次调用之后,UG就会很卡,紧接着UG就会停止工作,调试显示错误为:执行引擎异常。:NXOpen.Features.AdmResizeFace nullAdmResizeFace = null;
NXOpen.Features.AdmResizeFaceBuilder theAdmResizeFaceBuilder;
theAdmResizeFaceBuilder = workPart.Features.CreateAdmResizeFaceBuilder(nullAdmResizeFace);
Face[] faces = new Face;
faces = face;
FaceDumbRule faceDumbRule1;
faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(faces);
SelectionIntentRule[] rules1 = new SelectionIntentRule;
rules1 = faceDumbRule1;
theAdmResizeFaceBuilder.FaceToResize.FaceCollector.ReplaceRules(rules1, false);
theAdmResizeFaceBuilder.Diameter.RightHandSide = NewDiamter.ToString();
theAdmResizeFaceBuilder.Commit();
Expression expression1 = theAdmResizeFaceBuilder.Diameter;
faceDumbRule1.Dispose();
theAdmResizeFaceBuilder.Destroy();
由于以前的函数求值超时,函数求值被禁用。必须继续执行才能重新启用函数求值
你就这一段代码吗?
其他的代码会不会有问题
这是你录制的代码吧,你的face选择都是同一个? 这是子函数中的代码,是在录制“调整面大小”操作代码的基础上修改得到的。完整代码如下:
using System;
using System.IO;
using NXOpen;
using NXOpen.UF;
namespace InstanceFeature
{
public class InstanceFeatureEdit
{
private static UFSession theUfSession;
private static Session theSession;
public static void Main(string[] args)
{
theSession = Session.GetSession();
theUfSession = UFSession.GetUFSession();
theUfSession.Ui.OpenListingWindow();
Part theWorkPart = theSession.Parts.Work;
NXOpen.Features.FeatureCollection theFeatureCollection = theWorkPart.Features;
NXOpen.Features.Feature[] theFeatures = theFeatureCollection.GetFeatures();
for (int i = 0; i < theFeatures.Length; i++)
{
theUfSession.Ui.WriteListingWindow("特征类型名:"+theFeatures.FeatureType+"\n");
if (theFeatures.FeatureType == "BREP")
{
NXOpen.Features.Brep theBrep=(NXOpen.Features.Brep)theFeatures;
Face[] faces_of_brep = theBrep.GetFaces();
theUfSession.Ui.WriteListingWindow("面的个数:" + faces_of_brep.Length + "\n");
for (int j = 0; j < faces_of_brep.Length; j++)
{
string facetype = faces_of_brep.SolidFaceType.ToString();
theUfSession.Ui.WriteListingWindow("面的类型:" + facetype +"\n");
if (facetype == "Cylindrical")
{
int type;
double[] center=new double;
double[] dir=new double;
double[] box=new double;
double radius;
double rad_data;
int norm_dir;
theUfSession.Modl.AskFaceData(faces_of_brep.Tag, out type, center, dir, box, out radius, out rad_data, out norm_dir);
theUfSession.Ui.WriteListingWindow("center: (" + center + "," + center + "," + center + ")\n" + "radius = " + radius + "\n" + "direction: (" + dir + "," + dir + "," + dir + ")\n");
//DeleteFace(theWorkPart,faces_of_brep);
double NewDiamter = radius * 2-2;
ResizeFace(theWorkPart, faces_of_brep, NewDiamter);
//theWorkPart.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.False);
}
}
}
if (theFeatures.FeatureType == "CYLINDER")
{
NXOpen.Features.CylinderBuilder theCyliderBuilder = theWorkPart.Features.CreateCylinderBuilder(theFeatures);
Vector3d dir = new Vector3d(1, 1, 1);
theCyliderBuilder.Direction = dir;
string str = theCyliderBuilder.GetFeature().FeatureType;
//theUfSession.Ui.WriteListingWindow(str + "\n");
theCyliderBuilder.Commit();
Point3d point1 = theFeatures.Location;
theUfSession.Ui.WriteListingWindow("(" + point1.X + "," + point1.Y + "," + point1.Z + ")\n");
theCyliderBuilder.Destroy();
}
}
}
public static void ResizeFace(Part workPart, Face face,double NewDiamter)
{
try
{
NXOpen.Features.AdmResizeFace nullAdmResizeFace = null;
NXOpen.Features.AdmResizeFaceBuilder theAdmResizeFaceBuilder;
theAdmResizeFaceBuilder = workPart.Features.CreateAdmResizeFaceBuilder(nullAdmResizeFace);
Face[] faces = new Face;
faces = face;
FaceDumbRule faceDumbRule1;
faceDumbRule1 = workPart.ScRuleFactory.CreateRuleFaceDumb(faces);
SelectionIntentRule[] rules1 = new SelectionIntentRule;
rules1 = faceDumbRule1;
theAdmResizeFaceBuilder.FaceToResize.FaceCollector.ReplaceRules(rules1, false);
theAdmResizeFaceBuilder.Diameter.RightHandSide = NewDiamter.ToString();
theAdmResizeFaceBuilder.Commit();
Expression expression1 = theAdmResizeFaceBuilder.Diameter;
faceDumbRule1.Dispose();
theAdmResizeFaceBuilder.Destroy();
}
catch (Exception ex)
{
theUfSession.Ui.WriteListingWindow(ex.Message+"\n");
}
}
public static int GetUnloadOption(string dummy)
{
theUfSession.Ui.WriteListingWindow("GetUnload函数\n");
return UFConstants.UF_UNLOAD_IMMEDIATELY;
}
}
}
如果我模型中有一个孔,我调用该dll文件两到三次以后就会出现异常。或者模型中有好几个孔,可能前几个能处理,到了一定数量以后UG就死掉了。 坚守 发表于 2013-12-18 19:25
如果我模型中有一个孔,我调用该dll文件两到三次以后就会出现异常。或者模型中有好几个孔,可能前几个能处 ...
估计那个地方要释放内存
这个需要调试的
Java 我不怎么用 , 你自己把代码 一段段的调试看看 坚守 发表于 2013-12-18 19:25
如果我模型中有一个孔,我调用该dll文件两到三次以后就会出现异常。或者模型中有好几个孔,可能前几个能处 ...
另外你干嘛要用同步建模的功能
直接使用 偏置面 不是更好 mildcat 发表于 2013-12-18 19:28
另外你干嘛要用同步建模的功能
直接使用 偏置面 不是更好
偏置面我没接触过,我还要用同步建模来实现孔的移动、删除等操作。 坚守 发表于 2013-12-18 20:07
偏置面我没接触过,我还要用同步建模来实现孔的移动、删除等操作。
具体这个 我还真没怎么研究过
不过我建议你换 成偏置面 ,然后 试试 看到底是那里有问题
偏置面功能很简单,在 插入 --修剪与偏置 -- 偏置面 坚守 发表于 2013-12-18 20:07
偏置面我没接触过,我还要用同步建模来实现孔的移动、删除等操作。
你主要要实现什么功能, 需求告诉我我写下看看 mildcat 发表于 2013-12-18 20:12
你主要要实现什么功能, 需求告诉我我写下看看
我想实现对模型中的圆柱面的半径进行放大缩小,模型是被移除参数的。谢谢!
页:
[1]
2