Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

CST Studio Suite VBA Script Not Exporting FarField Images

embedded_n00b

Newbie
Newbie level 1
Joined
Aug 12, 2024
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
19
Hello everyone,

I'm currently working on a project that involves automating the generation and export of far-field images using CST Studio Suite. I followed this video the get the patch antenna. I’ve written a VBA script intended to scale the patch length and width of an antenna, rebuild the project, run the solver, and then export the resulting far-field plots as PNG images. Unfortunately, although the script runs without errors, it doesn't seem to be exporting any images.

Here’s a simplified version of the code I’m using:

Code:
'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

Despite the script running without errors, it doesn’t seem to produce any exported images in the specified directory. I’ve double-checked the paths and filenames, but no images are saved. Is there something that I'm missing here or is there another way to do this?
 
In times past I asked some program to create a new file while I specified a concatenated name of the target directory, and it failed to do so. There was no error message, no reason for the failure. I decided I needed to streamline the process. I commanded some short default name for the file. I let the program save it at the root level. I let it choose a default disk. Afterward I did a search for the file which was a minute old. I made sure my commands opened the file and device, then closed the file.

To verify proper file I/O, it's important to get numerous verbose messages from the program, step-by-step before perfoming a step, and after completing a step.
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top