-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathCBlockUtil.cpp
More file actions
130 lines (116 loc) · 3.33 KB
/
CBlockUtil.cpp
File metadata and controls
130 lines (116 loc) · 3.33 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
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
#include "stdafx.h"
#include "CBlockUtil.h"
#include "CDwgDatebaseUtil.h"
#include <geassign.h>
#include <acutmem.h>
CBlockUtil::CBlockUtil()
{
}
CBlockUtil::~CBlockUtil()
{
}
void CBlockUtil::addMyBlockDefine()
{
AcDbBlockTable *pBlockTable=NULL;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable,AcDb::kForWrite);
AcDbBlockTableRecord *pBlockTableRecord = new AcDbBlockTableRecord();
TCHAR BlockName[40];
if (acedGetString(Adesk::kFalse,_T("\n输入图块的名称:"),BlockName)!=RTNORM)
{
pBlockTable->close();
delete pBlockTableRecord;
return;
}
pBlockTableRecord->setName(BlockName);
AcDbObjectId BlockDefineid;
pBlockTable->add(BlockDefineid, pBlockTableRecord);
pBlockTable->close();
AcGePoint3d p1(-10, 0, 0);
AcGePoint3d p2(10, 0, 0);
AcDbLine *pLine1 = new AcDbLine(p1, p2);
p1.set(0, 10, 0);
p2.set(0, -10, 0);
AcDbLine *pLine2 = new AcDbLine(p1, p2);
AcGeVector3d ver(0, 0, 1);
AcDbCircle *pCircle = new AcDbCircle(AcGePoint3d::kOrigin, ver, 6);
AcDbAttributeDefinition *pAttributeName = new AcDbAttributeDefinition(p1, _T("准星"), _T("名称:"), _T("部件名称"));
AcDbAttributeDefinition *pAttributeDiametion = new AcDbAttributeDefinition(p2, _T("12"), _T("圆心直径"), _T("准星圆心直径"));
pBlockTableRecord->appendAcDbEntity(pLine1);
pBlockTableRecord->appendAcDbEntity(pLine2);
pBlockTableRecord->appendAcDbEntity(pCircle);
pBlockTableRecord->appendAcDbEntity(pAttributeDiametion);
pBlockTableRecord->appendAcDbEntity(pAttributeName);
pBlockTableRecord->close();
pLine1->close();
pLine2->close();
pCircle->close();
pAttributeDiametion->close();
pAttributeName->close();
return;
}
void CBlockUtil::InsertBlock()
{
TCHAR BlockName[40];
if (acedGetString(Adesk::kFalse,_T("输入要插入的图快名称"),BlockName)!=RTNORM)
{
return;
}
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlockTable, AcDb::kForWrite);
CString strBlkName;
strBlkName.Format(TEXT("%S"), BlockName);
if (!pBlockTable->has(strBlkName))
{
acutPrintf(_T("\n当前图层中未包含指定名称的图块"));
pBlockTable->close();
return;
}
ads_point pt;
if (acedGetPoint(NULL,_T("\n输入块参照的插入点"),pt)!=RTNORM)
{
pBlockTable->close();
return;
}
AcDbObjectId pBlockDefId;
pBlockTable->getAt(strBlkName,pBlockDefId);
AcGePoint3d InsertPoint = asPnt3d(pt);
AcDbBlockReference *pBlockRef = new AcDbBlockReference(InsertPoint, pBlockDefId);
CDwgDatebaseUtil::PostToModelSpace(pBlockRef);
}
bool CBlockUtil::GetAttributeValue(AcDbBlockReference *pBlockRef, TCHAR *Tag, AcString &Value)
{
bool bifFind = false;
AcDbObjectIterator *it = pBlockRef->attributeIterator();
if (it)
{
for (it->start(); !it->done(); it->step())
{
AcDbAttribute *pAttribute=NULL;
AcDbObjectId objectid = it->objectId();
if (pBlockRef->openAttribute(pAttribute,objectid,AcDb::kForRead)==Acad::eOk)
{
TCHAR *szTag = pAttribute->tag();
CString TagName = Tag;
TagName.MakeUpper(); //块参照中属性Tag永远都会是大写字母,因此传入的参数需要进行转换
if (TagName.Compare(szTag)==0)
{
TCHAR *szValue = pAttribute->textString();
Value = szValue;
bifFind = true;
acutDelString(szValue);
acutDelString(szTag);
pAttribute->close();
break;
}
acutDelString(szTag);
pAttribute->close();
}
}
delete it;
return bifFind;
}
else
{
return false;
}
}