HELP! Pick instance & delete category C#

HELP! Pick instance & delete category C#

Anonymous
Not applicable
762 Views
1 Reply
Message 1 of 2

HELP! Pick instance & delete category C#

Anonymous
Not applicable

I'm still a beginner with C# & Revit API. I would like to have the user start the Macro and have it ask "Please select a Family". I need the Macro to find the Category and delete all of them found in the entire project.

 

I am stuck on the last entry (see bold) I can't figure out how to have the element selected find the Built-in-Category and delete them all.

 

namespace DeleteCategory
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class DeleteCategory : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get application and document objects
UIApplication uiApp = commandData.Application;
Document doc = uiApp.ActiveUIDocument.Document;

 

//Define a Reference object to accept the pick result
Reference pickedRef = null;

 

//Pick a Family
Selection sel = uiApp.ActiveUIDocument.Selection;
pickedRef = sel.PickObject(ObjectType.Element, "Please select a Family");
Family fam = Element as FamilyInstance;

0 Likes
763 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk

I hope you have worked through the getting started material, especially the DevTV and My First Revit Plugin tutorials:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

I hope you have the SDK installed and the Revit API help file RevitAPI.chm ready at hand on your desktop.

 

You can only select a family instance.

 

The family defines a collection of family types

 

Each instance placed in the model has a type, which is also called symbol.

 

The associated classes are called FamilyInstance, FamilySymbol, and Family.

 

Each of these has a property to retrieve the related object higher up in the relationship tree: instance -> symbol -> family.

 

The rest of the solution is left to you as a beginner's exercise.

 

Good luck and have fun!

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes