呵呵,这么长时间没贴干货的原因是因为代码找不到了!当时对这个东西并不是特别的上心,所以被扔到角落里面去了。- using System;
- using System.IO;
- namespace ConsoleApplication2
- {
- /// <summary>
- /// Class1 的摘要说明。
- /// </summary>
- class Class1
- {
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- ///
- static string[][] zb;
- [STAThread]
- static void Main(string[] args)
- {
- //
- // TODO: 在此处添加代码以启动应用程序
- //
- zb=new string[141][];
- try
- {
- using (StreamReader sr = new StreamReader("D:\\my_project\\ConsoleApplication2\\TextFile1.txt"))
- {
- //swDoc.InsertSketch();
- int i=0;
- string line;
- while ((line = sr.ReadLine()) != null)
- {
- if (line != "")
- {
- Console.WriteLine(line);
- zb[i++]=line.Split();
- }
- }
- sr.Close();
- Draw();
- }
- }
- catch(Exception e)
- {
- Console.WriteLine("The file could not be read:");
- Console.WriteLine(e.Source);
- Console.WriteLine(e.TargetSite);
- Console.WriteLine(e.Message);
- }
- }
- static void Draw()
- {
- try
- {
- SldWorks.SldWorks swApp = new SldWorks.SldWorksClass();
- SldWorks.ModelDoc2 swDoc = swApp.IActiveDoc2;
- //swDoc.ActivateFeatureMgrView
- swDoc.ClearSelection2(true);
- swDoc.Insert3DSketch();
- swDoc.ClearSelection2(true);
- swDoc.SketchSpline(-1,0,0,0);
- for(int j=0;j<140;j++)
- {
- swDoc.SketchSpline(139-j,
- 0,
- System.Convert.ToDouble(zb[j][1])/1000,
- System.Convert.ToDouble(zb[j][0])/1000
- );
- }
- swDoc.ClearSelection2(true);
- swDoc.InsertSketch2( true);
- swDoc.ClearSelection2(true);
- swDoc.Insert3DSketch();
- swDoc.SketchSpline(-1,0,0,0);
- for(int j=0;j<140;j++)
- {
- swDoc.SketchSpline(139-j,
- System.Convert.ToDouble(zb[j][5])/1000,
- System.Convert.ToDouble(zb[j][4])/1000,
- System.Convert.ToDouble(zb[j][3])/1000
- );
- }
- swDoc.ClearSelection2(true);
- swDoc.InsertSketch2( true);
- swDoc.ClearSelection2(true);
- swDoc.Insert3DSketch();
- swDoc.SketchSpline(-1,0,0,0);
- for(int j=0;j<140;j++)
- {
- swDoc.SketchSpline(139-j,
- System.Convert.ToDouble(zb[j][29])/1000,
- System.Convert.ToDouble(zb[j][28])/1000,
- System.Convert.ToDouble(zb[j][27])/1000
- );
- }
- swDoc.ClearSelection2(true);
- swDoc.InsertSketch2(true);
- for(int j=0;j<140;j=j+10)
- {
- swDoc.ClearSelection2(true);
- swDoc.Insert3DSketch();
- swDoc.SketchSpline(-1,0,0,0);
- int id=8;
- for(int n=0;n<10;n++)
- {
- swDoc.SketchSpline(9-n,
- System.Convert.ToDouble(zb[j][n*3+2])/1000,
- System.Convert.ToDouble(zb[j][n*3+1])/1000,
- System.Convert.ToDouble(zb[j][n*3])/1000
- );
- }
- swDoc.ClearSelection2(true);
- swDoc.InsertSketch2(true);
- }
- }
- catch(Exception e)
- {
- Console.WriteLine("The file could not be read:");
- Console.WriteLine(e.Source);
- Console.WriteLine(e.TargetSite);
- Console.WriteLine(e.Message);
- }
- }
- }
- }
复制代码 |