6.3. Create a Script to add Attributes to Block Items
About this task
You can use a script to apply attributes to blocks that you create using the CIMPTRACK CimView screen.
A | Check the Modify Item dialog box>Attributes Tab in PRT_UI |
B | Create a New Region Object in the Add Blocks Button's Script |
C | Create a Set of String Variables that will Hold the Attribute Names |
D | Set up the Attributes for the Block Items |
E | Check the PRT_UI window to Verify that the Attributes were Added |
F | Assign Random Values to Selected Block Item Attributes |
G | Test the new Add Blocks Button Script |
- Check the Modify Item dialog box>Attributes Tab in PRT_UI
Procedure
- Open the PRT_UI
- Open the Modify Item dialog box for any of the blocks that you added through CimView.
-
Select the Attributes tab.
You can see that there are no attributes.
That is because when you created the attributes before you used the prt_attributes.cfg file. So they will be listed with an item when you add it through the PRT_UI, not when you add it using code.
You have to write more code to add attributes to a particular item.
- Create a New Region Object in the Add Blocks Button's Script
- Open the script that runs when you click the Add Blocks button.
-
Create a new region object after all of your existing code, but before the
End Sub
statement:Enter:
Dim Region As New PrtRegion
-
Specify the region where the items exist that you want to change.
Enter:
Region.Id="SCHEDULE"
- Create a Set of String Variables that will Hold the Attribute Names
Notice that you add the attributes
CUST ORDER #
andCOLOR
to the block items in this step.Enter:
A1$ = "CUST ORDER #" A2$ = "COLOR" A3$ = "CPU SER #" A4$ = "BASE PLATFORM" A5$ = "DRIVE HOUSING" A6$ = "SUB_ASSEMBLY A" A7$ = "SUB_ASSEMBLY B" A8$ = "ASSEMBLY HOUSING" A9$ = "POWER SUPPLY" A10$ = "PROD START TIME" A11$ = "AUTOCELL MACHINE" A12$ = "AUTOCELL TEMP" A13$ = "AUTOCELL PRESS" A14$ = "AUTOCELL TIME" A15$ = "DVD" A16$ = "MANUALS" A17$ = "WARRANTY" A18$ = "PACK TIME" value$ = " "
- Set up the Attributes for the Block Items
-
Create a loop that counts from 0 to the (total number of items - 1) in the region.
This will get the total number of items that exist in the region.
Enter:
Region.GetItemList
-
Now that you have the item list, you can determine how many items exist.
-
Use the
itemcount
property. - Loop through and modify the items to include all of the appropriate attributes.
Enter:
For j=0 To Region.ItemCount - 1 Region.Item(j).SetAttr A1$, Value$ Region.Item(j).SetAttr A2$, Value$ Region.Item(j).SetAttr A3$, Value$ Region.Item(j).SetAttr A4$, Value$ Region.Item(j).SetAttr A5$, Value$ Region.Item(j).SetAttr A6$, Value$ Region.Item(j).SetAttr A7$, Value$ Region.Item(j).SetAttr A8$, Value$ Region.Item(j).SetAttr A9$, Value$ Region.Item(j).SetAttr A10$, Value$ Region.Item(j).SetAttr A11$, Value$ Region.Item(j).SetAttr A12$, Value$ Region.Item(j).SetAttr A13$, Value$ Region.Item(j).SetAttr A14$, Value$ Region.Item(j).SetAttr A15$, Value$ Region.Item(j).SetAttr A16$, Value$ Region.Item(j).SetAttr A17$, Value$ Region.Item(j).SetAttr A18$, Value$ Region.Item(j).Modify Next j
Note: Since thevalue$
variable is an empty string, the script that will be tested- Will create the attributes.
- Will not assign any values.
- Check the PRT_UI window to Verify that the Attributes were Added
-
Use the
- Open the PRT_UI window.
- Select the SCHEDULE region.
-
Open the Modify Item dialog box>Attributes tab for any item created in CimView using the new script.
Result: The attributes should display .
- Assign Random Values to Selected Block Item Attributes
You can use a script to assign random selected attribute values automatically.
For this project, have values assigned to the following in the SCHEDULE region.
- Customer Order #'s
- Colors (RED, GREEN and BLUE)
-
Add the following code to the script.
A Note: After For j=0 To Region.ItemCount - 1 Enter: '****Random cust. order numbers and colors*************** Order$ = " " Color$ = " " Number = Random(5000,9999) Order$ = Number If(Number Mod 3) = 0 Then Color$ = "RED" ElseIf(Number Mod 3) = 1 Then Color$ = "GREEN" Else Color$ = "BLUE" End If '****End Random generation***************************
B Note: Replace existing code to add two specific values to the .modify
method Change:
To:Region.Item(j).SetAttr A1$, Value$ Region.Item(j).SetAttr A2$, Value$
Region.Item(j).SetAttr A1$, Order$ Region.Item(j).SetAttr A2$, Color$
- Compile the script.
- Close the Edit Script window.
-
Close the Properties - Object dialog box.
- Test the new Add Blocks Button Script
- Open the CIMPTRACK CimView screen.
-
Click the Add Blocks button.
The Item number should increase in the SCHEDULE region.
- Open the PRT_UI window>SCHEDULE region.
- Open the Modify Item dialog box>Attributes tab for any of the listed blocks.
Results
The CUST ORDER # and COLOR attributes should have assigned values.