Cancel
Showing results for 
Search instead for 
Did you mean: 

Execution of Method through Excel Makro

Experimenter
Experimenter

Hello there,

 

I have a problem here, dear fellow Plant Simulation users. I am trying to establish full control over my model in PS through Excel (DDE-Schnittstelle). Almost everything works by now, but the I cannot seem to execute the Method through it. Here is the piece of code from VBA. The uncommented line (DDE-Execute) is the one that does not work:

 

Public Sub CommandButtonStart_Click()
Dim channel As Long
Dim Cell As Object

channel = DDEInitiate("eM-Plant", "System")

'For i = 12 To 13

'DDEExecute channel, ".models.BlockAssembly_RK.eventController.reset;"

DDEExecute channel, ".models.BlockAssembly_RK.Datenerzeugung_Rk.m_applyChanges.execute"
'Range("A1").Offset(i, 6).value = DDERequest(channel, ".models.BlockAssembly_RK.Simulationszeit_v") 'DDEExecute channel, ".models.BlockAssembly_RK.eventController.start;" 'Call WaitForUpdate 'Range("A1").Offset(i, 6).value = DDERequest(channel, ".models.BlockAssembly_RK.Simulationszeit_v") 'Next i DDETerminate (channel) 'kanal wird geschlossen End Sub

In Console of PS the folloing output is shown after the code is run:

Fehler in Formel aufgerufen von '.execute': 'Ein 'void' kann keine Methode 'execute' empfangen.'


Thank you in advance for any suggestions!

7 REPLIES

Re: Execution of Method through Excel Makro

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi Artemiy,

 

try this:

DDEExecute channel, "ref(.models.BlockAssembly_RK.Datenerzeugung_Rk.m_applyChanges).execute"

 

The ref-operator prevents that the method is executed, otherwise you send 'execute' to the return value of the method, whic is void.

 

Or just write:

DDEExecute channel, ".models.BlockAssembly_RK.Datenerzeugung_Rk.m_applyChanges"
Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Execution of Method through Excel Makro

Experimenter
Experimenter

Thanks for your input, Ralf!

 

Unfortunately, it does not seem to work too. Have tried that with different combinations of "ref" operator and "execute" command and without as well. It looks like the DDE does not accept "normal" commands of SimTalk, like executing the method by simply writing its name or full path.

 

For instance, the PS console does not show any output at all after running this piece of code:

DDEExecute channel, ".models.BlockAssembly_RK.Datenerzeugung_Rk.m_applyChanges"

Even though there should be some data printed after the method "m_applyChanges" is properly executed.

Re: Execution of Method through Excel Makro

Siemens Phenom Siemens Phenom
Siemens Phenom

Just tested it, and it works for me.

 

What's the version of Plant Simulation you are using?

Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Execution of Method through Excel Makro

Experimenter
Experimenter

Hello Ralf,

 

thank you for your contribution. Could not test it during the weekend, as I work on PS part time by Uni. Unfortunately, it does not work for me still. I use 10.1 64-bit version (Research license). Can it have something to do with the fact that the "m_applyChanges" is Dialogmethod?

 

When I try to run any other method Console shows me that here:

 

Fehler in Formel aufgerufen von '.execute': 'Die Methode erwartet Parameter, aber es wurden keine übergeben.'

Re: Execution of Method through Excel Makro

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi Artemiy,

 

works fine for me in 10.1.

 

I've attached my example.

 

The error you get indicates that you call a method which expects parameters without parameters.

If you supply the parameters it should work.

Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.

Re: Execution of Method through Excel Makro

Experimenter
Experimenter

Hmmm. Again, sorry for late reply, but I am still working here only part time Smiley Happy

 

So, I might see what the problem is. I created the new method to check whether the code from PS works without the other lines of model itself. Here it is:

is
	wert, adresse:string;
	kanal, zeile, spalte:integer;
do
	--Excel import

	
	kanal:=DDEConnect("Excel","Tabelle1");
	spalte:=1;
	zeile:=str_to_num(ddeRequest(kanal,"Z2S1")); --Zeile durch Excel definiert (A2), loop läuft in Excel selbe
	root.Simulationsnummer:=zeile;
	
	root.Simulationszeit[1,zeile]:="Läuft";
	root.Simulationszeit_v:="Läuft"; 
	
	adresse:=("Z"+to_str(zeile)+"S"+to_str(spalte));
	wert:=to_str(ddeRequest(kanal,Adresse));
	Dialog.setCaption("blocklange",to_str(omit(wert,strlen(wert)-1,2)));
    
	adresse:=("Z"+to_str(zeile)+"S"+to_str(spalte+1));
	wert:=to_str(ddeRequest(kanal,Adresse));
	Dialog.setCaption("blockbreite",to_str(omit(wert,strlen(wert)-1,2)));
    
	adresse:=("Z"+to_str(zeile)+"S"+to_str(spalte+2));
	wert:=to_str(ddeRequest(kanal,Adresse));
	Dialog.setCaption("blockhohe",to_str(omit(wert,strlen(wert)-1,2)));
	
	--TeilezahlSektionen
	adresse:=("Z"+to_str(zeile)+"S"+to_str(spalte+3));
	wert:=to_str(ddeRequest(kanal,Adresse));
	Dialog.setCaption("TeilezahlSektionen_x",to_str(omit(wert,strlen(wert)-1,2)));
	
	adresse:=("Z"+to_str(zeile)+"S"+to_str(spalte+4));
	wert:=to_str(ddeRequest(kanal,Adresse));
	Dialog.setCaption("TeilezahlSektionen_y",to_str(omit(wert,strlen(wert)-1,2)));
	
	adresse:=("Z"+to_str(zeile)+"S"+to_str(spalte+5));
	wert:=to_str(ddeRequest(kanal,Adresse));
	Dialog.setCaption("TeilezahlSektionen_z",to_str(omit(wert,strlen(wert)-1,2)));
	
	ddedisconnect(kanal);
end;

It does work when I run it in PS, but does not when I try to execute it in Excel. Can it be that starting the code containing DDE channel established throught the command of another DDE channel results in conflict? Cause it still does not show anything inside the Console of PS.

 

Thanks, Ralf

Re: Execution of Method through Excel Makro

Siemens Phenom Siemens Phenom
Siemens Phenom

Using DDE in a method which is called through DDE is indeed not supported.

 

DDE is anyway a rather old technology.

 

Perhaps you want to have a look on the COM interface.

Regards,

Ralf
------------------------------------------------------------------------------------------------------
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.