示例#1
0
        private static void AddRelations(IpfcAsyncConnection AsyncConnection, string FileFullName, string[] rels)
        {
            IpfcModelDescriptor      descmodel;
            IpfcRetrieveModelOptions options;
            IpfcModel         model;
            Cstringseq        relations = new Cstringseq();
            IpfcRelationOwner relationOwner;
            Cstringseq        originrels;

            Console.WriteLine("打开" + FileFullName + "...");
            try
            {
                Console.WriteLine("开始添加" + FileFullName + "关系...");
                descmodel                = (new CCpfcModelDescriptor()).Create((int)EpfcModelType.EpfcMDL_PART, "", null);
                descmodel.Path           = FileFullName;
                options                  = (new CCpfcRetrieveModelOptions()).Create();
                options.AskUserAboutReps = false;
                model = ((IpfcBaseSession)(AsyncConnection.Session)).RetrieveModelWithOpts(descmodel, options);
                ((IpfcBaseSession)(AsyncConnection.Session)).CreateModelWindow(model);
            }
            catch
            {
                Console.WriteLine("无法打开" + FileFullName + "...");
                return;
            }


            relationOwner = (IpfcRelationOwner)model;
            originrels    = relationOwner.get_Relations();
            try
            {
                for (int i = 0; i <= originrels.Count - 1; i++)
                {
                    relations.Append(originrels[i]);
                }

                foreach (string line in rels)
                {
                    relations.Append(line);
                }
                relationOwner.set_Relations(relations);
                model.Save();
            }
            catch
            {
                Console.WriteLine("无法添加" + FileFullName + "关系...");
                return;
            }

            Console.WriteLine(FileFullName + "关系添加完毕...");

            try
            {
                ((IpfcBaseSession)(AsyncConnection.Session)).EraseUndisplayedModels();
                model.EraseWithDependencies();
            }
            catch
            {
            }
        }
示例#2
0
        /// <summary>
        /// 批量将给定目录drw导出到指定目录pdf文件
        /// </summary>
        /// <param name="args"> arg0: proe app path arg1 :dir of drw files arg2 :dir for output </param>
        private static void Main(string[] args)
        {
            IpfcAsyncConnection asyncConnection = null;
            Istringseq          Files;
            string proeapp, inputdir, outputdir;

            if (args.Length != 3)
            {
                Console.Write("参数数目不正确.");
                System.Environment.Exit(0);
            }
            proeapp   = args[0] + " -g:no_graphics -i:rpc_input";
            inputdir  = args[1] + "\\";
            outputdir = args[2] + "\\";
            if (Directory.Exists(inputdir) == false)//如果不存在就创建file文件夹
            {
                Console.Write("输入文件夹不存在,程序退出.");
                System.Environment.Exit(0);
            }
            if (Directory.Exists(outputdir) == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(outputdir);
            }
            Console.WriteLine("开始转换...");
            try
            {
                asyncConnection = new CCpfcAsyncConnection().Start(proeapp, "");
            }
            catch
            {
                Console.WriteLine("无法建立与Creo的连接.");
                System.Environment.Exit(0);
            }
            Console.WriteLine("Creo会话创建完毕...");
            try
            {
                Console.WriteLine(inputdir + "读取中...");
                Files = ((IpfcBaseSession)(asyncConnection.Session)).ListFiles("*.drw", (int)EpfcFileListOpt.EpfcFILE_LIST_LATEST, inputdir);
                Console.WriteLine("drw文件列表读取完毕...");
                foreach (string file in Files)
                {
                    ConvertToPdf(asyncConnection, file, outputdir);
                }
            }
            catch
            {
                Console.WriteLine("无法读取" + inputdir + "...");
            }
            finally
            {
                try
                {
                    asyncConnection.End();
                }
                catch
                {
                }
            }
        }
