Example #1
0
        public DoWork(string m_token, PowerMILL.PluginServices m_services, string _pSPath)
        {
            this._pSPath = _pSPath;

            bool   selectedSurfaces = false;
            object oSelectedSurfaces;

            m_services.DoCommandEx(m_token, "print selsurface", out oSelectedSurfaces);

            if (!string.IsNullOrEmpty(oSelectedSurfaces.ToString()))
            {
                selectedSurfaces = true;
            }

            m_services.DoCommand(m_token, @"STRING $modelNameForApp = """"");
            m_services.DoCommand(m_token, @"$modelNameForApp = """"");
            m_services.DoCommand(m_token, @"$modelNameForApp =  INPUT ENTITY MODEL ""Vyber model pro export""");

            object modelName;

            m_services.DoCommandEx(m_token, "print $modelNameForApp", out modelName);

            if (!string.IsNullOrEmpty(modelName.ToString()))
            {
                if (!CreateConection())
                {
                    if (!startPSandConnect())
                    {
                        System.Windows.Forms.MessageBox.Show("Connection to PS failed");
                    }
                }

                object modelPath;
                m_services.DoCommandEx(m_token, @"print $entity(""Model"",""" + modelName + @""").Path", out modelPath);

                if (!File.Exists(modelPath.ToString()) || selectedSurfaces)
                {
                    modelPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + modelName + ".dgk";
                    m_services.DoCommand(m_token, @"EXPORT MODEL """ + modelName + @""" FILESAVE """ + modelPath + @"""");
                    ImportModel(modelPath.ToString());
                    File.Delete(modelPath.ToString());
                }
                else
                {
                    ImportModel(modelPath.ToString());
                }
            }
        }
Example #2
0
        public static List <string> getEntitySorting(string entityType, string m_token, PowerMILL.PluginServices m_services)
        {
            List <string> returnValue = null;

            try {
                string pathMacroTemp = getCestaMakroTemp();

                using (var writeMacro = new StreamWriter(pathMacroTemp, false, Encoding.Default)) {
                    writeMacro.WriteLine(@"FOREACH $x IN FOLDER(""" + entityType + @""") {");
                    writeMacro.WriteLine("print $x.Name");
                    writeMacro.WriteLine("}");
                }

                object resultO = null;
                m_services.DoCommandEx(m_token, @"macro """ + pathMacroTemp + @"""", out resultO);
                string   result     = resultO.ToString().Replace(Environment.NewLine, "@");
                string[] resultList = result.Split('@');
                returnValue = new List <string>();
                foreach (string ft in resultList)
                {
                    if (!string.IsNullOrEmpty(ft))
                    {
                        returnValue.Add(ft);
                    }
                }
            } catch { returnValue = null; System.Windows.Forms.MessageBox.Show("Chyba čtení temp makra!"); }

            return(returnValue);
        }
        public static string ExecuteEx(string Command)
        {
            object sResponse;
            string sOutput;
            int    error = oPServices.DoCommandEx(oToken, Command, out sResponse);

            if (error != 0)
            {
                if (!Command.Equals("PRINT VALUE PROJECTPATH"))
                {
                    throw new Exception("Failed to obtain command value: " + Command);
                }
            }

            sOutput = (sResponse as string).Trim();
            if (sOutput.Contains(Command))
            {
                List <string> sTabCNInfos = new List <string>(sOutput.Split((char)13));
                if (sTabCNInfos.Count > 0)
                {
                    sTabCNInfos.RemoveAt(0);
                    if (sTabCNInfos.Count > 0)
                    {
                        sTabCNInfos.RemoveAt(0);
                        return(String.Join(((char)13).ToString(), sTabCNInfos.ToArray()).Trim());
                    }
                }
            }
            else
            {
                return(sOutput);
            }
            return("");
        }
Example #4
0
        /*public static string getMainWorkplane(PowerMILL.Application oAppliacation)
         * {
         *      List<string> jmenaWorkplanes = Gets.getEntitySorting("Workplane",oAppliacation);
         *      if (jmenaWorkplanes.Count > 0)
         *              return jmenaWorkplanes[0];
         *      return null;
         *
         * }
         *
         * public static string getNamedEntityParameterString(string entity,string jmeno, string parameter,PowerMILL.Application oAppliacation)
         * {
         *
         *      int err = 0;
         *      string returnValue = null;
         *      oAppliacation.ExecuteEx(@"print $entity("""+entity+@""","""+jmeno+@""")."+parameter,out err,out returnValue);
         *      returnValue = returnValue.Replace(Environment.NewLine,"").Trim();
         *
         *      return returnValue;
         * }
         *
         * public static bool getNamedEntityParameterBool(string entity,string jmeno, string parameter,PowerMILL.Application oAppliacation)
         * {
         *      string str = Gets.getNamedEntityParameterString(entity,jmeno,parameter,oAppliacation);
         *      return str.Trim() == "1";
         * }
         *
         * public static int getNamedEntityParameterInt(string entity,string jmeno, string parameter,PowerMILL.Application oAppliacation)
         * {
         *      string str = Gets.getNamedEntityParameterString(entity,jmeno,parameter,oAppliacation);
         *      return  int.Parse(str.Trim());
         * }
         *
         * public static double getNamedEntityParameterDouble(string entity,string jmeno, string parameter,PowerMILL.Application oAppliacation)
         * {
         *      string str = Gets.getNamedEntityParameterString(entity,jmeno,parameter,oAppliacation);
         *      return  double.Parse(str.Trim());
         * }
         *
         * public static double[] getNamedEntityParameterVector3(string entity,string jmeno, string parameter,PowerMILL.Application oAppliacation)
         * {
         *      double d0 = Gets.getNamedEntityParameterDouble(entity,jmeno,parameter+"[0]",oAppliacation);
         *      double d1 = Gets.getNamedEntityParameterDouble(entity,jmeno,parameter+"[1]",oAppliacation);
         *      double d2 = Gets.getNamedEntityParameterDouble(entity,jmeno,parameter+"[2]",oAppliacation);
         *
         *      return  new double[] {d0,d1,d2 };
         *
         * }*/

        public static string getActiveEntityParameterString(string entity, string parameter, string m_token, PowerMILL.PluginServices m_services)
        {
            object returnValueO = null;

            m_services.DoCommandEx(m_token, @"print $entity(""" + entity + @""","""")." + parameter, out returnValueO);
            string returnValue = returnValueO.ToString().Replace(Environment.NewLine, "");

            return(returnValue);
        }
Example #5
0
        /// <summary>
        /// This execute a PowerMILL command and return the answer in a string
        /// </summary>
        /// <param name="Command"></param>
        /// <returns></returns>
        public string ExecuteEx(string Command)
        {
            object sResponse;
            int    error = oPServices.DoCommandEx(oToken, Command, out sResponse);

            if (error != 0)
            {
                throw new Exception("Failed to obtain command value: " + Command);
            }
            return(sResponse as string);
        }