Announcements
Atención para clientes sin autenticación multifactor o inicio de sesión único: la verificación OTP se implementará en abril de 2025. Lee todo al respecto aquí.

Extraer parametro Comentario con WPF(Extract Comment parameter with WPF)

reylorente1
Collaborator

Extraer parametro Comentario con WPF(Extract Comment parameter with WPF)

reylorente1
Collaborator
Collaborator

Hice un pequeño script con WPF para extraer el parametro comentario(Ejemplo puertas).
No puedo hacerlo,aqui estas mi codigos,que falta?

 

I made a small script with WPF to extract the comment parameter (Example doors).
I can't do it, here are my codes, what's missing?

 

class Utils
    {
        //variable
       public string Nombre { get; set; }
        public string Comentario { get; set; }
        public string Marca { get; set; }
        public string datos { get; set; }

        //public Document _doc;


        #region Seleccionar Elemento
        /// <summary>
        /// Seleccionar un elemento
        /// </summary>
        /// <param name="uidoc"></param>
        /// <param name="doc"></param>
        /// <returns></returns>
        public Element SeleccElement(UIDocument uidoc)
        {
            //Documentos
            Document doc = uidoc.Document;

            //Seleccionar Elemento en la pantalla
            TaskDialog.Show("Info_Revit", "Seleccione un elemento");

            // Access current selection
            Selection sel = uidoc.Selection;

            //Obtener la referencia seleccionada
            Reference reference = sel.PickObject(ObjectType.Element, "Seleccione un Elemento");

            //Obtener el elemento elegido
            Element element = doc.GetElement(reference);

            return element;
        }
        #endregion

        public string Getdata(Document doc, Element elem)
        {
            BuiltInParameter built_name = BuiltInParameter.ELEM_FAMILY_PARAM;
            BuiltInParameter built_Comments = BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS;
            BuiltInParameter built_Marca = BuiltInParameter.ALL_MODEL_MARK;

            Nombre = string.Format("Nombre {0} => ID {1} ", elem.get_Parameter(built_name).AsValueString(), "<" + elem.Id.IntegerValue.ToString() + ">");
            Parameter param_Commen = elem.get_Parameter(built_Comments);
            Parameter param_Marca = elem.get_Parameter(built_Marca);

            if (param_Commen != null)
            {
                Comentario = param_Commen.AsValueString();
            }
            
            if (param_Marca != null)
            {
                Marca = param_Marca.AsValueString();
            }
            datos = Nombre + Comentario + Marca;

            return datos;
        }

        public void SetData(UIDocument uidoc, Element elem)
        {
            Document doc = uidoc.Document;
            
            BuiltInParameter built_Comments = BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS;
            //BuiltInParameter built_Marca = BuiltInParameter.ALL_MODEL_MARK;
            
            Parameter param_Commen = elem.get_Parameter(built_Comments);
           // Parameter param_Marca = elem.get_Parameter(built_Marca);

           // Comentario = param_Commen.AsValueString();

            //Iniciar una transaccion
            using (Transaction trans = new Transaction(doc, "Modificar Parametro"))
            {
                trans.Start();
                //Modificar los parametros
                if (param_Commen != null)
                {
                    //Comentario = param_Commen.AsValueString();
                    //param_Commen.Set(Comentario);
                    MessageBox.Show(Comentario);
                }
                //if (param_Marca != null)
                //{
                //    param_Marca.Set(Marca);
                //}
                trans.Commit();

                TaskDialog.Show("Info_Revit", "Parametro Modificado correctmente");
            }
        }
    }

/// <summary>
    /// Lógica de interacción para MainWindow_Seleccion.xaml
    /// </summary>
    public partial class MainWindow_Seleccion : Window
    {
        //Accesos
        UIDocument _uidoc;
        Document _doc;
        Element _elem;

        public MainWindow_Seleccion(UIDocument uidoc,Element elem)
        {
            Document doc = uidoc.Document;
            InitializeComponent();
            this._doc = doc;
            this._elem = elem;
            this._uidoc = uidoc;
            Utils u = new Utils();
            u.datos = u.Getdata(_doc, _elem);

            this.DataContext =u;
        }

        private void btnGuardar_Click(object sender, RoutedEventArgs e)
        {
            Utils u = new Utils();
            u.SetData(_uidoc, _elem);
            this.Close();
            
        }
    }

