MHJ-SoftwareMHJ WikiOnline manuals PLC-Lab 3D Studio v1

Tutorial 2

11 min readUpdated 2026-06-01

This page is relevant for ✅Studio ❌Player

Information

In this tutorial, you will import a prepared CAD file containing a sorting station into the 3D environment. The station is then configured step-by-step using various skills. The corresponding control program is first developed in C# and tested in parallel with the 3D model. Once the interaction between the C# program and the 3D model works correctly, the setup is tested with PLCSIM in TIA Portal. For this, the control program created in C# is ported to the SCL programming language.

Tutorial 2 - Front view
Image: Tutorial 2 station.

Target behavior of the station:
The sorting station uses a conveyor belt (1). By clicking a template workpiece (2) (metal or plastic cube), the Creator (3) generates the workpiece and places it on the belt. This interrupts the photoelectric sensor (8), which starts the conveyor. The cube is transported to the stopper (4). Two seconds after the photoelectric sensor (8) is interrupted, the stopper rotates counterclockwise and releases the cube.

  • If the inductive sensor (5) detects a metal cube, the first cylinder (6) pushes it onto the first tray.
  • A plastic cube is conveyed to the middle photoelectric sensor (9). As soon as this sensor is clear again, the second cylinder (7) pushes the cube onto the second tray.
  • The right-hand, third tray remains empty during correct operation.
  • After power-on, the conveyor remains enabled continuously.

Step 1: Create a new folder

Create a folder with any name on your hard drive (e.g., Desktop or Documents). All files for the digital twin will be stored there.

Step 2: Copy the CAD file and the symbol file

Download the following files and copy them into the folder you created:

File Description Download link
CAD file 3D model for Tutorial 2 CAD file for Tutorial 2
Symbol file Contains I/O for the simulation Symbol file for Tutorial 2
Note

When downloading the symbol file, make sure the filename is not changed (for example, if a file with the same name already exists in your Downloads folder). The symbol file must be named: station0.symbols.csv

Step 3: Open the CAD file in PLC-Lab 3D Studio

In the toolbar, click the CAD button to open the CAD file.

Step 4: Overview and first test

After opening the file, align the camera so the model is centered on the screen.
Save the view to Slot 1 using Shift + 1.

In the image you can see that the Tags button (1) is enabled and the Tags window with the inputs and outputs is shown (2).

Tutorial 2 - Front view
Image: After opening

3D objects highlighted in orange already have a skill assigned. Objects highlighted in red still need to be configured.

Skill editing
Image: Skill overview in the 3D station

Most orange objects already contain Collider skills. The cylinder indicator lights as well as the Creator with the template objects are already fully configured.

These objects still need to be configured:

No. Object Configuration required for:
1 Conveyor belt Belt motion
2 Stopper Rotational motion
3 Capacitive sensor Sensor properties
4,5 Cylinder rods Linear motion
Information

Thanks to the prepared CAD file, many skills are already correctly assigned and configured. Only a few skills still need to be adjusted manually—this saves time and significantly simplifies creating the digital twin.

First test without a PLC program:
Next to the Run button, select InternDevice and start the simulation with Run. The conveyor runs because no configuration is present yet.
Click the yellow cube and the metal cube (1) (2). They are created by the Creator and placed on the conveyor (3) (4).

Test without PLC program
Test without PLC program

Step 5: Configure the conveyor belt

Run mode is still active. Remove the two generated cubes by clicking them.
Hold Ctrl and click the conveyor belt. The Properties window appears on the right side of the screen. Note: In Stop mode, you no longer need to hold Ctrl to select objects in the scene (as of V1.4.7).

Set the following values:

  • Axis → Z (default)
  • MoveForward → Q0
  • TextureSpeed → 0.55 (matches the texture motion to the real belt speed)

In the Tags window, force the output Q0 to true:

  • Click the “F” button (highlighted red) (1)
  • Click Q0 → the belt starts running (2)

Click the yellow cube (3) — it is placed on the belt and moves to the stopper (4). Click again to remove it.

Conveyor settings
Conveyor settings

