I can't use Openfile function to open part in VBAPI .
using pfcls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testOpenPrt
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("请用;分隔序号数字,输入想要生成DXF的图纸\n所有打开模型将会关闭!!!\n");
string inputselest = Console.ReadLine();
IpfcBaseSession currentSeesion;
IpfcWindow Iwindow;
Connecting MYconnect = new Connecting();
IpfcAsyncConnection asyncConnection = MYconnect.asyncConnection;
currentSeesion = (IpfcBaseSession)asyncConnection.Session;
CCpfcModelDescriptor descModel = new CCpfcModelDescriptor();
IpfcModelDescriptor descModelC;
descModelC = descModel.CreateFromFileName(inputselest + ".prt");
Iwindow = currentSeesion.OpenFile(descModelC);
Iwindow.Activate();
}
}
public class CreoVBAPIProcess
{
public static void EndProcess()
{
Process[] a = Process.GetProcessesByName("pfclscom");
if (a.Length == 0)
{
return;
}
a[0].Kill();
}
}
class Connecting
{
public IpfcAsyncConnection asyncConnection = null;
public Connecting()
{
try
{
// Console.WriteLine("connecting");
asyncConnection = new CCpfcAsyncConnection().Connect(null, null, null, null);
//Console.WriteLine("Connection established to existing Creo Parametric Session");
}
catch (Exception ex)
{
if (!(asyncConnection is null || !asyncConnection.IsRunning()))
{
asyncConnection.Disconnect(1);
}
CreoVBAPIProcess.EndProcess();
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
//Console.WriteLine("Error occurred while connecting to existing Creo Parametric Session");
}
finally
{
}
}
}
}
I can open ",asm" and ".drw" file with this app,but when it coms to "prt",the program report "XToolkitNotFound ".
Here is the bug information.
System.Runtime.InteropServices.COMException HResult=0x80020009 Message=pfcExceptions::XToolkitNotFound Source=RunMarco StackTrace: at pfcls.IpfcBaseSession.OpenFile(IpfcModelDescriptor _MdlDescr) at OpenModel..ctor(Connecting MYconnect, String modelname, Int32 Buttonoption, String Macroname) in C:\Users\u214820\source\repos\RunMarco\Program.cs:line 112 at RunMarco.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\u214820\source\repos\RunMarco\Form1.cs:line 43 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at RunMarco.Program.Main() in C:\Users\u214820\source\repos\RunMarco\Program.cs:line 24
