How do we draw a leader with arrow? #375
-
Hello! I'm trying to draw a leader with an arrow but only get the following: I have the following code: dxf.AddEntity(
new Leader(new[] { new Vector2(x, y), new Vector2(x + 10, y + 10) })
{
Color = color,
ShowArrowhead = true
}); |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
Try with the latest source code. Remember that the arrowhead symbol size is controlled by the associated dimension style. |
Beta Was this translation helpful? Give feedback.
-
In our case/scale, the arrows are very small by default. We did the following to increase the arrow size
|
Beta Was this translation helpful? Give feedback.
-
Your best place to find this kind of information is the official AutoCAD documentation, it is freely available online. Like all dimension entities, the leader properties, such as the arrow size, is controlled by its style. One note about why it does not work using the Default dimension style. When you add entities to a document, its properties that refer to table objects like layers, line types,...; or in your case the dimension style associated with the leader will not overwrite the existing one, this is intended. It is like when you copy an entity from a document to another. Imagine that you have a Line which layer, let's called "MyLayer" that has a Red color, and you want to copy it to another document that has a layer with the same name, but this time the "MyLayer" has the color Blue. The destination layer will always take precedence and the color of the layer associated with original Line will become Blue and not Red. Same thing happens with your arrow size and the Default dimension style. The DimensionStyle.Default, the style called "Standard", is always present in the document, therefore, it will not be overwritten when you add your leader entity to the document. You can create a new style for your leader, directly modify the dimension style of the document, modify the arrow size after it has been added to the document, or you can use the dimension style overrides to individually change its properties, your choice. Check this code. // OPTION 1 - Modify the default "Standard" dimension style of the document
DxfDocument doc1 = new DxfDocument();
DimensionStyle style1 = doc1.DimensionStyles[DimensionStyle.DefaultName];
style1.ArrowSize = 1.0;
Leader leader1 = new Leader(new List<Vector2>{new Vector2(0,0), new Vector2(10, 10)}, style1);
// You could also use:
// Leader leader1 = new Leader(new List<Vector2> {new Vector2(0, 0), new Vector2(10, 10)});
// This will achieve the same result, but until the leader is not added to the document
// the default "Standard" style of the document and the default "Standard" of the leader,
// although they have the same name, they reference two different objects.
// Keep in mind that two table objects are the same when their names (case insensitive) are the same,
// independently if they reference two different objects, also remember that the style in the document takes precedence.
// Therefore, modifying the style of the leader before its is added to the document will have no effect.
// This is what is happening to you when using the DimensionStyle.Default.
// leader1.Style.ArrowSize = 1.0;
doc1.Entities.Add(leader1);
// Now, after adding the leader is added to the document, it is safe to use:
// leader1.Style.ArrowSize = 1.0;
// Without having to access the "Standard" style of the document directly,
// Both the "Standard" style of the document and the "Standard" style of the leader point to the same object.
doc1.Save("test1.dxf");
// OPTION 2 - Create you own dimension style
DxfDocument doc2 = new DxfDocument();
DimensionStyle style2 = new DimensionStyle("MyStyle");
style2.ArrowSize = 1.0;
// Optionally you can manually add the new dimension style to the document.
// This will be done automatically when adding the leader to the document, if the leader style is not found in the document.
// It is what is happening when you use the predefined Iso25 style. It is a new style not present in the document.
doc2.DimensionStyles.Add(style2);
Leader leader2 = new Leader(new List<Vector2>{new Vector2(0,0), new Vector2(10, 10)}, style2);
doc2.Entities.Add(leader2);
doc2.Save("test2.dxf");
// OPTION 3 - Adding a dimension style override.
DxfDocument doc3 = new DxfDocument();
Leader leader3 = new Leader(new List<Vector2>{new Vector2(0,0), new Vector2(10, 10)});
// Dimension style overrides affects only individual entities and overrides any value defined in its associated style
leader3.StyleOverrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ArrowSize, 1.0));
doc3.Entities.Add(leader3);
doc3.Save("test3.dxf"); |
Beta Was this translation helpful? Give feedback.
-
I like option 2 better for keeping amd setting standards and with the added code to set the dimstyle properties, but it's love all around. It's all excellent. |
Beta Was this translation helpful? Give feedback.
-
As @DavidWishengrad pointed out all dimension style properties will be shared among all dimensions, so, unless, for some special reason you need to change a specific style property for a dimension, it is always better to make the changes through the dimension style. |
Beta Was this translation helpful? Give feedback.
In our case/scale, the arrows are very small by default. We did the following to increase the arrow size