/* ------------------------------------------------------------
Title : Create Load / Unload / Transform Activities + Group
Purpose : For a given machine resource, create a Load,
Unload, Transform and a Group Activity only if
they do not already exist.
Description : The script resolves the machine via its occurrence,
checks existing activities using the appropriate
getters (GetLoadedItems, GetUnloadedItem,
GetTransformInputItems, GetTransformOutputItems),
creates any missing activities, creates a Group
Activity if none exists and adds the newly created
activities to the group.
Arguments :" MfgProduct--> ProductOccurance"
" Res1--> ProductOccurance"
------------------------------------------------------------ */
// ----------------------------------------------------------------
// 1️⃣ Resolve the machine resource from its occurrence reference.
// ----------------------------------------------------------------
let root (VPMReference)
root = GetEditorRoots("VPMReference").GetItem(1)
let machineInst (VPMInstance)
machineInst = Res1.Instance // instance of the machine reference
let rootRevision (String)
rootRevision = root.revision
let occPath (String)
occPath = root.Name + " " + rootRevision + "\\" +
root.CreatePathString(NULL, Res1)
occPath = ReplaceAll(occPath, "\\", "/")
let machineRes (FFS_Resource)
machineRes = CreateOrRetrieveResourceFromOccurrencePath(occPath)
// ----------------------------------------------------------------
// 2️⃣ Retrieve the part “O1” as an FFS_Item (using the occurrence‑path API)
// ----------------------------------------------------------------
let productPath (String)
productPath = "O1" // edit if a different occurrence path is needed
let partItem (FFS_Item)
partItem = GetItemFromName(productPath, MfgProduct)
// ----------------------------------------------------------------
// 3️⃣ Determine which activities already exist on the machine.
// ----------------------------------------------------------------
let allActs (List) // List[FFS_Activity]
allActs = machineRes.GetActivities()
// Flags – assume they do NOT exist until proven otherwise
let loadExists (Boolean)
loadExists = FALSE
let unloadExists (Boolean)
unloadExists = FALSE
let transExists (Boolean)
transExists = FALSE
let groupExists (Boolean)
groupExists = FALSE
// Scan the activity list
let aIdx (Integer)
aIdx = 1
for aIdx while aIdx <= allActs.Size()
{
// Generic activity reference
let curAct (FFS_Activity)
curAct = allActs.GetItem(aIdx)
// ------------------------------------------------------------
// Load activity check (GetLoadedItems)
// ------------------------------------------------------------
let ldAct (FFS_LoadActivity)
set ldAct = curAct // cast – will be NULL if not a LoadActivity
if ldAct <> NULL
{
let loadedItems (List) // List[FFS_Item]
loadedItems = ldAct->GetLoadedItems()
if loadedItems <> NULL
{
let li (Integer)
li = 1
for li while li <= loadedItems.Size()
{
let liItem (FFS_Item)
liItem = loadedItems.GetItem(li)
if liItem <> NULL AND liItem.Name == partItem.Name
{
loadExists = TRUE
BREAK
}
}
}
}
// ------------------------------------------------------------
// Unload activity check (GetUnloadedItem)
// ------------------------------------------------------------
let uldAct (FFS_UnloadActivity)
set uldAct = curAct
if uldAct <> NULL
{
let unloadedItem (FFS_Item)
unloadedItem = uldAct->GetUnloadedItem()
if unloadedItem <> NULL AND unloadedItem.Name == partItem.Name
{
unloadExists = TRUE
}
}
// ------------------------------------------------------------
// Transform activity check (inputs & outputs)
// ------------------------------------------------------------
let TAct (FFS_TransformActivity)
set TAct = curAct
if TAct <> NULL
{
let transIn (List) // List[FFS_Item]
let transOut (List) // List[FFS_Item]
transIn = TAct->GetTransformInputItems()
transOut = TAct->GetTransformOutputItems()
if transIn <> NULL AND transOut <> NULL
{
let inMatch (Boolean)
inMatch = FALSE
let outMatch (Boolean)
outMatch = FALSE
let ti (Integer)
ti = 1
for ti while ti <= transIn.Size()
{
let tiItem (FFS_Item)
tiItem = transIn.GetItem(ti)
if tiItem <> NULL AND tiItem.Name == partItem.Name
{
inMatch = TRUE
BREAK
}
}
ti = 1
for ti while ti <= transOut.Size()
{
let toItem (FFS_Item)
toItem = transOut.GetItem(ti)
if toItem <> NULL AND toItem.Name == partItem.Name
{
outMatch = TRUE
BREAK
}
}
if inMatch AND outMatch
{
transExists = TRUE
}
}
}
// ------------------------------------------------------------
// Group activity check (any GroupActivity present)
// ------------------------------------------------------------
let grplst (List)
grplst = machineRes.GetGroupActivities()
if grplst.Size() <> 0
{
groupExists = TRUE
}
// If everything we need already exists we can stop scanning
if loadExists AND unloadExists AND transExists AND groupExists
{
BREAK
}
}
// ----------------------------------------------------------------
// 4️⃣ Build the input lists only if the corresponding activity is missing.
// ----------------------------------------------------------------
let loadList (List)
if loadExists == FALSE
{
loadList.Append(partItem) // Load needs List[FFS_Item]
}
let unloadItem (FFS_Item)
if unloadExists == FALSE
{
unloadItem = partItem // Unload takes a single FFS_Item
}
let transformInputs (List)
let transformOutputs (List)
if transExists == FALSE
{
transformInputs.Append(partItem) // Transform inputs list
transformOutputs.Append(partItem) // Transform outputs list
}
// ----------------------------------------------------------------
// 5️⃣ Create missing activities.
// ----------------------------------------------------------------
let loadAct (FFS_LoadActivity)
if loadExists == FALSE
{
loadAct = machineRes.AddLoadActivity(loadList) // EKL_FFS_OpenessList (1).txt
}
let unloadAct (FFS_UnloadActivity)
if unloadExists == FALSE
{
unloadAct = machineRes.AddUnloadActivity(unloadItem) // EKL_FFS_OpenessList (1).txt
}
let transformAct (FFS_TransformActivity)
if transExists == FALSE
{
transformAct = machineRes.AddTransformActivity(
transformInputs, transformOutputs) // EKL_FFS_OpenessList (1).txt
}
// ----------------------------------------------------------------
// 6️⃣ Ensure a Group Activity exists and add any newly created activities
// to that group.
// ----------------------------------------------------------------
let groupAct (FFS_GroupActivity)
// If a group already exists, retrieve the first one; otherwise create a new group
if groupExists == FALSE
{
groupAct = machineRes.AddGroupActivity() // EKL_FFS_OpenessList (1).txt
}
else
{
// Retrieve the existing group activities list and take the first group
let existingGroups (List)
existingGroups = machineRes.GetGroupActivities()
groupAct = existingGroups.GetItem(1) // assume at least one group exists
}
// Add the newly created activities (if any) to the group
if loadExists == FALSE
{
groupAct.AddActivity(loadAct)
}
if unloadExists == FALSE
{
groupAct.AddActivity(unloadAct)
}
if transExists == FALSE
{
groupAct.AddActivity(transformAct)
}
// ------------------------------------------------------------
// End of script
// ------------------------------------------------------------