fbpx

CS-Lab Support Forum for CNC Community

Help to run this brand-new forum and stay with us.
Ask your questions, we are here to help! 

 

Please or Register to create posts and topics.

Using an macro with an argument

Hello!

I have some trouble to fix some code in an macro i want to use. I tried in SimCNC 3.5 .

I want to use one macro (called M300) with 12 arguments (A1, A2, A3 ... and so on). 

When i create following macro:

# M300.py

def M300_A1():

print("M300 A1.")

# Codedummy

def M300_A2():

print("M300 A2.")

# Codedummy

def M300_A3():

print("M300 A3.")

# Codedummy

def process_M300(arg):

if arg == "A1":

M300_A1()

elif arg == "A2":

M300_A2()

elif arg == "A3":

M300_A3()

else:

print("Invalid Argument. Choose A1, A2 or A3.")

if __name__ == "__main__":

import sys

if len(sys.argv) != 2:

print("Using: python M300.py <Argument>")

sys.exit(1)

arg = sys.argv[1]

process_M300(arg)

 

I tested to run it in the MDI. When i enter M300 A1 etc. i get following error message:

Warning

Motion (group 1) is not set

M300 A1

 

I cant figure out how to solve this.

 

Maybe you got an idea?

 

thanks!

Dobbelju

Hello,

Because of how Python scripts are internally implemented in simCNC, standard argument passing (through sys.argv) will not work.

You have to use machine params for that manner.

It works like this:

  1. set machine param or multiple params beforecalling a macro
  2. read these params in a macro using getMachineParam function

example m300.py:

#m300.py

value_a1 = d.getMachineParam( 1000 )

value_a2 = d.getMachineParam( 1001 )

print(value_a1)

print(value_a2)

 

execution example from gcode:

#1000=1 #1001=2 m300

 

Regards,

Andrew

Dobbelju has reacted to this post.
Dobbelju

Hello!

Thanks!

That helps alot. 

Regards

dobbelju

PARTNERS:

 

USA

Germany

Slovenia / Bosnia

Spain

South Africa

UNI-CAM

The Netherlands

Portugal

Greece

  Distrib milionis logo

Hungary

Distrib logot

Bulgaria

Master

Kenya

Proteq Automation

Egypt

Germanelectronix

China

Jun Ma

Serbia

ALCO

Italy

LVL tech r

Denmark

Varntoft Dania

Finland

×

Hello!

Click one of our contacts below to chat on WhatsApp

× How can I help you?