Geometry Import/Export

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 over 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; 
MaterialKeyedCollection matList = 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(devDept.Eyeshot.Environment environment)
    {
       // access/change the loaded items
       Entity[] entList = Entities;

       // add items to the scene
       AddToScene(environment);
    }
}

// custom class usage
MyReadOBJ mro = 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 Form1()
{
    InitializeComponent();          

    viewportLayout1.WorkCompleted += new devDept.Eyeshot.Model.WorkCompletedEventHandler(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);
}

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

  

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(); 

 

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. Substitute Wpf with Win if you are using WinForms.

File format Import Export Assembly
DXF ReadAutodesk class WriteAutodesk class devDept.Eyeshot.Control.x86.Wpf.v12.dll or .x64.Wpf.v12.dll
DWG ReadAutodesk class WriteAutodesk class devDept.Eyeshot.Control.x86.Wpf.v12.dll or .x64.Wpf.v12.dll
OBJ ReadOBJ class WriteOBJ class devDept.Eyeshot.Control.Wpf.v12.dll
IGES ReadIGES class WriteIGES class devDept.Eyeshot.Control.Wpf.v12.dll
STEP ReadSTEP class WriteSTEP class devDept.Eyeshot.Control.Wpf.v12.dll
STL binary ReadSTL class WriteSTL class devDept.Eyeshot.Control.Wpf.v12.dll
STL ASCII ReadSTL class WriteSTL class devDept.Eyeshot.Control.Wpf.v12.dll
LAS ReadLAS class WriteLAS class devDept.Eyeshot.Control.Wpf.v12.dll
ASC ReadASC class   devDept.Eyeshot.Control.Wpf.v12.dll
IFC ReadIFC class   devDept.Eyeshot.Control.Wpf.v12.dll
WebGL   WriteWebGL class devDept.Eyeshot.Control.Wpf.v12.dll
3D PDF   WritePDF class  devDept.Eyeshot.Control.x86.Wpf.v12.dll or .x64.Wpf.v12.dll

 

DWG/DXF/PDF file formats 

As all professional CAD systems do, Eyeshot relies on Open Design Alliance for these file formats. 
We have specific articles on how to add the required DLLs for WinForms and WPF.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.