Announcement

Collapse
No announcement yet.

New Automation APIs in SolidCAM2022 RFC (Request For Comments)

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

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

    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:
    • 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

    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")
    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:

    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)
    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):

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

    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")
    Next, we need to get a geometry. We will take the first one from the collection:

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

    Code:
    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.

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

    Code:
    operation = template.CreateOperation(geom, submachine, home)
    Once we have an operation object, we can calculate it and generate the G-code:

    Code:
    operation.Calculate()
    operation.GenerateGCode(path)
    We can even show the operation toolpath in the host CAD:

    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" )
    Then we need to get a geometry. We will take the first one from the collection:

    Code:
    geom = part.Geometries[0]
    And finally, we can create operations:

    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")
    Now we just call Generate():

    Code:
    template.Generate()

    Scenario 6: Changing operation tool


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

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

    Comment


    • #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.

      Code:
      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:
          part.Synchronize()
          part.Operations.Calculate()
          part.Close()
      
      cam.Exit()
      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.

      Comment


      • 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.

      Comment


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

        Comment


        • #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.

          Comment


          • #7
            Andrey,
            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.
            Thanks

            Comment

            Working...
            X