textNoteTypeSet in Revit 2016 api

textNoteTypeSet in Revit 2016 api

rahalabi
Participant Participant
659 Views
3 Replies
Message 1 of 4

textNoteTypeSet in Revit 2016 api

rahalabi
Participant
Participant

I am upgrading  a script witten in C# for Revit 2012 to Revit 2016,

In in the script there is a usage of txtNoteTypeSet which is obsolete in revit 2016 API

how can we solve this issue?

I am putting down the scipt for reference

**********************************************************************************************

   textNoteTypeSet availableTextNotes;

 

public NewSchedulefrm(TextNoteTypeSet iAvaialableTextNotes, List<LightingFixtureObject> iLightingFixtures)

 

 foreach (TextNoteTypeSet tnt in availableTextNotes)

**********************************************************************************************

 

0 Likes
Accepted solutions (1)
660 Views
3 Replies
Replies (3)
Message 2 of 4

arnostlobel
Alumni
Alumni

Rahalabi:

 

Your snippet does not show how did you use the TextNoteTypeSet with RevitAPI so I cannot give you a concrete suggestion. However, as a general approach, wherever the TextNoteTypeSet used to be used, those method are now likely to take (as arguments) or return either IList<TextNoteType> or ISet<TextNoteType>. Therefore it is going to be rather trivial to update your code to comply with the new approach.

 

For methods that used to return TextNoteTypeSet (if any), you’ll do:

 

IList<TextNoteType> myList = SomeRevitAPIMethod(...);

For method that used to take TextNoteTypeSet as an argument, you’ll do this:

 

 

IList<TextNoteType> myList =  new List<TextNoteType>();
{ .. /*some code to populate the list*/ }
SomeRevitAPIMethod( ... myList ...)

 

I hope this helps.

 

Arnošt Löbel
0 Likes
Message 3 of 4

rahalabi
Participant
Participant

Dear arnostlobel,

thanks for your reply, I will put down the whole script that I am working on it so you will have an idea of what i am talking about, I have done some modifications , what is colored in green is what i modified and what is colored n red needs modification

 

***************************************************************************************************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autodesk.Revit.DB;

namespace Lighting_Fixture_Schedule
{
    public partial class NewSchedulefrm : System.Windows.Forms.Form
    {
        #region Identifiers
        String _ViewName;
        // modified by ramzi al halaby on 22-07-2015 during upgrade to revit 2016
        // *************************************************************************
       //textNoteTypeSet availableTextNotes;
        TextNoteType availableTextNotes;
        
        TextNoteType _HeaderType = null, _CellType = null;
        List<LightingFixtureObject> lightingFixtures;
        double _ScheduleWidth = 0, _ImageWidth = 0;

        public double ScheduleWidth
        {
            get
            {
                return _ScheduleWidth;
            }
        }

        public double ImageWidth
        {
            get
            {
                return _ImageWidth;
            }
        }


        public TextNoteType HeaderType
        {
            get
            {
                return _HeaderType;
            }
        }

        public TextNoteType CellType
        {
            get
            {
                return _CellType;
            }
        }

        public String ViewName
        {
            get
            {
                return _ViewName;
            }
        }
        #endregion

        // modified by ramzi al halaby on 22-07-2015 during upgrade to revit 2016
        // *************************************************************************
        //public NewSchedulefrm(TextNoteTypeSet iAvaialableTextNotes, List<LightingFixtureObject> iLightingFixtures)
        public NewSchedulefrm(TextNoteType iAvaialableTextNotes, List<LightingFixtureObject> iLightingFixtures)
        {
            InitializeComponent();
            availableTextNotes = iAvaialableTextNotes;
            lightingFixtures = iLightingFixtures;
        }