Step 6: Configure stopper M1

Exit Run mode. Click the stopper (1) (horizontal cylinder) to open its properties.

Settings M1, stopper
Settings M1, stopper

Set the following operands:

  • Axis → Zn (default)
  • ToMax → M1_1
  • ToMin → M1_0
  • IsAtMax → B5
  • IsAtMin → B6

In the settings you will also find the Demomode switch. Enable it to test the motion (Run mode must not be active). The rotation is still too small—so also set:

  • DurationInSeconds → 0.5
  • MaxDegree → 75

Toggle DemoMode off and on again if the motion stops.
If the behavior is correct, disable DemoMode again.

Step 7: Cylinder rods M2 and M3

3D Studio is in Stop mode.
In the CAD file, the {Collider} skill is missing on the two cylinder rods. Add it now.

Click the left cylinder rod (M2) to open the properties:

Open Skill Manager
Open Skill Manager

In the title area of the Properties window, click the SkillManager link (3). The Skill Manager opens and filters for cylinder rod M2.
Now add the {Collider} skill:

Add Collider
Add Collider
  1. Enter col in the skill filter
  2. Collider is shown in the skill selection
  3. Click Add
  4. The rod now has a Collider as a second skill (see yellow rectangle), so it can push the cube. No changes are required to the collider properties.
Information

The cylinder rod is equipped with a box collider. In our case this is fine even though the rod has a different shape. Use a box collider whenever possible because it requires the least CPU performance.

Now also add a collider to the second cylinder rod (M3).

Configure the motion of cylinder M2:

Settings M2, cylinder rod
Settings M2, cylinder rod

Click cylinder rod M2. Settings for the Drive-2-Point skill:

  • Axis → Z (default)
  • ToMax → M2_0
  • ToMin → M2_1
  • IsAtMax → B8
  • IsAtMin → B7
  • DurationInSeconds → 0.5
  • StrokeLength → 70

Configure the motion of cylinder M3 (no image):

  • Axis → Z (default)
  • ToMax → M3_0
  • ToMin → M3_1
  • IsAtMax → B10
  • IsAtMin → B9
  • DurationInSeconds → 0.5
  • StrokeLength → 70

Step 8: Capacitive sensor B4

Switch the simulation to Run, show the Tags window, and force Q0 to TRUE again (if it is no longer forced).
Place a yellow cube on the belt → it is blocked at the stopper.
To adjust sensor B4, we need to make the stopper temporarily pass-through.

Hold Ctrl and click the barrier (1) at the stopper, then disable EnableCollision (2):

Settings M1, stopper
Settings M1, stopper

Now create yellow and metal cubes alternately.
Watch the indicator light on the sensor housing. Currently, both react to sensor B4—but the sensor should only detect the metal cube. We will change that now.

We are in Run mode. Sensor B4 is invisible because the Skill Manager is not open. Move the mouse pointer under the B4 sensor housing while holding Ctrl. The invisible sensor should highlight. Click the left mouse button to open the settings.

Set SensorTriggerType to Inductive

Settings Sensor B4
Settings Sensor B4

Information: In Run mode you must hold Ctrl to display a skill’s properties. In Run mode, for example, switches are operated with the mouse, so Ctrl is required to open the skill properties instead.

Now B4 detects only inductive objects. The metal cube must also be configured correctly:

  1. Ctrl + click the metal template cube (1)
  2. In the Properties window, click the Collider skill (2)
  3. Set SensorTriggerType to Inductive (3)
Settings metal cube
Settings metal cube

Test the sensor response again. Only metal cubes should trigger B4.

Finally, re-enable EnableCollision at the stopper.
Also turn off forcing of Q0 by clicking the red F in the Tags window.

All skills are now set and the station is fully prepared.

Step 9: Create and simulate a C# script

Follow the instructions under C# Scripting to install the free editor Visual Studio Code.

After Visual Studio Code is set up:

  1. Exit Run mode
  2. In the Device menu, select CSharpScript (1)
  3. Open the settings (2) and verify PathCodeEditor. The correct editor path should be configured here. In SubFolder, you must specify a directory. For example, enter MyScript.
  4. Click Create C# project (4)
