Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

FontFamilyName getting overwritten #471

Open
ChristianSchroth opened this issue Aug 3, 2023 · 6 comments
Open

FontFamilyName getting overwritten #471

ChristianSchroth opened this issue Aug 3, 2023 · 6 comments
Labels

Comments

@ChristianSchroth
Copy link

When I want to add a Text to my DxfDocument, the FontFamilyName gets overwritten.
Code to reproduce the bug:

DxfDocument doc = new DxfDocument();
TextStyle textStyle = TextStyle.Default;
textStyle.FontFamilyName = "Arial";
Text text = new Text() { Value = "Some Text", Position = new Vector3(0), Style = textStyle };
doc.Entities.Add(text);

doc.Save(@"C:\Temp\Test.dxf");

I can open the exported DXF-File with my CAD program an the text is at right position, but the Font is now "simplex"
The only workaround that I found was to add the following line after adding the entity:

text.Style.FontFamilyName = "Arial";
@haplokuon
Copy link
Owner

Read this. It is the same kind of problem, your Default text style is being overwritten by the one already present in your DxfDocument.

@DavidWishengrad
Copy link

DavidWishengrad commented Aug 3, 2023

It's just like adding a block to a drawing that already has that block definition.

Running into these errors with code can be a little tricky. If your code breaks after your drawing has a text style or block incorrectly defined then you will always get that wrong definition inserting a new style or block with the same name, until you remove all references to it and then purge it out. You don't get the warning prompt
'block already exists, do you wish to redefine, when doing it directly from code.

@ChristianSchroth
Copy link
Author

Thank you for the quick reply.
What I don´t understand is, that its a new Document add I add a Entity. So there is nothing inside this document.
So I thought it would apply the style of the new Element.
The example with the layers is understandable. If you add the same layer again it doesn´t get overwritten.
But in my case I don´t overwrite anything, I just add a new EntityObject.
Maybe I don´t understand DXF right, but I thought that the individual options are higher ranked than the layer options.

Did I get it right, that its the normal behavior of the DXF-Definition?

@DavidWishengrad
Copy link

DavidWishengrad commented Aug 4, 2023

There is a defualt dimstyle already present in a new doc, as is clearly stated in the link that will solve your problem. Read the link and try using the code which was supplied to you in it.

@haplokuon
Copy link
Owner

haplokuon commented Aug 4, 2023

A Text entity holds a reference to a TextStyle, so when the text is added to the document so does the style, same thing happens with its layer. All classes derived form TableObject behave in the same way, the destination document always takes precedence. If for whatever reason you want to change this behavior it is your responsibility to check if a table already exists with the same name and act in consequence.

@ChristianSchroth
Copy link
Author

Thanks for your replies. I will keep that in mind.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants