-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass1.cs
69 lines (66 loc) · 2.46 KB
/
Class1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace Lap1PlaceGroup
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class Class1 : 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;
try
{
//Define a reference Object to accept the pick result
Reference pickedref = null;
//Pick a group
Selection sel = uiapp.ActiveUIDocument.Selection;
GroupPickFilter selFilter = new GroupPickFilter();
pickedref = sel.PickObject(ObjectType.Element, selFilter, "Please select a group");
Element elem = doc.GetElement(pickedref);
Group group = elem as Group;
//Pick point
XYZ point = sel.PickPoint("Please pick a point to place group");
//Place the group
Transaction trans = new Transaction(doc);
trans.Start("Lab");
doc.Create.PlaceGroup(point, group.GroupType);
trans.Commit();
return Result.Succeeded;
}
//If the user right-clicks or presses Esc,handle the exception
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
return Result.Cancelled;
}
catch (Exception ex)
{
message = ex.Message;
return Result.Failed;
}
}
// Filter to constrain picking to model groups, Only model groups
// are highlighted and can be selected when cursor is hovering.
public class GroupPickFilter : ISelectionFilter
{
public bool AllowElement(Element e)
{
return
(e.Category.Id.IntegerValue.Equals((int)BuiltInCategory.OST_IOSModelGroups));
}
public bool AllowReference(Reference r,XYZ p)
{
return false;
}
}
}
}