发帖
 找回密码
 立即注册
搜索
4 0 0

flexsim代码区起始部位代码解析

技术交流2 4 4 2013-9-12 13:51:36
[i=s] 本帖最后由 zorsite 于 2013-9-12 20:14 编辑 [/i]

在触发器中常会看到顶端已经自动写好的一些代码,通常如下: [code]treenode current = ownerobject(c);
treenode item = parnode(1);
int port = parval(2);[/code] 
意思大概是声明了三个变量,current表示当前实体,item表示当前临时实体,port表示端口。
在接下来的代码中可以直接引用这三个已经声明好了的变量。
对于初学者来说,这段神奇的文字就像各种分布一样让人不解其意。
下面是我自己的一点不成熟的理解,有些地方也不明白,可能理解有误的地方,请大家帮忙释疑、纠正、完善。

[size=4]treenode[/size]
Variable Types
Flexsim uses just four variable types. Each of the four types can also be used in an array structure. The following explains each of these types.
Type Description
[color=darkorange]int[/color]  integer type  
[color=darkorange]double[/color]  double precision floating point type  
[color=darkorange]string[/color]  text string  
[color=darkorange]treenode[/color]  reference to a Flexsim node or object  
[color=sienna]flexsim中有4种类型的变量:int,double,string,treenode。treenode指的是flexsim中的一个节点或者一个实体。[/color]

[size=4]current<no parentheses>[/size]
[color=darkred]Description:[/color]  
Deprecated. This should not be [color=darkgreen]used[/color] as a special command[color=blue] [/color][color=darkgreen]with [/color]the setcurrent command anymore. Instead, declare a treenode variable type as current, then use current in your code [color=darkolivegreen]as any other variable type.[/color]
[color=sienna]不建议使用。current和setcurrent不应再被用作命令。如果需要设置某实体为当前实体,应先声明一个名为current的树节点型变量,然后在代码中引用该变量。[/color]
[color=sienna]不解:
1.used...with....是什么意思?
以前current是必须和setcurrent一起使用的吗?

2.as any other variable type是什么意思?
前面说要声明一个名为current的树结点型变量,然后在代码中可以把current作为任意类型的变量使用?可以用为string型变量吗?[/color]
[color=darkred]Example:
[/color][code]treenode current = rank(model(),3);
pt(getname(current));[/code] 
This sets the object that is ranked 3 in the model to current and prints its name to the output console.  


[size=4]ownerobject(node thenode)
[/size][color=darkred]Description:[/color]
This command returns the node with object data attached to it that is the start of the sub-tree that thenode is in. In other words, it returns the object node that contains thenode.
This command is used in most code fields and trigger fields to set the access variable current. In these fields, c references the node that contains the code, and ownerobject(c) references the object that "owns" that node.
[font=Calibri][color=sienna]该函数返回参数节点所在的实体。[/color][/font]

[color=darkred]Example:
[/color][code]string objname = getname(ownerobject(c));[/code] 
This sets objname to the name of the object that contains the node referenced by c. The c usually refers to the node where the code is being written.   [code]treenode current = ownerobject(c);[/code] 
This example is present in most code fields in Flexsim, and retrieves access to the "current" object.
[color=sienna]这段代码出现在大多数flexsim代码的开头部位,指的是“当前”实体,就是代码所在实体。[/color]

[size=4]c<no parentheses>[/size]
[color=darkred]Description:[/color]  
This command is used to reference the active node during a function's execution.
If the function was called using nodefunction(), c returns a reference to the node on which the function is written.
If the function is an event function, c returns a reference to the object that contains the event.
[color=sienna]c在函数执行的过程中指向活动实体。[/color]
[color=sienna]如果是节点型函数,c指向函数所在实体,[/color]
[color=sienna]如果是事件型函数,c指向事件所在实体。[/color]
[color=darkred]Example: [/color][code]treenode current = ownerobject(c);[/code] 

