<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create object using custom code in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539706#M46774</link>
    <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;I have written the code OnRunStart&lt;/P&gt;
 &lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1658743479525.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1511625iB20688C06C20CB95/image-size/large?v=v2&amp;amp;px=999" role="button" title="1658743479525.png" alt="1658743479525.png" /&gt;&lt;/span&gt;&lt;/P&gt;
 &lt;P&gt;But I am getting this error.&lt;/P&gt;
 &lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Image.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1520006i83B4E9ACAF5A0FAC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Image.png" alt="Image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
 &lt;P&gt;What keyvalue should be used?&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Mon, 25 Jul 2022 10:01:00 GMT</pubDate>
    <dc:creator>anjunittur123</dc:creator>
    <dc:date>2022-07-25T10:01:00Z</dc:date>
    <item>
      <title>Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539697#M46765</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 20.0.10 ]&lt;/I&gt;&lt;/P&gt;&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;In my model, I want to generate 25 items on floor storage type rack using code (no process flow).&lt;/P&gt;
 &lt;P&gt;Unless I connect source to floor storage, it is not generating any item. After I connect source and use the createcopy(), it is generating 150 items for the one time looping in the source inter-arrival code.&lt;/P&gt;
 &lt;P&gt;Also I want to assign label to each item through code. The labels should be assigned during the generation of the items.&lt;/P&gt;
 &lt;P&gt;Can you please help? &lt;A rel="user" href="https://answers.flexsim.com/users/19365/felixmh.html" nodeid="19365"&gt;@Felix Möhlmann&lt;/A&gt;&lt;/P&gt;
 &lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/55376-create-object-using-code.fsm" target="_blank"&gt;Create_object_using code.fsm&lt;/A&gt;&lt;/P&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
 &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 22 Jul 2022 09:20:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539697#M46765</guid>
      <dc:creator>anjunittur123</dc:creator>
      <dc:date>2022-07-22T09:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539698#M46766</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;Where did you put the code before adding the source?&lt;/P&gt;&lt;P&gt;You always need some event to trigger the execution of the code. The 'On Run Start' model trigger might be a good option for this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1658483747340.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1511623i59AB13A8EEC045D1/image-size/large?v=v2&amp;amp;px=999" role="button" title="1658483747340.png" alt="1658483747340.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Instead of creating the item directly in the storage, you might want to first create them in the model and then move them into the storage ('moveobject(object, destination)'). Otherwise the placement logic won't work correctly.&lt;/P&gt;&lt;P&gt;The 'createcopy()' command returns a reference to the created object (which you already assign to the 'item' variable). As such you can assign labels with the normal syntax (item.labelName = value).&lt;/P&gt;&lt;PRE&gt;if(Model.time == 0) // Only on first start
{
&amp;nbsp; &amp;nbsp; // Get references to reuse them in the loop
&amp;nbsp; &amp;nbsp; Object destination = Model.find("FloorStorage1");
&amp;nbsp; &amp;nbsp; treenode flowItem = Model.find("/Tools/FlowItemBin/Box/1");
&amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; for(int i = 1; i &amp;lt;= 25; i++)
&amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Object item = createcopy(flowItem, model());
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;item.creationRank = i;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;moveobject(item, destination);
&amp;nbsp; &amp;nbsp; }
}&lt;/PRE&gt;&lt;P&gt;Because you put the code in the inter-arrival time but don't return any value (the time value that is expected from the code), the value is assumed to be zero and the inter-arrival time triggers again immediately. This repeats until the storage is full.&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/55367-create-object-using-code-fm.fsm" target="_blank"&gt;create-object-using-code-fm.fsm&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 22 Jul 2022 10:03:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539698#M46766</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2022-07-22T10:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539699#M46767</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Thank you &lt;A rel="user" href="https://answers.flexsim.com/users/19365/felixmh.html" nodeid="19365"&gt;@Felix Möhlmann&lt;/A&gt; , If i want to assign label in the code to each box?&lt;/P&gt;
 &lt;P&gt;Also I want to generate boxes on top of pallets, how to do this purely with code OnRunStart?&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2022 02:26:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539699#M46767</guid>
      <dc:creator>anjunittur123</dc:creator>
      <dc:date>2022-07-25T02:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539700#M46768</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;"If i want to assign label in the code to each box?"&lt;/P&gt;&lt;P&gt;That is what the code in my answer does. Could you specify what should be different to the way the way that code works?&lt;/P&gt;&lt;P&gt;To generate the boxes on pallets, create a pallet. For that just adjust the path in the find() command to refer to the pallet flow item instead. Then move the box into the pallet with 'moveobject(object, destination)'. &lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2022 06:00:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539700#M46768</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2022-07-25T06:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539701#M46769</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 Yes , I am able to generate boxes on pallets using the commands. Thank you
 &lt;P&gt;"To assign label"&lt;/P&gt;
 &lt;P&gt;I want to assign particular part number to each part. The creationrank assigns unique numbers to all the parts. Similarly I want to assign part name as "Part1", "Part2"...&lt;/P&gt;
 &lt;P&gt;How to do that?&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2022 06:22:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539701#M46769</guid>
      <dc:creator>anjunittur123</dc:creator>
      <dc:date>2022-07-25T06:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539702#M46770</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;The for-loop works by incrementing an index variable 'i'. You can use that variable to determine which value should be assigned to the label. This could be the number itself, like above. &lt;/P&gt;&lt;P&gt;Or the data could be stored in a table and the index is used as the rows number.&lt;/P&gt;&lt;PRE&gt;item.labelName = Table(...)&lt;I&gt;[column];&lt;/I&gt;&lt;/PRE&gt;&lt;P&gt;To use the number as part of a text, such as 'Part1', you first have to convert it into a string variable.&lt;/P&gt;&lt;PRE&gt;item.labelName = "Part" + string.fromNum(i);&lt;/PRE&gt;&lt;P&gt;The name of an item can be changed similar to labels, through the 'name' property.&lt;/P&gt;&lt;PRE&gt;item.name = "...";&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2022 07:00:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539702#M46770</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2022-07-25T07:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539703#M46771</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 Thank you 
 &lt;A rel="user" href="https://answers.flexsim.com/users/19365/felixmh.html" nodeid="19365"&gt;@Felix Möhlmann&lt;/A&gt; it was helpful
