- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear all,
The following application macro (for Revit 2024) does not allow the user to input using the TaskDialog function.
I would appreciate a resolution concerning this matter.
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace DDA_CSharpModule4
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("8469C11C-9426-4B76-8910-02E720C07230")]
public partial class ThisApplication
{
private void Module_Startup(object sender, EventArgs e)
{
}
private void Module_Shutdown(object sender, EventArgs e)
{
}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion
public void RotateModelFileAboutIO()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
// Prompt the user for the rotation angle in degrees using a TaskDialog
TaskDialog angleDialog = new TaskDialog("Rotate Model File About Internal Origin");
angleDialog.MainInstruction = "Enter the angle (in degrees) to rotate the model:";
angleDialog.MainContent = "Please enter a numeric value for the angle.";
angleDialog.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel;
angleDialog.DefaultButton = TaskDialogResult.Ok;
TaskDialogResult result = angleDialog.Show();
if (result == TaskDialogResult.Cancel)
{
TaskDialog.Show("Info", "Operation cancelled by user.");
return;
}
// Here, we assume the user can input the value using a better method or predefined angles
double rotationAngleDegrees = 0;
// Alternatively, a list of predefined angles can be added for selection.
// Convert the rotation angle to radians
double rotationAngle = rotationAngleDegrees * (Math.PI / 180.0);
// Get the internal origin point as the center of rotation
XYZ centerPoint = XYZ.Zero;
// Define the rotation axis (Z-axis)
Line rotationAxis = Line.CreateBound(centerPoint, centerPoint + XYZ.BasisZ);
// Collect all elements that can be transformed
FilteredElementCollector collector = new FilteredElementCollector(doc)
.WhereElementIsNotElementType();
List<ElementId> elementIds = new List<ElementId>();
foreach (Element element in collector)
{
// Skip certain elements that are not transformable (e.g., levels, views, phases, grids)
if (!(element is Level) && !(element is View) && !(element is Phase) && !(element is Grid))
{
elementIds.Add(element.Id);
}
}
// Start a transaction to rotate the model
using (Transaction transaction = new Transaction(doc, "Rotate Entire Model"))
{
try
{
transaction.Start();
// Rotate all collected elements around the internal origin
ElementTransformUtils.RotateElements(doc, elementIds, rotationAxis, rotationAngle);
transaction.Commit();
TaskDialog.Show("Success", string.Format("The model has been successfully rotated by {0} degrees about the internal origin.", rotationAngleDegrees));
}
catch (Exception e)
{
transaction.RollBack();
TaskDialog.Show("Error", string.Format("An error occurred while rotating the model: {0}", e.Message));
}
}
}
}
}
Solved! Go to Solution.