Reads an external CAD file and translates its contents into Eyeshot objects at runtime.
Overview
The Eyeshot Conversion Example shows how to import CAD model and convert its data (ModelData_Model object) into Eyeshot entities using Eyeshot_EntityFactory class.
In this example we create a special Eyeshot WorkUnit for asynchronious read and convert data from external CAD file. Example performs following actions:
- Prepare and show the main form with Eyeshot Viewer and Design.
- Get the CAD model file name via File Open Dialog on
Import
button click.
- Activate special ReadFileCadEx work unit for asynchronious reading and conversion CAD file data.
- Integrate the converted data into Eyeshot document after ReadFileCadEx completion.
Conversion Processing
The main work perform in method Process() of class ReadFileCadEx. This method consist of following steps:
- Read a CAD file and transfer its data to a ModelData_Model object.
ModelData_Model aModel = new ModelData_Model();
ModelData_ModelReader aReader = new ModelData_ModelReader();
if (!aReader.Read(new Base_UTF16String(theFileName), aModel))
{
Console.WriteLine("Failed to open and convert the file");
return null;
}
- Create Eyeshot integration factory Eyeshot_EntityFactory and call Create() method for creation Eyeshot entities.
myFactory = new Eyeshot_EntityFactory();
return myFactory.Create(aModel, theMap);
- Return root entity object and store it in work unit.
BlockReference aRoot = Process(aFileName, myMask);
if (aRoot != null)
{
Entities = new Entity[] { aRoot };
}
- After work unit is completed main frame invokes AddTo() method to transfer data into Eyeshot document (in design1_WorkCompleted event handler).
ReadFileAsync aReadAsync = theEventArgs.WorkUnit as ReadFileAsync;
aReadAsync.AddTo(design1);
- The transfer data into Eyeshot perfomed using Eyeshot_EntityFactory.AddTo() and adding the root Entity to Eyeshot document Entities property.
public override void AddTo(DesignDocument theDoc, RegenOptions theRegenOptions = null)
{
if (myFactory != null && theDoc != null && Entities.Length > 0)
{
myFactory.AddTo(theDoc);
theDoc.Entities.AddRange(Entities);
}
}
- Finally, the last step of the main form process is loading new textures of the converted materials.
foreach (Material aMaterial in design1.Materials)
{
aMaterial.LoadTexture(design1.RenderContext);
}
Files