&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2022 07:30:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539703#M46771</guid>
      <dc:creator>anjunittur123</dc:creator>
      <dc:date>2022-07-25T07:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539704#M46772</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;Hi &lt;A rel="user" href="https://answers.flexsim.com/users/19365/felixmh.html" nodeid="19365"&gt;@Felix Möhlmann&lt;/A&gt; , I am storing part destination data in global table, what is the command to reference it using code? &lt;/P&gt;
 &lt;P&gt;I am using Model.find() as of now to refer each buffer. I have 10 buffers to send parts. In that case, how can I read the row and column from global table and use it to find the destination of that part?&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2022 08:49:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539704#M46772</guid>
      <dc:creator>anjunittur123</dc:creator>
      <dc:date>2022-07-25T08:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539705#M46773</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;PRE&gt;Table(tableName)[row][column]&lt;/PRE&gt;&lt;P&gt;If you first need to find the correct row by looking up a value in a different column, you can use&lt;/P&gt;&lt;PRE&gt;Table(tableName).getRowByKey(keyValue, keyColumn)&lt;/PRE&gt;&lt;P&gt;The key value could be a label value or the name, etc.&lt;/P&gt;&lt;P&gt;So together it would be something like this:&lt;/P&gt;&lt;PRE&gt;int row = Table(tableName).getRowByKey(keyValue, keyColumn);
string destName = Table(tableName)[row]['destColumn'];
Object destination = Model.find(destName);&lt;/PRE&gt;&lt;P&gt;All in one command&lt;/P&gt;&lt;PRE&gt;Model.find(Table(...)&lt;TABLE&gt;[destColumn])&lt;/TABLE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2022 09:15:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539705#M46773</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2022-07-25T09:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539706#M46774</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;I have written the code OnRunStart&lt;/P&gt;
 &lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1658743479525.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1511625iB20688C06C20CB95/image-size/large?v=v2&amp;amp;px=999" role="button" title="1658743479525.png" alt="1658743479525.png" /&gt;&lt;/span&gt;&lt;/P&gt;
 &lt;P&gt;But I am getting this error.&lt;/P&gt;
 &lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Image.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1520006i83B4E9ACAF5A0FAC/image-size/large?v=v2&amp;amp;px=999" role="button" title="Image.png" alt="Image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
 &lt;P&gt;What keyvalue should be used?&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2022 10:01:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539706#M46774</guid>
      <dc:creator>anjunittur123</dc:creator>
      <dc:date>2022-07-25T10:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539707#M46775</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;You declare (or 'create') the 'item' variable inside the for-loop. It is therefor only valid inside that 'scope'. A scope is defined by the {}-parentheses. The entire if-statement is also a scope. You can use variables in a scope that is nested within (like how you can use 'destination' inside the for-loop, but not the other way around).&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="1658743843390.png"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1511627iFB966020950CEC08/image-size/large?v=v2&amp;amp;px=999" role="button" title="1658743843390.png" alt="1658743843390.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Because 'item' is not defined at that point, 'KitName' can't be read from it (one of the errors) and 'getRowByKey()' returns 0, which is not a valid row number (first error).&lt;/P&gt;&lt;P&gt;What is your goal here? If you want to assign 'destination2' to the item, then that should also happen within the for-loop. Iin this case you also already know the row through the index 'i'.&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 25 Jul 2022 10:14:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539707#M46775</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2022-07-25T10:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539708#M46776</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 &lt;P&gt;I agree with you &lt;A rel="user" href="https://answers.flexsim.com/users/19365/felixmh.html" nodeid="19365"&gt;@Felix Möhlmann&lt;/A&gt; &lt;/P&gt;
 &lt;P&gt;My goal here is to refer the destination from global table to be sent to buffer. In this example model below, I want to send the item to 2 buffers referencing from the global table "destination" column.&lt;/P&gt;
 &lt;P&gt;Can you tell me what mistake I am doing here?&lt;/P&gt;
 &lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/55527-create-object-using-code.fsm" target="_blank"&gt;create-object-using-code.fsm&lt;/A&gt;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 26 Jul 2022 02:57:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539708#M46776</guid>
      <dc:creator>anjunittur123</dc:creator>
      <dc:date>2022-07-26T02:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539709#M46777</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;&lt;P&gt;You correctly determine the destination object but you don't do anything with that information. The code just ends after the 'destination2' variable is declared.&lt;/P&gt;&lt;P&gt;If you need the reference to the destination object later, for example in a process flow, you should write it to a label on the item.&lt;/P&gt;&lt;P&gt;If you know that the dest. object is connected to the current object via an a-connection, you can also directly assign the corresponding port number with 'ipopno()' and use that in the 'Send to Port' field.&lt;/P&gt;&lt;P&gt;You can of course also combine these: Assign the object reference to a label and then use 'ipopno' in Send to Port.&lt;/P&gt;&lt;P&gt;&lt;A rel="noopener noreferrer" href="https://answers.flexsim.com/storage/attachments/55541-create-object-using-code1.fsm" target="_blank"&gt;create-object-using-code(1).fsm&lt;/A&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 26 Jul 2022 06:32:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539709#M46777</guid>
      <dc:creator>moehlmann_fe</dc:creator>
      <dc:date>2022-07-26T06:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create object using custom code</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539710#M46778</link>
      <description>&lt;DIV class="fr-view clearfix"&gt;
 Thank you for the help and for solving the queries.
&lt;/DIV&gt;</description>
      <pubDate>Tue, 26 Jul 2022 08:37:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/create-object-using-custom-code/m-p/13539710#M46778</guid>
      <dc:creator>anjunittur123</dc:creator>
      <dc:date>2022-07-26T08:37:47Z</dc:date>
    </item>
  </channel>
</rss>

