Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawing file is not valid #452

Open
amirj0914 opened this issue Sep 17, 2024 · 4 comments
Open

Drawing file is not valid #452

amirj0914 opened this issue Sep 17, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@amirj0914
Copy link

Autocad gives the error after wrriting DWG file with this simple code :

`

        string dwgFilePath = @"G:/output.dwg";

        CadDocument doc = new CadDocument(ACadVersion.AC1024);

        //Create a point located in (10, 10, 0)
        Point pt = new Point
        {
            Location = new CSMath.XYZ(10, 10, 0)
        };

        //Create a line from the origin to the point (5, 5, 0)
        Line line = new Line
        {
            StartPoint = CSMath.XYZ.Zero,
            EndPoint = new CSMath.XYZ(5, 5, 0)
        };

        doc.Entities.Add(pt);
        doc.Entities.Add(line);

        DwgWriter writer = new DwgWriter(dwgFilePath, doc);

`
After opening the exported file with Autocad 2017 :

err

@amirj0914 amirj0914 added the bug Something isn't working label Sep 17, 2024
@thaiguer
Copy link
Contributor

thaiguer commented Sep 18, 2024

Hello, @amirj0914

Make shure you are using the latest version: dotnet add package ACadSharp --version 1.0.0

I created a new file with the following code, and I had success opening it with BricsCad.

There are a few diferences to your code. First, the dwgFilePath, the way you wrote it, seems to be incorrect. And in the end, you forgot to use the method "Write", from the class DwgWriter.`

Here is the code:

using ACadSharp;
using ACadSharp.Entities;
using ACadSharp.IO;

//old line:
//string dwgFilePath = @"G:/output.dwg";

//new line:
string dwgFilePath = @"C:\dev\output.dwg";

CadDocument doc = new CadDocument(ACadVersion.AC1024);

//Create a point located in (10, 10, 0)
Point pt = new Point
{
    Location = new CSMath.XYZ(10, 10, 0)
};

//Create a line from the origin to the point (5, 5, 0)
Line line = new Line
{
    StartPoint = CSMath.XYZ.Zero,
    EndPoint = new CSMath.XYZ(5, 5, 0)
};

doc.Entities.Add(pt);
doc.Entities.Add(line);

DwgWriter writer = new DwgWriter(dwgFilePath, doc);

//new line:
writer.Write();

@amirj0914
Copy link
Author

amirj0914 commented Sep 18, 2024

Thank you so much for your quick reply.
The problem has been resolved. Exporting DWG files without AutoCAD was an ambition of mine.
I need two help :

  • Exportin DWG for Autocad AC1021 (version 2007)
  • Displying DWG on a Form without needing Autocad.

@DomCR
Copy link
Owner

DomCR commented Sep 18, 2024

Hi @amirj0914,

Right now ACadSharp can export in this versions.

Unfortunately the version AC1021 is not available due this version has an specific encryption, it has been resolved for the reader but reversing the code for the writer is quite a job.

For AC1027 there is an unknown error in the code that I have to find.

I'll open a branch to keep in mind to add the feature to write files in AC1021 but I cannot guarantee that this will be implemented soon.

@amirj0914
Copy link
Author

Thank yo so much,
My target is AC1021 for writing dwg file , I will appricate you if you resolve the problem for this version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants