Your Products have been synced, click here to refresh
dim app as object set app = CreateObject("PCDLRN.Application")
// code to open pc-dmis, if pc-dmis is open, this c# application will connect to the currently running instance of PC-DMIS using PCDLRN; // class containing functions for interacting with pcdmis public class PCDMISInterop { Appliction pcdApp; // don't use IAppliction, instances of interface types cannot be created, Interfaces can only be inherated public Application PCDMISApplication { get{return this.Application;} } public PCDMISInterop() { startPCDMIS(); } bool StartPCDMIS() { try { Type pcdObjType = Type.GetTypeFromProgID("PCDLRN.Application"); this.pcdApp = Activator.CreateInstance(pcdObjType); pcdApp.WaitUntilReady(60); return true; //pc-dmis started } catch { return false; // an error occured } } // Gets the active part program }
using PCDLRN; int main(void) { PCDMISInterop PCDMIS = new PCDMISInterop(); PartProgram pcdProgram = PCDMIS.PCDMISApplication.ActivePartProgram // the following 2 methods could be put into the PCDMISInterop Class to simplify the coding. // to open a part program PCDMIS.PCDMISApplication.PartPrograms.Open("C:\test.prg","CMM1"); // "CMM1" for online, "OFFLINE" for offline // to create a new part program PCDMIS.PCDMISApplication.PartPrograms.Add("C:\test2.prg",UNITTYPE.INCH/*UNITTYPE.MM for metric*/,"TESTPROBE"); }
Hey, thanks cappy! I'll try this out asap!
I assume I need to use the Interop.PCDLRN.dll for this? I have added it as reference to my solution, is that enough (and to distribute it with the app)?
vpt,
I'll start with a question. How would you connect to a currently running program in a PC-DMIS script?
dim app as object set app = CreateObject("PCDLRN.Application")
the c# equivalent is very easy, there is actually a doc burried in the script editor help file called "Windows 7 automation notes"
the following code is derived from that.
// code to open pc-dmis, if pc-dmis is open, this c# application will connect to the currently running instance of PC-DMIS using PCDLRN; // class containing functions for interacting with pcdmis public class PCDMISInterop { Appliction pcdApp; // don't use IAppliction, instances of interface types cannot be created, Interfaces can only be inherated public Application PCDMISApplication { get{return this.Application;} } public PCDMISInterop() { startPCDMIS(); } bool StartPCDMIS() { try { Type pcdObjType = Type.GetTypeFromProgID("PCDLRN.Application"); this.pcdApp = Activator.CreateInstance(pcdObjType); string status = ""; /* this while loop starts with status = "", and will query PC-DMIS for the text in the status bar at the bottom of the screen. when it finally says "READY" or it contains "DONE INIT", the loop will exit */ while (status != "READY" && !status.Contains("DONE INIT")) { System.Threading.Thread.Sleep(1000); // give pc-dmis a second to work status = this.pcdApp.StatusBar.ToUpper(); } return true; //pc-dmis started } catch { return false; // an error occured } } // Gets the active part program }
this is how you would use it in the main part of the program
using PCDLRN; int main(void) { PCDMISInterop PCDMIS = new PCDMISInterop(); PartProgram pcdProgram = PCDMIS.PCDMISApplication.ActivePartProgram // the following 2 methods could be put into the PCDMISInterop Class to simplify the coding. // to open a part program PCDMIS.PCDMISApplication.PartPrograms.Open("C:\test.prg","CMM1"); // "CMM1" for online, "OFFLINE" for offline // to create a new part program PCDMIS.PCDMISApplication.PartPrograms.Add("C:\test2.prg",UNITTYPE.INCH/*UNITTYPE.MM for metric*/,"TESTPROBE"); }
I hope this helps.
I do a lot of Interop with PC-DMIS in C# so if you need anything send me a PM.
bool StartPCDMIS() { try { Type pcdObjType = Type.GetTypeFromProgID("PCDLRN.Application"); this.pcdApp = Activator.CreateInstance(pcdObjType); int timeout = 100; // the number of seconds to wait... pcdApp.WaitUntilReady(timeout); return true; //pc-dmis started } catch { return false; // an error occured } }
© 2024 Hexagon AB and/or its subsidiaries. | Privacy Policy | Cloud Services Agreement |