Script Editing - Tutorial 4 - Default Values

To set custom default values for newly generated machine works or setup object , is possible create a dedicated function.

It's a good idea write this function in a separated script file , so we can share it with others script file.

  • Create a new file , "CommonFunctions" , you can define an other filename if you prefer.
  • Inside this file you can write all the common function you are going to use in other files.
  • Insert the code below into "CommonFunctions" file :
/// <summary>
/// Define default values for MachineWork objects
/// </summary>
/// <param name="work"></param>
public MachineWork InitWithCustomParameters(MachineWork work)
{
    ///////////////////////////////
    // METRIC SYSTEM (millimeter) /
    ///////////////////////////////
    if (Unit == MeasureUnit.Metric)
    {

        //
        // MILLING DEFAULT PROPERTIES (mm)

        work.MillingParams.ZLevel_SecureHeight = 10;
        //work.MillingParams.DepthMachining = 10;
        //work.MillingParams.RoughingOp_HelixAngle = 4;

        //work.MillingParams.DepthCenterDrill = 5;
        //work.MillingParams.DrillHoleDiameter = 10;
        //work.MillingParams.DepthDrill = 10;
        //work.MillingParams.ChamferDefinedByDiameter = true;
        //work.MillingParams.DiameterChamfer = 12;
        //work.MillingParams.DepthReamer = 10;
        //work.MillingParams.DepthBore = 10;
        //work.MillingParams.DepthCounterbore = 10;



        //
        // TURNING  DEFAULT PROPERTIES (mm)

        //work.TurningParams.AllowanceMaterialX = .3;
        //work.TurningParams.AllowanceMaterialZ = .1;
    }

    /////////////////////////////
    // IMPERIAL SYSTEM ( inch )//
    /////////////////////////////
    else if (Unit == MeasureUnit.Imperial)
    {
        //
        // MILLING DEFAULT PROPERTIES (inch)

        //work.MillingParams.ZLevel_SecureHeight = 0.2;
        //work.MillingParams.DepthMachining = 0.4;
        //work.MillingParams.RoughingOp_HelixAngle = 4;

        //work.MillingParams.DepthCenterDrill = 0.2;
        //work.MillingParams.DrillHoleDiameter = 0.4;
        //work.MillingParams.DepthDrill = 0.4;
        //work.MillingParams.ChamferDefinedByDiameter = true;
        //work.MillingParams.DiameterChamfer = .45;
        //work.MillingParams.DepthReamer = 0.4;
        //work.MillingParams.DepthBore = 0.4;
        //work.MillingParams.DepthCounterbore = 0.4;



        //
        // TURNING  DEFAULT PROPERTIES (inch)

        //work.TurningParams.AllowanceMaterialX = .012;
        //work.TurningParams.AllowanceMaterialZ = .004;
    }


    return work;
}
  • It's manage both the metric default values and inch default values.
  • UnComment this line and change the default value, if you want.
work.MillingParams.ZLevel_SecureHeight = 10;

You can define also other properties .

This is the script editor window, you can see the CommonFunctions file in left column.


Call functions from other file

Now i want call the function "InitWithCustomParameters" in other script file.

To do so :

  • I open the other script file , "Example1" in this case.
  • Add this line on top of script file
#load "CommonFunctions.csx"

Note :

If i load "CommonFunctions.csx" in "Example1.csx" , i can't load "Example1.csx" in "CommonFunctions.csx" , otherwise it will lead to a circular reference problem.

Now i edit the wrench slot script, visible in tutorial 3, with this :

....

    var millingWork = AddMachineWork(WorkType.Mill_SideMilling);

    /// ADD THIS LINE TO SET CUSTOM DEFAULT PARAMETERS ////
    millingWork = InitWithCustomParameters(millingWork); 
    //////////////////////////////////////////////////////

    millingWork.MillingParams.MaterialToRemove = halfDiameter - halfDistance;

....

Now if you run again the script , you can see the Secure Z level is edited with your new custom default value.


results matching ""

    No results matching ""