示例#3
0
 public bool StartCreo()
 {
     try
     {
         asyncConnection = new CCpfcAsyncConnection().Start(_cmdLine, _textPath);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#4
0
        private static void ConvertToDwg(IpfcAsyncConnection AsyncConnection, string FileFullName, string Outputdir)
        {
            IpfcModelDescriptor      descmodel;
            IpfcRetrieveModelOptions options;
            IpfcModel model;
            IpfcDWG3DExportInstructions dwginstructions;

            Console.WriteLine("打开" + FileFullName + "...");
            try
            {
                Console.WriteLine("开始转换" + FileFullName + "...");
                descmodel                = (new CCpfcModelDescriptor()).Create((int)EpfcModelType.EpfcMDL_DRAWING, "", null);
                descmodel.Path           = FileFullName;
                options                  = (new CCpfcRetrieveModelOptions()).Create();
                options.AskUserAboutReps = false;
                model = ((IpfcBaseSession)(AsyncConnection.Session)).RetrieveModelWithOpts(descmodel, options);
                ((IpfcBaseSession)(AsyncConnection.Session)).CreateModelWindow(model);
                model.Display();
            }
            catch
            {
                Console.WriteLine("无法打开" + FileFullName + "...");
                return;
            }

            try
            {
                dwginstructions = (new CCpfcDWG3DExportInstructions()).Create();
                model.Export(Outputdir + model.InstanceName.ToLower() + ".dwg", (IpfcExportInstructions)dwginstructions);
            }
            catch
            {
                Console.WriteLine("无法转换" + FileFullName + "...");
                return;
            }

            Console.WriteLine(FileFullName + "转换完毕...");

            try
            {
                ((IpfcBaseSession)(AsyncConnection.Session)).EraseUndisplayedModels();
                model.EraseWithDependencies();
            }
            catch
            {
            }
        }
示例#5
0
        private static void ConvertToStep(IpfcAsyncConnection AsyncConnection, string FileFullName, string Outputdir)
        {
            IpfcModelDescriptor      descmodel;
            IpfcRetrieveModelOptions options;
            IpfcModel model;
            IpfcSTEP3DExportInstructions stepinstructions;
            IpfcGeometryFlags            flags;

            Console.WriteLine("打开" + FileFullName + "...");
            try
            {
                Console.WriteLine("开始转换" + FileFullName + "...");
                descmodel                = (new CCpfcModelDescriptor()).Create((int)EpfcModelType.EpfcMDL_PART, "", null);
                descmodel.Path           = FileFullName;
                options                  = (new CCpfcRetrieveModelOptions()).Create();
                options.AskUserAboutReps = false;
                model = ((IpfcBaseSession)(AsyncConnection.Session)).RetrieveModelWithOpts(descmodel, options);
            }
            catch
            {
                Console.WriteLine("无法打开" + FileFullName + "...");
                return;
            }

            try
            {
                flags            = (new CCpfcGeometryFlags()).Create();
                flags.AsSolids   = true;
                stepinstructions = (new CCpfcSTEP3DExportInstructions()).Create((int)EpfcAssemblyConfiguration.EpfcEXPORT_ASM_MULTI_FILES, flags);
                model.Export(Outputdir + model.InstanceName.ToLower() + ".stp", (IpfcExportInstructions)stepinstructions);
            }
            catch
            {
                Console.WriteLine("无法转换" + FileFullName + "...");
                return;
            }

            Console.WriteLine(FileFullName + "转换完毕...");

            try
            {
                model.Erase();
            }
            catch
            {
            }
        }
示例#6
0
        private static void ConnectToSession()
        {
            Console.WriteLine("Connecting to Creo session...");

            try
            {
                asyncConnection = (IpfcAsyncConnection) new CCpfcAsyncConnection().Connect(null, null, null, 5);
                Console.WriteLine("Connected!");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error connecting to Creo Parametric Session!");
                Console.WriteLine(ex.Message);
                WriteTips();
                Environment.Exit(1);
            }
        }
示例#7
0
        private static void ConvertToIges(IpfcAsyncConnection AsyncConnection, string FileFullName, string Outputdir)
        {
            IpfcModelDescriptor      descmodel;
            IpfcRetrieveModelOptions options;
            IpfcModel model;
            IpfcIGES3DExportInstructions igesinstructions;
            IpfcGeomExportFlags          flags;

            Console.WriteLine("打开" + FileFullName + "...");
            try
            {
                Console.WriteLine("开始转换" + FileFullName + "...");
                descmodel                = (new CCpfcModelDescriptor()).Create((int)EpfcModelType.EpfcMDL_PART, "", null);
                descmodel.Path           = FileFullName;
                options                  = (new CCpfcRetrieveModelOptions()).Create();
                options.AskUserAboutReps = false;
                model = ((IpfcBaseSession)(AsyncConnection.Session)).RetrieveModelWithOpts(descmodel, options);
            }
            catch
            {
                Console.WriteLine("无法打开" + FileFullName + "...");
                return;
            }

            try
            {
                flags            = (new CCpfcGeomExportFlags()).Create();
                igesinstructions = (new CCpfcIGES3DExportInstructions()).Create(flags);
                model.Export(Outputdir + model.InstanceName.ToLower() + ".igs", (IpfcExportInstructions)igesinstructions);
            }
            catch
            {
                Console.WriteLine("无法转换" + FileFullName + "...");
                return;
            }

            Console.WriteLine(FileFullName + "转换完毕...");

            try
            {
                model.Erase();
            }
            catch
            {
            }
        }
示例#8
0
        private static void ClearRel(IpfcAsyncConnection AsyncConnection, string FileFullName)
        {
            IpfcModelDescriptor      descmodel;
            IpfcRetrieveModelOptions options;
            IpfcModel model;

            Console.WriteLine("打开" + FileFullName + "...");
            try
            {
                Console.WriteLine("开始清空" + FileFullName + "关系...");
                descmodel                = (new CCpfcModelDescriptor()).Create((int)EpfcModelType.EpfcMDL_PART, "", null);
                descmodel.Path           = FileFullName;
                options                  = (new CCpfcRetrieveModelOptions()).Create();
                options.AskUserAboutReps = false;
                model = ((IpfcBaseSession)(AsyncConnection.Session)).RetrieveModelWithOpts(descmodel, options);
                ((IpfcBaseSession)(AsyncConnection.Session)).CreateModelWindow(model);
            }
            catch
            {
                Console.WriteLine("无法打开" + FileFullName + "...");
                return;
            }

            try
            {
                ((IpfcRelationOwner)model).DeleteRelations();
                model.Save();
            }
            catch
            {
                Console.WriteLine("无法清空" + FileFullName + "关系...");
                return;
            }

            Console.WriteLine(FileFullName + "关系清空完毕...");

            try
            {
                ((IpfcBaseSession)(AsyncConnection.Session)).EraseUndisplayedModels();
                model.EraseWithDependencies();
            }
            catch
            {
            }
        }
示例#9
0
 public bool ConnectCreo()
 {
     try
     {
         if (asyncConnection == null || !asyncConnection.IsRunning())
         {
             asyncConnection = new CCpfcAsyncConnection().Connect(null, null, null, null);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
示例#10
0
 private Timer eventTimer; //定时器,用于定时处理asyncConnection.EventProcess,防止Creo无法处理事件导致程序锁死
 /// <summary>
 /// 连接现有会话并添加菜单
 /// </summary>
 /// <returns>是否连接成功</returns>
 public bool ConnectCreo()
 {
     try
     {
         if (asyncConnection == null || asyncConnection.IsRunning() == true)
         {
             asyncConnection = new CCpfcAsyncConnection().Connect(null, null, null, null);
             AddEventProcess();
             AddPushButtonMenu();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
示例#11
0
        /// <summary>
        /// 批量将给定目录prt的添加指定txt文件下的关系
        /// </summary>
        /// <param name="args"> arg0: proe app path arg1: dir of prt files arg2: txt file contents relations </param>
        private static void Main(string[] args)
        {
            IpfcAsyncConnection asyncConnection = null;
            Istringseq          Files;

            string[] relations;
            string   proeapp, inputdir, relfile;

            if (args.Length != 3)
            {
                Console.Write("参数数目不正确.");
                System.Environment.Exit(0);
            }
            proeapp  = args[0] + " -g:no_graphics -i:rpc_input";
            inputdir = args[1] + "\\";
            relfile  = args[2];
            if (Directory.Exists(inputdir) == false)
            {
                Console.Write("输入文件夹不存在,程序退出.");
                System.Environment.Exit(0);
            }
            if (File.Exists(relfile) == false)
            {
                Console.Write("输入关系文件不存在,程序退出.");
                System.Environment.Exit(0);
            }
            relations = Getrels(relfile);
            Console.WriteLine("开始添加...");
            try
            {
                asyncConnection = new CCpfcAsyncConnection().Start(proeapp, "");
            }
            catch
            {
                Console.WriteLine("无法建立与Creo的连接.");
                System.Environment.Exit(0);
            }
            Console.WriteLine("Creo会话创建完毕...");
            try
            {
                Console.WriteLine(inputdir + "读取中...");
                Files = ((IpfcBaseSession)(asyncConnection.Session)).ListFiles("*.prt", (int)EpfcFileListOpt.EpfcFILE_LIST_LATEST, inputdir);
                Console.WriteLine("prt文件列表读取完毕...");
                foreach (string file in Files)
                {
                    AddRelations(asyncConnection, file, relations);
                }
            }
            catch
            {
                Console.WriteLine("无法读取" + inputdir + "...");
            }
            finally
            {
                try
                {
                    asyncConnection.End();
                }
                catch
                {
                }
            }
        }
示例#12
0
 public TestButtonUICommandAccessListener(ref IpfcAsyncConnection aC)
 {
     asyncConnection = aC;
 }