ドキュメント オブジェクトには、すべての AutoCAD Civil 3D 図面要素(サーフェス、線形など)のコレクションだけではなく、これらの要素を変更するすべてのオブジェクト(スタイル、ラベル スタイルなど)が含まれています。 これらのコレクションには、同じメソッドのコア セットである Count、Item、Remove、および Add が存在します。Count は、コレクション内の項目数を表します。Item は、コレクションからオブジェクトを返します。通常、これはオブジェクトの ID 番号またはオブジェクト名によって指定されます。Remove は、指定された項目をコレクションから削除します。Add は、新しい項目を作成し、コレクションに追加し、その項目の参照を返します。この項目は、既にドキュメント環境設定で定義されている既定値に設定されています。
次の例では、新しいポイント スタイルを作成します。
Dim oPointStyle As AeccPointStyle Set oPointStyle = oAeccDocument.PointStyles.Add("Name") ' Now a new point style is added to the collection of styles, ' and we can modify it by setting the properties ' of the oPointStyle object. oPointStyle.Elevation = 114.6
既存の要素とプロパティが一致する要素を追加しようとした場合、存在しない項目にアクセスしようとした場合、または存在しないか使用されていない項目を削除しようとした場合は、エラーが発生します。エラーをトラップし、適切に応答する必要があります。
次の例は、こうしたエラーを処理する方法の 1 つを示しています。
' Try to access the style named "Name". Dim oPointStyle As AeccPointStyle On Error Resume Next Set oPointStyle = oAeccDocument.PointStyles.Item("Name") ' Turn off error handling as soon as we no longer need it. On Error Goto 0 ' If there was a problem retrieving the item, then ' the oPointStyle object will remain empty. Check if that ' is the case. If so, it is most likely because the item ' does not exist. Try making a new one. If (oPointStyle Is Nothing) Then Set oPointStyle = oAeccDocument.PointStyles.Add("Name") End If