Eyeshot 11 Documentation
WinForms Control / Tutorials / Geometry Import/Export
In This Topic
    Geometry Import/Export
    In This Topic

    This article explains how to import and export geometry from Eyeshot.

     

    Import

    Supposing you want to import an OBJ file (all the import methods follow the same scheme) you need the ReadOBJ class. This class gives you full control on all the imported items (entities, blocks, layers, materials, etc.) before adding them to the scene. During file import, you can also control whether to read the file synchronously or asynchronously. Read from stream is also supported through overloaded constructors.

     

    A ReadOBJ class example follows (for synchronous read). The AddToScene() method takes care of adding all the necessary items in the correct order to the scene.

    ReadOBJ ro = new ReadOBJ("fileName.obj");
    ro.DoWork();
    
    // access/change the loaded items
    Entity[] entList = ro.Entities;
    Dictionary<string, Material> matList = ro.Materials; 
    
    // add items to the scene
    ro.AddToScene(viewportLayout1);
    Dim ro As New ReadOBJ("fileName.obj")
    ro.DoWork()
    
    ' access/change the loaded items
    Dim entList As Entity() = ro.Entities
    Dim matList As Dictionary(Of String, Material) = ro.Materials
    
    ' add items to the scene
    ro.AddToScene(viewportLayout1)

    A custom ReadOBJ class example follows (asynchronous read).

    public class MyReadOBJ : ReadOBJ
    {
       public MyReadObj(string fileName) : base(fileName)
       {
       }
    
       protected override void WorkCompleted(ViewportLayout viewportLayout)
       {
          // access/change the loaded items
          Entity[] entList = Entities;
    
          // add items to the scene
          AddToScene(viewportLayout1);
       }
    }
    
    // custom class usage
    MyReadOBJ mro = new MyReadOBJ(fileName);
    viewportLayout1.StartWork(mro);
    Class MyReadOBJ
       Inherits ReadOBJ
    
       Public Sub New(fileName As String)
          MyBase.New(fileName)
       End Sub
    
       Protected Overrides Sub WorkCompleted(viewportLayout As ViewportLayout)
          ' access/change the loaded items
          Dim entList As Entity() = Entities
    
          ' add items to the scene
          AddToScene(viewportLayout1)
       End Sub
    End Class
    
    ' custom class usage
    Dim mro As MyReadOBJ = New MyReadOBJ(fileName)
    viewportLayout1.StartWork(mro)

    To avoid deriving a new class from ReadOBJ you can subscribe to the ViewportLayout.WorkCompletedEventHandler and access/change loaded items in the event handler.

    public class Form1 : Form
    {
       public Form1()
       {
          InitializeComponent();
    
          viewportLayout1.WorkCompleted += ViewportLayout1OnWorkCompleted;
    
          ReadOBJ ro = new ReadOBJ("fileName.obj");
    
          viewportLayout1.StartWork(ro);
       }
    
       private void ViewportLayout1OnWorkCompleted(object sender, WorkCompletedEventArgs workCompletedEventArgs)
       {
          ReadOBJ ro = (ReadOBJ) workCompletedEventArgs.WorkUnit;
    
          // access/change the loaded items
          Entity[] entList = ro.Entities;
    
          // add items to the scene
          ro.AddToScene(viewportLayout1);
       }
    }
    Public Class Form1
       Inherits Form
    
       public Sub New()
          InitializeComponent()
    
          AddHandler viewportLayout1.WorkCompleted, AddressOf ViewportLayout1OnWorkCompleted
    
          Dim ro As New ReadOBJ("fileName.obj")
    
          viewportLayout1.StartWork(ro)
       End Sub
    
       Private Sub ViewportLayout1OnWorkCompleted(sender As Object, workCompletedEventArgs As WorkCompletedEventArgs)
          Dim ro As ReadOBJ = DirectCast(workCompletedEventArgs.WorkUnit, ReadOBJ)
    
          ' access/change the loaded items
          Dim entList As Entity() = ro.Entities
    
          ' add items to the scene
          ro.AddToScene(viewportLayout1)
       End Sub
    
    End Class

    During asynchronous read, you can change the progress bar text using the class ReadingText, LoadingText, LoadingEntitiesText, etc. properties.

     

    DWG/DXF file formats

    Dealing with DWG/DXF files in Eyeshot requires several additional steps compared to other standard CAD file formats. As all professional CAD systems do, Eyeshot relies on Open Design Alliance for this file format translation. You'll find all the necessary DLLs inside the Bin folders of the Eyeshot installation.

    Basically, the required steps to read/write DWG/DXF files are:

    1. Prepare a working Eyeshot based Visual Studio project (or start from one of the WinForms source code samples)
    2. Change the Platform Target of your Visual Studio project to x86
    3. Add the Bin\x86\devDept.Eyeshot.Control.x86.v11.dll to your Visual Studio project references
    4. Use ReadAutodesk class in your code to load the file
    On end-user machines, the Microsoft Visual C++ 2012 Redistributable Package is required.

     

    Export

    Exporting geometry is straightforward. Assuming you want to write an OBJ file, you need the WriteOBJ class. Depending on the file format the desired unit system may need to be specified. To export the geometry asynchronously use ViewportLayout.StartWork() as explained above for import.

    WriteParamsWithMaterials wpwm = new WriteParamsWithMaterials(viewportLayout1);
    
    WriteOBJ wo = new WriteOBJ(wpwm, "fileName.obj");
    wo.DoWork();
    WriteParamsWithMaterials wpwm = new WriteParamsWithMaterials(viewportLayout1)
    
    Dim wo As WriteOBJ = new WriteOBJ(wpwm, "fileName.obj")
    wo.DoWork()

     

    Supported file formats

    The following table summarizes the class names/assemblies involved in data translation. You'll find these classes inside the devDept.Eyeshot.Translators namespace.

    File format Import Export Assembly
    DXF ReadAutodesk class WriteAutodesk class devDept.Eyeshot.Control.x86.Win.v11.dll or .x64.Win.v11.dll
    DWG ReadAutodesk class WriteAutodesk class devDept.Eyeshot.Control.x86.Win.v11.dll or .x64.Win.v11.dll
    OBJ ReadOBJ class WriteOBJ class devDept.Eyeshot.Control.Win.v11.dll
    IGES ReadIGES class WriteIGES class devDept.Eyeshot.Control.Win.v11.dll
    STEP ReadSTEP class WriteSTEP class devDept.Eyeshot.Control.Win.v11.dll
    STL binary ReadSTL class WriteSTL class devDept.Eyeshot.Control.Win.v11.dll
    STL ASCII ReadSTL class WriteSTL class devDept.Eyeshot.Control.Win.v11.dll
    LAS ReadLAS class devDept.Eyeshot.Control.Win.v11.dll
    ASC ReadASC class devDept.Eyeshot.Control.Win.v11.dll

    Table 1: Required classes for geometry import/export. 

    See Also

    Licensing and Distribution