<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Code optimization in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/code-optimization/m-p/8213382#M48163</link>
    <description>&lt;P&gt;The one thing that comes to mind at first glance is the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eliminate the two parameter lookup methods taking string arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where the string represents a GUID, you can create all the GUID instances from the strings up front, before starting the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will save the time and effort of recreating them many times over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, for the calls to LookupParameter taking a string: determine the Parameter id of&amp;nbsp;each corresponding parameter definition once and for all beforehand,&amp;nbsp;&lt;SPAN&gt;before starting the loop. Then, you can use Element.get_Parameter(Parameter) instead of LookupParameter.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Once that is done, the next step might be to profile your code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://stackoverflow.com/questions/3927/what-are-some-good-net-profilers" target="_blank"&gt;https://stackoverflow.com/questions/3927/what-are-some-good-net-profilers&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jeremy&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Aug 2018 09:03:23 GMT</pubDate>
    <dc:creator>jeremytammik</dc:creator>
    <dc:date>2018-08-21T09:03:23Z</dc:date>
    <item>
      <title>Code optimization</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/code-optimization/m-p/8208304#M48162</link>
      <description>&lt;P&gt;Good day, get the parameters of the concrete elements and assign it to all the bars that are housed in it, the code I have works, however it takes its time to load, I get the impression that there are other ways to do it so that I consume less resources. I appreciate your help, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;namespace RebarParameters
{
    class Parametros
    {
        //Instancio a Longitu de Rebar
        LongitudRebar longitudRebar = new LongitudRebar();
        
        //Devuelve Parametro compartido
        public Parameter Parameter(Element e, String guid)
        {
            Guid parameterShared = new Guid(guid);
            Parameter parameter = e.get_Parameter(parameterShared);
            return parameter;
        }

        public Parameter Parameter(Element e, String lookParameter,Boolean boolean)
        {            
            Parameter parameter = e.LookupParameter(lookParameter);
            return parameter;
        }

        //Devuelve Parametro BuiltInParameter
        public Parameter Parameter(Element e, BuiltInParameter parameterBuild)
        {
            Parameter parameter = e.get_Parameter(parameterBuild);
            return parameter;
        }

        //Devuelve Parametro de tipo BuiltInParameter
        public Parameter Parameter(ElementType et, BuiltInParameter parameterBuild)
        {
            Parameter parameter = et.get_Parameter(parameterBuild);
            return parameter;
        }

        //Devuelve parametro Double 0 si existe error
        public Double ConvertirDouble(Parameter parameter)
        {
            Double dimension;
            try
            {
                dimension = parameter.AsDouble();
            }
            catch (Exception)
            {
                dimension = 0;
            }
            return dimension;
        }
                
        public void GetSetParameterRebar(List&amp;lt;Element&amp;gt; listHost, Document doc)
        {           
            //Metodo parametros
            foreach (Element el in listHost)
            {
                //Parametro de Host
                ElementType HostType = doc.GetElement(el.GetTypeId()) as ElementType;
                Parameter HostTypeComments = Parameter(HostType, BuiltInParameter.ALL_MODEL_TYPE_COMMENTS);
                Parameter HostMark = Parameter(el, "1411f266-da7a-4faa-beb9-3848e3304161");
                Parameter QC_HostSector = Parameter(el, "0818baf0-dce1-4ea4-84ac-2f69fae50a84");
                Parameter QC_HostNivel = Parameter(el, "d25405d0-37af-43c2-be2d-7efc1c792fcc");
                Parameter QC_HostEje = Parameter(el, "2ee543a4-ec44-472e-80c4-520883abe8c0");
                Parameter QC_HostFamilia = Parameter(el, "8ca45e69-853c-4132-9452-8124c3b0f3ef");

                //rebar in host
                IList&amp;lt;Rebar&amp;gt; rebar = RebarHostData.GetRebarHostData(el).GetRebarsInHost();    

                if (rebar.Count != 0)
                {
                    // para cada rebar segun su host
                    List&amp;lt;String&amp;gt; formas = new List&amp;lt;string&amp;gt;();

                    foreach (Rebar r in rebar)
                    {
                        //Parametros Rebar de Ubicacion y Sectorización
                        Parameter partition = Parameter(r, BuiltInParameter.NUMBER_PARTITION_PARAM);
                        Parameter QC_HostMark = Parameter(r, "3be2f711-4769-463b-bda8-39ba39aa578d");
                        Parameter QC_Sector = Parameter(r, "0818baf0-dce1-4ea4-84ac-2f69fae50a84");
                        Parameter QC_Nivel = Parameter(r, "d25405d0-37af-43c2-be2d-7efc1c792fcc");
                        Parameter QC_Eje = Parameter(r, "2ee543a4-ec44-472e-80c4-520883abe8c0");
                        Parameter QC_Familia = Parameter(r, "8ca45e69-853c-4132-9452-8124c3b0f3ef");

                        //Parametros de Dimensiones
                        Parameter ParQC_RebarLength = Parameter(r, "8acbe253-9336-4934-925d-7e2dff0be89d");
                        Parameter ParA = Parameter(r, "A", true);
                        Parameter ParB = Parameter(r, "B", true);
                        Parameter ParC = Parameter(r, "C", true);
                        Parameter ParD = Parameter(r, "D", true);
                        Parameter ParE = Parameter(r, "E", true);
                        Parameter ParF = Parameter(r, "F", true);
                        Parameter ParG = Parameter(r, "G", true);
                        Parameter ParH = Parameter(r, "H", true);
                        Parameter ParI = Parameter(r, "I", true);
                        Parameter ParAlfa = Parameter(r, "fb540c64-8611-416a-9172-681a1847112d");
                        Parameter ParBeta = Parameter(r, "b4aa2db2-c434-4457-88a0-f097a6efd159");
                        Parameter ParGamma = Parameter(r, "da72b204-3415-4298-bc87-3c07fb7b8ce4");
                        Parameter ParQC_Codigo_Forma = Parameter(r, "f1fb3a75-4c81-4cd7-980d-7cc02d561a6c");

                        //definicion de parametros de longitud   
                        String QC_Codigo_Forma = ParQC_Codigo_Forma.AsString();
                        Double a = ConvertirDouble(ParA);
                        Double b = ConvertirDouble(ParB);
                        Double c = ConvertirDouble(ParC);
                        Double d = ConvertirDouble(ParD);
                        Double e = ConvertirDouble(ParE);
                        Double f = ConvertirDouble(ParF);
                        Double g = ConvertirDouble(ParG);
                        Double h = ConvertirDouble(ParH);
                        Double i = ConvertirDouble(ParI);
                        Double alfa = ConvertirDouble(ParAlfa);
                        Double beta = ConvertirDouble(ParBeta);
                        Double gamma = ConvertirDouble(ParGamma);

                        //Calcula la longitud
                        Double LongPieza = longitudRebar.LongitudBarra(QC_Codigo_Forma, a, b, c, d, e, f, g, h, i, alfa, beta, gamma);

                        if (LongPieza == 0)
                        {
                            formas.Add(QC_Codigo_Forma);
                        }

                        using (Transaction t = new Transaction(doc, "Parametros"))
                        {
                            t.Start("Parametros");
                            //Asignar Parametros a rebar                            
                            SetParameter(HostTypeComments, partition);
                            SetParameter(HostMark, QC_HostMark);
                            SetParameter(QC_HostSector, QC_Sector);
                            SetParameter(QC_HostNivel, QC_Nivel);
                            SetParameter(QC_HostEje, QC_Eje);
                            SetParameter(QC_HostFamilia, QC_Familia);
                            SetParameter(LongPieza, ParQC_RebarLength);
                            t.Commit();
                        }
                    }

                    if (formas.Count != 0)
                    {
                        String infoformas = "No se encuentra registrado el código de la forma: ";

                        foreach (string f in formas.Distinct())
                        {
                            infoformas += "\n\t" + f;
                        }
                        TaskDialog.Show("QC Ingenieros", infoformas);
                    }

                }
                else
                {                    
                    TaskDialog.Show("QC Ingenieros", "No se ha encontrado ningun elemento de refuerzo en el elemento: " + el.Id.ToString());
                }

            }
        }

        private void CounColorNumber(List&amp;lt;Rebar&amp;gt; list)
        {
            foreach (Rebar r in list)
            {

            }
        }

        private void SetParameter (Parameter HostParameter,Parameter RebarParameter)
        {
            try
            {
                RebarParameter.Set(HostParameter.AsString());

            }
            catch (Exception)
            {
                              
            }
        }

        private void SetParameter(Double HostParameter, Parameter RebarParameter)
        {
            try
            {
                RebarParameter.Set(HostParameter);

            }
            catch (Exception)
            {

            }
        }

    }
}&lt;/PRE&gt;</description>
      <pubDate>Sat, 18 Aug 2018 06:16:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/code-optimization/m-p/8208304#M48162</guid>
      <dc:creator>jamess166</dc:creator>
      <dc:date>2018-08-18T06:16:48Z</dc:date>
    </item>
    <item>
      <title>Re: Code optimization</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/code-optimization/m-p/8213382#M48163</link>
      <description>&lt;P&gt;The one thing that comes to mind at first glance is the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eliminate the two parameter lookup methods taking string arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where the string represents a GUID, you can create all the GUID instances from the strings up front, before starting the loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That will save the time and effort of recreating them many times over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Similarly, for the calls to LookupParameter taking a string: determine the Parameter id of&amp;nbsp;each corresponding parameter definition once and for all beforehand,&amp;nbsp;&lt;SPAN&gt;before starting the loop. Then, you can use Element.get_Parameter(Parameter) instead of LookupParameter.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Once that is done, the next step might be to profile your code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://stackoverflow.com/questions/3927/what-are-some-good-net-profilers" target="_blank"&gt;https://stackoverflow.com/questions/3927/what-are-some-good-net-profilers&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jeremy&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 09:03:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/code-optimization/m-p/8213382#M48163</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-08-21T09:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Code optimization</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/code-optimization/m-p/8214541#M48164</link>
      <description>&lt;P&gt;I appreciate your help, with the little I know of programming my code ended as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public void GetSetParameterRebar(List&amp;lt;Element&amp;gt; listHost, Document doc)
        {
            //Metodo parametros
            foreach (Element el in listHost)
            {
                //creacion de parametros guid host
                Guid guidHostMark = new Guid("1411f266-da7a-4faa-beb9-3848e3304161");
                Guid guidSector = new Guid("0818baf0-dce1-4ea4-84ac-2f69fae50a84");
                Guid guidNivel = new Guid("d25405d0-37af-43c2-be2d-7efc1c792fcc");
                Guid guidEje = new Guid("2ee543a4-ec44-472e-80c4-520883abe8c0");
                Guid guidHostFamilia = new Guid("8ca45e69-853c-4132-9452-8124c3b0f3ef");

                //creacion de parametros guid rebar
                Guid guidParQC_RebarLength = new Guid("8acbe253-9336-4934-925d-7e2dff0be89d");
                Guid guidParQC_Codigo_Forma = new Guid("f1fb3a75-4c81-4cd7-980d-7cc02d561a6c");
                BuiltInParameter buildPartition = BuiltInParameter.NUMBER_PARTITION_PARAM;
                
                //Parametro de Host
                ElementType HostType = doc.GetElement(el.GetTypeId()) as ElementType;
                Parameter HostTypeComments = HostType.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS);
                Parameter QC_HostMark = el.get_Parameter(guidHostMark);
                Parameter QC_HostSector = el.get_Parameter(guidSector);
                Parameter QC_HostNivel = el.get_Parameter(guidNivel);
                Parameter QC_HostEje = el.get_Parameter(guidEje);
                Parameter QC_HostFamilia = el.get_Parameter(guidHostFamilia);    

                //rebar in host
                IList &amp;lt;Rebar&amp;gt; rebar = RebarHostData.GetRebarHostData(el).GetRebarsInHost();


                if (rebar.Count != 0)
                {
                    // para cada rebar segun su host
                    List&amp;lt;String&amp;gt; formas = new List&amp;lt;string&amp;gt;();

                    foreach (Rebar r in rebar)
                    {
                        //Parametros Rebar de Ubicacion y Sectorización
                        Parameter partition = r.get_Parameter(buildPartition);
                        Parameter QC_RbHostMark = r.get_Parameter(guidHostMark);
                        Parameter QC_Sector = r.get_Parameter(guidSector);
                        Parameter QC_Nivel = r.get_Parameter(guidNivel);
                        Parameter QC_Eje = r.get_Parameter(guidEje);
                        Parameter QC_Familia = r.get_Parameter(guidHostFamilia);

                        ////Parametros de Dimensiones
                        Parameter ParQC_RebarLength = r.get_Parameter(guidParQC_RebarLength);
                        Parameter ParQC_Codigo_Forma = r.get_Parameter(guidParQC_Codigo_Forma);

                        ////definicion de parametros de longitud   
                        String QC_Codigo_Forma = ParQC_Codigo_Forma.AsString();


                        //Calcula la longitud
                        Double LongPieza = longitudRebar.LongitudBarra(doc,r,QC_Codigo_Forma);

                        if (LongPieza == 0)
                        {
                            formas.Add(QC_Codigo_Forma);
                        }

                        using (Transaction t = new Transaction(doc, "Parametros"))
                        {
                            t.Start("Parametros");
                            //Asignar Parametros a rebar                            
                            SetParameter(HostTypeComments, partition);
                            SetParameter(QC_RbHostMark, QC_RbHostMark);
                            SetParameter(QC_HostSector, QC_Sector);
                            SetParameter(QC_HostNivel, QC_Nivel);
                            SetParameter(QC_HostEje, QC_Eje);
                            SetParameter(QC_HostFamilia, QC_Familia);
                            SetParameter(LongPieza, ParQC_RebarLength);
                            t.Commit();
                        }
                    }

                    if (formas.Count != 0)
                    {
                        String infoformas = "No se encuentra registrado el código de la forma: ";

                        foreach (string f in formas.Distinct())
                        {
                            infoformas += "\n\t" + f;
                        }
                        TaskDialog.Show("QC Ingenieros", infoformas);
                    }

                    //}
                    else
                    {
                        TaskDialog.Show("QC Ingenieros", "No se ha encontrado ningun elemento de refuerzo en el elemento: " + el.Id.ToString());
                    }

                }
            }
        }&lt;/PRE&gt;&lt;P&gt;what I have not been able to do until now is to obtain the value of the Style parameter and apply an if it is Standard or Stirrup.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Captura.PNG" style="width: 382px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/537190i3D90463B75933F05/image-size/large?v=v2&amp;amp;px=999" role="button" title="Captura.PNG" alt="Captura.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2018 16:30:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/code-optimization/m-p/8214541#M48164</guid>
      <dc:creator>jamess166</dc:creator>
      <dc:date>2018-08-21T16:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Code optimization</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/code-optimization/m-p/8214690#M48165</link>
      <description>&lt;P&gt;Regarding the additional question I have achieved it after doing several tests.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;//obtener shape
            RebarShape rebarShape = doc.GetElement(r.GetShapeId()) as RebarShape;

            RebarStyle rb = rebarShape.RebarStyle;

if (rb.ToString() is "Standard")
            {
                TaskDialog.Show("QC", rb.ToString());
            }  &lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2018 17:42:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/code-optimization/m-p/8214690#M48165</guid>
      <dc:creator>jamess166</dc:creator>
      <dc:date>2018-08-21T17:42:04Z</dc:date>
    </item>
  </channel>
</rss>

