Welcome to WEAP's Website WEAP
WEAP is an initiative of the Stockholm Environment Institute.


About WEAP

Home
Why WEAP?
Features
What's New?
Sample Screens
Demonstration
Publications
History and Credits

Using WEAP
Download
Licensing
User Guide
Tutorial
Videos (YouTube)

User Forum
Discussions
Members List
Edit Profile

Additional Support
Training
University Courses
Collaboration

About Us
SEI-US Water Resources Program
Please Contact Us

LEAP
Interested in Energy?
Read about LEAP: SEI's software for energy planning.

Link WEAP and LEAP for combined Water-Energy planning.
Watch a video demo!
   

User Forum

All Topics | Topic "Componente Activex não pode criar Objeto"
Log in to post new messages or reply to existing messages.
 
Author Message
Eng. Fabiano da Silva de Oliveira

Subject: Componente Activex não pode criar Objeto   
Posted: 9/8/2023 Viewed: 3034 times
Hello

I am trying to run the sample script to access Weap but the error message "ActiveX Component cannot create Object" appears. I tested in Windows 10 and got no problems, but when exceeded in Windows 11 appears an error.
There is some incompatibility of Windows versions with the script.

Fabiano.
Mr. Jack Sieber

Subject: Re: Componente Activex não pode criar Objeto   
Posted: 9/8/2023 Viewed: 3003 times
What language is the script written in? Visual Basic? Python? If it is Python, can you please tell me what version of Python it is? What is the text of the script you are trying?

Jack
Eng. Fabiano da Silva de Oliveira

Subject: Re: Componente Activex não pode criar Objeto   
Posted: 9/11/2023 Viewed: 2914 times
Here is the code snippet that works on Windows 10, but not on Windows 11. It is running on Visual Studio 2022 on both operating systems:

public static void Calcular()
{
dynamic WEAP = Activator.CreateInstance(Type.GetTypeFromProgID("WEAP.WEAPApplication"));

WEAP.Verbose = 1;
WEAP.Logfile = Path.Combine(WEAP.Directory, "WeapErrors.txt");
WEAP.ActiveArea = "Weaping River Basin";
WEAP.ActiveScenario = "Supply Measures";
WEAP.Branch("\\Demand Sites\\South City").Variables("Consumption").Expression = "30";

for (int GrowthRate = 0; GrowthRate <= 5; GrowthRate++)
{
//corrigir pois os valores aparecem os mesmo na planilha de excel.
WEAP.Branch("\\Demand Sites\\South City").Variables["Annual Activity Level"].Expression = "Growth(" + GrowthRate.ToString("N0") + "%)";

// WEAP.Calculate(0, 0, false); // Only calculate scenarios that need calculation (for all years and timesteps)

if (!WEAP.Status)
break;

WEAP.ExportResults("GW_" + GrowthRate.ToString("N0") + ".csv", true, true);

// Atualize o TextBox no Form1 do namespace Acesso_Weap
acessoForm1.AdicionarTextoAoTextBox(GrowthRate.ToString("N0"));
acessoForm1.AdicionarValorAoDataGridView(GrowthRate.ToString("N0"));

}
// WEAP will close automatically when the script is done, and the changes will NOT be saved to the area
}
Mr. Jack Sieber

Subject: Re: Componente Activex não pode criar Objeto   
Posted: 9/13/2023 Viewed: 2898 times
I do not have Visual Studio, so I could not test your Visual Basic code, but I did test a simple Visual Basic Script (below) in Windows 11 and it worked fine.

Perhaps WEAP is not registered correctly in your Windows 11 system? To check this, open WEAP, then go to Help, About. Near the bottom of the first section ("WEAP"), it will tell you if it is registered correctly in the Windows Registry. It should say "WEAP is registered correctly in the Windows Registry"

If WEAP is NOT registered correctly, try running the batch file RegisterWEAP.bat, which is located in the WEAP program folder, e.g., c:\Program Files (x86)\WEAP. You will need to run the batch file As Administrator.

Jack


Here is the simple script I tested:

' Run WEAP as a COM Automation Server

Set WEAP = CreateObject("WEAP.WEAPApplication")

' Make sure WEAP is fully started
While Not WEAP.ProgramStarted
Sleep (1)
Wend

WEAP.Verbose = 1 ' 0 = no dialogs, 1 = errors only, 2 = questions & errors, 3 = warnings, questions & errors, 4 = all dialogs
WEAP.Logfile = WEAP.Directory + "WeapErrors.txt" ' log all errors and warnings to this text file

WEAP.ActiveArea = "Weaping River Basin"
WEAP.ActiveScenario = "Supply Measures"

Sleep (5) ' Make sure WEAP has started

FOR GrowthRate = 0 to 5 ' try various growth rates

WEAP.Branch("\Demand Sites\South City").Variables("Annual Activity Level").Expression = "Growth(" + FormatNumber(GrowthRate, 0) + "%)"

CALL WEAP.LoadFavorite("Groundwater Storage") ' This will calculate first

IF WEAP.Status = FALSE THEN ' If the user cancels the calculations, exit the FOR loop
EXIT FOR
END IF

CALL WEAP.ExportResults(WEAP.AreasDirectory + "GW_" + FormatNumber(GrowthRate, 0) + ".csv", FALSE, TRUE) ' e.g., GW_2.csv

NEXT

' WEAP will close automatically when the script is done, and the changes will NOT be saved to the area

Set WEAP = Nothing

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function Sleep(sec)
WScript.Sleep (sec * 1000) ' WScript is the built-in Windows scripting object
End Function
Eng. Fabiano da Silva de Oliveira

Subject: Re: Componente Activex não pode criar Objeto   
Posted: 9/14/2023 Viewed: 2835 times
Thanks for the reply, it worked correctly.
Topic "Componente Activex não pode criar Objeto"