-
Notifications
You must be signed in to change notification settings - Fork 1
/
Commands.cs
145 lines (137 loc) · 6.02 KB
/
Commands.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
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
135
136
137
138
139
140
141
142
143
144
145
// (C) Copyright 2016 by Jericho Masigan
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using RedditSharp;
using System.Linq;
using System.IO;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(AutoCADReddit.MyCommands))]
namespace AutoCADReddit
{
public class MyCommands
{
[CommandMethod("reddit")]
public void CreateReddit()
{
EntityData dimStyles = new EntityData();
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed;
if (doc != null)
{
ed = doc.Editor;
PromptStringOptions prmptStrOpt = new PromptStringOptions("\n\n Type subreddit name. Do not include '/r/' ");
PromptResult prmpRes = ed.GetString(prmptStrOpt);
PromptPointOptions prmptPtOptions = new PromptPointOptions("\n\nPick insertion point....");
PromptPointResult result = ed.GetPoint(prmptPtOptions);
PromptCornerOptions prmptCnrOptions = new PromptCornerOptions("\n\n Click on bottom corner..", result.Value);
PromptPointResult prmptCnrResult;
prmptCnrResult = ed.GetCorner(prmptCnrOptions);
string chosenSubReddit = prmpRes.StringResult;
RedditCAD.FormatRedditDim(dimStyles, result.Value, prmptCnrResult.Value);
if(RedditCAD.PlotSubReddit(dimStyles, chosenSubReddit) == "FAILED")
{
ed.WriteMessage("\n\nFAILED");
}
}
}
[CommandMethod("rpost")]
public void GetPost()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptStringOptions prmptStrOpt = new PromptStringOptions("\n\n Type RedditCAD Post ID : ");
PromptResult prmpRes = ed.GetString(prmptStrOpt);
string postId = prmpRes.StringResult.ToUpper();
if (PostIds.Contains(postId))
{
EntityData dimStyles = new EntityData();
PromptPointOptions prmptPtOptions = new PromptPointOptions("\n\nPick insertion point....");
PromptPointResult result = ed.GetPoint(prmptPtOptions);
PromptCornerOptions prmptCnrOptions = new PromptCornerOptions("\n\n Click on bottom corner..", result.Value);
PromptPointResult prmptCnrResult;
prmptCnrResult = ed.GetCorner(prmptCnrOptions);
RedditCAD.FormatRedditDim(dimStyles, result.Value, prmptCnrResult.Value);
RedditCAD.PlotPost(dimStyles, postId);
}
else
{
ed.WriteMessage("\n\n Invalid AutoCAD.Reddit Post Id..");
}
}
[CommandMethod("rfreeze")]
public void HideReddit()
{
string layerName = "";
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable layerTable;
layerTable = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
foreach(string layername in LayerNameList.GetLayerNames())
{
if(layerTable.Has(layername))
{
LayerTableRecord layerTableRec = tr.GetObject(layerTable[layername], OpenMode.ForWrite) as LayerTableRecord;
layerTableRec.IsFrozen = true;
}
}
tr.Commit();
}
}
[CommandMethod("rthaw")]
public void ThawReddit()
{
string layerName = "";
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable layerTable;
layerTable = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
foreach (string layername in LayerNameList.GetLayerNames())
{
if (layerTable.Has(layername))
{
LayerTableRecord layerTableRec = tr.GetObject(layerTable[layername], OpenMode.ForWrite) as LayerTableRecord;
layerTableRec.IsFrozen = false;
}
}
tr.Commit();
}
}
[CommandMethod("rdel")]
public void DeleteReddit()
{
string layerName = "";
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
LayerTable layerTable;
layerTable = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
foreach (string layername in LayerNameList.GetLayerNames())
{
//Select entities from layer names
ObjectIdCollection objects = DrawEntity.SelectByLayer(layername);
foreach(ObjectId obj in objects)
{
var ent = tr.GetObject(obj, OpenMode.ForWrite);
ent.Erase(true);
}
//Now delete the layer
LayerTableRecord layerTableRec = tr.GetObject(layerTable[layername], OpenMode.ForWrite) as LayerTableRecord;
layerTableRec.Erase(true);
}
tr.Commit();
}
}
}
}