[size=4]setcurrent(thing)
[/size][color=darkred]Description: [/color]Deprecated. Do not use.
[color=darkred]Example:[/color] /
[color=sienna]此命令不再使用。[/color]

[size=4]item<no parentheses>
[/size][color=darkred]Description:[/color]  
Deprecated. This should not be used as a special command with the setitem command anymore. Instead, declare a treenode variable type as item, then use item in your code as any other variable type.
[color=sienna]不要再使用item和setitem命令了。如果需要指向某一临时实体,应该先声明一个名为item的树节点型变量,然后在代码中引用该变量。[/color]
[color=darkred]Example: [/color][code]treenode item = rank(model(),3);
pt(getname(item));[/code] 
This sets the object that is ranked 3 in the model to item and prints its name to the output console.  


[size=4]setitem(thing)
[/size][color=darkred]Description: [/color]Deprecated. Do not use.
[color=darkred]Example:[/color] /
[color=#a0522d]此命令不再使用。[/color]
[color=#a0522d][/color]
[size=4]parnode(num index)[/size]
[color=darkred]Description:  [/color]
This command is used inside a function that is called by the nodefunction() command.
[color=sienna]此命令用在一个被nodefunction调用的函数中。"nodefunction() command"指的是什么?command和function有何不同?[/color]
It returns the parameter passed to nodefunction specified by index as a node (or treenode).
[color=#a0522d]此命令返回一个节点(或树结点)参数.该参数由序号指定,并会传递给nodefunction.[/color]
[color=#a0522d]节点和树节点有何不同?[/color]
The first additional parameter passed to nodefunction() is parameter 1, the second is parameter 2, etc.
[color=sienna]parnode,parval,parstr这三个命令真是让人搞不懂啊...[/color]
Parameters can also be retrieved using parval() and parstr() for casting them as numbers and strings respectively.
[color=darkred]Example:[/color]
If a trigger/field is called with:
nodefunction(thefuncnode, item)
then within the trigger/field, getting access to the item passed [color=red]as the first additional parameter[/color] would be done with:[code]treenode item = parnode(1); [/code]  

[size=4]port<no parentheses>[/size]
[color=darkred]Description: [/color]
Deprecated. This should not be used as a special command with the setport command anymore. Instead, declare an int variable type as port, then use port in your code as any other variable type.
[color=darkred]Example:[/color]
[color=darkred][/color][code]int port = parval(3);
pd(port);[/code] 
This sets port to parval(3) and then prints the value to the output console.

[color=sienna]不推荐使用。port和setport都不应再作为命令来使用。如果在代码中需要使用端口,需要声明一个名为port的整数型变量,然后在代码中直接使用port作为变量。[/color]
──── 0人觉得很赞 ────
2013-9-17 13:56:40
[b] [url=http://www.flexsim.asia/redirect.php?goto=findpost&pid=10804&ptid=4176]1#[/url] [i]zorsite[/i] [/b]


首先谢谢加老师分享,我在这里也补充一下,对于加老师你讲到的”c“,我们一般都是在代码框和做GUI时会遇得多些,下面我具体讲一下他们的区别。
    首先在GUI中,它是这样的,如下图:
而在代码框中却是这样的,如下图:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
2014-8-10 18:29:45
大神啊,解决了我多日的困惑:D
2014-8-11 13:56:35
额,很值得一看
2014-8-20 10:01:35
C 一扫疑惑,  但parval(),parnode() 还是有点不解
您需要登录后才可以回帖 立即登录
高级模式
返回
技术交流2
热门问答
查看更多
1
Flexsim初级建模工程师水平标准
Flexsim初级建模工程师水平标准
60
234
2
厂区生产线布局优化案例!新做的!
厂区生产线布局优化案例!新做的!
39
224
3
流水作业线的仿真
流水作业线的仿真
36
83
4
无意中找到的资料,非常适合于初学者
无意中找到的资料,非常适合于初学者
33
229
5
flexsim中文教程,pdf文档已整理-重新整理
flexsim中文教程,pdf文档已整理-重新整理
30
114
博主榜
+ 5