1
trying to convert dxf to any image
Question asked by steve lee - 12/21/2017 at 2:41 PM
Answered
trying to convert a dxf to any type of image.
Is this correct? Its generating something but nothing even close.    Thanks
protected void asdfx()
{
    string filePath = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("OUTLINED15QM7601860.DXF"));
 
    string filePath2 = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("OUTLINED15QM7601860.JPG"));
 
 
    MemoryStream ms = new MemoryStream();
    using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        file.CopyTo(ms);
 
 
    DocumentConverter dc = new DocumentConverter(ms, DocumentFormat.Dxf);
    dc.ConvertTo(filePath2, DocumentFormat.Jpg);
 
}

5 Replies

Reply to Thread
0
Cem Alacayir Replied
Employee Post
I don't know why you are using MemoryStream here but after copying to the MemoryStream you should rewind it to the beginning so that it can be consumed by the DocumentConverter (or any stream consumer):
 
MemoryStream ms = new MemoryStream();
    using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        file.CopyTo(ms);
 

ms.Position = 0;
 
    DocumentConverter dc = new DocumentConverter(ms, DocumentFormat.Dxf);
    dc.ConvertTo(filePath2, DocumentFormat.Jpg);
 
0
steve lee Replied
Thanks, I am trying to do a proof of concept and pasted something I found on google. For whatever reason it seems like the dxf file our engineer generated thorugh autocad is not rendering an image correctly so i downloaded a random dxf off the internet and your tool rendering an image correctly.
 
I don't really know enough about autocad or dxf to figure out the differences between the dxf's
0
Cem Alacayir Replied
Employee Post Marked As Answer
DocumentUltimate can convert these AutoCad formats:
 
AutoCAD Drawing (R13 to 2017) .dwg
AutoCAD Drawing Interchange (R12 to 2017) .dxf
 
So it can convert formats from1994 till 2017.
 
In your above code, you are making a mistake when using the MemoryStream, so to correct it you should use
 
ms.Position = 0;
as I described above.
 
However you don't need to use MemoryStream at all, here is the simple and correct code for converting files already on disk (it's very short actually):
 
var inputFile = System.Web.HttpContext.Current.Server.MapPath("OUTLINED15QM7601860.DXF");

//Option 1: The converted file be generated in the same folder
//as the input file and the extension will be automatically determined.
//So in this case the output file name will be OUTLINED15QM7601860.JPG 
//(automatically determined from the input file name OUTLINED15QM7601860.DXF)
DocumentConverter.Convert(inputFile, DocumentFormat.Jpg);

//Option 2: You can specify the path and file name of the output file explictly
var outputFile = System.Web.HttpContext.Current.Server.MapPath("Image.jpg");
DocumentConverter.Convert(inputFile, DocumentFormat.Dxf, outputFile, DocumentFormat.Jpg);
 
it seems like the dxf file our engineer generated thorugh autocad is not rendering an image correctly
So what's the AutoCad version he is using? Do you get any errors or an image with some missing rendering?
0
steve lee Replied
One version of the dxf file has this in the header (this dxf  file renders an image correctly)
SECTION
2
HEADER
9
$ACADVER
1
AC1006
0
ENDSEC
 
The other has this (this dxf doesnt render correctly) Generates a 1kb file with a few pixels
SECTION
  2
HEADER
  0
ENDSEC
 
 
Both look fine in  viewer.autodesk.com/designviews

I know pretty much nothing about AutoDesk and due to graphic card issues I can't install and run it on my development box. 
We are trying to look for an alternative to RealDWG since they don't have an eval version and I can't get AutoDesk installed to try the ObjectARX SDK to verify RealDWG would work.
 
 
I believe all our engineers are limited to version 2016.
 
If it will help, I can send / upload the file that isn't working.
0
steve lee Replied
Didn't realize I could link the views. If you remove the x from my links, I think you can see them. I'm not allowed to post hyperlinks
 
DocumentUltimate  does not render, just generates a 1kb jpg
https:/x/viewer.autodesk.com/id/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YTM2MHZpZXdlci90MTUxMzg5MjIyNzkwM18wOTM2MDQ4MTUxMDk2ODA4Ml8xNTEzODkyMjI3OTAzLmR4Zg?designtype=dxf
 

DocumentUltimate  renders and image looks just like this
https:/x/viewer.autodesk.com/id/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6YTM2MHZpZXdlci90MTUxMzk2MTc0NDEwNV8wNDI4MDY0NjU1MTMyMzM1MjdfMTUxMzk2MTc0NDEwNi5keGY?designtype=dxf
 

Reply to Thread