📜 ⬆️ ⬇️

Macro for Autodesk Revit that trim walls

The Autodesk made the walls different, but the designers came and drew the walls at an angle of 0.045 and 89.915 degrees. Therefore do not put dimensions between the walls. This went on for a long time, but now the Great Equalization Macro has appeared, it will return angles of 0.000 and 90.000 degrees to the walls.
The macro corrects the walls, which are drawn with an error of up to 1.2 degrees relative to the parallel or perpendicular to the selected wall sample.


The algorithm works as follows: the user runs a macro, selects uneven walls one by one or a frame, then selects a wall for the sample against which the selected walls are leveled. Thus, only walls that are almost parallel or perpendicular to the pattern are leveled. Walls with a relative angle to the pattern of 35, 45, 75, etc. not affected. They need to dub relative to another sample.


Macros are available to everyone! Everyone can easily set a macro in Revit.


Macro setting in 5 steps :


1. Open in Revit any project. Run the tool "Manage (Manage)" -> "Macros (Macros)" -> "Macro Manager (MacroManager)" .


2. In the "Macro Manager" window , go to the "Application (Application)" tab , then "Create) -> " Module (s) " .


3. In the Create a New Module dialog box , set the module name to Wall_Equalizer . After that, the SharpDevelop program window will immediately open with our module. The most important thing is done!


4. Go to work in the program "SharpDevelop". In the main window, delete all the text and paste the macro code, which can be copied below.


5. When we insert the macro code, press F9 .


