-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathCLayerUtil.cpp
More file actions
93 lines (82 loc) · 2.29 KB
/
CLayerUtil.cpp
File metadata and controls
93 lines (82 loc) · 2.29 KB
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
#include "stdafx.h"
#include "CLayerUtil.h"
CLayerUtil::CLayerUtil()
{
}
CLayerUtil::~CLayerUtil()
{
}
void CLayerUtil::add(TCHAR * LayerName, int colorindex)
{
assert(LayerName != NULL);
assert(colorindex >= 1 && colorindex <= 255);
AcDbLayerTable *pLayerTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable, AcDb::kForWrite);
if (!pLayerTable->has(LayerName))
{
AcDbLayerTableRecord *pLayerTableRecord = new AcDbLayerTableRecord();
pLayerTableRecord->setName(LayerName);
AcCmColor color;
color.setColorIndex(colorindex);
pLayerTableRecord->setColor(color);
pLayerTable->add(pLayerTableRecord);
pLayerTableRecord->close();
}
pLayerTable->close();
}
AcDbObjectId CLayerUtil::GetLayerID(TCHAR * LayerName)
{
assert(LayerName);
AcDbLayerTable *pLayerTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable, AcDb::kForRead);
AcDbObjectId Layerid = AcDbObjectId::kNull;
if (pLayerTable->has(LayerName))
{
pLayerTable->getAt(LayerName, Layerid);
}
pLayerTable->close();
return Layerid;
}
bool CLayerUtil::SetLayerColor(TCHAR * layerName, int colorindex)
{
bool result = false;
AcDbObjectId layerid = GetLayerID(layerName);
AcDbLayerTableRecord *pLayerTableRecord = NULL;
if (acdbOpenObject(pLayerTableRecord,layerid,AcDb::kForWrite)==Acad::eOk)
{
AcCmColor color;
color.setColorIndex(colorindex);
pLayerTableRecord->setColor(color);
result = true;
pLayerTableRecord->close();
}
return result;
}
void CLayerUtil::GetAllLayerIDList(AcDbObjectIdArray & layerids)
{
AcDbLayerTable *pLayerTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTable, AcDb::kForRead);
AcDbLayerTableIterator *it;
pLayerTable->newIterator(it);
for (it->start();!it->done();it->step())
{
AcDbLayerTableRecord *pLayerTableRecord = NULL;
if (it->getRecord(pLayerTableRecord, AcDb::kForRead) == Acad::eOk)
{
layerids.append(pLayerTableRecord->objectId());
pLayerTableRecord->close();
}
}
delete it;
pLayerTable->close();
}
void CLayerUtil::DeleteLayer(TCHAR * LayerName)
{
AcDbObjectId Layerid = GetLayerID(LayerName);
AcDbLayerTableRecord *pLayerRecord = NULL;
if (acdbOpenObject(pLayerRecord,Layerid,AcDb::kForWrite)==Acad::eOk)
{
pLayerRecord->erase();
pLayerRecord->close();
}
}