大家好,今天继续分享我们的通用方法系列。
下面是今天要分享的通用方法:
(1)这个通用方法为替换文本:
/// <summary>
/// 替换文本
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Replace()
{
string sTestFileName = @"C:\\测试.txt";
//int iInsertLine = int.Parse(textBox1.Text);//要写入的行数
string sInsertText = textBox2.Text;//要搜索的内容
string sInsertText1 = textBox3.Text;//要写入的内容
string sText = "";
string line;
System.IO.StreamReader sr = new System.IO.StreamReader(sTestFileName);
while ((line = sr.ReadLine())!=null)
{
if (line.Contains(sInsertText))
{
sText += sInsertText1 + "\r\n";//将值插入
}
string sTmp = sr.ReadLine(); //记录当前行
sText += sTmp + "\r\n";
}
sr.Close();
System.IO.StreamWriter sw = new System.IO.StreamWriter(sTestFileName, false);
sw.Write(sText);
sw.Flush();
sw.Close();
MessageBox.Show("插入完成");
}
(2)这个通用方法为ug删除面方法:
/// <summary>
/// ug删除面方法
/// </summary>
/// <param name="tagfaces"></param>
public static void DeleteFace(Face[] tagfaces)//删除面方法
{
NXOpen.Session theSession = NXOpen.Session.GetSession();
NXOpen.Part workpart = theSession.Parts.Work;
NXOpen.Part displayPart = theSession.Parts.Display;
NXOpen.Features.Feature nullNXOpen_Features_Feature = null;
NXOpen.Features.DeleteFaceBuilder deleteFaceBuilder1 = null;
deleteFaceBuilder1 = workpart.Features.CreateDeleteFaceBuilder(nullNXOpen_Features_Feature);
NXOpen.Point3d origin1 = new Point3d(0.0, 0.0, 0.0);
NXOpen.Vector3d normal1 = new Vector3d(0.0, 0.0, 1.0);
NXOpen.Plane plane1;
plane1 = workpart.Planes.CreatePlane(origin1, normal1, NXOpen.SmartObject.UpdateOption.WithinModeling);
deleteFaceBuilder1.CapPlane = plane1;
deleteFaceBuilder1.FaceEdgeBlendPreference = NXOpen.Features.DeleteFaceBuilder.FaceEdgeBlendPreferenceOptions.Cliff;
NXOpen.Plane plann1 = null;
deleteFaceBuilder1.CapPlane = plann1;
//NXOpen.SelectionIntentRule selectionIntentRule1;
FaceDumbRule faceDumbRule1;
faceDumbRule1 = workpart.ScRuleFactory.CreateRuleFaceDumb(tagfaces);
SelectionIntentRule[] rule1 = new SelectionIntentRule[1];
rule1[0] = faceDumbRule1;
deleteFaceBuilder1.FaceCollector.ReplaceRules(rule1, false);
deleteFaceBuilder1.Type = NXOpen.Features.DeleteFaceBuilder.SelectTypes.Face;
NXObject nXObject1;
nXObject1 = deleteFaceBuilder1.Commit();
deleteFaceBuilder1.Destroy();
plane1.DestroyPlane();
}
今天要介绍的通用方法就是这么多,我们下篇文章再见。