No announcement yet.

New Automation APIs in SolidCAM2022 RFC (Request For Comments)

This is a sticky topic.
  • Time
  • Show
Clear All
new posts

  • New Automation APIs in SolidCAM2022 RFC (Request For Comments)


    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:
    1. 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.
    2. 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.
    3. All function arguments and return values are now VARIANTs for better support of scripting languages.

    Object hierarchy



    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:

    import win32com.client
    cam = win32com.client.GetActiveObject("SolidCAM2.Application")
    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:

    part = cam.OpenPart("c:\\parts\\my_part.prz")

    Scenario 1: Creating a new milling part

    coordinate_system = cam.CAD.CoordinateSystems[0]
    machine = cam.Machines[2]
    inch = False
    part = cam.CreateNewMillingPart("c:\\parts\\my_part.prz", coordinate_system, machine, inch)
    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):

    home = part.Homes.Create(0)
    home = part.Homes.Create("topcorner")
    or by CAD coordinate system:

    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.

    template = cam.Templates[template_index]
    template = cam.Templates.GetByName("MyTemplate")
    Next, we need to get a geometry. We will take the first one from the collection:

    geom = part.Geometries[0]
    Then we get the submachine of the machine defined in the part:

    submachine = part.Machine.Submachines[submachine_index]
    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.

    home = part.Homes[0]
    home = part.Homes.GetByName("MyHome")
    Finally, we can call CreateOperation(…) which returns a newly created operation object.

    operation = template.CreateOperation(geom, submachine, home)
    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:

    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:

    process_template = cam.ProcessTemplates[0]
    process_template = cam.ProcessTemplates.GetByName("MyProcessTemplate" )
    Then we need to get a geometry. We will take the first one from the collection:

    geom = part.Geometries[0]
    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:

    index = 0
    template = cam.ToolSheetTemplates[index]
    template = cam.ToolSheetTemplates("MyTemplate")
    Now we just call Generate():


    Scenario 6: Changing operation tool

    part.Operations[operation_index].Tool = part.Tools[tool_index]
    Last edited by FilipPavlovic; 01-17-2022, 11:55 AM.

  • #2
    File is the zipped (because .chm files are not allowed) auto-generated documentation for the new (and old) APIs.


    • #3
      Following example launches a hidden instance of SolidCAM using the new APIs.
      Then it opens the part, synchronizes and calculates it, all in the background.
      Finally, it closes the instance of SC it used.

      import win32com.client
      launcher = win32com.client.Dispatch("SolidCAM2.Launcher")
      hidden = True
      cam = launcher.Launch(hidden)
      part = cam.OpenPart("c:\\some\\part\\name.prz")
      if not part is None:
      All this was done without showing SC GUI to the user.
      It can be used, for example, to iterate through all part files in a folder and re-calculate them.


      • Michael Stockmann
        Michael Stockmann commented
        Editing a comment
        Hi, when using operations.calculate method, is there an option to show/hide the toolpath?

        Best Regards,
        Michael Stockmann
        SolidCAM Customer Experience Programm

      • FilipPavlovic
        FilipPavlovic commented
        Editing a comment
        Hi Michael.
        You can show/hide toolpaths for each operation like this:
        for op in part.operations: op.checked = True
        And now, in revision 133332, I added checked property to the Operations object so you can do following, too:
        part.operations.checked = True

    • #4
      The new APIs have been merged to the 2022 developer version (DV).
      They have to be registered first: "regsvr32 scautom2.dll". Old APS are registered with "regsvr32 scautom.dll"
      Unlike previous versions of SC, which did this registration every time SC is run, 2022 DV does not do that. APIs are registered only once, during the installation process.


      • #5
        Hi all!
        Can I get the tool's component parts from Tool: holder, arbor list, insert list?​


        • #6
          Currently you can't, Andrey, unfortunately. The new tool table is not well supported.
          Hopefully, support for tool parameters will be added in the future.
          Last edited by FilipPavlovic; 01-17-2023, 07:17 AM.


          • #7
            It might help if you could provide an example scenario of API usage. Just a simple example with made up API names could be of great help.


            • #8
              Dear Filip,
              please help me,
              is the Operations.CalculateAndGcodeSelected(FilePath) method currently implemented or not?​
              Last edited by Dmitry Anpilogov; 07-19-2023, 12:27 PM.


              • #9
                Hello, Dimitry.

                Yes, CalculateAndGcodeSelected is implemented and should be working.
                That being said, the new APIs haven't been tested by the QA yet.


                • Dmitry Anpilogov
                  Dmitry Anpilogov commented
                  Editing a comment
                  Hello Filip!
                  I understood and implemented it in my project. Please test this method with a combination of suppressed operations.

              • #10
                There seem to be some issues with GetObject and GetActiveObject implementations in the .NET framework.
                This is the workaround (in VB):

                Dim launcher As New SOLIDCAM2Lib.Launcher
                Dim app As SOLIDCAM2Lib.Application
                If launcher.Count > 0 Then
                    app = launcher.Item(0)
                    If app IsNot Nothing Then
                        Console.WriteLine("pid: " +
                        Console.WriteLine("Version: " + app.Version.ToString())
                        Console.WriteLine("Build: " + app.Build.ToString())
                        Console.WriteLine("Log path: " + app.LogFile.ToString())
                        Console.WriteLine("GPP path: " + app.GppPath.ToString())
                    End If
                ​End If
                And another note: code should be built for "x64" and NOT "Any CPU"
                Last edited by FilipPavlovic; 08-16-2023, 04:07 PM.