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

DXF spline import tied to frame settings. Cannot be used headless. #187

Closed
ChrisClems opened this issue Dec 4, 2024 · 3 comments · Fixed by #188
Closed

DXF spline import tied to frame settings. Cannot be used headless. #187

ChrisClems opened this issue Dec 4, 2024 · 3 comments · Fixed by #188

Comments

@ChrisClems
Copy link
Contributor

ChrisClems commented Dec 4, 2024

On line 533-534, ImportDxf is attempting to get the precision value to approximate a spline:

double maxError = project.Frame.GetDoubleSetting("Approximate.Precision", 0.01);

It is using Project.Frame.GetDoubleSetting(). In a headless environment, Project.Frame will be null so it is throwing an exception and failing to import the DXF when a spline that triggers this line of code is encountered. It works fine when loading the DXF through CADAbility.App.

I removed the rest of the original comment on troubleshooting this issue as it appears to be a bug in Rider. Program works as expected in Visual Studio when hard-coding the maxError value.

@dsn27
Copy link
Collaborator

dsn27 commented Dec 5, 2024

GetDoubleSetting is implemented like this.

public double GetDoubleSetting(string Name, double Default)
{
    object s = GetSetting(Name);
    if (s != null)
    {
        try
        {
            return Settings.GetDoubleValue(s);
        }
        catch (InvalidCastException)
        {
            return Default;
        }
    }
    return Default;
}

You could create a new function in ImportDxf to help you replace project.Frame.GetDoubleSetting(...).
If this works fine, a PR would be appreciated to fix this use case.

Thanks in advance,
Michel

@ChrisClems
Copy link
Contributor Author

GetDoubleSetting is implemented like this.

public double GetDoubleSetting(string Name, double Default)
{
    object s = GetSetting(Name);
    if (s != null)
    {
        try
        {
            return Settings.GetDoubleValue(s);
        }
        catch (InvalidCastException)
        {
            return Default;
        }
    }
    return Default;
}

You could create a new function in ImportDxf to help you replace project.Frame.GetDoubleSetting(...). If this works fine, a PR would be appreciated to fix this use case.

Thanks in advance, Michel

I'll play around with in over the next couple of weeks and find a comfortable pattern. I'm doing a lot of work with DXF import and export for a project and I'm hitting a lot of little limitations that I plan to submit PRs for as I have time to test them.

@ChrisClems
Copy link
Contributor Author

Turned out to only take a couple of hours. I used the GlobalSettings class to re-use existing functionality without having to change the signature for the DXF export or make it difficult to set on the user side.

In the process I found a bug in SetValue() that wasn't handling DoubleProperties. I added a handler so all DoubleProperties in the GlobalSettings can now be set via code. There might be more missing.

When digging into the GlobalSettings structure, I found more references to Project.Frame for properties. Might be worth opening a new issue just to find them and convert them to library-accessible formats.

@dsn27 dsn27 closed this as completed in #188 Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants