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.
What is the full text of the error? There could be an exception that is encountered when the macro runs. This is a different problem than an error that SharpDevelop can find during compilation.
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
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
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
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
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
What is the full text of the error? There could be an exception that is encountered when the macro runs. This is a different problem than an error that SharpDevelop can find during compilation.
You might try Step Into (instead of Run) to go through the execution of the macro line-by-line to see where it goes wrong
https://boostyourbim.wordpress.com/2013/01/11/stepping-into-your-macros-and-is-this-an-import-or-a-link/
a question
you can filter the Drafting Views
that have CADlink elements
I appreciate the information
regards
Thanks for the question. I’ve added a lecture showing how to do this to the Boost Your BIM Revit API course at Udemy – http://bitly.com/revitapi
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
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
https://www.revitapidocs.com/2018.2/d8e0d449-98fc-6a08-8d88-54f68cdfeb3c.htm
The ProjectPosition.ProjectLocation property was deprecated in Revit 2018. The API help says to use ProjectLocation.Get/SetProjectPosition() instead.