The class contains information of a sample item to be added into samples menu
        /// <summary>
        /// Add sample item to pulldown menu
        /// </summary>
        /// <param name="pullDownButton">Pulldown menu</param>
        /// <param name="item">Sample item to be added</param>
        private void AddSampleToPulldownMenu(PulldownButton pullDownButton, SampleItem item)
        {
            PushButtonData pushButtonData = new PushButtonData(item.DisplayName, item.DisplayName, item.Assembly, item.ClassName);
            PushButton     pushButton     = pullDownButton.AddPushButton(pushButtonData);

            if (!string.IsNullOrEmpty(item.LargeImage))
            {
                BitmapImage largeImageSource = new BitmapImage(new Uri(item.LargeImage, UriKind.Absolute));
                pushButton.LargeImage = largeImageSource;
            }
            if (!string.IsNullOrEmpty(item.Image))
            {
                BitmapImage imageSource = new BitmapImage(new Uri(item.Image, UriKind.Absolute));
                pushButton.Image = imageSource;
            }

            pushButton.ToolTip = item.Description;
        }
Exemple #2
0
        /// <summary>
        /// Add a new command to the corresponding pulldown button.
        /// </summary>
        /// <param name="lines">Array of lines defining sample's category, display name, description, large image, image, assembly and classname</param>
        /// <param name="n">Total number of lines in array</param>
        /// <param name="i">Current index in array</param>
        void AddSample(string[] lines, int n, ref int i)
        {
            if (n < i + 6)
            {
                throw new Exception(string.Format("Incomplete record at line {0} of {1}", i, m_fileNameStem));
            }

            string categories  = lines[i++].Trim();
            string displayName = lines[i++];
            string description = lines[i++];
            string largeImage  = lines[i++].Remove(0, 11).Trim();
            string image       = lines[i++].Remove(0, 6).Trim();
            string assembly    = lines[i++];
            string className   = lines[i++];

            //
            // If sample belongs to default category, add the sample item to the sample list of the default category
            // If not, store the information for adding to RvtSamples panel later
            //
            string[] entries = categories.Split(s_charSeparatorOfCategory, StringSplitOptions.RemoveEmptyEntries);
            foreach (string value in entries)
            {
                string     category = value.Trim();
                SampleItem item     = new SampleItem(category, displayName, description, largeImage, image, assembly, className);
                if (m_pulldownButtons.ContainsKey(category))
                {
                    m_defaultMenus.Values[m_defaultMenus.IndexOfKey(GetEnumNameByDisplayName(category))].Add(item);
                }
                else if (m_customizedMenus.ContainsKey(category))
                {
                    List <SampleItem> sampleItems = m_customizedMenus.Values[m_customizedMenus.IndexOfKey(category)];
                    sampleItems.Add(item);
                }
                else
                {
                    List <SampleItem> sampleItems = new List <SampleItem>();
                    sampleItems.Add(item);
                    m_customizedMenus.Add(category, sampleItems);
                }
            }
        }
 /// <summary>
 /// Comparer to sort sample items by their display name
 /// </summary>
 /// <param name="s1">sample item 1</param>
 /// <param name="s2">sample item 2</param>
 /// <returns>compare result</returns>
 private static int SortByDisplayName(SampleItem item1, SampleItem item2)
 {
     return(string.Compare(item1.DisplayName, item2.DisplayName));
 }
        /// <summary>
        /// Add a new command to the corresponding pulldown button.
        /// </summary>
        /// <param name="lines">Array of lines defining sample's category, display name, description, large image, image, assembly and classname</param>
        /// <param name="n">Total number of lines in array</param>
        /// <param name="i">Current index in array</param>
        void AddSample(string[] lines, int n, ref int i)
        {
            if (n < i + 6)
            {
                throw new Exception(string.Format("Incomplete record at line {0} of {1}", i, m_fileNameStem));
            }

            string categories  = lines[i++].Trim();
            string displayName = lines[i++].Trim();
            string description = lines[i++].Trim();
            string largeImage  = lines[i++].Remove(0, 11).Trim();
            string image       = lines[i++].Remove(0, 6).Trim();
            string assembly    = lines[i++].Trim();
            string className   = lines[i++].Trim();

            if (!File.Exists(assembly)) // jeremy
            {
                ErrorMsg(string.Format("Assembly '{0}' specified in line {1} of {2} not found",
                                       assembly, i, m_fileNameStem));
            }

            bool testClassName = false; // jeremy

            if (testClassName)
            {
                Debug.Print("RvtSamples: testing command {0} in assembly '{1}'.", className, assembly);

                try
                {
                    // first load the revit api assembly, otherwise we cannot query the external app for its types:

                    //Assembly revit = Assembly.LoadFrom( "C:/Program Files/Revit Architecture 2009/Program/RevitAPI.dll" );
                    //string root = "C:/Program Files/Autodesk Revit Architecture 2010/Program/";
                    //Assembly adWindows = Assembly.LoadFrom( root + "AdWindows.dll" );
                    //Assembly uiFramework = Assembly.LoadFrom( root + "UIFramework.dll" );
                    //Assembly revit = Assembly.LoadFrom( root + "RevitAPI.dll" );

                    // load the assembly into the current application domain:

                    Assembly a = Assembly.LoadFrom(assembly);

                    if (null == a)
                    {
                        ErrorMsg(string.Format("Unable to load assembly '{0}' specified in line {1} of {2}",
                                               assembly, i, m_fileNameStem));
                    }
                    else
                    {
                        // get the type to use:
                        Type t = a.GetType(className);
                        if (null == t)
                        {
                            ErrorMsg(string.Format("External command class {0} in assembly '{1}' specified in line {2} of {3} not found",
                                                   className, assembly, i, m_fileNameStem));
                        }
                        else
                        {
                            // get the method to call:
                            MethodInfo m = t.GetMethod("Execute");
                            if (null == m)
                            {
                                ErrorMsg(string.Format("External command class {0} in assembly '{1}' specified in line {2} of {3} does not define an Execute method",
                                                       className, assembly, i, m_fileNameStem));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorMsg(string.Format("Exception '{0}' \ntesting assembly '{1}' \nspecified in line {2} of {3}",
                                           ex.Message, assembly, i, m_fileNameStem));
                }
            }

            //
            // If sample belongs to default category, add the sample item to the sample list of the default category
            // If not, store the information for adding to RvtSamples panel later
            //
            string[] entries = categories.Split(s_charSeparatorOfCategory, StringSplitOptions.RemoveEmptyEntries);
            foreach (string value in entries)
            {
                string     category = value.Trim();
                SampleItem item     = new SampleItem(category, displayName, description, largeImage, image, assembly, className);
                if (m_pulldownButtons.ContainsKey(category))
                {
                    m_defaultMenus.Values[m_defaultMenus.IndexOfKey(GetEnumNameByDisplayName(category))].Add(item);
                }
                else if (m_customizedMenus.ContainsKey(category))
                {
                    List <SampleItem> sampleItems = m_customizedMenus.Values[m_customizedMenus.IndexOfKey(category)];
                    sampleItems.Add(item);
                }
                else
                {
                    List <SampleItem> sampleItems = new List <SampleItem>();
                    sampleItems.Add(item);
                    m_customizedMenus.Add(category, sampleItems);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Add sample item to pulldown menu
        /// </summary>
        /// <param name="pullDownButton">Pulldown menu</param>
        /// <param name="item">Sample item to be added</param>
        private void AddSampleToPulldownMenu(PulldownButton pullDownButton, SampleItem item)
        {
            PushButtonData pushButtonData = new PushButtonData(item.DisplayName, item.DisplayName, item.Assembly, item.ClassName);
            PushButton pushButton = pullDownButton.AddPushButton(pushButtonData);
            if (!string.IsNullOrEmpty(item.LargeImage))
            {
                BitmapImage largeImageSource = new BitmapImage(new Uri(item.LargeImage, UriKind.Absolute));
                pushButton.LargeImage = largeImageSource;
            }
            if (!string.IsNullOrEmpty(item.Image))
            {
                BitmapImage imageSource = new BitmapImage(new Uri(item.Image, UriKind.Absolute));
                pushButton.Image = imageSource;
            }

            pushButton.ToolTip = item.Description;
        }
Exemple #6
0
        /// <summary>
        /// Add a new command to the corresponding pulldown button.
        /// </summary>
        /// <param name="lines">Array of lines defining sample's category, display name, description, large image, image, assembly and classname</param>
        /// <param name="n">Total number of lines in array</param>
        /// <param name="i">Current index in array</param>
        void AddSample(string[] lines, int n, ref int i)
        {
            if (n < i + 6)
            {
                throw new Exception(string.Format("Incomplete record at line {0} of {1}", i, m_fileNameStem));
            }

            string categories = lines[i++].Trim();
            string displayName = lines[i++];
            string description = lines[i++];
            string largeImage = lines[i++].Remove(0, 11).Trim();
            string image = lines[i++].Remove(0, 6).Trim();
            string assembly = lines[i++];
            string className = lines[i++];

            //
            // If sample belongs to default category, add the sample item to the sample list of the default category
            // If not, store the information for adding to RvtSamples panel later
            //
            string[] entries = categories.Split(s_charSeparatorOfCategory, StringSplitOptions.RemoveEmptyEntries);
            foreach (string value in entries)
            {
                string category = value.Trim();
                SampleItem item = new SampleItem(category, displayName, description, largeImage, image, assembly, className);
                if (m_pulldownButtons.ContainsKey(category))
                {
                    m_defaultMenus.Values[m_defaultMenus.IndexOfKey(GetEnumNameByDisplayName(category))].Add(item);
                }
                else if (m_customizedMenus.ContainsKey(category))
                {
                    List<SampleItem> sampleItems = m_customizedMenus.Values[m_customizedMenus.IndexOfKey(category)];
                    sampleItems.Add(item);
                }
                else
                {
                    List<SampleItem> sampleItems = new List<SampleItem>();
                    sampleItems.Add(item);
                    m_customizedMenus.Add(category, sampleItems);
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// Comparer to sort sample items by their display name
 /// </summary>
 /// <param name="s1">sample item 1</param>
 /// <param name="s2">sample item 2</param>
 /// <returns>compare result</returns>
 private static int SortByDisplayName(SampleItem item1, SampleItem item2)
 {
     return string.Compare(item1.DisplayName, item2.DisplayName);
 }