/* * Created by SharpDevelop. * User: Alexandr Akunets * Date: 1/30/2018 * Time: 9:50 AM * * version 1.000 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using Autodesk.Revit.UI; using Autodesk.Revit.DB; using Autodesk.Revit.UI.Selection; using System.Collections.Generic; using System.Linq; namespace Wall_Equalizer { [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)] [Autodesk.Revit.DB.Macros.AddInId("31DDFC5C-59FF-416B-8482-49568A640EE5")] public partial class ThisApplication { private void Module_Startup(object sender, EventArgs e) { } private void Module_Shutdown(object sender, EventArgs e) { } public void WallEqualizer () { var uiapp = this.ActiveUIDocument; var doc = uiapp.Document; //Dictionary<Element, Sherif> elms = new Dictionary<Element, Sherif>(); //var wallist = new FilteredElementCollector(doc, doc.ActiveView.Id).OfCategory(BuiltInCategory.OST_Walls).ToElements(); List<Element> wallist = new List<Element>(); var rs = uiapp.Selection.PickObjects (ObjectType.Element, new PickFilter(BuiltInCategory.OST_Walls), "Select wrong walls"); foreach(var w in rs) { var e = doc.GetElement(w.ElementId) as Wall; wallist.Add(e); } var r = uiapp.Selection.PickObject (ObjectType.Element, new PickFilter(BuiltInCategory.OST_Walls), "Select wall - sample"); Wall selwall = doc.GetElement(r.ElementId) as Wall; Line line = GetLine(selwall); try { foreach(Element el in wallist) { using (Transaction t = new Transaction(doc, "r")) { t.Start(); var wLine = GetLine(el); if(wLine != null) { var wcos = (line.Direction.X * wLine.Direction.X + line.Direction.Y * wLine.Direction.Y); var angleR = Math.Acos (wcos); if (el.Id.IntegerValue != r.ElementId.IntegerValue) { BustEquiizer90(el, line, angleR ); BustEquiizer0(el, line, angleR ); } } t.Commit(); } } } catch(Exception ex) { if ( (ex is Autodesk.Revit.Exceptions.ArgumentsInconsistentException) == false) { TaskDialog.Show("Error", ex.Message + ex.StackTrace); } } } private void BustEquiizer90(Element el, Line line, double angleR) { var angle = RadiansToDegrees( angleR ); if ( Math.Abs(angle - 90) > 0.0000001 && Math.Abs(angle - 90) < 1.2) { Equalizer(el, -(DegreesToRadians(90) - angleR)); var wLine = GetLine(el); var wcos = (line.Direction.X * wLine.Direction.X + line.Direction.Y * wLine.Direction.Y); angleR = Math.Acos (wcos); angle = RadiansToDegrees( angleR ); if ( Math.Abs(angle - 90) > 0.0000001 && Math.Abs(angle - 90) < 2.4) { Equalizer(el, (DegreesToRadians(90) - angleR)); } } } private void BustEquiizer0(Element el, Line line, double angleR) { var angle = RadiansToDegrees( angleR ); if ( (Math.Abs(angle) > 0.0000001 && Math.Abs(angle) < 1.2) || Math.Abs(angle -180) > 0.0000001 && Math.Abs(angle -180) < 2.4) { Equalizer(el, -angleR); var wLine = GetLine(el); var wcos = (line.Direction.X * wLine.Direction.X + line.Direction.Y * wLine.Direction.Y); angleR = Math.Acos (wcos); angle = RadiansToDegrees( angleR ); if ( Math.Abs(angle) > 0.0000001 && Math.Abs(angle) < 2.4 || Math.Abs(angle -180) > 0.0000001 && Math.Abs(angle -180) < 2.4) { Equalizer(el, -angleR); wLine = GetLine(el); wcos = (line.Direction.X * wLine.Direction.X + line.Direction.Y * wLine.Direction.Y); angleR = Math.Acos (wcos); angle = RadiansToDegrees( angleR ); if ( Math.Abs(angle) > 0.0000001 && Math.Abs(angle) < 5 || Math.Abs(angle -180) > 0.0000001 && Math.Abs(angle -180) < 5) { Equalizer(el, angleR); } } } } private void Equalizer(Element el, double angle) { LocationCurve wLine = el.Location as LocationCurve; var mid = Midpoint(wLine.Curve); Line axis = Line.CreateBound(mid, new XYZ( mid.X, mid.Y, mid.Z + 1)); ElementTransformUtils.RotateElement( this.ActiveUIDocument.Document, el.Id, axis, angle); } private Line GetLine(Element el){ var selCurve = (el.Location as LocationCurve).Curve; if( selCurve is Line) { XYZ p0 = new XYZ(selCurve.GetEndPoint(0).X, selCurve.GetEndPoint(0).Y, 0); XYZ p1 = new XYZ(selCurve.GetEndPoint(1).X, selCurve.GetEndPoint(1).Y, 0); Line line = Line.CreateBound (p0, p1); return line; } else return null; } public static double RadiansToDegrees(double angle) { return (angle * 180 / Math.PI); } public static double DegreesToRadians(double angle) { return (angle * Math.PI / 180); } public static XYZ Midpoint(Curve curve) { return 0.5 * (curve.GetEndPoint(0) + curve.GetEndPoint(1)); } #region Revit Macros generated code private void InternalStartup() { this.Startup += new System.EventHandler(Module_Startup); this.Shutdown += new System.EventHandler(Module_Shutdown); } #endregion } public class PickFilter : ISelectionFilter { //BuiltInCategory SelectionCategory { get; set; } BuiltInCategory [] SelCats; /* public PickFilter(BuiltInCategory cat) { SelCats = new BuiltInCategory[] { cat }; } */ public PickFilter(params BuiltInCategory[] cat) { SelCats = cat; } public bool AllowElement (Element elem) { foreach(BuiltInCategory cat in SelCats) { if (elem.Category.Id.IntegerValue == (int)cat) return true; } return false; } public bool AllowReference (Reference r, XYZ p) { return false; } } } 

If there are no errors and the message “Build finished successfully” appears, the macro is set correctly. If there are errors, then re-read the instructions and do it all over again. At the end of the work we close the program "SharpDevelop" and return to Revit.


Work with macro:


Start the Macro Manager again, go to the Application tab , expand the Wall_Equalizer macro, select the Wall_Equalizer macro option and click the Run button. The macro is running.


Macro operation algorithm:


1. Select the walls to be aligned, one by one or a frame. Do not choose too many walls. The optimal number of walls is about 50. When the selection of the walls is completed, click "Finish" in the options bar (Option Bar).


2. Choose a wall that is drawn exactly and can serve as a model.


3. We get the result.


Remember, a macro cannot process walls that are arranged in groups. If you want to align the walls that are in groups, you need to ungroup such walls before running the macro.


')

Source: https://habr.com/ru/post/352948/


All Articles