....
try
            {
                Utils utils = new Utils();
                Element elem = utils.SeleccElement(uidoc);
                MainWindow_Seleccion _Seleccion = new MainWindow_Seleccion(uidoc,elem);
                _Seleccion.ShowDialog();

                // Assuming that everything went right return Result.Succeeded
                return Result.Succeeded;
            }
            // This is where we "catch" potential errors and define how to deal with them
            catch (Autodesk.Revit.Exceptions.OperationCanceledException)
            {
                // If user decided to cancel the operation return Result.Canceled
                return Result.Cancelled;
            }
<Window x:Class="Seleccionar.MainWindow_Seleccion"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Seleccionar"
             mc:Ignorable="d" 
             Height="280" Width="420" 
             Title="Ventana de Seleccion"
             Background="Lavender" WindowStartupLocation="CenterScreen"
             ResizeMode="CanResize">
    <Grid>
        <!-- Crear filas-->
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="25"/>
            <RowDefinition Height="250*"/>
            <RowDefinition Height="25"/>
        </Grid.RowDefinitions>
        <Label Content="Editar Parametros" FontSize="18" FontWeight="Black" HorizontalContentAlignment="Center" />
        <Label Grid.Row="1" Content="Informacion del Elemento" 
               FontSize="14" Foreground="Black" 
               ScrollViewer.VerticalScrollBarVisibility="Disabled" 
               Background="#FF2AB25B" />
        <DockPanel  Grid.Row="2" Margin="5">
            <Border CornerRadius="6" BorderBrush="Gray" BorderThickness="2" >
                <StackPanel Grid.Column="0" Grid.Row="2">
                    <!-- Nombre-->
                    <StackPanel Orientation="Horizontal" Margin="10" Width="372" >
                        <Label Content="Nombre:" FontSize="16" Foreground="Black" />
                        <TextBox  Width="250" Margin="50,0,0,0" IsReadOnly="true" Background="Beige"
                                  Text="{Binding Path = Nombre}" FontWeight="Bold" />
                    </StackPanel>
                    <!-- Fin Nombre-->
                    <!-- Commentario-->
                    <StackPanel Orientation="Horizontal" Margin="10" Width="372">
                        <Label Content="Comentario:" FontSize="16" Foreground="Black" Width="98"/>
                        <TextBox Width="244" Margin="30,0,20,0" 
                                 Text="{Binding Path = Comentario}" Background="Beige"/>
                    </StackPanel>
                    <!-- Fin Commentario-->
                    <!-- Marca-->
                    <StackPanel Orientation="Horizontal" Margin="10" Width="369">
                        <Label Content="Marca:" FontSize="16" Foreground="Black" Width="88"/>
                        <TextBox  Width="251" Margin="30,0,20,0" 
                                 Text="{Binding Path = Marca}" Background="Beige"/>
                    </StackPanel>
                    <!-- Fin Marca-->
                </StackPanel>
            </Border>
        </DockPanel>
        <Button x:Name="btnGuardar" 
                Content="GUARDAR" Grid.Row="3" 
                FontWeight="Black" Click="btnGuardar_Click" />
            
    </Grid>
</Window>
....

 

0 Likes
Reply
360 Views
4 Replies
Replies (4)

RPTHOMAS108
Mentor
Mentor

For

 

 if (param_Commen != null)
            {
                Comentario = param_Commen.AsValueString();
            }

 

Use instead param_Commen.AsString.

 

AsValueString only applicable to value types normally.

0 Likes

reylorente1
Collaborator
Collaborator

No sobrescribes,

 

 
Do not overwrite,not working

 

0 Likes

RPTHOMAS108
Mentor
Mentor

I don't know the nature of your error in terms of exception messages or what part of code isn't working specifically?

 

You can't interact with Revit when showing modal dialogue. For modal you need to close, interact with Revit and re-show. For modeless you need to use ExternalEvent and implement IExternalEventHandler.

0 Likes

reylorente1
Collaborator
Collaborator

Siguiendo el ejemplo,estoy usando MVVM.
Como podria cambiar el parametro Comentario?
Aqui estas en WinRar.

 

Following the example, I am using MVVM.
How could I change the Comment parameter?
Here you are at WinRar.
0 Likes