-
Notifications
You must be signed in to change notification settings - Fork 9
/
CreateIExternalCommand.snippet
134 lines (101 loc) · 4.03 KB
/
CreateIExternalCommand.snippet
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Create IExternal Command</Title>
<Author>Maycon Freitas</Author>
<Description>Creates a sample of a IExternal Command implemented with the main codes.</Description>
<Shortcut>rvtiexcom</Shortcut>
</Header>
<Snippet>
<Code Language="CSharp">
<![CDATA[[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class $ClassName$ : IExternalCommand
{
#region Private Variables
private UIApplication $uiapp$;
private UIDocument $uidoc$;
private Application $app$;
private Document $doc$;
#endregion Private Variables
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
$uiapp$ = commandData.Application;
$uidoc$ = $uiapp$.ActiveUIDocument;
$app$ = $uiapp$.Application;
$doc$ = $uidoc$.Document;
try
{
//TODO: Write your code that doesn't need a transaction down here....
$end$
//Created a transaction inside using block
using (Transaction $trans$ = new Transaction($doc$, "$TransactionName$"))
{
//Starts the transaction
$trans$.Start();
//TODO: Write your code that needs a transaction down here....
//Finishes the transaction
$trans$.Commit();
}
}
catch (Exception e)
{
//Shows a message with the error body
TaskDialog.Show("Error", e.Message);
return Result.Failed;
}
return Result.Succeeded;
}
}]]>
</Code>
<Declarations>
<Literal>
<ID>ClassName</ID>
<Default>ClassName</Default>
<ToolTip>The name of the class that you're creating. The name of your command.</ToolTip>
</Literal>
<Literal>
<ID>uiapp</ID>
<Default>uiapp</Default>
<ToolTip>The name of the varible to receive the UIApplication.</ToolTip>
</Literal>
<Literal>
<ID>uidoc</ID>
<Default>uidoc</Default>
<ToolTip>The name of the varible to receive the UIDocument.</ToolTip>
</Literal>
<Literal>
<ID>app</ID>
<Default>app</Default>
<ToolTip>The name of the varible to receive the Application.</ToolTip>
</Literal>
<Literal>
<ID>doc</ID>
<Default>doc</Default>
<ToolTip>The name of the varible to receive the Document.</ToolTip>
</Literal>
<Literal>
<ID>trans</ID>
<Default>trans</Default>
<ToolTip>The name of the varible to receive the Transaction.</ToolTip>
</Literal>
<Literal>
<ID>TransactionName</ID>
<Default>Transaction Name</Default>
<ToolTip>The name of the Transaction.</ToolTip>
</Literal>
</Declarations>
<Imports>
<Import>
<Namespace>Autodesk.Revit.ApplicationServices</Namespace>
</Import>
<Import>
<Namespace>Autodesk.Revit.DB</Namespace>
</Import>
<Import>
<Namespace>Autodesk.Revit.UI</Namespace>
</Import>
</Imports>
</Snippet>
</CodeSnippet>
</CodeSnippets>