cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Run Creo Parametric as scheduled task

JVerhagen78
5-Regular Member

Run Creo Parametric as scheduled task

Hi all,
 
I would like to create a program that automatically starts Creo Parametric and do a set of operations. To start I created a basic program that only starts Creo and connects to Windchill. Here I already run into some problem where the program runs fine when started normally. However when i start it from Windows Task Scheduler it only runs when the user is logged on. If I select "Run wether the user is logged on or not", Creo fails to start and returns a general error. The user account and machine are the same in all situations. Anyone have an idea how to run Creo as scheduled task? I am using Creo Parametric version 10.0.4.0 and Windows Server 2019.
 
---------- VB.net code ----------
Imports System.IO
Imports pfcls

 

Module Module1
    Const creoOptions As String = "-g:no_graphics -i:rpc_input"
    Const creoStartup As String = "C:\PTC\Creo_10\Creo 10.0.4.0\Parametric\bin\parametric.exe"
    Const logFilePath As String = "D:\_TaskScheduler\DXFWorker\CreoAsyncConnect.log"
    Const proCommMsg As String = "C:\PTC\Creo_10\CREO10~1.0\COMMON~1\X86E_W~1\obj\pro_comm_msg.exe"
    Const ptcWfCache As String = "D:\_TaskScheduler\DXFWorker\work\.cache"
    Const ptcWfRoot As String = "D:\_TaskScheduler\DXFWorker\work\.wf"
    Const ptcWldRoot As String = "D:\_TaskScheduler\DXFWorker\work\.wld"
    Const windchillLogin As String = "********"
    Const windchillPassword As String = "********"
    Const windchillServer As String = "********"

 

    Sub Main()
        Using sw As New StreamWriter(logFilePath)
            Environment.SetEnvironmentVariable("PRO_COMM_MSG_EXE", proCommMsg, EnvironmentVariableTarget.Process)
            Environment.SetEnvironmentVariable("PTC_WF_CACHE", ptcWfCache, EnvironmentVariableTarget.Process)
            Environment.SetEnvironmentVariable("PTC_WF_ROOT", ptcWfRoot, EnvironmentVariableTarget.Process)
            Environment.SetEnvironmentVariable("PTC_WLD_ROOT", ptcWldRoot, EnvironmentVariableTarget.Process)

 

            Dim asyncConnection As IpfcAsyncConnection = Nothing
            Try
                sw.WriteLine("Start Creo")
                Dim cAC As New CCpfcAsyncConnection
                asyncConnection = cAC.Start(Chr(34) & creoStartup & Chr(34) & " " & creoOptions, Nothing)
                Dim session As IpfcBaseSession = CType(asyncConnection.Session, IpfcBaseSession)
                sw.WriteLine("Creo started")

 

                sw.WriteLine("Connect Creo to Windchill")
                session.AuthenticateBrowser(windchillLogin, windchillPassword)
                Dim serverLocation As IpfcServerLocation = session.GetServerLocation(windchillServer)
                sw.WriteLine("Creo connected to Windchill")
            Catch ex As Exception
                sw.WriteLine(ex.Message & vbCrLf & ex.StackTrace)
            Finally
                sw.WriteLine("Close Creo")
                If Not IsNothing(asyncConnection) Then
                    asyncConnection.End()
                End If
                sw.WriteLine("Creo closed")
            End Try
        End Using
    End Sub

 

End Module
 
---------- Script output ----------
Start Creo
pfcExceptions::XToolkitGeneralError
at pfcls.ICpfcAsyncConnection.Start(String _CmdLine, Object _TextPath)
at CreoAsyncConnect.Module1.Main()
Close Creo
Creo closed
14 REPLIES 14
BenLoosli
23-Emerald II
(To:JVerhagen78)

Windows does things differently when apps are run through the task manager.

You do not have any mapped drives, etc.

Take that into account in your application.

 

Can you explain for what purpose you need to run Windchill/Creo as a task?

JVerhagen78
5-Regular Member
(To:BenLoosli)

