Your Products have been synced, click here to refresh
Ok, I just finished the Automating PC-DMIS online course... Where should I go next to learn more about how to use this with DMIS?
A fun one for me was to re-create a scripts that floating around here somewhere that takes all programs in a directory and reads all of the probes used and tips for each one. I adopted to use as much Object Oriented Programming as I could, what a blast!
I would create small checker/helper programs to assist you in developing part routines... think of the one thing you always forget to do when writing Pc-Dmis part programs.... like forgetting to change that pesky default tolerance you forgot to correct.
Another would be to figure out how to send arguments to console applications and/or how to fire console .exe from within Pc-Dmis.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using PCDLRN; using Microsoft.VisualBasic; using System.Diagnostics; using System.IO.Compression; using System.Threading; using System.Runtime.InteropServices; using System.ComponentModel; using System.Windows.Interop; namespace PCD_Operator_App { /// <summary> /// Interaction logic for LoadScreen.xaml /// </summary> public partial class LoadScreen : Window { private const int GWL_STYLE = -16; private const int WS_SYSMENU = 0x80000; [DllImport("user32.dll", SetLastError = true)] private static extern int GetWindowLong(IntPtr hWnd, int nIndex); [DllImport("user32.dll")] private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); public LoadScreen() { InitializeComponent(); BackgroundWorker backgroundStartup = new BackgroundWorker(); backgroundStartup.WorkerReportsProgress = true; backgroundStartup.DoWork += startup_DoWork; backgroundStartup.ProgressChanged += startup_ProgressChanged; backgroundStartup.RunWorkerCompleted += startup_RunWorkerCompleted; backgroundStartup.RunWorkerAsync(); } void startup_DoWork(object sender, DoWorkEventArgs e) { bool startCondition = true; Process[] pcdStartupCheck = Process.GetProcessesByName("PCDLRN"); if (pcdStartupCheck.Length > 0) { startCondition = false; } else { Type PCDRLN_Application = null; object PCDObj = null; PCDLRN.Application PCDApp = null; try { PCDRLN_Application = Type.GetTypeFromProgID("PCDLRN.Application"); PCDObj = Activator.CreateInstance(PCDRLN_Application); } catch (System.Exception em) { MessageBox.Show(em.Message); } PCDApp = new PCDLRN.Application(); PCDApp.OperatorMode = true; PCDApp.Visible = false; PCDApp.ApplicationEvents.OnMachineConnected += new IApplicationEvents_OnMachineConnectedEventHandler(onMachineConnect); void onMachineConnect(Machine machine) { //MessageBox.Show("machine connected"); //loadScreenStatus.Content = "PC-DMIS active, connecting to machine..."; startCondition = false; } if (startCondition) { WindowSearcher homeWindowSearch = new WindowSearcher(); homeWindowSearch.BeginWindowLook_Home(); } } } void startup_ProgressChanged(object sender, ProgressChangedEventArgs e) { } void startup_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { new MainWindow().Show(); this.Close(); } private void WindowLoaded(object sender, RoutedEventArgs e) { var hwnd = new WindowInteropHelper(this).Handle; SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU); } } }
One major improvement with automating PCDMIS I learned along the way was using a "BackgroundWorker" (there are other ways to accomplish this as well) to execute certain tasks. One thing you'll eventually notice is that when you hit a button and the buttons "freeze" until the code block(s) finish executing, running a part program for example.
Below is an example of launching pcdmis with a BackgroundWorker. I just copied and pasted this so if you have a question about what something is let me know
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using PCDLRN; using Microsoft.VisualBasic; using System.Diagnostics; using System.IO.Compression; using System.Threading; using System.Runtime.InteropServices; using System.ComponentModel; using System.Windows.Interop; namespace PCD_Operator_App { /// <summary> /// Interaction logic for LoadScreen.xaml /// </summary> public partial class LoadScreen : Window { private const int GWL_STYLE = -16; private const int WS_SYSMENU = 0x80000; [DllImport("user32.dll", SetLastError = true)] private static extern int GetWindowLong(IntPtr hWnd, int nIndex); [DllImport("user32.dll")] private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); public LoadScreen() { InitializeComponent(); BackgroundWorker backgroundStartup = new BackgroundWorker(); backgroundStartup.WorkerReportsProgress = true; backgroundStartup.DoWork += startup_DoWork; backgroundStartup.ProgressChanged += startup_ProgressChanged; backgroundStartup.RunWorkerCompleted += startup_RunWorkerCompleted; backgroundStartup.RunWorkerAsync(); } void startup_DoWork(object sender, DoWorkEventArgs e) { bool startCondition = true; Process[] pcdStartupCheck = Process.GetProcessesByName("PCDLRN"); if (pcdStartupCheck.Length > 0) { startCondition = false; } else { Type PCDRLN_Application = null; object PCDObj = null; PCDLRN.Application PCDApp = null; try { PCDRLN_Application = Type.GetTypeFromProgID("PCDLRN.Application"); PCDObj = Activator.CreateInstance(PCDRLN_Application); } catch (System.Exception em) { MessageBox.Show(em.Message); } PCDApp = new PCDLRN.Application(); PCDApp.OperatorMode = true; PCDApp.Visible = false; PCDApp.ApplicationEvents.OnMachineConnected += new IApplicationEvents_OnMachineConnectedEventHandler(onMachineConnect); void onMachineConnect(Machine machine) { //MessageBox.Show("machine connected"); //loadScreenStatus.Content = "PC-DMIS active, connecting to machine..."; startCondition = false; } if (startCondition) { WindowSearcher homeWindowSearch = new WindowSearcher(); homeWindowSearch.BeginWindowLook_Home(); } } } void startup_ProgressChanged(object sender, ProgressChangedEventArgs e) { } void startup_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { new MainWindow().Show(); this.Close(); } private void WindowLoaded(object sender, RoutedEventArgs e) { var hwnd = new WindowInteropHelper(this).Handle; SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU); } } }
Um... yeah... I question all of it. This is my first time getting into any kind of programming except programming part programs in DMIS. Maybe I should have them send me to the local community college for classes.
I bought a book here that got me started, I liked it a lot. Answered a lot of questions not regarding pc-dmis. Now that I've taken a few college level courses in coding, a lot of them follow these books very closely. Learning this will start to happen much quicker as you go along, like putting a puzzle together
https://www.amazon.com/Microsoft-Visual-Step-Developer-Reference/dp/1509307761/ref=asc_df_1509307761/?tag=hyprod-20&linkCode=df0&hvadid=312125971120&hvpos=&hvnetw=g&hvrand=56322634205378343&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9016977&hvtargid=pla-527352025378&psc=1&tag=&ref=&adgrpid=61316180839&hvpone=&hvptwo=&hvadid=312125971120&hvpos=&hvnetw=g&hvrand=56322634205378343&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9016977&hvtargid=pla-527352025378
© 2024 Hexagon AB and/or its subsidiaries. | Privacy Policy | Cloud Services Agreement |