[rvtApi]_010_FirstCommand in Revit
Get UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
Get Element
Reference r = uidoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
try
{
if (r != null)
{
TaskDialog.Show("Element ID", r.ElementId.ToString());
}
return Result.Succeeded;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
#Register Addin Revit
Add file Application Manifest File, note (xxx.addin)
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<Assembly>MyFristCommand.dll</Assembly>
<ClientId>xxx</ClientId>
<FullClassName>MyFirstCommand.MyElement</FullClassName>
<Text>GetElemenyId</Text>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<AddInId>50930344-E64B-4AF6-9AD8-3D23311D4B56</AddInId>
<LanguageType>Unknown</LanguageType>
<VendorId>TeeMee</VendorId>
<VendorDescription>FelixTran, www.teemee.com</VendorDescription>
</RevitAddIns>
Get GUIDs from https://www.guidgen.com/ and paste to AddInId
How To Build Project
Build project to file .dll
copy "$(TargetPath)" "%ProgramData%/Autodesk\Revit\Addins\2021\"
copy "$(ProjectDir)DeleteDoors.addin" "%ProgramData%/Autodesk\Revit\Addins\2021\"
How to Debug Project
Get Element Form ElementID
Get ElementType
FilteredElementCollector
Create Collection
FilteredElementCollector collection = new FilteredElementCollector(doc);
Create Filter
ElementCategoryFilter filterDoor = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
Apply Filter to collection
IList<Element> doors = collection.WherePasses(filterDoor).WhereElementIsNotElementType().ToElements();
Transaction
using (Transaction trans = new Transaction(doc, "change element"))
{
trans.Start();
doc.Delete(r.ElementId);
TaskDialog tDialog = new TaskDialog("Delete Element");
tDialog.MainContent = "Are you sure delete object?";
tDialog.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel;
if (tDialog.Show() == TaskDialogResult.Ok)
{
trans.Commit();
TaskDialog.Show("Delete Element", " Yu delete this object" + r.ElementId.ToString())
}
else
{
trans.Commit();
TaskDialog.Show("Delete Element", "Phan tu" +r.ElementId.ToString()+"chua bi xoa")
}
}