Create/open C# project
Create/open C# project

Visual Studio Code opens the project.
Start the simulation by pressing the Run button.

In module Program.cs, add the following line in the MainPrg() function:

csharp
Q0 = true; // Turn on conveyor belt

Save with Ctrl + S → The belt runs.

Then add these two lines and save again:

csharp
M2_0 = true; // Extend cylinder M2
M3_0 = true; // Extend cylinder M3

Now cylinders M2 and M3 should extend.

C# test
C# test
  • (1) shows the new code lines
  • (2) conveyor belt is running
  • (3,4) cylinders M2 and M3 are extended

Switch the station to Stop to return to the home position.

Now download the complete C# program: Download C# Program Tutorial 2

Delete all lines in Program.cs: select all with Ctrl + A and delete with Del. Then paste the downloaded content.

Switch the station to Run. The simulation should now run as shown in the next video:

Video: Simulation sequence

The video uses an older version of PLC-Lab 3D Studio. However, the basic principle is identical.

Step 10: Simulation with PLCSIM from TIA Portal

For PLC-Lab 3D Studio to connect to PLCSIM-1200, you must use a TIA Portal template project. This template project already contains the required settings for a successful connection. Depending on your TIA Portal version, use the corresponding download:

TIA Portal version Download Notes
V14–V19 TIA Portal V14 project When using V15–V19, TIA Portal automatically upgrades the project.
V20 or later TIA Portal V20 project -

Download for the finished SCL program with variable table for Tutorial 2:

Create the TIA Portal project for the mechatronic station:

  1. Download and unzip the TIA Portal template project.
  2. Open the template project.
  3. Save the template project under the name Tutorial2-PLC-Lab-3D-Studio (1) and rename the node in the project tree to Tutorial2 (2)
    Project after renaming
  4. Open the default variable table. In the variable table, right-click to open the context menu. Select Import file and choose Tutorial2-variablen.xlsx from the ZIP file tutorial2-tia-quellen.zip. When prompted how the variables should be imported, select "Synchronize by address".
    After importing variables
  5. Now import the blocks for the mechatronic station. In the ZIP file tutorial2-tia-quellen.zip, you will find Tutorial2.scl. It contains multiple blocks in source format that can be imported with TIA Portal. In the project tree, open External sources. Click "Add new external file" and select Tutorial2.scl. Right-click the new Tutorial2.scl entry (1) and select "Generate blocks from source". You will now have three new blocks (2) under Program blocks: HiEdge, LoEdge, and Tutorial2.

    3 new blocks in the project
  6. Create the instance data block for FB Tutorial2: In the project tree, choose Add new block. Click Data block and select type "Tutorial2". Name it Tutorial2_DB and press OK.
    Create instance DB
  7. In OB1, FB Tutorial2 must now be called using the created instance data block. Open OB1 and right-click Network 1 to open the context menu. Select "Insert SCL network" and enter the code below.
pascal
IF #Initial_Call THEN // initialize FB on first call
    "Tutorial2_DB"(Init := TRUE);
    RETURN;
END_IF;
"Tutorial2_DB"(Init := FALSE); // cyclic call

The program is now complete. Next, start PLCSIM:

  1. Click Start simulation.
    Start simulation icon
  2. The Advanced download dialog appears (it may be behind the PLCSIM window). Select PLCSIM at (1). At (2) you should see CPU-1200 Simulation. Click Load.
    Advanced download dialog
  3. In the Load preview dialog, choose Overwrite all (1). Click Load (2).
    Load preview
  4. In the Download results dialog, select Start module. This switches PLCSIM to RUN mode.
    Download results
  5. In the PLCSIM window, verify that PLCSIM is in Run mode.
    PLCSIM in Run mode

Now start the simulation in PLC-Lab 3D Studio:

Set the device to TiaPortalPlcSim1200 (1), click the Settings icon (2), and select your TIA Portal version in the settings (3).

Set device PLCSIM 1200
Set device PLCSIM 1200