APIオブジェクトの一括変更
APIオブジェクトによっては、プロパティを一括変更できるものがあります。一括変更に対応しているオブジェクトは、プロパティのディクショナリ(Luaテーブル)を使用できるSetPropertiesメソッドを備えています。
変更を必要とするプロパティが複数存在し、それらに相互の依存性がある状況で、一括変更を実行することにより、それらの変更を1回の操作で実現できます。
一括変更を理解するには、例を使用することをお勧めします。以下の各例はすべて同じ問題を扱っていて、その実行結果は同じです。ここでは立方体オブジェクトを例として使用します。
例1
app = cf.GetApplication() project = app:NewProject() -- Create a cuboid with its base corner at the specified ' Point ' corner = cf.Point(-0.25, -0.25, 0) cube = project.Geometry:AddCuboid(corner, 0.5, 0.5, 1.25) -- Modify the cuboid cube.Depth = 2 cube.Height = 2 cube.Depth = 2 cube.Origin.U = 2.5 cube.Origin.V = -0.5 cube.Origin.N = 1
例2
app = cf.GetApplication() project = app:NewProject() -- Create a cuboid with its base corner at the specified ' Point ' corner = cf.Point(-0.25, -0.25, 0) cube = project.Geometry:AddCuboid(corner, 0.5, 0.5, 1.25) -- Modify the cuboid newSettings = {} newSettings["Depth"] = 2 newSettings["Height"] = 2 newSettings["Origin.U"] = 2.5 newSettings["Origin.V"] = -0.5 newSettings["Origin.N"] = 1 cube:SetProperties(newSettings)
例3
app = cf.GetApplication() project = app:NewProject() -- Create a cuboid with its base corner at the specified ' Point ' corner = cf.Point(-0.25, -0.25, 0) cube = project.Geometry:AddCuboid(corner, 0.5, 0.5, 1.25) -- Modify the cuboid cube:SetProperties({["Depth"] = 2, ["Height"] = 2, ["Origin.U"] = 2.5, ["Origin.V"] = -0.5, ["Origin.N"] = 1})
SetPropertiesメソッドを使用した一括変更では、オブジェクトの検証と更新を1つの手順で実行できるので、パフォーマンスが向上する利点があります(ただし、上記のように小規模な例では確認できません)。また、GetPropertiesメソッドも用意されています。このメソッドを使用すると、オブジェクトに適用されている設定にアクセスして、目的の変更を適用したうえで、SetPropertiesを使用してプロパティを設定できます。オブジェクトのデフォルトプロパティは、GetDefaultPropertiesメソッドを使用して取得できます。