# Export Data

## Export Photo

如下方的指令集，利用此方式可以將3D圖檔打包成JPG格式檔案匯出到資料夾中。

```python
// Export Photo
oEditor.FitAll()
view="Dimetric","Trimetric", "Front", "Top", "Right", "Bottom"
photo_name = oDesign.GetName()
path =  'D://AEDT_file' # 給定路徑 #
for i in view:
        oEditor.ExportModelImageToFile("{}\{}_{}.jpg".format(path,photo_name,i), 2400, 1200, 
              [
                             "NAME:SaveImageParams",
                             "ShowAxis:="                   , "False",
                             "ShowGrid:="                  , "False",
                             "ShowRuler:="                 , "True",
                             "ShowRegion:="                            , "Default",
                             "Selections:="                  , "",
                             "FieldPlotSelections:="  , "",
                             "FitToSelections:="         , "",
                             "FitToFieldPlotSelections:=", "",
                             "Orientation:="               , i
              ])
        AddWarningMessage("Export {}_{}.jpg to {}".format(photo_name,i,path))

```

匯出的3D模型圖，如圖3-20所示。

<figure><img src="/files/sdACwbMUS6JZDzcu16gD" alt=""><figcaption><p>圖3-20</p></figcaption></figure>

## Export Field Report

類似匯出圖片的指令，我們能將場圖用指令匯出成JPG檔到資料夾中。

```python
// Export Field Report
fieldplot=[]
fieldplot=oModule1.GetMeshPlotNames()+oModule1.GetFieldPlotNames()
for field in fieldplot:
    AddWarningMessage("Export: {}.jpg".format(field))
    oModule1.ExportPlotImageToFile("{}\{}.jpg".format(path, field), "", "{}".format(field),"")
```

匯出的場圖，如圖3-21所示。

<figure><img src="/files/RoJjrioPC14kLEirapUN" alt=""><figcaption><p>圖3-21</p></figcaption></figure>

## Export Report to CSV

利用ExportToFile的指令，能將Result中的資料匯出成CSV格式，如圖3-20所示。

```python
// Export Report to CSV
oModule = oDesign.GetModule("ReportSetup")
oModule.ExportToFile("L with different gap", "D:/L with different gap.csv", False)
```

<figure><img src="/files/0OHXlOh07bteCNcCfVXN" alt=""><figcaption><p>圖3-22</p></figcaption></figure>

## Export List to CSV

假設有兩個lsit，分別是design\_variable\['A', 'N', 'E', 'D', 'W', 'C', 'Gap', 'Ff']；design\_variable\_value \['D*2+E*2+C', '40mm', '30mm', '40mm', '85mm', '40mm', '1.1mm', '120mm']，要如何將這兩個list存入csv檔案中呢？此時我們可以使用CSV模組的功能。請參考下面程式碼：

```python
// Export List to CSV_1
import csv

# 設計的List參數
design_variable = ['A', 'N', 'E', 'D', 'W', 'C', 'Gap', 'Ff']
design_variable_value = ['D*2+E*2+C', '40mm', '30mm', '40mm', '85mm', '40mm', '1.1mm', '120mm']
# 指定輸出的CSV文件路徑
csv_file_path = 'D://AEDT_file.csv'
# 使用csv模組寫入CSV文件
with open(csv_file_path, 'w') as csvfile:
    csv_writer = csv.writer(csvfile)

    # 將設計變量和設計變量值分别寫入CSV文件的兩列
    csv_writer.writerow(['Design Variable', 'Design Variable Value'])
    for variable, value in zip(design_variable, design_variable_value):
        csv_writer.writerow([variable, value])
        
AddWarningMessage("Export Data to {}".format(csv_file_path))

```

上面的方式匯出後，csv檔案會中間插入空白欄位，如圖3-23。

<figure><img src="/files/mpOy096lLl6Uq6EeEtQ6" alt="" width="298"><figcaption><p>圖3-23</p></figcaption></figure>

如果要避免空白欄位，可以將 " 用csv模組寫入CSV文件" 幾行程式碼修改如下：

```python
// Export List to CSV_2
# 使用csv模組寫入CSV文件
with open(csv_file_path, 'w') as csvfile:
    csv_writer.writerow(['Design Variable', 'Design Variable Value'])
    
    # 將每一行的數據寫入CSV，不換行
    for variable, value in zip(design_variable, design_variable_value):
        csvfile.write("{},{}\n".format(variable, value))
```

執行後的csv檔案，如圖3-24所示。

<figure><img src="/files/Rffz8rmHDvNvwQcosmpJ" alt="" width="299"><figcaption><p>圖3-24</p></figcaption></figure>


---

# 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://eemans-organization.gitbook.io/maxwell-automation/iron-python/export-data.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.
