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
  1. Check the Modify Item dialog box>Attributes Tab in PRT_UI

Procedure

  1. Open the PRT_UI
  2. Open the Modify Item dialog box for any of the blocks that you added through CimView.
  3. 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.

    1. Create a New Region Object in the Add Blocks Button's Script
  4. Open the script that runs when you click the Add Blocks button.
  5. Create a new region object after all of your existing code, but before the End Sub statement:

    Enter:

    Dim Region As New PrtRegion

  6. Specify the region where the items exist that you want to change.

    Enter:

    Region.Id="SCHEDULE"

    1. Create a Set of String Variables that will Hold the Attribute Names

    Notice that you add the attributes CUST ORDER # and COLOR 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$ = " "

    1. Set up the Attributes for the Block Items
  7. 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

  8. Now that you have the item list, you can determine how many items exist.
    1. Use the itemcount property.
    2. 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 the value$ variable is an empty string, the script that will be tested
    • Will create the attributes.
    • Will not assign any values.
    1. Check the PRT_UI window to Verify that the Attributes were Added
  9. Open the PRT_UI window.
  10. Select the SCHEDULE region.
  11. Open the Modify Item dialog box>Attributes tab for any item created in CimView using the new script.

    Result: The attributes should display .

    1. 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)
  12. 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:
    Region.Item(j).SetAttr A1$, Value$
    Region.Item(j).SetAttr A2$, Value$
    To:
    Region.Item(j).SetAttr A1$, Order$
    Region.Item(j).SetAttr A2$, Color$
  13. Compile the script.
  14. Close the Edit Script window.
  15. Close the Properties - Object dialog box.
    1. Test the new Add Blocks Button Script
  16. Open the CIMPTRACK CimView screen.
  17. Click the Add Blocks button.

    The Item number should increase in the SCHEDULE region.

  18. Open the PRT_UI window>SCHEDULE region.
  19. 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.