I want Creo to process a batch of files and report symbols that occur on drawings. Since there are many files (1000's), I thought it would be best to start Creo, process say 20 drawings, and then restart and cleanup the cache. This way there should not be any problems caused by disk space or full memory.

Dale_Rosema
23-Emerald III
(To:JVerhagen78)

Not sure, but couldn't you just clear the memory after certain number of files instead of restarting Creo?

 

Automate:

File

Manage session

Erase Not Displayed

 

I used a trail file to run through hundreds of drawing files in order to generate DXF files. This was all done in one session. The trick is exactly what was suggested; to close all the opened files, then use

 

File->Manage Session->Erase Not Displayed

 

after each file was processed. Otherwise you'd hit a limit on opened files, or other undesirable failures. The only inescapable problems were the files that were saved in an incomplete or failed state by whoever created them.


@KenFarley wrote:

I used a trail file to run through hundreds of drawing files in order to generate DXF files. This was all done in one session. The trick is exactly what was suggested; to close all the opened files, then use

 

File->Manage Session->Erase Not Displayed

 

after each file was processed. Otherwise you'd hit a limit on opened files, or other undesirable failures. The only inescapable problems were the files that were saved in an incomplete or failed state by whoever created them.


Hi,

Erase Not Displayed command does not free RAM as expected. If you run a trail file that repeats a certain operation for 1000 files, you will see that the RAM keeps growing even if Erase Not Displayed command is applied.


Martin Hanák

That's dissapointing. Then what purpose does the erase no displayed command serve, I wonder? I guess it shortens the "In Session" model list, but I was always under the assumption that it was freeing up memory from large models I no longer am working with.


@KenFarley wrote:

That's dissapointing. Then what purpose does the erase no displayed command serve, I wonder? I guess it shortens the "In Session" model list, but I was always under the assumption that it was freeing up memory from large models I no longer am working with.


Hi,

yes, that's dissapointing. But that's how it works.


Martin Hanák
RPN
17-Peridot
17-Peridot
(To:KenFarley)

For sure the memory which is allocated gets freed, but due to the fact that PTC is actively managing the memory by themselves, you will not see this. If you would write an application like Creo you would do this as well. Once you have the memory, reuse it, don't give it away to the OS. That means, erase not display, is still recommended 🙂 if you open hundreds of files and work on it. But even this has limitations and you may crash 🙂

RPN
17-Peridot
17-Peridot
(To:JVerhagen78)

You can’t start Creo in that way, either with parametric.exe plus psf or just start the batch, The Creo exe is since years the xtop.exe, no idea why this was never changed. And yes g:no_graphics -i:rpc_input this args are required as well. This args must be given to the xtop. If you just start the parametric.exe you need to know which keys you want to use. Try it by yourself.

Hi,

login to PTC Support and use following link

https://www.ptc.com/en/support/search/#q=g%3Ano_graphics

 

In  CS300745  I found following information ...

Creo Parametric when launched with -g:no_graphics is made to run a trail file

This means you can:

1.] generate trail file

2.] run batch file containing parametric.exe -g:no_graphics PATH_to_trail_file

 


Martin Hanák
RPN
17-Peridot
17-Peridot
(To:MartinHanak)

@MartinHanak @your answer is off topic, he tries to create an asynchronous session, and this does not work because the specified Creo command is invalid, as far I can see.

Sibu
4-Participant
(To:JVerhagen78)

create batch file to open the creo. and call this batch file in the Task sheduler with repeat interval timings , and set it dont start a new instance.

I'm not sure what the Windows Task Scheduler adds/removes to/from the environment of a task (others named mapped network drives).
(Maybe a graphical desktop session is "promised" to exist for the task somehow, but not present in your use case?)

Maybe the PTC TOOLKIT related COM service does not work in this context? From VB/VBA/.NET, the connection to Creo is established via the Windows COM technique.
If you can, try the C/C++ (both paid) or Java OTK (free/paid) API avoiding COM. (Sorry, this is a workaround, not a solution.)


We successfully automated Creo for processing 10k..100k objects with an asynchronous Pro/TOOLKIT (C/C++) application, with and without Windchill.
Creo stability issues occurred (despite erasing everything from session), too, but are prevented by restarting Creo every 500..1000 processed objects. During this restart, all PTC/Creo related interprocess communication processes are killed and caches are cleared (to have a clean next Creo start).

This works in a context of an interactive desktop session and also in a no-graphics Windows Service context using this tool chain:

Create/configure a Windows Service with something like, for example, nssm.exe ( https://nssm.cc/download )

nssm -> Java application -> batch script (incl. kill-script/cache reset etc.) -> ansynchronous TOOLKIT application -> Creo

(It works without the Java application, too.)
This service runs as a user, created only for this purpose.

Where exactly and with what error code/exception fails the connection attempt?

FV
17-Peridot
17-Peridot
(To:JVerhagen78)

try autologon registry hack - this will take care of task scheduler 'run whether user...' property

try to run creo without 'no_graphics' switch, if possible, otherwise creo will run in WIN32_GDI graphics mode and that may cause you some grief...

try not to run your vbs app directly from the task scheduler - create a wrapper batch or powershell script and set task's property to allow interaction - this will help with debugging

you could try to use tasklist and taskkill commands or powershell ...-Process cmdlets to clear up memory when a creo footprint exceeds some given limit 

Announcements


Top Tags