Abstract
This document presents the new API structure and explains some of the differences between the old and the new API.
It would be of great help if your feedback would address the following points:
The new APIs have not been released yet. Once they are released they cannot be changed, only expanded with new objects, functions and properties.
What’s new?
There are three main differences between the old and new APIs:
Object hierarchy
SolidCAM_Object_Model.png
Initialization
All code in this document is in Python.
First thing that we have to do in order to use the new Automation API is to get the instance of the running SolidCAM process:
If there is no running SolidCAM process then the code above will cause an exception and fail.
Once we have connected to the running instance of SolidCAM, we can open a part:
Scenario 1: Creating a new milling part
Creating a new part does not work in standalone mode and it needs that a model is currently open in CAD.
Scenario 2: Creating a new home
We can create a new home either by using the origin position (0 - top corner, 1 - top center, 2 - CAD Origin):
or by CAD coordinate system:
Scenario 3: Creating an operation from template
First, we select a template from the collection. We can do this in two ways: by index and by name.
Next, we need to get a geometry. We will take the first one from the collection:
Then we get the submachine of the machine defined in the part:
Now we need to select a home. We can do this in four ways. First, we can get the existing home by index. If we know the home name, we can also get it by it’s name.
Finally, we can call CreateOperation(…) which returns a newly created operation object.
Once we have an operation object, we can calculate it and generate the G-code:
We can even show the operation toolpath in the host CAD:
Scenario 4: Creating a set of operations from a process template
As with templates, we first need to select a process template from the collection:
Then we need to get a geometry. We will take the first one from the collection:
And finally, we can create operations:
Scenario 5: Creating a tool sheet from a template
As with process and operation templates , we need to select a process template from the collection:
Now we just call Generate():
Scenario 6: Changing operation tool
This document presents the new API structure and explains some of the differences between the old and the new API.
It would be of great help if your feedback would address the following points:
- Do proposed scenarios look intuitive to a scriptwriter?
- Are the objects properly organized?
- Do the functions take expectable input (homes, geometries, coordinate systems, etc.)?
- Are there other scenarios that should be considered with existing objects?
- etc.
The new APIs have not been released yet. Once they are released they cannot be changed, only expanded with new objects, functions and properties.
What’s new?
There are three main differences between the old and new APIs:
- New APIs are accessing SolidCAM directly through the use of functions like GetActiveObject. If the connection fails then the exception occurs right away in the calling script. Old APIs had an intermediate object called “Automation” which was being instantiated in the calling process by using CreateObject(…). If there was a problem with the connection then it was not easily traceable.
- Unlike the old API, which consisted of a number of functions for accessing functionalities, the new SolidCAM API is implemented as a hierarchy of objects. Object’s functionalities can be accessed through its properties and methods. Properties can also be objects, i.e. part’s tool. We can change the part’s tool by selecting a tool object from the tools list and then assign it to the part.
- All function arguments and return values are now VARIANTs for better support of scripting languages.
Object hierarchy
SolidCAM_Object_Model.png
Initialization
All code in this document is in Python.
First thing that we have to do in order to use the new Automation API is to get the instance of the running SolidCAM process:
Code:
import win32com.client cam = win32com.client.GetActiveObject("SolidCAM2.Application")
Once we have connected to the running instance of SolidCAM, we can open a part:
Code:
part = cam.OpenPart("c:\\parts\\my_part.prz")
Scenario 1: Creating a new milling part
Code:
coordinate_system = cam.CAD.CoordinateSystems[0] machine = cam.Machines[2] inch = False part = cam.CreateNewMillingPart("c:\\parts\\my_part.prz", coordinate_system, machine, inch)
Scenario 2: Creating a new home
We can create a new home either by using the origin position (0 - top corner, 1 - top center, 2 - CAD Origin):
Code:
home = part.Homes.Create(0) home = part.Homes.Create("topcorner")
Code:
coordinate_system = cam.CAD.CoordinateSystems[0] home = part.Homes.CreateFromCAD(coordinate_system)
Scenario 3: Creating an operation from template
First, we select a template from the collection. We can do this in two ways: by index and by name.
Code:
template = cam.Templates[template_index] template = cam.Templates.GetByName("MyTemplate")
Code:
geom = part.Geometries[0]
Code:
submachine = part.Machine.Submachines[submachine_index]
Code:
home = part.Homes[0] home = part.Homes.GetByName("MyHome")
Code:
operation = template.CreateOperation(geom, submachine, home)
Code:
operation.Calculate() operation.GenerateGCode(path)
Code:
operation.Checked = True
Scenario 4: Creating a set of operations from a process template
As with templates, we first need to select a process template from the collection:
Code:
process_template = cam.ProcessTemplates[0] process_template = cam.ProcessTemplates.GetByName("MyProcessTemplate" )
Code:
geom = part.Geometries[0]
Code:
process_template.CreateOperations(geom)
Scenario 5: Creating a tool sheet from a template
As with process and operation templates , we need to select a process template from the collection:
Code:
index = 0 template = cam.ToolSheetTemplates[index] template = cam.ToolSheetTemplates("MyTemplate")
Code:
template.Generate()
Scenario 6: Changing operation tool
Code:
part.Operations[operation_index].Tool = part.Tools[tool_index]
Comment