        private void TbleWidthTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            const char Delete = (char)8;
            e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete && e.KeyChar != '.';
        }
        private void ImgWidthTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            const char Delete = (char)8;
            e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete && e.KeyChar != '.';
        }

        private void NewSchedulefrm_Load(object sender, EventArgs e)
        {
            // added by ramzi on 22-07-2015 while upgrading to revit 2016(needs work still)
            // ****************************************************************************
            List<TextNoteType> noteTypeList = new List<TextNoteType>();
            //List<TextNoteType> noteTypeList
            //    = new FilteredElementCollector(revitDoc)
            //    .OfClass(typeof(TextNoteType))
            //    .Cast<TextNoteType>()
            //    .ToList();


            //load the text styles
            //foreach (TextNoteTypeSet tnt in availableTextNotes)
            foreach (TextNoteType tnt in noteTypeList)
            {
                HeaderStyleComboBox.Items.Add(tnt.Name);
                CellTypeComboBox.Items.Add(tnt.Name);
            }
            createDGVColumns();
        }

        /// <summary>
        /// Creates and Sets the columns for the Schedule DataGridView
        /// </summary>
        private void createDGVColumns()
        {
            try
            {
                ScheduleDGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;

                DataGridViewTextBoxColumn TypeColumn = new DataGridViewTextBoxColumn();
                TypeColumn.HeaderText = "Type";
                TypeColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                TypeColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                

                DataGridViewTextBoxColumn LampColumn = new DataGridViewTextBoxColumn();
                LampColumn.HeaderText = "Lamp";
                LampColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                LampColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

                DataGridViewTextBoxColumn DescriptionColumn = new DataGridViewTextBoxColumn();
                DescriptionColumn.HeaderText = "Description";
                DescriptionColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                DescriptionColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

                DataGridViewTextBoxColumn ManufacturerColumn = new DataGridViewTextBoxColumn();
                ManufacturerColumn.HeaderText = "Manufacturer";
                ManufacturerColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                ManufacturerColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

                DataGridViewTextBoxColumn VoltageColumn = new DataGridViewTextBoxColumn();
                VoltageColumn.HeaderText = "Voltage";
                VoltageColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                VoltageColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

                DataGridViewTextBoxColumn KeynoteColumn = new DataGridViewTextBoxColumn();
                KeynoteColumn.HeaderText = "Keynote";
                KeynoteColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                KeynoteColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

                DataGridViewTextBoxColumn ModelColumn = new DataGridViewTextBoxColumn();
                ModelColumn.HeaderText = "Model";
                ModelColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                ModelColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                ModelColumn.Visible = false;

                ScheduleDGV.Columns.AddRange(new DataGridViewColumn[] { TypeColumn, LampColumn, DescriptionColumn, ManufacturerColumn, VoltageColumn, KeynoteColumn, ModelColumn});
                ScheduleDGV.AutoGenerateColumns = false;

                BindingSource bs = new BindingSource();
                bs.DataSource = typeof(LightingFixtureObject);
                ScheduleDGV.DataSource = bs;

                //Set the properties
                TypeColumn.DataPropertyName = "FixtureType";
                LampColumn.DataPropertyName = "Lamp";
                DescriptionColumn.DataPropertyName = "Description";
                ManufacturerColumn.DataPropertyName = "Manufacturer";
                VoltageColumn.DataPropertyName = "Voltage";
                KeynoteColumn.DataPropertyName = "KeyNote";
                ModelColumn.DataPropertyName = "Model";

                bs.DataSource = lightingFixtures;

            }
            catch (Exception x)
            {
                MessageBox.Show("Error creating Schedule Data\n" + x.Message, "Data Table Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            if (HeaderStyleComboBox.SelectedItem == null)
            {
                MessageBox.Show("Select Schedule's Header Text Style", "Invalide Header Style", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.None;
            }
            else if (CellTypeComboBox.SelectedItem == null)
            {
                MessageBox.Show("Select Schedule's Cells Text Style", "Invalide Cell Style", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.None;
            }
            else if (NameTextBox.Text == "")
            {
                MessageBox.Show("Enter a view name", "Invalid View Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.None;
            }
            else if (TbleWidthTextBox.Text == "")
            {
                MessageBox.Show("Enter Schedule Width", "Invalid Schedule Width", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.None;
            }
            else if (ImgWidthTextBox.Text == "")
            {
                MessageBox.Show("Enter Image Width", "Invalid Image Width", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.None;
            }
            else
            {
                //Set Selected Text Notes
                setSelectedTextNotes();

                _ViewName = NameTextBox.Text;

                _ScheduleWidth = Convert.ToDouble(TbleWidthTextBox.Text);
                _ImageWidth = Convert.ToDouble(ImgWidthTextBox.Text);
            }
        }


        /// <summary>
        /// Set the Selected Text Notes
        /// </summary>
        private void setSelectedTextNotes()
        {
            TextNoteTypeSetIterator itor = availableTextNotes.ForwardIterator();
            itor.Reset();
            while (itor.MoveNext())
            {
                TextNoteType current = itor.Current as TextNoteType;
                if (current.Name.Equals(HeaderStyleComboBox.SelectedItem.ToString()))
                {
                    _HeaderType = current;
                }

                if (current.Name.Equals(CellTypeComboBox.SelectedItem.ToString()))
                {
                    _CellType = current;
                }

            }
        }


    }
}

***************************************************************************************************************************************

0 Likes
Message 4 of 4

Revitalizer
Advisor
Advisor
Accepted solution

Hi,

 

TextNoteTypeSetIterator is deprecated in 2016, so forget it.

 

You can use something like this:

 

private IEnumerable<TextNoteType> GetTextNoteTypes(Document doc)
{
    return new FilteredElementCollector(doc).OfClass(typeof(TextNoteType)).ToElements().Cast<TextNoteType>();
}

 

And then iterate with a foreach loop through its members:

 

IEnumerable<TextNoteType> textNoteTypes = GetTextNoteTypes(doc);

foreach (TextNoteType tnt in textNoteTypes)
{
    // do your stuff here
}

 

That's all.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes