private void btnImport_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = "STL File|*.STL", Multiselect = false, AddExtension = true, CheckFileExists = true, CheckPathExists = true }; openFileDialog.InitialDirectory = "c:\\"; // openFileDialog.Filter = "Object files (*.STL,*.OBJ,*.FBX,*.3DS)|*.STL,*.OBJ,*.FBX,*.3DS|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { //Get the path of specified file var filePath = openFileDialog.FileName; //Read the contents of the file into a stream var fileStream = openFileDialog.OpenFile(); var fileContent = ""; using (StreamReader reader = new StreamReader(fileStream)) { //devDept.Eyeshot.Translators.ReadFile filePath = new devDept.Eyeshot.Translators.ReadFile(filePath); model1.Clear(); var readAutodesk = new ReadAutodesk(filePath); readAutodesk.DoWork(); readAutodesk.AddToScene(model1); var ReadObj = new ReadSTL(filePath); ReadObj.DoWork(); Entity[] toAdd = ReadObj.Entities; //fileContent = reader.ReadToEnd(); //ModelVisual3D device3D = new ModelVisual3D(); //Viewport3DVisual viewport = new Viewport3DVisual(); //viewport readFile; model1.Entities.AddRange(toAdd, System.Drawing.Color.Chocolate); //model1.SetView(viewType.Top); //model1.ZoomFit(); model1.Invalidate(); } //view.Export(filePath); } }
public void OpenFile(Model model, Label labelPath) { OpenFileDialog openFileDialog1 = new OpenFileDialog() { Filter = "DWG File|*.dwg", Multiselect = false, AddExtension = true, CheckFileExists = true, CheckPathExists = true }; if (openFileDialog1.ShowDialog().Value) { beforeButton.IsEnabled = afterButton.IsEnabled = false; labelPath.Content = "Loading . . ."; //Force WPF refresh System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { })); var rfa = new ReadAutodesk(openFileDialog1.FileName); rfa.DoWork(); model.Clear(); rfa.AddToScene(model, NOT_MODIFIED_COLOR); Entity[] toAdd = model.Entities.Explode(); model.Entities.AddRange(toAdd, NOT_MODIFIED_COLOR); beforeButton.IsEnabled = afterButton.IsEnabled = true; labelPath.Content = openFileDialog1.FileName; model.SetView(viewType.Top); model.ZoomFit(); model.Invalidate(); } }