February 26, 2019

SmartCAM Code Generator: New String function


Welcome back once again to the SmartCAMcnc blog ☺


Code Generator String expressions

Technical stuff: bring it on. I'm not going to mess about with an introduction this time: as someone who thrives on the technical I'm heading straight to the interesting technical content of this post.

The Interesting Bit

A new Code Generator String Processing function became
available in the latest release of SmartCAM, Version 2019 SP1.


Over the years we have had many interesting discussions regarding strings and string handling in the SmartCAM Code Generator ( CG ) and Customization ToolKit ( CTK ).

We want to tell you about a new Macro String Expression function - #MSE - that can now be used in CG template ( .cgt ) files.

The SmartCAM macro mechanism has a whole load of string variable functions available, any of which can be incorporated within macro logic for all manner of purposes, such as outputs and conditional-tests.

Examples of macro string functions are:


GET_CNC_PATHReturns the folder path where SmartCAM
will write NC code files
VERSIONReturns the current SmartCAM application's
'Header text'
CODFILEReturns the current CNC Code path and file name
SHPFILEReturns the current Process Model path and file name

All macro string expressions can now be used within the SmartCAM Code Generator Template file.

The syntax for accessing macro string processing functionality in a CG template file is a #MSE function embedded in a #EVAL string assignment:


#EVAL ( #my_string =#MSEmacro string expression ))

If you are experienced with the SmartCAM Code Generator tools then you'll understand that stuff. But for the general benefit of all, let's break down that statement.





User Variables can be used within the SmartCAM Code Generator Template file.

They are declared in the @DECLARE section of the code generator template file, defining which type of data they will contain - string, integer or decimal type.

Since our example will return a string expression, it follows that our user variable would be declared as being of string type:

#STR #my_string

There is a User Variables topic in Learning SmartCAM, browse to Code Generation > Variables

#EVAL
To borrow the description from Learning SmartCAM , the #EVAL command is used to "Assign numeric and string words via numeric and string expressions."

I'll sneak in here a simple example of the use of that command, again borrowed from Learning SmartCAM:

#EVAL( #diam = #radius * 2 )

using decimal variables in that case.

And so our example

#EVAL ( #my_string =#MSEmacro string expression ))

Assigns to a user string variable named #my_string the value returned by the #MSE function.






Here's a use case. A common request is to retrieve file names and paths, such as those for the current CNC code file, or the current Shape FilePM5 file ).

The last variable in our list of examples above, SHPFILE can be used to illustrate that type of case:


#EVAL ( #my_string =#MSE( SHPFILE() ))

Macro functions can be found in the SmartCAM Customization Guide, navigate to Automating SmartCAM with macros > Macro functions

Functions that begin with S= in the documentation are string functions.

We want to let you know that the function is still in a beta state, but felt it was worth including in the SP1 release. At the time of writing, our testing has found that the EL_NAME() function is the only function not working correctly.

Please go ahead and try it if you have a use case!





If you have yet to discover SmartCAM

Here's a little background information, just for you.

CAM engineers who use SmartCAM know that the Code Generator ( let's refer to that as 'The CG' ) and Customization ToolKit ( 'The CTK' ) tools excel.

Sure, they are technical, but once you have grasped the fundamentals you can achieve really good things using those tools. 

I've said it before and no doubt will say it again - because we here at SmartCAMcnc have a deep-seated belief in the statement - that the SmartCAM Code Generator and Customization tools are amongst the most open and flexible in the CAM software world. 


Complete Automation of Hydraulic Seal
manufacturing Toolpath
One of these days I'll create a blog post dedicated to the concepts of the Code Generator and the CTK.  Probably one for each of those really interesting technical topics.

But in a nutshell a SmartCAM user can apply  the particularly open CG tools to setup detail code requirements for themselves, and can use the CTK to create additional functionality that is often unique to their particular application requirements. 


CTK Projects can range from small everyday useful commands and functions through to large-scale  automation

CTK work can comprise of a short and simple macro that is 'executed' by the SmartCAM engineer, or it can be the development of a whole suite of macros and can be enabled with custom user-interface panels.

A key element in both systems is variables, system- and user-defined. This blog post highlighted a new function that enhances string variable handling in the SmartCAM Code Generator.


I hope it has been helpful and as technically interesting as it was for me.




Take care.
Have a great day / evening / weekend.

Talk CAM with us. We're at:


+1 (541) 344-4563

sales@smartcamcnc.com




The SmartCAMcnc Team

No comments:

Post a Comment