SYNCHRO SCRIPT

There are many questions when we want to do one action using Synchro Script.

First step is to learn from Synchro Help.

Second, you can always search from Synchro Community page:

SYNCHRO Construction Solution - Bentley Communities

   

 

Here we have some example script that may help you to start your script learning journey.

Create User Field and Calculation:

  1. Calculate from Resource to Task Level

TASK  ASSIGN_UF ("MHour" , FLOAT , 0 )
TASK  ASSIGN_UF ("MHour" , FLOAT , SUM(RESOURCE.UFV ("MHour") )

  1. Get Total MHour - WBS Level

TASK (NUM_CHILDREN>0) ASSIGN_UF ("MHour" ,FLOAT, SUM (CHILD.UFV ("MHour") )

  1. Copy UFV from String to Numeric

RESOURCE ASSIGN_UF("[SYNC]Volume", FLOAT, UFV("Volume"))

  1. Copy UF to other UF

3D (EXIST  UFV("WBS_A")) ASSIGN_UF ("WBS",STRING,STRING(UFV("WBS_A")))

  1. Create UF for Group to get multi TASK using MODIFY_UF_NAME

GROUP ASSIGN_UF(MODIFY_UF_NAME , "TASK NAME" , STRING ,  EACH (TASK.PROPERTY("Name")))

  1. Create UF for Delayed days (planned date – baseline date)

TASK ASSIGN_UF("Synchro Delay", FLOAT, (PROPERTY("Planned Start") - PROPERTY("BL Early Start")) / ( 3600*24 )  )

  1. Compare duration

TASK ( PROPERTY("Actual Duration") <= PROPERTY("Planned Duration") )  ASSIGN_UF ("ALERT" , STRING , "OFF" )  
TASK ( PROPERTY("Actual Duration") >  PROPERTY("Planned Duration") )  ASSIGN_UF ("ALERT" , STRING , "ON" )  

  1. Create UF = Sum of certain Status Name

TASK(SELECTED) ASSIGN_UF("Task Complete Quantity ", DOUBLE, SUM(RESOURCE(STATUS_NAME("Default category")=="Status Name").UFV("Complete Quantity")))

  1. To copy “Level” attribute from Parent to Child. 

RESOURCE(SELECTED AND NUM_CHILDREN == 0)  ASSIGN_UF ("Level" ,STRING, PARENT.PARENT.UFV("Level"))
RESOURCE(SELECTED AND NUM_CHILDREN == 0)  ASSIGN_UF ("Level" ,STRING, PARENT.UFV("Level"))

  1. To copy “Level” attribute from Child to Parent. 

RESOURCE ASSIGN_UF ("Isometric", STRING, CHILD(NUM_CHILDREN == 0 AND EXIST UFV("Isometric") >= "").UFV("Isometric"))

 

Set Resource Status:

  1. Update Resource Status from Task User Field

TASK(SELECTED AND  STRING(UFV("Material Status")) == "No Material" ).RESOURCE (NOT STATUS_HISTORY("Material Status") >="No Material")  SET_PROPERTY (STATUS_NAME  , "Material Status::Construction Component::"+ "No Material")


TASK(SELECTED AND  STRING(UFV("Material Status")) == "Partially Allocatted" ).RESOURCE (NOT STATUS_HISTORY("Material Status") >="Partially Allocatted")  SET_PROPERTY (STATUS_NAME  , "Material Status::Construction Component::"+ "Partially Allocatted")

TASK(SELECTED AND  STRING(UFV("Material Status")) == "Fully Allocated" ).RESOURCE (NOT STATUS_HISTORY("Material Status") >="Fully Allocated")  SET_PROPERTY (STATUS_NAME  , "Material Status::Construction Component::"+ "Fully Allocated")

  1. Update Resource Status from Task %Complete

TASK(SELECTED AND PROPERTY("% Complete") = 0 ).RESOURCE (NOT STATUS_HISTORY("Installation Status") >="Not Started")  SET_PROPERTY (STATUS_NAME  , "Installation Status::Construction Component::"+ "Not Started")


TASK(SELECTED AND PROPERTY("% Complete") >0 AND PROPERTY("% Complete") <=25 ).RESOURCE (NOT STATUS_HISTORY("Installation Status") >=">0% and <=25%")  SET_PROPERTY (STATUS_NAME  , "Installation Status::Construction Component::"+ ">0% and <=25%")


TASK(SELECTED AND PROPERTY("% Complete") >25 AND PROPERTY("% Complete") <=50 ).RESOURCE (NOT STATUS_HISTORY("Installation Status") >=">25% and <=50%")  SET_PROPERTY (STATUS_NAME  , "Installation Status::Construction Component::"+ ">25% and <=50%")


TASK(SELECTED AND PROPERTY("% Complete") >50 AND PROPERTY("% Complete") <=75 ).RESOURCE (NOT STATUS_HISTORY("Installation Status") >=">50% and <=75%")  SET_PROPERTY (STATUS_NAME  , "Installation Status::Construction Component::"+ ">50% and <=75%")


TASK(SELECTED AND PROPERTY("% Complete") >75 AND PROPERTY("% Complete") <=100 ).RESOURCE (NOT STATUS_HISTORY("Installation Status") >=">75% and <=100%")  SET_PROPERTY (STATUS_NAME  , "Installation Status::Construction Component::"+ ">75% and <=100%")


TASK(SELECTED AND PROPERTY("% Complete") == 100).RESOURCE (NOT STATUS_HISTORY("Installation Status") >="Completed")  SET_PROPERTY (STATUS_NAME  , "Installation Status::Construction Component::"+ "Completed")

 

Create Resource Group:

  1. Create Group from the Task

TASK.RESOURCE ASSIGN_GROUP_BY_ID EACH TASK NAME

  1. Create Group from the User Field

RESOURCE (EXIST UFV ("Work Package")) ASSIGN_GROUP_BY_ID (UFV ("Work Package"))

  1. Sync Group Data from Task

GROUP UNASSIGN_OBJECT RESOURCE
GROUP ASSIGN_OBJECT VAR TASK (NAME == $0.NAME).RESOURCE

 

Set Property

  1. Rename Task name

TASK SET_PROPERTY (NAME, "Install " + " - " +  UFV("Category"))

 

  1. Actual Cost Form Budget Cost:

TASK SET_PROPERTY(PROPERTY("Actual Direct Cost"),PROPERTY("Budgeted Direct Cost")*PROPERTY("% Complete")/100)

  1. Set Task – Resource Plan Unit quantity:

RESOURCE(NAME=="Concrete").ASSIGNMENT SET_PROPERTY (PLANNED_WORK, TASK.UFV("[SYNC]Volume"))

  1. Set Task – Resource Actual Unit quantity:

RESOURCE (NAME=="Concrete").ASSIGNMENT SET_PROPERTY (ACTUAL_WORK, PROPERTY("Planned Units") * TASK.PROPERTY("% Complete") / 100)

  1. Resource Actual Unit calculation

TASK(SELECTED.ASSIGNMENT SET_PROPERTY(ACTUAL_WORK, PROPERTY("Planned Units") * TASK.PROPERTY("% Complete")/100)

  1. Change Appearance Profile

TASK(SELECTED).ASSIGNMENT SET_PROPERTY (PROPERTY("Appearance Profile"), ALL_USE_PROFILE( NAME == "Concrete" ))

 

TASK.ASSIGNMENT (RESOURCE.UFV("Structural Material")>="Concrete" OR RESOURCE.UFV("Type")>="Concrete" OR RESOURCE.UFV("Material")>="Concrete" ) SET_PROPERTY ( PROPERTY("Appearance Profile"), ALL_USE_PROFILE( NAME == "Concrete" ))

  1. Physical Quantity / Volume

 

TASK SET_PROPERTY (PHYSICALVOL_SH, "Cubic metre", UFV("Total Volume"))

 

TASK(SELECTED) SET_PROPERTY(PHYSICALVOL_SH, "Ton", SUM (3D.UFV("Weight.FLOAT")) /2000.0)

 

  1. Physical Quantity from 3D geometric volume

RESOURCE  ASSIGN_UF ("Volume", STRING,3D_CALCULATE_VOLUME(3D)))
TASK ASSIGN_UF ("Volume", FLOAT , 3D_CALCULATE_VOLUME(3D))
TASK SET_PROPERTY(PHYSICALVOL_SH, "Cubic metre", UFV("Volume"))

  1. Calculate and set Task Duration

 

TASK SET_PROPERTY(PROPERTY("Task_Duration”), STRING(SUM(RESOURCE.UFV("TheDuration"))) + "h"))

 

  1. Round the Task Duration to 8 hours

TASK SET_PROPERTY(TASK_DURATION , ( (TASK_DURATION  + "7.99h") / ( 3600*8 ) ) * (3600*8))

 

Or to 4 hours

TASK SET_PROPERTY(TASK_DURATION , ((TASK_DURATION  + "3.99h")/(3600*4 )*(3600*4)))

  1. Set Task Budgeted Direct Cost:

TASK SET_PROPERTY(PROPERTY("Budgeted Direct Cost"), SUM(RESOURCE.UFV("Pris")))

Anonymous