Import
Supposing you want to import an OBJ file (all the import methods follow the same scheme), you need the ReadOBJ class. Before adding them to the scene, this class gives you full control over all the imported items (entities, blocks, layers, materials, etc.). During file import, you can also control whether to read the file synchronously or asynchronously. Reading from a stream is also supported through overloaded constructors.
Import workflow overview
Geometry import in Eyeshot is a two-step process:
File parsing, performed by
ReadXXXclasses (for exampleReadOBJ,ReadDXF,ReadSTEP) or byReadFileAsync.
This step loads and parses the file content and exposes entities, blocks, layers, and materials.Geometry integration, performed using the
OpenTo,InsertTo, orAppendTomethods (or their asynchronous counterparts).
This step inserts the parsed geometry into aDesignand triggers entity regeneration.
ReadOBJ synchronous example
Here's a ReadOBJ class example (for synchronous read). The OpenTo() method adds all the necessary items to the scene in the correct order.
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.OpenTo(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
OpenTo((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.OpenTo(design1);
}Note
You can customize the progress bar text shown during asynchronous reading 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() for import as explained above.
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. These classes are defined 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 | ||
| ReadPDF class | 2021 | |||
| glTF | ReadGLTF class | WriteGLTF class | 2023 | |
| NAS | ReadNastran class | WriteNastran class | 2024 | |
| SVG | ReadSVG class | 2025 | ||
| E57 | ReadE57 class | 2025 |
For details about geometry integration methods and regeneration behavior, refer to the Geometry Import article.
DWG/DXF/DWF/3D PDF file formats
Like many other professional CAD systems, Eyeshot depends on the Open Design Alliance for these file formats. We have a specific article on how to add the necessary NuGet packages.
Comments
Is JT Reader to be upgraded in order to import also new version of he file format?
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?
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.
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?
Hi Gert,
Sorry, you're right, the short answer is no.
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.
can it be used for displaying the entity from the file on the viewport???
Will it be possible in near future to open JT files newer than version 9.5?
Please sign in to leave a comment.