hexagon logo

How to open a python script in pcdmis?

I've got a couple basic scripts running on our programs and you simply go to INSERT > BASIC SCRIPT and chose the .bas file. But it won't let me choose a python file .py.
I tried external command and that doesn't work and I've tried INSERT > FILE I/O COMMAND > FILE OPEN, but when I run the program it runs the program without doing anything inside the python script.

How were those running some python scripts here actually getting pcdmis to open the python script?

Thanks.

Parents
  • Have you tried to shell the application?

    Here is an example of C# application being shell using the Insert Basic Script.

    The C# Administrator application will check if PC-DMIS is running as administrator. I haven't tried this with python and probably won't because I find it much simpler to use C# with the PC-DMIS library.

    Here is the PC-DMIS code.
    $$ NO,
    <Administration Check. Some directories are not available while running as administrator.>​
    ADMIN_CHECK_CS1 =SCRIPT/FILENAME= C:\USERS\PUBLIC\DOCUMENTS\HEXAGON\ROUTINE BUILDER\ROUTINE BASIC SCRIPTS\AMINISTRATOR_NOTIFICATION.BAS
    FUNCTION/Main,SHOW=YES,,
    STARTSCRIPT/
    ENDSCRIPT/​
    


    Here is the AMINISTRATOR_NOTIFICATION.BAS script for the example.

    Sub Main
    
    Dim shellpath
    
    shellpath = "C:\Users\Public\Documents\Hexagon\Routine Builder\Routine Exe Scripts\AministratorNotificationConsoleApp1.exe"
    
    Close shellpath
    
    'Launch application & Open file
    Shell shellpath
    
    End Sub
    


    Here is the C# application.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Security.Principal;
    using System.Runtime.InteropServices;
    namespace AministratorNotificationConsoleApp1
    {
        internal class Program
        {
            [DllImport("User32.dll", CharSet = CharSet.Unicode)]
            public static extern int MessageBox(IntPtr h, string m, string c, int type);
            static void Main(string[] args)
            {
                bool isRunningAsAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
                // found this syntax executes faster
                if (isRunningAsAdmin)
                {
                    MessageBox((IntPtr)0, "This application is running as administrator.", "Admin Warning", 0);
                    Console.WriteLine("This application is running as administrator.");
                    Console.ReadKey();
                }
            }
        }
    }
    /*
     Using .NET 4.8 FrameWork
    To switch this app from using the Console. Select AministratorNotificationConsoleApp1 within the
    Solution Explorer right mouse click and select properties.
    Change the OutPut Type to Windows Application.​
    */
    


    For more information on the Shell function.

    PC-DMIS Help

    Shell Function
    1. Shell ( app [, style])
    Runs an executable program.
    The shell function has two parameters. The first one, app is the name of the program to be executed. The name of the program in app must include a .PIF, .COM, .BAT, or .EXE file extension or an error will occur. The second argument, style is the number corresponding to the style of the window . It is also optional and if omitted the program is opened minimized with focus.
    Window styles:
    1. Normal with focus 1,5,9
      Minimized with focus (default) 2
      Maximized with focus 3
      normal without focus 4,8
      minimized without focus 6,7
    Return value: ID, the task ID of the started program.



    Link: https://docs.hexagonmi.com/pcdmis/2021.1/en/helpcenter/index.htm?rhcsh=1&rhnewwnd=0#t=mergedProjects%2Fba sic%2FShell_Function.htm&rhsearch=shell&rhsyns=%20 &rhhlterm=shell
Reply
  • Have you tried to shell the application?

    Here is an example of C# application being shell using the Insert Basic Script.

    The C# Administrator application will check if PC-DMIS is running as administrator. I haven't tried this with python and probably won't because I find it much simpler to use C# with the PC-DMIS library.

    Here is the PC-DMIS code.
    $$ NO,
    <Administration Check. Some directories are not available while running as administrator.>​
    ADMIN_CHECK_CS1 =SCRIPT/FILENAME= C:\USERS\PUBLIC\DOCUMENTS\HEXAGON\ROUTINE BUILDER\ROUTINE BASIC SCRIPTS\AMINISTRATOR_NOTIFICATION.BAS
    FUNCTION/Main,SHOW=YES,,
    STARTSCRIPT/
    ENDSCRIPT/​
    


    Here is the AMINISTRATOR_NOTIFICATION.BAS script for the example.

    Sub Main
    
    Dim shellpath
    
    shellpath = "C:\Users\Public\Documents\Hexagon\Routine Builder\Routine Exe Scripts\AministratorNotificationConsoleApp1.exe"
    
    Close shellpath
    
    'Launch application & Open file
    Shell shellpath
    
    End Sub
    


    Here is the C# application.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Security.Principal;
    using System.Runtime.InteropServices;
    namespace AministratorNotificationConsoleApp1
    {
        internal class Program
        {
            [DllImport("User32.dll", CharSet = CharSet.Unicode)]
            public static extern int MessageBox(IntPtr h, string m, string c, int type);
            static void Main(string[] args)
            {
                bool isRunningAsAdmin = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
                // found this syntax executes faster
                if (isRunningAsAdmin)
                {
                    MessageBox((IntPtr)0, "This application is running as administrator.", "Admin Warning", 0);
                    Console.WriteLine("This application is running as administrator.");
                    Console.ReadKey();
                }
            }
        }
    }
    /*
     Using .NET 4.8 FrameWork
    To switch this app from using the Console. Select AministratorNotificationConsoleApp1 within the
    Solution Explorer right mouse click and select properties.
    Change the OutPut Type to Windows Application.​
    */
    


    For more information on the Shell function.

    PC-DMIS Help

    Shell Function
    1. Shell ( app [, style])
    Runs an executable program.
    The shell function has two parameters. The first one, app is the name of the program to be executed. The name of the program in app must include a .PIF, .COM, .BAT, or .EXE file extension or an error will occur. The second argument, style is the number corresponding to the style of the window . It is also optional and if omitted the program is opened minimized with focus.
    Window styles:
    1. Normal with focus 1,5,9
      Minimized with focus (default) 2
      Maximized with focus 3
      normal without focus 4,8
      minimized without focus 6,7
    Return value: ID, the task ID of the started program.



    Link: https://docs.hexagonmi.com/pcdmis/2021.1/en/helpcenter/index.htm?rhcsh=1&rhnewwnd=0#t=mergedProjects%2Fba sic%2FShell_Function.htm&rhsearch=shell&rhsyns=%20 &rhhlterm=shell
Children
No Data