🌶️ 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 AddTo() 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.AddTo(design1);

A custom ReadOBJ class example follows (asynchronous read).

public class MyReadOBJ : ReadOBJ
{
    public MyReadOBJ(string fileName) : base(fileName)
    {
    }

    public override void WorkCompleted(object sender)
    {
        // access/change the loaded items
        Entity[] entList = Entities;

        // add items to the scene
        AddTo((Design) sender);
    }
}

// custom class usage
MyReadOBJ mro = new MyReadOBJ(fileName);
viewportLayout1.StartWork(mro);

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

public Form1()
{
    InitializeComponent();

    design1.WorkCompleted += Design1OnWorkCompleted;

    ReadOBJ ro = new ReadOBJ("fileName.obj");

    design1.StartWork(ro);
}

private void Design1OnWorkCompleted(object sender, WorkCompletedEventArgs workCompletedEventArgs)
{
    ReadOBJ ro = (ReadOBJ)workCompletedEventArgs.WorkUnit;

    // access/change the loaded items
    Entity[] entList = ro.Entities;

    // add items to the scene
    ro.AddTo(design1);
}

Note

You can customize the progress bar text shown during asynchronous read by setting the properties ReadingText, ParsingText, ParsingEntitiesText, etc.

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 Design.StartWork() as explained above for import.

WriteParamsWithMaterials wpwm = new WriteParamsWithMaterials(design1);

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.

File format Import Export Available from version Retired in version
DXF ReadAutodesk / ReadDXF classes WriteAutodesk class    
DWG ReadAutodesk / ReadDWG classes WriteAutodesk class    
OBJ ReadOBJ class WriteOBJ class    
IGES ReadIGES class WriteIGES class    
STEP ReadSTEP class WriteSTEP class    
STL binary ReadSTL class WriteSTL class    
STL ASCII ReadSTL class WriteSTL class    
ASC ReadASC class WriteASC     
LAS ReadLAS class WriteLAS class 9  
WebGL   WriteWebGL class 10  
IFC ReadIFC class   11  
3DS Read3DS class   11 2023
3D PDF   WritePDF class  12  
PRC   WritePRC class  12  
DWF ReadDWF class    12  
CNC ReadGCode class   2020  
JT (up to version 9.5) ReadJT class   2020  
PDF ReadPDF class   2021  

 

DWG/DXF/DWF/3D PDF file formats 

Similarly to many other professional CAD systems, Eyeshot relies on Open Design Alliance for these file formats. We have a specific article on how to add the required DLLs.

Was this article helpful?
0 out of 0 found this helpful

Comments

6 comments
Date Votes
  • Is JT Reader to be upgraded in order to import also new version of he file format?

    0
  • I'm trying to implement a simple converter that reads PDF and writes DXF. Therefore i'm trying to get this working without using the winforms/wpf design control. However it seems that these classes depend on the devDept.Eyeshot.Control.Windows package. I suspect this is due to the fact that it uses the background worker stuff. Is there a way to use a lower level implementation that does not depend on the UI controls, so I could use it in an API for instance?

    1
  • Hi Gert,

    This article explains how to read/write DWG/DXF files without UI.

    Problem is that devDept.Eyeshot.Translators.ReadPDF is defined in devDept.Eyeshot.Control assembly, that's why you need to reference it.

    0
  • Hi Marcello. I guess that asking the question is answering it... So, in essence we can conclude that what I want is impossible to do without the Winforms/WPF package and therefore it's not possible to create a console app or aspnetcore app that can handle this scenario?

    0
  • Hi Gert,

    Sorry, you're right, the short answer is no.

    0
  • Hi Marcello, 

    Thanks ;-) 

    The obvious follow-up question would then be, "can we expect this class to become available without this dependency?".

    Logically, for me there is no obvious reason to require winforms-related (UI) classes to read and interpret PDF content...

     As a side note: Maybe it would be a good idea in general to open-source these parts of the component/framework for us devs to pitch in and be able to contribute by attempting these "refactorings" ourselves.

    0

Please sign in to leave a comment.

Articles in this section