ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 11-02-2007
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default Use of user DLL in Flexsim

Hi,

I am looking at how to use my own DLL in Flexsim and I understand to use the DLL from a trigger as in the demo model in the old forum.

What I really want to do is in a trigger call a function in a DLL with parameters that I supply the DLL with and the DLL should return a value. The call of the function in the DLL will be on a line in a Flexscript code, the trigger is toggled as Flexscript and not as a DLL.
  • What is the best way to call a function in a DLL with my own parameters?
  • What is the best way to call a function without toggle the whole trigger as a DLL? Probably I need to use nodefunction.
  • Is it possibly to send my own parameters to a DLL function from a trigger call? The trigger is toggled as a DLL.
  • Must all functions in a DLL have FLEXSIMINTERFACE declartion?
  • If I have FLEXSIMINTERFACE declaration and want my own parameters passed to the function. How do I do that from Flexsim?
I have lost my link to the old forum so I can not use the old forum to find the discussion about the use of DLL.

If somebody has some demo code they can share I would appreciate that.

Lars-Olof
  #2  
Old 11-02-2007
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Hi Lars,

We have already done a few projects/libraries with DLL's and I'll try to give you some info:

Quote:
Originally Posted by Lars-Olof Leven View Post
What is the best way to call a function in a DLL with my own parameters?
If you have a node(trigger, label, variable) toggled as DLL, you can simply call nodefunction on that node and specify all the parameters that you want (max. 10). Within the DLL you extract the parameters with parval and parnode. (parval(1) is the first parameter)

Quote:
Originally Posted by Lars-Olof Leven View Post
What is the best way to call a function without toggle the whole trigger as a DLL? Probably I need to use nodefunction.
yes, you can use a nodefunction, but what is even easier with reading and programming is making a usercommand and toggle the node with the code as DLL. That way it is just as using a function directly. Simpy pass the parameters and the usercommand will pass them on. I attached a bitmap of this usercommand option.


Quote:
Originally Posted by Lars-Olof Leven View Post
Is it possibly to send my own parameters to a DLL function from a trigger call? The trigger is toggled as a DLL.
Yes, if you call a trigger with nodefunction you can specify max 10 parameters.

Quote:
Originally Posted by Lars-Olof Leven View Post
Must all functions in a DLL have FLEXSIMINTERFACE declartion?
No, but in that case you can't call them directly from within Flexsim. You can make an interface functions that has the FLEXSIMINTERFACE and call a different function from within that interface function. But that 2nd function can only be accessed from within the DLL.

Quote:
Originally Posted by Lars-Olof Leven View Post
If I have FLEXSIMINTERFACE declaration and want my own parameters passed to the function. How do I do that from Flexsim?
See above.


I hope this helps you any further.

Regards,

Steven
Attached Thumbnails
Click image for larger version
Name:	usercommandexample.JPG
Views:	643
Size:	32.3 KB
ID:	55  
The Following 3 Users Say Thank You to Steven Hamoen For This Useful Post:
Paulo Lopes (03-11-2015)
  #3  
Old 11-02-2007
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default

Hi Steven,

Thanks for the answer and help.

This will help me a lot.

Now it I need to start do some testing before I start asking more questions.

Regards,
Lars-Olof
  #4  
Old 11-05-2007
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default

Hi Steven,

I am trying to use User Command to call my own function in a dll, but I can not get it to work. I managed to get work once (do not know how) and when I saved the model and did a small change to the dll, after that I can not get it to work.
Even when I go back to my original code I can not get it to work.

