Answered

native .net PDF writer for eyeshot

 Native .net DWG/DXF  writer is coming to eyeshot 2021, here I request native .net PDF writer also.

 

Or else I have to use code ( such a PITA) like this to do platform agnostic PDF write/read, which is hard to write, hard to debug and even harder to maintain:

 

private void GetDWGExportCPUAgnostic(string file)
{
var dir = AssemblyUtil.GetCurrAssemblyDir();
var eyeshotControlName = $"devDept.Eyeshot.Control.{AssemblyUtil.GetCPUTarget()}.Wpf.v2020.dll";
var dllPath = System.IO.Path.Combine(dir, eyeshotControlName);
if (!System.IO.File.Exists(dllPath))
throw new System.IO.FileNotFoundException($"{dllPath} cannot be found");
var currAssembly = Assembly.LoadFrom(dllPath);
var writeString = nameof(eyeshotx86::devDept.Eyeshot.Translators.WriteAutodesk);

var translatorNamespace = "devDept.Eyeshot.Translators";
var paramsString = nameof(eyeshotx86::devDept.Eyeshot.Translators.WriteAutodeskParams);
var paramsType = currAssembly.GetType($"{translatorNamespace}.{paramsString}");
var paramsConstructor = paramsType.GetConstructor(new Type[] { model1.GetType(), typeof(Drawings),typeof(bool), typeof(bool), typeof(int) });
var paramsObj = paramsConstructor.Invoke(new object[] { model1, null, false,false, 1 });


var writeType = currAssembly.GetType($"{translatorNamespace}.{writeString}");
var writeConstructor = writeType.GetConstructor(new Type[] { paramsObj.GetType(), typeof(string) });
var writeObj = (WorkUnit)writeConstructor.Invoke(new object[] { paramsObj, file });
writeObj.DoWork();
}
private void GetPDFExportCPUAgnostic(string file)
{

var dir = AssemblyUtil.GetCurrAssemblyDir();
var eyeshotControlName = $"devDept.Eyeshot.Control.{AssemblyUtil.GetCPUTarget()}.Wpf.v2020.dll";
var dllPath = System.IO.Path.Combine(dir, eyeshotControlName);
if (!System.IO.File.Exists(dllPath))
throw new System.IO.FileNotFoundException($"{dllPath} cannot be found");
var currAssembly = Assembly.LoadFrom(dllPath);


var translatorNamespace = "devDept.Eyeshot.Translators";
var pdfParamsString = nameof(eyeshotx86::devDept.Eyeshot.Translators.WritePdfParams);
var pdfParamsType = currAssembly.GetType($"{translatorNamespace}.{pdfParamsString}");
var pdfParamsConstructor = pdfParamsType.GetConstructor(new Type[] { model1.GetType() });
var pdfParamsObj = pdfParamsConstructor.Invoke(new object[] { model1 });
var writePDFString = nameof(eyeshotx86::devDept.Eyeshot.Translators.WritePDF);

var renderValueString = nameof(eyeshotx86::devDept.Eyeshot.Translators.WritePDF.renderMode);
var renderValueType = currAssembly.GetType($"{translatorNamespace}.{writePDFString}+{renderValueString}");
var SolidWireframeVal = renderValueType.GetField(nameof(eyeshotx86::devDept.Eyeshot.Translators.WritePDF.renderMode.SolidWireframe)).GetValue(null);
var renderMode = nameof(eyeshotx86::devDept.Eyeshot.Translators.WritePdfParams.RenderMode);
pdfParamsObj.SetPropValue(renderMode, SolidWireframeVal); //to show also the edge 

var WritePDFType = currAssembly.GetType($"{translatorNamespace}.{writePDFString}");
var writePdfConstructor = WritePDFType.GetConstructor(new Type[] { pdfParamsObj.GetType(), typeof(string) });
var writePDFObj = (WorkUnit)writePdfConstructor.Invoke(new object[] { pdfParamsObj, file });
writePDFObj.DoWork();
}

 

If it's done for DWG, why not also do it for PDF?

What's more, there seems to be sample source code floating around. 

0

Comments

2 comments
Date Votes
  • We're not even sure if we can implement a .NET module for DWG/DXF files.

    0
  • I'm using the variant of the above code ( targeted to eyeshot 2020.1) for WriteAutodeskParams, here's how I instantiate this object in 2020.1

    var translatorNamespace = "devDept.Eyeshot.Translators";
    var paramsString = nameof(eyeshotx86::devDept.Eyeshot.Translators.WriteAutodeskParams);
    var paramsType = currAssembly.GetType($"{translatorNamespace}.{paramsString}");var paramsConstructor = paramsType.GetConstructor(new Type[] { model.GetType(), typeof(Drawings), typeof(bool), typeof(bool), typeof(int) });

     

    This code works fine in 2020.1, and still compiles fine in 2020.2, but it won't work in runtime because the last argument type is changed from int to double. In order words, in 2020.2, the correct code is:

    var translatorNamespace = "devDept.Eyeshot.Translators";
    var paramsString = nameof(eyeshotx86::devDept.Eyeshot.Translators.WriteAutodeskParams);
    var paramsType = currAssembly.GetType($"{translatorNamespace}.{paramsString}");var paramsConstructor = paramsType.GetConstructor(new Type[] { model.GetType(), typeof(Drawings), typeof(bool), typeof(bool), typeof(double)});

    It didn't give me a compilation error, and just fail when running. Such silent failure is frustrating and even quite impossible to check against. So I really hope that you can do a native version for your PDF/DWG read/write library. If that's not possible, then at least make your API such that I don't get such a failure. 

    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post