Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Macro taking a long time to run

  1. #1
    Member
    Join Date
    2005-12
    Posts
    44
    Login to Give a bone
    0

    Default Macro taking a long time to run

    I have written a c# macro and run it on my floor plans to add a 'x' to the end of my room numbers in order to renumber the rooms in the order we prefer-instead of renumbering them in the schedule. Does anyone know why it takes up to 10 min on the floor plan even using the Filter option for Rooms only?? The code is not terribly long although it has to scan thru built in parameters in order to change the room number. Any ideas would be appreciated. Here's the code:


    using System;
    using System.IO;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections;
    using System.Collections.Generic;

    using Autodesk.Revit;
    using Autodesk.Revit.Elements;
    using Autodesk.Revit.Parameters;
    using Autodesk.Revit.Structural.Enums;
    using DocCSharp.csproj;

    namespace Revit.SDK.Samples.Renumbrmx.CS
    {
    /// <summary>
    /// Renumbers Rooms with a "x" - takes a while to do
    /// Pick only Rooms(not Room tag) using 'Filter' in Revit
    /// March 24, 2009
    /// </summary>
    public class Renumbrmx
    {
    ThisDocument m_doc; //ThisDocument data for VSTA

    /// <summary>
    /// Ctro without parameter is not allowed
    /// </summary>
    private Renumbrmx()
    {
    }

    /// <summary>
    /// Ctor with ThisDocument as
    /// </summary>
    /// <param name="hostApp">ThisDocument handler</param>
    public Renumbrmx(ThisDocument hostDoc)
    {
    m_doc = hostDoc;
    }

    /// <summary>
    /// Run this sample
    /// </summary>
    public void Run()
    {
    ElementSet collection = m_doc.Selection.Elements;
    // check user selection
    if (collection.Size < 1)
    {
    MessageBox.Show("Please select an object.", "Renumber Rooms");
    return;
    }
    //string file_name = "c:\\Myfile.txt";
    //open file
    //StreamWriter sr = File.CreateText(file_name);

    bool error = true;
    try
    {
    error = true;

    //Page thru each element picked
    IEnumerator e = collection.GetEnumerator();
    bool MoreValue = e.MoveNext();
    while (MoreValue)
    {
    Element comp = e.Current as Element;
    foreach (BuiltInParameter bip in Enum.GetValues(typeof(BuiltInParameter)))
    {
    Parameter p = comp.get_Parameter(bip);

    if (p != null) // it will be null if the BuiltInParameter did not work for it
    {

    //sr.WriteLine("Name = " + p.Definition.Name);
    if (p.Definition.Name == "Number")
    {
    string rmno = p.AsString();
    p.Set(rmno + "x");
    }
    }
    }

    MoreValue = e.MoveNext();
    }
    //sr.Close();
    error = false;
    }
    catch
    {
    // if revit threw an exception, try to catch it
    foreach (Element c in collection)
    {
    m_doc.Selection.Elements.Insert(c);
    }
    MessageBox.Show("Element(s) can't be shown.", "Renumber Rooms");
    return;
    }
    finally
    {
    // if revit threw an exception, display error and return failed
    if (error)
    {
    MessageBox.Show("Room number failed.");
    }
    }

    return;
    }
    }
    }
    Last edited by drodrigues679334; 2009-06-05 at 04:19 PM. Reason: adding code

  2. #2
    AUGI Addict sfaust's Avatar
    Join Date
    2004-01
    Location
    Littleton, CO (Denver Metro)
    Posts
    1,535
    Login to Give a bone
    0

    Default Re: Macro taking a long time to run

    I would set some stopwatches to narrow down which parts are taking so long, then post some snippets if you can't figure out why and it will help determine the problem...

  3. #3
    I could stop if I wanted to Phil Read's Avatar
    Join Date
    2003-05
    Location
    Charlotte, NC
    Posts
    398
    Login to Give a bone
    0

    Default Re: Macro taking a long time to run

    What'd ya expect. Its a 'macro'. ;0

  4. #4
    Modérateur Forum Français Pierre-Nelson NAVARRA's Avatar
    Join Date
    2007-10
    Location
    Nantes (France)
    Posts
    531
    Login to Give a bone
    0

    Default Re: Macro taking a long time to run

    Maybe you can give us the code?

  5. #5
    100 Club
    Join Date
    2004-09
    Posts
    104
    Login to Give a bone
    0

    Default Re: Macro taking a long time to run

    In my experience, external commands run 10 to 20 times faster than macros. (Theoretical impossibility, street reality)

    Try converting to an external cammand.

  6. #6
    Active Member
    Join Date
    2005-09
    Posts
    69
    Login to Give a bone
    0

    Default Re: Macro taking a long time to run

    If it snot just a macro vs command thing, then one thing to look at is if you are doing something inside the loop that you could do outside, i.e. just once instead of a 1000 times.
    If you post the code, then someone might spot something like that

  7. #7
    Member
    Join Date
    2005-12
    Posts
    44
    Login to Give a bone
    0

    Default Re: Macro taking a long time to run

    ok so i've included the code with the original post

  8. #8
    Member
    Join Date
    2005-12
    Posts
    44
    Login to Give a bone
    0

    Default Re: Macro taking a long time to run

    i didn't go with the external command because i did not know how to create the dll file needed for the revit.ini command line call-I would be gratedful for any suggestions!

  9. #9
    100 Club
    Join Date
    2004-09
    Posts
    104
    Login to Give a bone
    0

    Default Re: Macro taking a long time to run

    Try replacing your Run() with this.

    Code:
          public void Run()
            {
                Application m_app = m_doc.Application;
                List<Element> rooms = new List<Element>();
                Filter filterrooms = m_app.Create.Filter.NewTypeFilter(typeof(Room));
                m_doc.get_Elements(filterrooms, rooms);
                foreach (Room r in rooms)
                {
                    Parameter bip = r.get_Parameter(BuiltInParameter.ROOM_NUMBER);
                    string px = bip.AsString();
                    bip.Set(px + "x");
                }
    
            }

    You were iterating through all Built-in Parameters for all rooms- this just grabs the one you want. Add back in your selection and error trapping as required.
    Last edited by RobertB; 2009-06-08 at 03:59 PM. Reason: Added [code] tags

  10. #10
    Member
    Join Date
    2005-12
    Posts
    44
    Login to Give a bone
    0

    Default Re: Macro taking a long time to run

    Heh that worked great! Thanks for the tip. I did not know you could do that. You know with every code you learn something new!

Page 1 of 2 12 LastLast

Similar Threads

  1. Synchronizing with Central all of a sudden taking a VERY long time
    By jameswest77 in forum Revit - Hardware & Operating Systems
    Replies: 8
    Last Post: 2011-02-04, 06:12 AM
  2. Enabling Worksharing problem: taking long time ???
    By ACE001 in forum Revit - Worksharing/Worksets/Revit Server
    Replies: 1
    Last Post: 2011-02-02, 10:50 PM
  3. Pasting taking to long
    By cstephensen in forum AutoCAD Mechanical - General
    Replies: 6
    Last Post: 2008-08-25, 07:32 PM
  4. Exporting 3d to Autocad, taking too long
    By sifuentes in forum Revit Architecture - General
    Replies: 3
    Last Post: 2005-03-10, 05:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •