新しい要素を作成したり、要素を修正した後には、モデル全体にわたって変更を配置するために、要素の再生成と自動結合が必要です。再生成がない場合(あるいは自動結合がない場合)、要素のジオメトリ プロパティおよびAnalyticalModel が取得不能になったり(新しい要素を作成する場合)、無効となる場合があります。要素のジオメトリや AnalyticalModel にアクセスする前に、再生成が発生する方法とタイミングについて理解しておくことが重要です。
モデル内の変更の伝達には再生成と自動結合が必要ですが、時間がかかる場合があります。必要なときのみこれらのイベントが発生することが求められます。
モデルを修正するトランザクションが正しくコミットされた場合や、Document.Regenerate()や Document.AutoJoinElements()メソッドが呼び出された場合に、再生成と自動結合は自動的に実行されます。Regenerate()や AutoJoinElements()は開いたトランザクション内でのみ呼び出されます。Regeneration()メソッドは失敗する場合があり、失敗すると RegenerationFailedException がスローされますので注意してください。このような場合には、現在のトランザクションやサブトランザクションをロールバックさせて、ドキュメントへの変更をロールバックする必要があります。
AnalyticalModel オブジェクトの詳細は、「AnalyticalModel」(「Revit Structure」)を参照してください。ジオメトリ プロパティの詳細は、「ジオメトリ」を参照してください。
次のサンプル プログラムは、トランザクションがこれらのプロパティを設定する方法を表しています。
コード領域 23-3: ジオメトリと AnalyticalModel プロパティを設定するトランザクション |
public void TransactionDuringElementCreation(UIApplication uiApplication, Level level) { Autodesk.Revit.DB.Document document = uiApplication.ActiveUIDocument.Document; // Build a location line for the wall creation XYZ start = new XYZ(0, 0, 0); XYZ end = new XYZ(10, 10, 0); Autodesk.Revit.DB.Line geomLine = Line.CreateBound(start, end); // All and any transaction should be enclosed in a 'using' // block or guarded within a try-catch-finally blocks // to guarantee that a transaction does not out-live its scope. using (Transaction wallTransaction = new Transaction(document, "Creating wall")) { // To create a wall, a transaction must be first started if (wallTransaction.Start() == TransactionStatus.Started) { // Create a wall using the location line Wall wall = Wall.Create(document, geomLine, level.Id, true); // the transaction must be committed before you can // get the value of Geometry and AnalyticalModel. if (wallTransaction.Commit() == TransactionStatus.Committed) { Autodesk.Revit.DB.Options options = uiApplication.Application.Create.NewGeometryOptions(); Autodesk.Revit.DB.GeometryElement geoelem = wall.get_Geometry(options); Autodesk.Revit.DB.Structure.AnalyticalModel analyticalmodel = wall.GetAnalyticalModel(); } } } } |
この例のトランザクションのタイムラインは次のとおりです。
図 134: トランザクションのタイムライン