[API][python] only one solidworks instance

Discussion in 'SolidWorks' started by thomas.rademacher, Aug 31, 2007.

  1. Hello,

    I start my script convert.py simultaneously in any dos-shells several
    times. But I get every time the same solidworks instance.
    I see in the proccess (task) manager only one solidworks.exe
    Therefore I get for all simultaneous conversions the same output file.

    I tested the same code with excel (test_excel.py) and I get many
    instances of excel in proccess (task) manager.
    How can I get many instances of solidworks?

    Is it a problem of python?
    Or is it a problem of the Solidworks-COM-Implemention and I get the
    same problem with an C++ client implementation?

    Thanks for your help, Thomas

    convert.py
    import pythoncom
    pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)

    sldworks = gencache.EnsureModule('{83A33D31-27C5-11CE-
    BFD4-00400513BB57}', 0x0, 13, 0)
    sw = sldworks.ISldWorks(DispatchEx('SldWorks.Application'))
    swmodel, errors, warnings = sw.OpenDoc6(sourceName,
    constants.swDocPART, constants.swOpenDocOptions_Silent, "")
    activeDoc = sw.ActiveDoc
    retval, errors, warnings = swmodel.SaveAs4(targetName,
    constants.swSaveAsCurrentVersion ,
    constants.swOpenDocOptions_Silent )

    pythoncom.CoUninitialize()

    test_excel.py

    import pythoncom
    pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)

    myExcel = win32com.client.DispatchEx('Excel.Application')
    myExcel.Visible = 1
    Excel = myExcel.Workbooks.Open(excelfile, 0, False, 2)
    Excel.Saved = 1
    Excel.Close()
    myExcel.Quit()
    del myExcel
    del Excel

    pythoncom.CoUninitialize()
     
    thomas.rademacher, Aug 31, 2007
    #1
  2. thomas.rademacher

    TOP Guest

    I found this:

    Hello Thomas,

    excel registers its COM objects with REGCLS_SINGLEUSE that means one
    COM
    object is created
    per process. In Solidworks it seems that that they register with
    REGCLS_MULTIPLEUSE, which means
    on process can serve more than one COM object. Hence you have no
    chance
    to get multiple instances
    running in any COM client.

    Stefan

    Which leads to this:
    http://support.microsoft.com/kb/q169321/

    We know that SW can be started multiple times from the desktop. This
    is usually not a good thing unless you are running a dual core
    machine. SW has a much larger footprint than excel. With multiple
    instances you would quickly run out of resources. And since SW
    rewrites the registry all the time during use, running multiple
    instances would seem to be a recipe for disaster.

    I have to wonder why you would want to run multiple instances?

    TOP
     
    TOP, Aug 31, 2007
    #2
  3. Hello Stefan,
    thanks for your answer.
    I want to run my script convert.py in batch processes parallel.
    I started following 3 tests parallel:
    test 1:
    sourceName = test1.sldprt
    targetName = test1.step
    test 2:
    sourceName = test2.sldprt
    targetName = test2.step
    test 3:
    sourceName = test3.sldprt
    targetName = test3.step

    I got for every test the right taget file (test<n>.step). But the
    (model) content of all files was the content of the third file.
    Thomas
     
    Thomas Rademacher, Sep 3, 2007
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.