Blog

8 thoughts on “Blog

  1. Hello Harry,

    I am trying to run a macro to copy one view template from one project into another in RVT14. But, an unexpected error that I don’t know how to fix comes up every time I run the macro. It states that “revit failed to execute the macro”.

    I don’t know where the error can lay in, as I don’t have experience with API and the macro compiles with no errors.

    Thank you.

    Luis

  2. buenas tardes, tengo un problema con una macro que en la version de revit 2018 se deja montar perfectamente ahora en la version 2020 y 2021 no me deja montarla…. aqui les dejao la macro para ver si alguin me puede ayudar, esta macro es para obtener las coordenadas de cualquier elemento….

    public void FijaXYZShared()
    {
    String ParametroX=”PosicionX”;
    String ParametroY=”PosicionY”;
    String ParametroZ=”PosicionZ”;
    int copiados=0;
    int errores=0;
    Boolean dialogo=true; // Muestrame el resultado

    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = uidoc.Document;
    Selection selection = uidoc.Selection;
    ICollection selectedIds = uidoc.Selection.GetElementIds();

    ProjectLocation projectLocation = doc.ActiveProjectLocation;

    using(Transaction t = new Transaction(doc,”Fijando XYZ”))
    if (0 == selectedIds.Count){TaskDialog.Show(“Revit”,”No hay selección, ningun elemento a fijar coordenadas.”);}
    else
    {
    // Inicio transaccion…
    t.Start();
    // Recorro elementos
    foreach (ElementId id in selectedIds)
    {
    Element elem= doc.GetElement(id);
    if (elem==null){continue;}

    LocationPoint loc = elem.Location as LocationPoint;
    XYZ pos= loc.Point;

    ProjectPosition position = projectLocation.get_ProjectPosition(pos);

    var Parametro1 = elem.LookupParameter(ParametroX);
    if (Parametro1==null){continue;} // Si no tiene lo descarto
    var Parametro2 = elem.LookupParameter(ParametroY);
    if (Parametro2==null){continue;} // Si no tiene lo descarto
    var Parametro3 = elem.LookupParameter(ParametroZ);
    if (Parametro3==null){continue;} // Si no tiene lo descarto

    try{ // Si estoy aqui es que existem ambos parámetros!. Trato de copiarlos
    double X=position.EastWest*0.3048;
    double Y=position.NorthSouth*0.3048;
    double Z=position.Elevation*0.3048;
    //Parametro1.Set(trans.X.ToString());
    if (X>0){Parametro1.Set(“+”+X.ToString(“0.000”));}
    else{Parametro1.Set(X.ToString(“0.00”));}
    if (Y>0){Parametro2.Set(“+”+Y.ToString(“0.000”));}
    else{Parametro2.Set(Y.ToString(“0.00”));}
    if (Z>0){Parametro3.Set(“+”+Z.ToString(“0.000”));}
    else{Parametro3.Set(Z.ToString(“0.00”));}
    copiados++;
    }
    catch{
    errores++;
    }
    } //foreach
    doc.Regenerate();
    t.Commit();
    } // else

    if (dialogo){
    TaskDialog.Show(“Fija XYZ Shared”,
    “Elementos Seleccionados: “+ selectedIds.Count.ToString() +
    “\nElementos Modificados: “+ copiados.ToString() +
    “\nNo Modificados: “+ (selectedIds.Count-copiados).ToString() +
    “\nCon errores: “+ errores.ToString()
    );
    } // dialogo
    } //FijaXYZShared

  3. good afternoon, I have a problem with a macro that in the revit 2018 version lets itself mount perfectly now in the 2020 and 2021 version does not let me mount it … here I leave the macro to see if anyone can help me, this macro is to get the coordinates of any element ….

    public void FijaXYZShared()
    {
    String ParametroX=”PosicionX”;
    String ParametroY=”PosicionY”;
    String ParametroZ=”PosicionZ”;
    int copiados=0;
    int errores=0;
    Boolean dialogo=true; // Muestrame el resultado

    UIDocument uidoc = this.ActiveUIDocument;
    Document doc = uidoc.Document;
    Selection selection = uidoc.Selection;
    ICollection selectedIds = uidoc.Selection.GetElementIds();

    ProjectLocation projectLocation = doc.ActiveProjectLocation;

    using(Transaction t = new Transaction(doc,”Fijando XYZ”))
    if (0 == selectedIds.Count){TaskDialog.Show(“Revit”,”No hay selección, ningun elemento a fijar coordenadas.”);}
    else
    {
    // Inicio transaccion…
    t.Start();
    // Recorro elementos
    foreach (ElementId id in selectedIds)
    {
    Element elem= doc.GetElement(id);
    if (elem==null){continue;}

    LocationPoint loc = elem.Location as LocationPoint;
    XYZ pos= loc.Point;

    ProjectPosition position = projectLocation.get_ProjectPosition(pos);

    var Parametro1 = elem.LookupParameter(ParametroX);
    if (Parametro1==null){continue;} // Si no tiene lo descarto
    var Parametro2 = elem.LookupParameter(ParametroY);
    if (Parametro2==null){continue;} // Si no tiene lo descarto
    var Parametro3 = elem.LookupParameter(ParametroZ);
    if (Parametro3==null){continue;} // Si no tiene lo descarto

    try{ // Si estoy aqui es que existem ambos parámetros!. Trato de copiarlos
    double X=position.EastWest*0.3048;
    double Y=position.NorthSouth*0.3048;
    double Z=position.Elevation*0.3048;
    //Parametro1.Set(trans.X.ToString());
    if (X>0){Parametro1.Set(“+”+X.ToString(“0.000”));}
    else{Parametro1.Set(X.ToString(“0.00”));}
    if (Y>0){Parametro2.Set(“+”+Y.ToString(“0.000”));}
    else{Parametro2.Set(Y.ToString(“0.00”));}
    if (Z>0){Parametro3.Set(“+”+Z.ToString(“0.000”));}
    else{Parametro3.Set(Z.ToString(“0.00”));}
    copiados++;
    }
    catch{
    errores++;
    }
    } //foreach
    doc.Regenerate();
    t.Commit();
    } // else

    if (dialogo){
    TaskDialog.Show(“Fija XYZ Shared”,
    “Elementos Seleccionados: “+ selectedIds.Count.ToString() +
    “\nElementos Modificados: “+ copiados.ToString() +
    “\nNo Modificados: “+ (selectedIds.Count-copiados).ToString() +
    “\nCon errores: “+ errores.ToString()
    );
    } // dialogo
    } //FijaXYZShared

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s