# 在 Dynamo 中有效率地處理大型資料集

本頁將向您介紹一些在 Dynamo 中有效率處理大型資料集的經驗法則。希望您可以使用這些技巧來識別圖表中的瓶頸，讓您的圖表在短時間就能執行完成。

內容：

* 幾何圖形產生與鑲嵌
* 記憶體使用
* Revit API

### 幾何圖形產生與鑲嵌

在 Dynamo 中，建立幾何圖形和繪製幾何圖形是兩種完全不同的事件。一般而言，建立幾何圖形比繪製物件要快得多，使用的記憶體也較少。您可以將幾何圖形想像成是製作一套西裝的尺寸清單，而鑲嵌是西裝本身。您可以從西裝尺寸得知很多關於這套西裝的資訊：手臂有多長，要花多少錢等等，但總是要看一看並試穿成品，才知道是否合適。同樣地，使用未鑲嵌的幾何圖形，您可以決定其邊界框、面積、體積；與其他幾何圖形相交；以及將其匯出為 SAT 或 Revit。但是，您還是必須鑲嵌幾何圖形，才能感覺它是否正確。

如果您的 Dynamo 圖表有許多物件，而且在執行過程中變慢，可以從圖表中移除鑲嵌步驟來加快速度。

Dynamo 中的幾何圖形節點永遠是經過鑲嵌的\*。您有兩個選項來處理未鑲嵌的幾何圖形：Python 節點和 ZeroTouch 節點。只要您沒有從 Python 或 ZeroTouch 節點傳回物件幾何圖形，就不會鑲嵌幾何圖形。舉例來說，如果您的圖表有幾個點節點、連接到幾個線節點、連接至幾個斷面混成節點、連接到幾個增厚節點，幾何圖形在每一步都會進行鑲嵌。您可以改為將此邏輯綁定到 Python 或 ZeroTouch 節點，只傳回節點中的最終物件。

如需使用 ZeroTouch 節點的更多資訊，請參閱本 Primer 的[為 Dynamo 開發](https://github.com/DynamoDS/DynamoPrimerNew/blob/master-cht/9_best_practices/11_developer_primer/3_developing_for_dynamo/README.md)一節。

### 記憶體使用

如果您不再鑲嵌幾何圖形，則可能會因為累積過多幾何圖形而遇到記憶體瓶頸。Dynamo 中的幾何圖形物件在建立時會消耗少量但並非可忽視不計的記憶體。如果您處理的是數十萬或數百萬個物件，這加總起來可能會導致 Dynamo 或 Revit 當機。在 Dynamo 2.5 版及更高版本中會透過處置未使用的物件來隱性處理，但如果使用 2.5 之前的版本，則避免建立大量幾何圖形的一種方法，是在用完物件後就加以處置。舉例來說，假設您要建立幾十萬條 NurbsCurve，每條都需要幾十個點。建立這些曲線的一種方式是在 Dynamo 中建立一個二維清單，並提供給 NurbsCurve.ByPoints 節點。但是這要建立幾百萬個點。另一種方法是使用 Python 或 ZeroTouch 節點。在這類節點中，您可以建立十幾個點，將這些點提供給 NurbsCurve.ByPoints，然後使用 .Dispose() 方法呼叫來處置這十幾個點。如需使用 ZeroTouch 節點的更多資訊，請參閱本 Primer 的[為 Dynamo 開發](https://github.com/DynamoDS/DynamoPrimerNew/blob/master-cht/9_best_practices/11_developer_primer/3_developing_for_dynamo/README.md)一節。建立幾何圖形物件後加以處置，在某些情況下可以顯著減少您使用的記憶體量，雖然我們會在 Dynamo 2.5 及更高版本中為使用者處理這個問題，但如果使用案例需要在明確的時間點減少記憶體用量，我們建議使用者仍需明確處置幾何圖形。請參閱 [Dynamo 幾何圖形穩定性的改進](https://forum.dynamobim.com/t/dynamo-geometry-stability-improvements-request-for-feedback/39297)，以進一步瞭解 Dynamo 2.5 中引入的新穩定性功能。

### Revit API

如果您積極處置 ZeroTouch 或 Python 節點中的物件，但仍遇到記憶體或效能問題，請完全不要考慮 Dynamo，直接透過 API 建立 Revit 物件。例如，您可以剖析 Excel 檔案中的點資訊，然後使用此資訊透過其 API 建立 XYZ 和其他 Revit 元素。此時，Revit 就會成為無法避免的最終瓶頸。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://primer2.dynamobim.org/zh-tw/9_best_practices/5-efficiently-working-with-large-datasets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