The error I get is
Flexscript Error MAIN:/project/model/Tools/GlobalVarGen>variables/commands/kalle/code line 2 parse error, expecting `$'
Could not finish parsing because of previous errors.

I have tried to use dll: and code directly from a trigger in the user command still same problem.

When I call my function in the dll from a trigger direct, there is no problem. For example when I toggle the OnExit trigger on a processor to dll and write in "../libraries/dll.dll" "exitmessage" I get it to work. When I use the same information in a User Command I do not get it to work.
The problem I have, is for the User Command to understand that I want to call a dll. I have toggled the User Command as dll.

Any tips how I should get User Command to understand that I want to call a dll? How should I do the User Command to get it to call the dll?

Hope somebody can help me.

Lars-Olof
The Following User Says Thank You to Lars-Olof Leven For This Useful Post:
Brandon Peterson (10-08-2009)
  #5  
Old 11-20-2007
Tom David's Avatar
Tom David Tom David is offline
Flexsim User
 
Join Date: Aug 2007
Location: Schwaebisch Gmuend, Germany
Posts: 430
Downloads: 157
Uploads: 47
Thanks: 486
Thanked 450 Times in 233 Posts
Rep Power: 520
Tom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant future
Default

Steven,

looks like you have some experience with DLL's.

Can I also pass a string over to a DLL?
You only speak from parnode and parval. So no parstring?

If I understand it right, you need for every DLL call an own User Command, right?
So if you have 10 DLL calls for 10 different DLL functions, you need 10 different User Commands?

Is there a way to make the DLL call dynamic?

What I am looking for is, that I could call e.g. a nodefunction or the User Command to call the DLL function and hand over the function name.

I am pretty sure you understand what I am trying to do.
Than I would only need one User Command to call all my DLL functions.

Does anyone has an idea how to do this?

Another way would be maybe something to put the function call in the DLL itself together to call an internal function.
Unfortunately I am not a C++ programmer but this might be a way. But it is still needed to pass a string over to the DLL.

Thanks in advance.
tom the (A)tom
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions."
  #6  
Old 11-20-2007
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

@Lars-Olof:

Could you send me a small model example containing the usercommand and the cpp files/h files of the dll? Than I can take a look what is going wrong.

@Tom:
Tom, as far as I know you can't pass strings because the flexsim interface doesn't support strings in this way. So I use a workaround. I take a node somewhere under tools and write the string that I want to pass onto that node. And then either pass the node reference or in the DLL I simply refer to that node and get the string out. But there are some problems with strings in DLL, so to be on the safe side I always use gets and sets.

Concerning your calling different DLL functions with 1 usercommand, you can quite easily use a case statement based on a parameter that you pass in the usercommand. And if you do it properly you define a global variable as a constant and use that. For instance you make a global variable MYOBJECT_RESETTRIGGER and give it the value 1. That way you don't have to pass in strings, simply use numbers. Inside the case statement you call different nodefunctions that do the actual DLL call.

This could be done the same way inside the DLL. Inside the Overal function that you call, you use the case statement to distinguish the different functions you want to call.

But the disadvantage of both approaches is that if you want to do this for the triggers, every trigger has different parameters and those are not passed in or you have to do that for every trigger seperately.

So my question is why you want to do this? Because if you use this to have code on triggers you simply toggle the variable trigger nodes as DLL and call the DLL functions directly. Once you have that in place you never have to look at it again and inside Visual Studio you can create seperate cpp file to keep functions together and you have all kinds of tools like outlining to make it easier to work with.

let me know if you want to know more.

Regards,

Steven

Last edited by Cliff King; 11-20-2007 at 02:17 PM.
The Following User Says Thank You to Steven Hamoen For This Useful Post:
Brandon Peterson (10-08-2009)
  #7  
Old 11-21-2007
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default

Hi Steven,

I get it to work.

I will try to explain what happend for me, I maybe do something wrong.
  1. First I create the User Command from the Tools menu.
  2. Now I open up the tree for the User Command and toggle the code section to DLL.
    What happens now is that the icon looks like D overlapping a S. If I stop now, I get the error.
  3. After toggle the code section to a D I now toggle it back to Flexscript. Now I have only the D and the call to the DLL works.
    Strange????
The problem for me was the toggling of the code section of the User Command.
Can someone else replicate this problem?
It can be something with my system and installation.

Regards,
Lars-Olof
  #8  
Old 11-21-2007
Tom David's Avatar
Tom David Tom David is offline
Flexsim User
 
Join Date: Aug 2007
Location: Schwaebisch Gmuend, Germany
Posts: 430
Downloads: 157
Uploads: 47
Thanks: 486
Thanked 450 Times in 233 Posts
Rep Power: 520
Tom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant futureTom David has a brilliant future
Default

Lars-Olof,

As far as I see this issue everything is right with your system and installation.
If a node is already toggled (e.g. Flexscript) you need to toggle it as Flexscript to make it blank again. Than you can toggle it to the one you like to have it (e.g. DLL).
This is how Flexsim works as far as I know.

Take care
tom the (A)tom
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions."
  #9  
Old 11-21-2007
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default

Hi,

This thought is maybe not on the right place.

I have start looking into using DLL in Flexsim and the only thing I do not like (a matter of taste) is this toggle to DLL. It is probably easier for Flexsim do the coding for this solution.
What I had prefer is to have under Tools menu something like User Add In.
In user Add In the user tells which DLL and functions from that DLL he want to use in the model.
When this is done we could the use the functions from the DLL directly in Flexscript or C++.

The advantage I see that is:
  • I do not need to create User Commands
  • I have one place to see if I use DLL.
  • Do not need to toggle between Flexecript/C++/DLL
Disadvantage is:
  • If using more than one DLL, you can not have the same function name in both DLL.
There are probably more disadvantage.

This is one idea that I think can make use of DLL little easier.

Lars-Olof
  #10  
Old 11-21-2007
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

Lars-Olof,
The reason that the user command/dll thing isn't very user friendly right now is simply because we haven't extended the features of the regular code editor (including quick buttons for toggling code as dll/flexscript/c++) to the user command code editor yet. This will be addressed in the next release, so it will be much easier to connect user commands to dll's in future releases. You will just check the "DLL" radio buttion at the bottom of the user command editor, then specify the dll path and function name for that user command.

I disagree, though, with your assertion that we shouldn't use the user commands window to add dll commands. That's what the user command window is there for, to extend flexscript/c++ functionality, and your suggestion would simply add another unnecessary method by which the user basically does the same thing. Also, the user command mechanism provides a method and encourages the documentation of those commands that you are adding, so that they will be included with the standard command documentation and will be documented for other users who use the model.

Also, on the string issue, right now there are problems in passing strings into and out of user commands. Depending on the calling environment (flexscript/c++/dll), and the callee/user command's internal environment (flexscript/c++/dll), sometimes it can cause memory leaks (I think) and even crashing (I've seen it with the saker guys). The crashing problem was caused when caller was flexscript and callee was c++, and it was fixed when caller was changed to c++. I need to take some time to figure out exactly what the issue is and resolve it. So for now there's no guarantee on passing strings into user commands, meaning do it at your own risk, but eventually I hope to fix that.

Last edited by Anthony Johnson; 11-21-2007 at 10:52 AM.
  #11  
Old 11-21-2007
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default

Anthony,

If you are planing to change the behaviour of the code editor I will wait and try it to see if I like it better.

One thing more. When setting the dll path, how are Flexsim checking for the dll? Is it under Flexsim4\program, Flexsim4\libraries, or are Flexsim checking the model directory?

What I want Flexsim to do when I only write testdll.dll for the dll is ti chech in this order:
  1. In the directory I have the model
  2. In libraries or program under Flexsim installation directory
  3. In the path for Windows.
I can see me to do 2 different type of dll. The first one is unique for each model and the second
is more general that can be used in more then one model.
I in the school that all files belong to one model (program) should be in the same directory, this
make it easier to delete files and move to another computer.

At least think to add a command that returns the path to the model, like the cdir command.
It is easier for user to use a command instead of reading from the tree.
Both cdir and the new command should be able to be used when declaring the path to the dll.
Then the user developing a model can have one structure of directories and a user who only will run models can have a different structure.

I prefer to have the model directory as base, some else want to have Flexsim installation directory as base when calling dll, for input and output files.

Here in Sweden will it be that we at Rejlers will do most of the models and the hand them over to a customer. Therefor would it be great for us to have the model directory as base for all calls for input and output.

Lars-Olof
  #12  
Old 11-26-2007
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Quote:
Originally Posted by Anthony Johnson View Post
Also, on the string issue, right now there are problems in passing strings into and out of user commands.
Anthony,

Does this mean that you can pass strings into a usercommand or even a nodefunction? I know that there is also a parstr function but I thought that it could not be used because then you (being Flexsim) have to overload the functions in every possible parameter combination of string and double? And I have never seen it being used.

Steven
  #13  
Old 11-26-2007
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default DLL search order

Lars-Olof,
Flexsim uses the Windows API's LoadLibrary command to load dll's. I'm attaching the documentation for the dll search found in Visual Studio help. I think the SafeDllSearchMode is a machine specific parameter found in the Windows registry, but it shouldn't matter either way. Right now, you will have to either put the dll in the directory where the executable is found, which is Flexsim4\program\, or make the path to the dll relative to that directory, such as "..\libraries\mydll.dll" and put the dll in the libraries directory. You can also put the dll in the Windows directory, although I personally don't like that idea because I stay away from the Windows system directory as much as I can. Also, the "current directory" is one of the items in the search. In the next release we have changed it so that before loading a dll, Flexsim will change the current directory to the directory of the model, so that if you have your dll stored in the model directory, it can be loaded from there as well.

As a side note, we've also changed it so that media paths can be relative to the model directory, so you can put all of your media in the model directory, and then move the model directory anywhere you want, so you're no longer strapped to the userprojects directory. There will also be additional commands: modeldir(), documentsdir() (for My Documents), and currentfile() (for the path of the current model), and we're going to make default model save/open paths in a My Documents\Flexsim 4 Projects\ directory, so it will be much more of a "windows standard" functionality.

Here's the dll search path documentation:
Quote:
Dynamic-Link Library Search Order

Starting with Windows XP, the dynamic-link library (DLL) search order used by the system depends on the setting of the HKLM\System\CurrentControlSet\Control\Session Manager\SafeDllSearchMode value.
Windows Server 2003: The default value is 1.
Windows XP: The default value is 0.
If SafeDllSearchMode is 1, the search order is as follows:
  1. The directory from which the application loaded.
  2. The system directory. Use the GetSystemDirectory function to get the path of this directory.
  3. The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
  4. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  5. The current directory.
  6. The directories that are listed in the PATH environment variable.
If SafeDllSearchMode is 0, the search order is as follows:
  1. The directory from which the application loaded.
  2. The current directory.
  3. The system directory. Use the GetSystemDirectory function to get the path of this directory.
  4. The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched.
  5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
  6. The directories that are listed in the PATH environment variable.

Last edited by Anthony Johnson; 11-27-2007 at 11:38 PM.
The Following User Says Thank You to Anthony Johnson For This Useful Post:
Brandon Peterson (10-08-2009)
  #14  
Old 11-26-2007
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default

Anthony,

That sounds perfect.

Will it be for version 4.1 or 5?

Lars-Olof

Last edited by Cliff King; 11-26-2007 at 02:52 PM.
  #15  
Old 11-26-2007
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

Steven,
The capability of user commands taking a string is really dependent on how you want users to interact with those user commands. User commands have really always supported the capability to pass strings in, there are just some caveats, depending on the "caller's" environment. If the caller is using c++, then in c++, the user command is always declared as usercommandname(double p1, double p2, double p3,...). So if that is the only overload available to the caller, then he will have to pass in all doubles. If the command wants one of the parameters passed as a string, then the caller (in c++) has to cast the string to a double with tonum(), or else he'll get a compile error. But as long as he uses tonum(), he should be fine calling the user command directly, and the user command would use parstr() to get that parameter out. Now, since the caller is using c++, you can always overload the user command with your own implementations of that command, so that the caller can pass whatever he wants. If the caller is flexscript, however, it's quite different. In flexscript, all calls to that user command will be routed to the nodefunction for that user command, so it doesn't really care whether you pass in "my string" or 5.5 as a parameter, it just calls the nodefunction. And even then, I think you should be able to get a string parameter properly using parstr(). However, I have found that there are some issues with memory leaks/memory corruption if caller is flexscript and callee is (I think) c++. But I'll have to look into this and dig a little deeper before I can say exactly what the issue is. Also, there's the other caveat of how you go about having a user command return a string, which I think might work, but you have to do some special things for it. So for now, even though it may seem to work properly, we discourage people from passing strings into user commands.

Once I have the time to figure out all of this stuff, I'd like to put a detailed help document together to help people out in figuring out how to do all of these caller/callee caveats.
The Following User Says Thank You to Anthony Johnson For This Useful Post:
Brandon Peterson (10-08-2009)
  #16  
Old 11-27-2007
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 225
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

Quote:
Originally Posted by Anthony Johnson View Post
As a side note, I've also changed it so that media paths can be relative to the model directory, so you can put all of your media in the model directory, and then move the model directory anywhere you want, so you're no longer strapped to the userprojects directory. There will also be additional commands: modeldir(), documentsdir() (for My Documents), and currentfile() (for the path of the current model), ...
This is nice to know. Putting model specific files in the same directory as the model improves portability. And to be get the model directory and the model name is a lacking feature of the current version of the Flexsim.

Alan
  #17  
Old 11-27-2007
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 225
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

Quote:
Originally Posted by Lars-Olof Leven View Post
  • I have one place to see if I use DLL.
This could be really an advantage. When I download a new model, I always need to go into each object and to see if any default code have been changed, not only for DLL, but also for Flexscript or C++ code. If the model is big, that is not a simple task. Is there any easy and quick way to know what part of default Flexsim code has been changed when we get a model at the first time? Such a way could benifit both model builders and viewers.

Alan
  #18  
Old 11-27-2007
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

Quote:
Will it be for version 4.1 or 5?
This will all be in 4.1 (actually, I think we're going to call it 4.3 so as not to confuse it with 4.01. We've made a quasi rule to have our "feature" releases be odd numbers whereas our minor or bug-fix releases are even, i.e. 4.02, 4.04 for minor releases, 4.1,4.3,4.5 for feature releases, but we haven't been holding to that rule very well)

Last edited by Anthony Johnson; 11-27-2007 at 09:57 PM.
  #19  
Old 11-27-2007
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

Quote:
Is there any easy and quick way to know what part of default Flexsim code has been changed when we get a model at the first time? Such a way could benifit both model builders and viewers.
For the next release, we've changed the Model Documentation feature in the Reports and Statistics menu so that it is a little more picky as to what it prints out (and it writes to more reader-friendly html format). If you don't check the "Verbose" box, then it will only document parts of objects that have actually been changed from the default.

Funny, I think this thread has gotten a little off its original topic, but oh well. Kind of how conversations go anyway.

Last edited by Anthony Johnson; 11-27-2007 at 11:35 PM.
  #20  
Old 02-20-2009
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

I have added it to this thread because there is already a string issue mentioned here. I have the following problem and I think only Anthony can answer it but I invite anybody else to say something about it.

I have a usercommand that calls a DLL function and it should return a string, so the DLL functions is defined as a string function:

visible string DLL_GetDateStringFromOfficeDays ( FLEXSIMINTERFACE )
{
int OfficeDays = parval(1);
return GetDateStringFromOfficeDays ( OfficeDays );
}


But when I now call the usercommand from within Flexsim via the script window:

string Date = GetDateStringFromOfficeDays( 31000.0);


I get the following error message:


ex: double F_parval(parametersinterface) ex:
exception: parval retrieval
warning: throw - code may have been terminated.
ex: double linkedlist::executememberfunctionwithexceptionhand ling(FLEXSIMINTERFACE) #3 ex: MAIN:/project/model/Tools/GlobalVarGen>variables/commands/GetDateStringFromOfficeDays/code
member function exception handled
details: class: code instance: code code: 0
warning: throw - code may have been terminated.
ex: Exception caught in flexscript execution of ex: line 1 instruction 3. Discontinuing execution.
ex: Exception caught in flexscript execution of ex: line 1 instruction 3. Discontinuing execution.
ex: Exception caught in flexscript execution of ex: line 1 instruction 3. Discontinuing execution.


And I have no idea what exactly is going on. I assume it has something todo with passing a string which is not appreciated by Flexsim

Any suggestions?

Steven



All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.