在 CST Studio Suite 中导出 3-D 远场图图像

问题描述 投票:0回答:1

我正在为 CST Studio Suite 编写 VBA 脚本来生成和导出多个远场图像。我按照this有关在 CST Studio 中构建贴片天线的教程来获得总体设计。

目标是缩放补丁的长度和宽度,重建项目,运行求解器,然后将远场图导出为图像。

'Language "WWB-COM"

Option Explicit

Sub Main()
    ' Define and initialize variables
    Dim i As Integer
    Dim scalingFactor As Double
    Dim project As Object
    Dim exportPath As String
    Dim fileName As String
    Dim SL, SW, SH, Mt, PL, PW, ML, MW, InL, InW, k As Double

    ' Initialize the CST project
    Set project = CreateObject("CSTStudio.Application")

    ' Path to save the exported images
    exportPath = "C:\Path\To\Export\Directory\" ' Change this to your desired path

    ' Initialize the base values from your parameter list
    SL = 59
    SW = 76
    SH = 1.5
    Mt = 0.035
    PL = 29.5
    PW = 38
    ML = 14.75 ' This is typically calculated as SL/2 - PL/2
    MW = 2.86
    InL = 9
    InW = 0.74
    k = 5.62

    ' Reset before each execution of this script
    Call StoreParameter("PL", PL)
    Call StoreParameter("PW", PW)

    ' Loop to generate images for different sizes
    For scalingFactor = 0.30 To 0.6 Step 0.10
        ' Calculate new parameters only for the patch length and width
        PL = 29.5 * scalingFactor
        PW = 38 * scalingFactor

        ' Update CST with new parameters
        Call StoreParameter("PL", PL)
        Call StoreParameter("PW", PW)

        ' Rebuild and solve the project
        Call Rebuild
        Call RunSolver()

        ' Export the farfield plot
        fileName = exportPath & "Antenna_Size_" & scalingFactor & ".png" ' Adjusted to export as .png
        With FarfieldPlot
            .Reset
            .Plottype "3d"
            .SetThetaStart 0
            .SetThetaEnd 180
            .SetPhiStart 0
            .SetPhiEnd 360
            .Step 1
            .Step2 1
            .SetPlotMode "directivity"
            .SetScaleLinear True
            .SetLogRange 40
            .EnablePhaseCenterCalculation True
            .SetPhaseCenterComponent "Theta"
            .SetPhaseCenterPlane "both"
            .SetPhaseCenterAngularLimit 30
            Call SelectTreeItem("Farfields")
            .Plot
            .ASCIIExportAsSource fileName
        End With

    Next scalingFactor

    ' Notify completion
    MsgBox "Generation of far-field images completed."
End Sub

脚本运行没有错误,但不导出任何图像。
我验证了路径和文件名是正确的。
我查阅了 CST Studio Suite 文档。

vba image
1个回答
-1
投票

导出方法可能不正确:

您可能需要使用

.ASCIIExportAsSource
,而不是以 ASCII 格式导出数据的
.ExportPlotImage
。此方法应直接将绘图导出为图像(PNG 或 JPG)。调整方法如下:

.ExportPlotImage fileName, "png", 1920, 1080
© www.soinside.com 2019 - 2024. All rights reserved.