AutoCAD Civil 3D Help: Defining a Label Style
定义一个标签样式
一个标签样式包含了一个标签的不同要素的各种集合,称为“组件(components)”。这些组件的集合通过LabelStyle::GetComponents()方法来访问,需要用到组件的类型(LabelStyleComponentType):
- Text
- Line
- Block - symbols
- Tick - for both major and minor tick marks
- ReferenceText
- DirectionArrow
- TextForEach
并非所有上述类型都是有效的,要看标签样式的类型。例如:给一个点标签增加一个小标记并无实际的视觉效果。标签样式也取决于图形对象是不是属于当前文档。例如,如果一个样式所引用的块并不是当前图形的一部分,那么指定的块或者小标记组件就不会显示。
To add a feature to a label style, add a new component to the corresponding collection using the LabelStyle::AddComponent() method. Then set the properties of that component to the appropriate values. Always make sure to set the Visible property to true.
用LabelStyle::AddComponent() 方法来给一个标签样式增加一个要素,或者给相应的集合增加一个组件。然后给该组件的属性设定一个适当的值。永远不要忘记把Visible属性设为true。
try
{
// Add a line to the collection of lines in our label style
ObjectId lineComponentId = oLabelStyle.AddComponent("New Line Component", LabelStyleComponentType.Line);
// Get the new component:
ObjectIdCollection lineCompCol = oLabelStyle.GetComponents(LabelStyleComponentType.Line);
var newLineComponent = ts.GetObject(lineComponentId, OpenMode.ForWrite) as LabelStyleLineComponent;
// Now we can modify the component
newLineComponent.General.Visible.Value = true;
newLineComponent.Line.Color.Value = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 40); // orange-yellow
newLineComponent.Line.Angle.Value = 2.094; // radians, = 120 deg
// negative lengths are allowed - they mean the line is drawn
// in the opposite direction to the angle specified:
newLineComponent.Line.Length.Value = -0.015;
newLineComponent.Line.StartPointXOffset.Value = 0.005;
newLineComponent.Line.StartPointYOffset.Value = -0.005;
}
// Thrown if component isn't valid, or name is duplicated
catch (System.ArgumentException e)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Error: {0}\n", e.Message);
}
创建伊始,标签样式对象由环境设置进行初始化设定。所以一个新的标签样式对象已经包含了一些要素。如果你创建了一个新的标签样式对象,请确保对既存的要素进行检查,或者,确保你的样式不包括你不想要的元素。
// Check to see whether any text components already exist.
// If not, add one.
if (oLabelStyle.GetComponentsCount(LabelStyleComponentType.Text) == 0)
{
// Add a text component
oLabelStyle.AddComponent("New Text ", LabelStyleComponentType.Text);
}
// Now modify the first one:
ObjectIdCollection textCompCol = oLabelStyle.GetComponents(LabelStyleComponentType.Text);
var newTextComponent = ts.GetObject(textCompCol[0], OpenMode.ForWrite) as LabelStyleTextComponent;
环境设置也会指定单位。如果你正在为不同的图形设计应用程序,请不要忘记对环境设置进行确认,否则标签在不同的文档中可能会产生意外的效果。
父主题: