-
-
Save ricaun/5145ce37c3bbf0613930c8d167d4ab73 to your computer and use it in GitHub Desktop.
RevitAddin Command to edit a selected DirectShape, if DirectShape has a DirectShapeType the type is edited instead.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Autodesk.Revit.Attributes; | |
using Autodesk.Revit.DB; | |
using Autodesk.Revit.UI; | |
using Autodesk.Revit.UI.Selection; | |
using System.Linq; | |
namespace RevitAddin.Commands | |
{ | |
[Transaction(TransactionMode.Manual)] | |
public class CommandShapeEdit : IExternalCommand | |
{ | |
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet) | |
{ | |
UIApplication uiapp = commandData.Application; | |
UIDocument uidoc = uiapp.ActiveUIDocument; | |
Document document = uidoc.Document; | |
View view = uidoc.ActiveView; | |
Selection selection = uidoc.Selection; | |
var elements = selection.GetElementIds().Select(id => document.GetElement(id)); | |
var shapes = elements.OfType<DirectShape>(); | |
using (Transaction transaction = new Transaction(document)) | |
{ | |
transaction.Start("Shape Edit"); | |
var lines = new[] { | |
Line.CreateBound(-XYZ.BasisX, XYZ.BasisX), | |
Line.CreateBound(-XYZ.BasisY, XYZ.BasisY), | |
Line.CreateBound(-XYZ.BasisZ, XYZ.BasisZ) | |
}; | |
foreach (var shape in shapes) | |
{ | |
if (document.GetElement(shape.TypeId) is DirectShapeType shapeType) | |
{ | |
shapeType.SetShape(lines); | |
continue; | |
} | |
shape.SetShape(lines); | |
} | |
transaction.Commit(); | |
} | |
return Result.Succeeded; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment