Selection to Subprog in CNC Simulator Pro

Introduction

The "Selection to Subprog" feature in CNC Simulator Pro allows users to convert a selected section of G-code into a subprogram. Subprograms are useful for repeating a sequence of operations multiple times without having to rewrite the entire code. This function helps streamline the CNC programming process and improves code readability and maintainability.


How to Use the Selection to Subprog Feature

Step 1: Select the Code

- Open your CNC program in the CNC Simulator Pro editor.
 - Highlight the section of the G-code that you want to convert into a subprogram.



Step 2: Access the Selection to Subprog Function

- With the section of code highlighted, go to the Edit menu at the top of the CNC Simulator Pro window.
 - From the dropdown menu, click on Selection to Subprog.


A screenshot of a computer program

Description automatically generated 


Step 3: Review the Created Subprogram

After selecting Selection to Subprog, the software will automatically generate a subprogram from the highlighted code. The main program will include a call to this subprogram using the M98 command, and the subprogram itself will be stored separately with a unique identifier.


Example:

Before Conversion:

G01 X-23.224 Y0 Z2
G91 (Switch to incremental mode)
G01 Z-22.000 F500 M08
 G03 X38.400 I19.200 J0.000

After Conversion:

Main Program:

G00 X-23.224 Y0 Z2
 M98 P1002 L1

O1002:

G91 (Switch to incremental mode)
G01 Z-22.000 F500 M08
G03 X38.400 I19.200 J0.000
 M17


Step 4: Save and Use

- After the subprogram is created, save your main program and the subprogram. You can now run the CNC simulation, and the subprogram will be called as needed, reducing code duplication and simplifying the main program.


Benefits of Using Subprograms

- Efficiency: Reduces the amount of code needed by allowing repeated sequences to be stored in subprograms.
- Maintainability: Simplifies the main program, making it easier to read and manage.
 - Reusability: Subprograms can be reused in different parts of the main program or in different programs, enhancing versatility.