此方法可获取字段名称及其属性值的字典。
- 如果仅提供 ArcGIS for AutoCAD ObjectId,则将返回存储在实体上的所有属性字段及其值。
- 如果提供 flName 值,则仅包括属于该要素图层的属性。
- 如果提供 flName 和 fieldName 值,则仅返回字段的存储值或其默认值,并且只有在该字段属于要素图层时才会返回。
声明
public Dictionary<string, IConvertible> Esri.ArcGISForAutoCAD.Attributes.Get(Document doc, ObjectId objId, string flName = null, string fieldName = null)
参数
| 类型 | 名称 | 描述 | 必填 |
|---|---|---|---|
文档 | doc | 要进行操作的 AutoCAD 文档。 | 必填 |
ObjectId | objId | 要素的 AutoCAD ObjectId。 | 必填 |
string | flName | 要素图层名称。 假设实体是要素图层的成员,且将仅包含指定要素图层的字段值。 如果未设置任何值,则会返回默认值。 | 如果提供了 fieldName 则为必填 |
string | fieldName | 单个字段名称。 返回值仅限于这一个字段。 | 可选 |
返回
| 类型 | 描述 |
|---|---|
Dictionary<string, IConvertible> | 字段名称及其属性值的字典。 Key:字段名称,Value:属性值。 |
错误条件备注
如果参数无效,则此方法可能会抛出异常或者返回 null。
示例 1
打印指定实体的 Centerlines 要素图层属性。// Initialize
var doc = Application.DocumentManager.MdiActiveDocument;
var flName = "Centerlines";
var objId = Esri.ArcGISForAutoCAD.FeatureLayer.SelectEntity(doc, flName);
// Get the attributes
var centerlinesAttributes = Esri.ArcGISForAutoCAD.Attributes.Get(doc, objId, flName);
// Print the attributes
foreach (var attribute in centerlinesAttributes)
{
doc.Editor.WriteMessage("\nKey = {0}, Value = {1}", attribute.Key, attribute.Value);
}
/* Example output
Key = EntityHandle, Value = 252
Key = EntityType, Value = LWPOLYLINE
Key = StreetName, Value = S Roosevelt Blvd
Key = Pavement, Value = 6
Key = Rating, Value = 0.6259
*/
示例 2
从指定实体的 Centerlines 要素图层打印单个 StreetName 字段值。// Initialize
var doc = Application.DocumentManager.MdiActiveDocument;
var flName = "Centerlines";
var objId = Esri.ArcGISForAutoCAD.FeatureLayer.SelectEntity(doc, flName);
// Get the attribute from the single field
var streetNameAttribute = Esri.ArcGISForAutoCAD.Attributes.Get(doc, objId, flName, "StreetName");
// Print the street name
doc.Editor.WriteMessage("The street name is " + streetNameAttribute["StreetName"]);
/* Example output
The street name is Truman Avenue
*/
另请参阅
FeatureLayer.GetAttributes - 此 .NET 方法将返回工程图的指定要素图层中所有要素的所有字段名称和值的字典集合。
FeatureLayer.SelectEntity - 此 .NET 方法将提示选择一个实体并返回其 AutoCAD ObjectId。
esri_attributes_get - 此 AutoLISP 函数用于获取字段名称及其默认属性值的关联列表。