Beispiel #1
0
        public Result Execute(ExternalCommandData commandData,
                              ref string message,
                              ElementSet elements)
        {
            #region Declaracion de varables para acceder al documento
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Document      doc   = uidoc.Document;
            #endregion

            #region Seleccion de elementos
            IList <Reference> pickedObjs;
            pickedObjs = uidoc.Selection.PickObjects(ObjectType.Element, "Seleccione los elementos");
            List <Element> els = (from Reference r in pickedObjs select doc.GetElement(r.ElementId)).ToList();
            #endregion

            //TaskDialog.Show("Cantidad de Elementos", "Usted selecciono " + els.Count.ToString());
            frm_selectParameters frm = new frm_selectParameters();
            frm.ShowDialog();

            if (frm_selectParameters.ejecutar)
            {
                foreach (Element el in els)
                {
                    using (Transaction t1 = new Transaction(doc, "T01"))
                    {
                        t1.Start();

                        /// Parametro 01 - Donde guardamos la información
                        var parameters = el.GetParameters(frm_selectParameters.parametro_01);
                        if (parameters.Count == 0)
                        {
                            TaskDialog.Show("Mensaje de Error", "El parametro seleccionado no existe");
                            return(Result.Cancelled);
                        }
                        var parameter = parameters.First();
                        /// Parametro 02 - Donde obtenemos la información
                        parameter.Set(ParameterToString(el.LookupParameter(frm_selectParameters.parametro_02)) + " Automatización");
                        t1.Commit();
                    }
                }
                TaskDialog.Show("Mensaje de Exito", "Se modificaron " + els.Count.ToString() + " elementos");
                return(Result.Succeeded);
            }
            else
            {
                TaskDialog.Show("Mensaje de Error", "No se modifico los elementos por que el usuario cancelo la ejecución");
                return(Result.Cancelled);
            }


            ///###CASO DONDE SELECCIONE UN ELEMENTO###
            ///1. SELECCIONAR SOLO UN ELEMENTO
            ///uidoc.Selection.PickObject(ObjectType.Element);
            ///2. OBTENDRIA LOS PARAMETROS DEL ELEMENTO el.getorderParameters
            ///3. RECORRERIA TODOS LOS PARAMETROS Y OBTENDRIA SU valueString y lo guardaria dentro de una lista de String.
            ///List<string>
            ///4. LO MOSTRARIA EN UN COMBOBOX
            ///Cmb_any.datasource
        }
Beispiel #2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            #region TRABAJAR CON EXCEL

            frm_selectParameters frm = new frm_selectParameters();
            frm.ShowDialog();

            if (frm_selectParameters.ejecutar)
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Title  = "Seleccione un excel";
                dlg.Filter = "Archivos Excel (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm|All files(*)|*";
                if (DialogResult.OK != dlg.ShowDialog())
                {
                    TaskDialog.Show("Mesaje de Error", "Usted no selecciono ningun archivo");
                    return(Result.Cancelled);
                }

                X.Application excel = new X.Application();

                if (excel == null)
                {
                    TaskDialog.Show("Mesaje de Error", "Error para crear el archivo excel");
                    return(Result.Cancelled);
                }

                X.Workbook wb = excel.Workbooks.Open(dlg.FileName, Missing.Value, Missing.Value,
                                                     Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                     Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                     Missing.Value, Missing.Value, Missing.Value, Missing.Value);

                X.Worksheet ws = excel.ActiveWorkbook.Sheets["Hoja1"];

                excel.Visible = false;



                ws.Cells[2, 2] = frm_selectParameters.parametro_01;
                ws.Cells[2, 3] = frm_selectParameters.parametro_02;

                TaskDialog.Show("Mensaje desde Excel", ws.Cells[2, 4].value());
                excel.Visible = true;
                //wb.Save();

                #endregion
                return(Result.Succeeded);
            }
            else
            {
                return(Result.Cancelled);
            }
        }