ポイントのユーザ定義プロパティ

ユーザ定義プロパティ(UDP)を使用することにより、追加データをポイントにアタッチすることができます(UDP を区画に割り当てることもできます)。UDP は、UDP 分類というグループに編成され、順に PointGroups に割り当てられます。UDP が「未分類」であることもあります。UDPClassificationPointGroup オブジェクトに関連付けられている(UseCustomClassification() メソッドを使用)場合、UDPClassification 内の UDP 定義はPointGroup の各ポイントに割り当てられます。UDP の値は各ポイントごとに一意であり、個別に変更することができます。割り当てにより、各ポイントは UDP の既定値を取得します(UseDefaultUDP に対して True の場合)。

UDP の各インスタンスは UDP 基本クラスから派生されたクラスで、データ型に応じて追加のプロパティがあります。UDPDoubleUDPInteger 型には、範囲を示す下限および上限プロパティがあります。UDPEnumeration 型には、定義されているすべての値の配列を取得する GetEnumerationValues() メソッドがあります。

UDP を作成するには、最初に AttributeTypeInfo<type> オブジェクトを作成し(UDP タイプごとに 1 つ)、既存の UDPClassificationCreateUDP() メソッドに渡します。UDP には、名前と同様に GUID もあり、名前+GUID の組み合わせによって一意の識別子であることが保証されます。CreateUDP() メソッドは省略可能な GUID パラメータを受け入れるため、特定の名前+GUID の組み合わせを使用して UDP を作成することができます。これにより、複数の図面で同じ UDP を作成することができます。

ユーザ定義プロパティおよびユーザ定義分類の詳細は、『AutoCAD Civil 3D ユーザガイド』の「ユーザ定義プロパティの分類」を参照してください。

次の例では、"Example" というポイントの新しいユーザ定義のプロパティ分類を作成し、上限と下限および既定値で新しいユーザ定義プロパティを追加します。

[CommandMethod("C3DSAMPLES", "UDPExample", CommandFlags.Modal)]
public void UDPExample()
{
    using (Transaction tr = startTransaction())
    {
        // _civildoc is the active CivilDocument instance.
        UDPClassification udpClassification = _civildoc.PointUDPClassifications.Add("Example");
        AttributeTypeInfoInt attributeTypeInfoInt = new AttributeTypeInfoInt("Int UDP");
        attributeTypeInfoInt.DefaultValue = 15;
        attributeTypeInfoInt.UpperBoundValue = 20;
        attributeTypeInfoInt.LowerBoundValue = 10;
        UDP udp = udpClassification.CreateUDP(attributeTypeInfoInt);

        // assign a point group
        ObjectId pointGroupId = _civildoc.PointGroups.AllPointGroupsId;
        PointGroup pointGroup = pointGroupId.GetObject(OpenMode.ForWrite) as PointGroup;
        pointGroup.UseCustomClassification("Example");


        tr.Commit();
    }
}

この例では、ドキュメント内のすべてのポイントの UDPClassifications のコレクショにアクセスし、各 UDPClassificationreading の 各 UDP を読み出す方法を示します。

[CommandMethod("C3DSAMPLES", "ListUDPs", CommandFlags.Modal)]
public void ListUDPs()
{
    using (Transaction tr = startTransaction())
    {
        // _civildoc is the active CivilDocument instance.
        foreach (UDPClassification udpClassification in _civildoc.PointUDPClassifications)
        {
            _editor.WriteMessage("\n\nUDP Classification: {0}\n", udpClassification.Name);
            foreach (UDP udp in udpClassification.UDPs)
            {
                _editor.WriteMessage(" * UDP name: {0} guid: {1}, description: {2}, default value: {3}, use default? {4}\n",
                    udp.Name, udp.Guid, udp.Description, udp.DefaultValue, udp.UseDefaultValue);

                _editor.WriteMessage("\tUDP type: {0}\n", udp.GetType().ToString());

                var udpType = udp.GetType().Name;
                switch (udpType)
                {
                    // Booleans and String types do not define extra properties
                    case "UDPBoolean":
                    case "UDPString":
                        break;

                    case "UDPInteger":
                        UDPInteger udpInteger = (UDPInteger)udp;
                        _editor.WriteMessage("\tUpper value: {0}, inclusive? {1}, Lower bound value: {2}, inclusive? {3}\n",
                            udpInteger.UpperBoundValue, udpInteger.UpperBoundInclusive, udpInteger.LowerBoundValue, udpInteger.LowerBoundInclusive);
                        break;

                    case "UDPDouble":
                        UDPDouble udpDouble = (UDPDouble)udp;
                        _editor.WriteMessage("\tUpper value: {0}, inclusive? {1}, Lower bound value: {2}, inclusive? {3}\n",
                            udpDouble.UpperBoundValue, udpDouble.UpperBoundInclusive, udpDouble.LowerBoundValue, udpDouble.LowerBoundInclusive);
                        break;

                    case "UDPEnumeration":
                        UDPEnumeration udpEnumeration = (UDPEnumeration)udp;
                        _editor.WriteMessage("\tEnumeration values: {0}\n", udpEnumeration.GetEnumValues());
                        break;
                }
            }
        }

        tr.Commit();
    }
}