Professional Documents
Culture Documents
CAD
CAD
.NET ObjectARX
zf9568@263.net
2007-7-15
ObjectARX
1 ObjectARX
ObjectARX
ObjectARX Hello,World
ObjectARX
1.1 ObjectARX
1.1.1
ObjectARX AutoCAD
2002
AutoCAD 2002
VC++ 6.0
ObjectARX 2002
ObjectARX AutoCAD
AutoCAD R14AutoCAD 2000 AutoCAD 2002 VC++ 6.0
AutoCAD 2004 AutoCAD 2005 VC.NET 2002
ObjectARX
ObjectARX ObjectARX
1.1.2
1.1.3
AutoCAD 2002
VC++ 6.0 AutoCAD 2002 ObjectARX 2002
VC++ 6.0
1.1
ObjectARX
VC++ ObjectARX
2ObjectARXAutodesk
http://www.autodesk.com/adn
arxlabs ObjectARX
classmap DWG ObjectARX
docs
docsampsObjectARX docs
inc ObjectARX
lib ObjectARX
redistribDLL ObjectARX
samples ObjectARX
utils ObjectARX brep
ObjectARX 2002
E:\ObjectARX 2002\
3ObjectARX\utils\ObjARXWiz\
wizards.exeWizardSetup.exe
1.1Install
1.1
ObjectARX
1.2ObjectARX
ObjectARX
1.2
VC++ 6.0File/NewNew
ObjectARX 2000/2000i/2002 AppWizard 1.3
1.3 ObjectARX
4ObjectARXObjectARXNew
ObjectARX 1.4
1.4 ObjectARX
1.1
ObjectARX
arxdoc.chm
1.5
ObjectARX
1.6
VC
1.1.4
1.1.5
ObjectARX 2002 ObjectARX
AutoCAD 2000
VC++.NET 2002
1.2 ObjectARX
1.2.1
ObjectARX
6
1.2
ObjectARX
ObjectARX
1.2.2
ObjectARX
APPLOAD
ARX
ARX
ObjectARX
1.2.3
ObjectARX
1APPLOADAutoCAD 2004
1.7
1.7
AutoCAD 2004
AutoCAD 2004
1.8
ObjectARX
1.8
AutoCAD ObjectARX
2 ARX ARX
: arx
[?/(L)/(U)/(C)/(O)]: l
LEnter
1.9
1.9
ARX
ARX
1.2
ObjectARX
3ARXAutoCADARX
1.10
1.10 ARX
4 ObjectARX Enter
AutoCAD
ARX 3
1.3 ARX
1.11
1.11
HelloEnter 1.12
1.12 ARX
1.2.4
ObjectARX
1.2.5
APPLOAD ObjectARX
ARX
1.3 HelloWorld
1.3.1
Hello,World
Hello,World
ObjectARX
AutoCAD Hello,World
1.3.2
ObjectARX .arxDLL
Windows ObjectARX AutoCAD
AutoCAD
ObjectARX AutoCAD ARX
ObjectARX
ObjectARX
1.3.3
1VC++ 6.0 File/NewNew
ProjectsWin32 Dynamic-Link LibraryProject
nameHello1Location
1.13OK
10
1.3
HelloWorld
1.13
1.14
ObjectARX
1.15OK
1.15 DLL
4Project/SettingProject SettingsGeneral
Settings for:All configurations
5Project SettingsC/C++Category:
Code GenerationUse run-time libraryMultithreaded
DLLCategory:PreprocessorAdditional include directories:
ObjectARXE:\ObjectARX 2002\inc
1.16
12
1.3
HelloWorld
1.16
6Project SettingsLinkCategory:
GeneralSettings for:Win32 debug
Output File Name:dllarx 1.17
arx AutoCAD ARX
arx
Settings for:Win32 releaseOutput File Name:
dll arx
arx
ObjectARX AutoCAD ARX
13
ObjectARX
1.17
7Settings for:All
configurationsObject/library
moduleARXrxapi.libacrx15.lib
acutil15.libacedapi.lib 1.18
1.18 ARX
14
1.3
HelloWorld
8Category:Input
Additional Library Path:ObjectARXARX
E:\ObjectARX 2002\lib
1.19
1.19 ObjectARX
9Project settingsOK
AutoCAD
Hello World!
10Project/ Add to Project/ New...NewFiles
C++ Source FileFileHello
1.20OK
15
ObjectARX
1.20 C++
11 ObjectARX
#include <aced.h>
#include <rxregsvc.h>
ARX AutoCAD
aced.h acrxXXX rxregsvc.h
void HelloWorld();
14 initApp() AutoCAD
AutoCAD
ARX initApp()
void initApp()
{
//AutoCAD
acedRegCmds->addCommand("Hello1",
"Hello", //
16
1.3
"Hello",
HelloWorld
//AutoCAD
ACRX_CMD_MODAL,
HelloWorld);
}
ObjectARX AcEdCommandStack
acedRegCmds AcEdCommandStack AcEdCommandStack
addCommand AutoCAD removeGroup
addCommand
virtual Acad::ErrorStatus addCommand(
const char* cmdGroupName,
const char* cmdGlobalName,
const char* cmdLocalName,
Adesk::Int32 commandFlags,
AcRxFunctionPtr FunctionAddr,
AcEdUIContext * UIContext = NULL,
int fcode = -1,
HINSTANCE hResourceHandle = NULL,
AcEdCommand** cmdPtrRet = NULL) = 0;
5
AutoCAD
AutoCAD AutoCAD
LINE
AutoCAD LINE Enter
LINE
L Enter L LINE
addCommand 4
ZOOM CIRCLE
ACRX_CMD_MODAL 4
5 HelloWorld
Hello HelloWorld
15 unloadApp() AutoCAD EX01
initApp()
17
ObjectARX
unloadApp()
void unloadApp()
{
//
acedRegCmds->removeGroup("Hello1");
}
removeGroup
void HelloWorld()
{
acutPrintf("\nHello, World!");
}
acutPrintf() C printf \n
17 Windows
acrxEntryPoint() switch AcRx::kInitAppMsg
AcRx::kUnloadAppMsg
18
1.3
HelloWorld
initApp()
unloadApp()ObjectARX DLL
main()AutoCAD ObjectARX acrxEntryPoint()
18File/New 1.21New
Text FileFileHello.def
1.21
19
LIBRARY Hello1
DESCRIPTION "First ARX Application."
EXPORTS
acrxEntryPoint
acrxGetApiVersion
PRIVATE
PRIVATE
Windows
AutoCAD
LIBRARY
EXPORTS ARX
acrxEntryPoint acrxGetApiVersion
19
ObjectARX
DESCRIPTION
Hello,World
//////////////////////////////////////////////////////////////////////////
// Hello.cpp
// by
//////////////////////////////////////////////////////////////////////////
//
#include <aced.h>
#include <rxregsvc.h>
//
void initApp();
void unloadApp();
//
void HelloWorld();
//
void initApp()
{
//AutoCAD
acedRegCmds->addCommand("Hello1",
"Hello",
//
"Hello",
//AutoCAD
ACRX_CMD_MODAL,
HelloWorld);
}
//
void unloadApp()
{
//
acedRegCmds->removeGroup("Hello1");
}
// Hello
void HelloWorld()
20
1.3
HelloWorld
{
acutPrintf("\nHello, World!");
}
//
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
switch (msg)
{
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(pkt);
acrxRegisterAppMDIAware(pkt);
initApp();
break;
case AcRx::kUnloadAppMsg:
unloadApp();
break;
default:
break;
}
return AcRx::kRetOK;
}
//////////////////////////////////////////////////////////////////////////
// Hello.def
// by
//////////////////////////////////////////////////////////////////////////
LIBRARY Hello1
DESCRIPTION "First ARX Application."
EXPORTS
acrxEntryPoint
acrxGetApiVersion
PRIVATE
PRIVATE
1.3.4
ARX
1Hello1 Build/Start Debug/Go
F5 1.22ARX
21
ObjectARX
1.22
2 1.23
DLLAutoCAD 2002
Browseracad.exe
AutoCAD 2002 OK
3 1.24AutoCAD 2002
Do not prompt in the futureOK
1.24
4AutoCAD 2002
1.25
Hello.arxAutoCAD 2002
22
1.3
HelloWorld
1.25 ARX
1.26
1.3.5
ARX
ARX
ObjectARX
58
ObjectARX
23
ObjectARX
1.27 ObjectARX
1.28 ObjectARX
Options ObjectARX 5
8 ARX
Options
ObjectARX Options
ObjectARX
1.4
Hello,World
1.4 Hello,World
1.4.1
ObjectARX Hello,World
ObjectARX
AutoCAD HelloWorld!
1.4.2
ObjectARX
MFC
1.4.3
1VC++ 6.0File/New1.29
ObjectARX 2000/2000i/2002 AppWizardHello2
OK
25
ObjectARX
1.29
21.30
Next
1.30
31.31
26
1.4
Hello,World
StdAfx.cpp StdAfx.h
Hello2.cpp
Hello2.def
StdArx.h
Resource.h
res\Hello2.rc2
ObjectARX.prjObjectARX 2000
RxDebug.cpp RxDebug.h
DocData.h DocData.cpp
AdskDMgr.h Autodesk
1.31
4 OK
Project/SettingsDebugExecutable for debug session
AutoCAD 20021.32
1.23
27
ObjectARX
5 AsdkDataManager CDocData
Hello2.cpp
AcrxEntryPoint ObjectARX
InitApplication
UnloadApplication
_hdllInstance DllMain
DllMain DLL
AddCommand addCommand AutoCAD
6HelloObjectARXObjectARX commands
1.33Command flags
DocumentShared writeUse picksetGroup
BASICInternationalHelloLocal
HelloZffBASICHelloHello
AddOK
28
1.4
Hello,World
1.33 Hello
7 Hello2Commands.cpp Hello
ZffBASICHello
void ZffBASICHello()
{
acutPrintf("Hello,World!");
}
1.4.4
VC++ 6.0F5AutoCAD 2002
APPLOADARXHello1.34
1.34
29
ObjectARX
1.4.5
Hello,World
ObjectARX
30
2.1
2
ObjectARX
ObjectARX
2.1
2.1.1
AutoCAD 2002000
1001000
AutoCAD
VBA AutoLISP
2.1.2
AutoCAD LINE
: _line
: 0,0
[(U)]: 100,100
[(U)]:
2.1AutoCAD
1
2
3
31
2.1
2.1.3
1VC++ 6.0ObjectARXCreateLine
1.4ObjectARX2.2
2.2
32
2.1
// AcDbLine
AcGePoint3d ptStart(0, 0, 0);
AcGePoint3d ptEnd(100, 100, 0);
AcDbLine *pLine = new AcDbLine(ptStart, ptEnd);
AutoCAD
2 ZffCHAP2CreateLine
//
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlockTable, AcDb::kForRead);
acdbHostApplicationServices()->workingDatabase()
getBlockTable AcDbDatabase
getBlockTable
3 ZffCHAP2CreateLine
//
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
getAt AcDbBlockTable
33
Acad::ErrorStatus getAt(
const char* entryName,
AcDbBlockTableRecord*& pRec,
AcDb::OpenMode openMode,
bool openErasedRec = false) const;
ACDB_MODEL_SPACE ObjectARX
*Model_Space
AcDb::kForWrite
4 ZffCHAP2CreateLine
// AcDbLine
AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);
appendAcDbEntity AcDbBlockTableRecord pEntity
Acad::ErrorStatus appendAcDbEntity(
AcDbObjectId& pOutputId,
AcDbEntity* pEntity);
ID
AcDbObjectId ID
9527
AcDbObjectId
5 ZffCHAP2CreateLine
//
pBlockTable->close();
pBlockTableRecord->close();
pLine->close();
AutoCAD
ObjectARX
34
2.1
appendAcDbEntity
6
void ZffCHAP2CreateLine()
{
// AcDbLine
AcGePoint3d ptStart(0, 0, 0);
AcGePoint3d ptEnd(100, 100, 0);
AcDbLine *pLine = new AcDbLine(ptStart, ptEnd);
//
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlockTable, AcDb::kForRead);
//
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
// AcDbLine
AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);
//
pBlockTable->close();
pBlockTableRecord->close();
pLine->close();
}
7F72.3
ObjectARX
35
2.3
AcDbLine AcDbLine
ObjectARX
AcDbLine
ObjectARXObjectARX Reference
AcDbLineObjectARX
Alt+F1AcDbLine Class
2.4
36
2.1
2.4
ObjectARX
8 AcDbLine
CreateLineCommands.cpp
#include "dbents.h"
F7
ZffCreateLine.arx
ObjectARX StdArx.h
//
Ok
ObjectARX
2.1.4
AutoCAD 2002CreateLine
2.5
37
2.5
2.1.5
3 getAt
ACDB_PAPER_SPACE getAt
ObjectARX
2.2
2.2.1
2.2.2
ZffCHAP2CreateLine
38
2.2
pLine->setColorIndex(1);
CreateLine
AutoCAD
2.1 AcDbObjectId ID
ID ID
AcDbBlockTableRecord appendAcDbEntity
ID acdbOpenAcDbEntity
ID
Acad::ErrorStatus acdbOpenAcDbEntity(
AcDbEntity*& pEnt,
AcDbObjectId id,
AcDb::OpenMode mode,
bool openErasedEntity = false);
ID
acdbOpenAcDbEntity AcDbEntity
acdbOpenAcDbObject AcDbEntity
acdbOpenObject AcDbEntity
close
2IDAcDbObjectIdHandle ads_name
IDads_name
IDIDads_name 2.6
39
ID
2.6
ID ads_name
ID ads_name Windows
ObjectARX AcDbHandle Windows
64 DWG
ads_name ADS ObjectARX
ID ads_name
ID AutoCAD ID
AutoCAD ID
AutoCAD
DWG
ads_name AutoCAD
AutoCAD ads_name
ID ads_name
ID acdbOpenAcDbEntity
acdbOpenAcDbObject acdbOpenObject
ID AcDbObject AcDbObject
objectId ID
ID AcDbDatabase::getAcDbObjectId
ID AcDbObjectId::handle
AcDbObject::getAcDbHandle
ads_name ID acdbGetObjectId
ID ads_name acdbGetAdsName
2.2.3
1VC++ 6.0 ObjectARX ModifyEnt
ObjectARX ChangeColor
2 CreateLine
40
2.2
ModifyEntCommands.cpp
AcDbObjectId CreateLine()
{
AcGePoint3d ptStart(0, 0, 0);
AcGePoint3d ptEnd(100, 100, 0);
AcDbLine *pLine = new AcDbLine(ptStart, ptEnd);
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);
pBlockTable->close();
pBlockTableRecord->close();
pLine->close();
return lineId;
}
AcDbObjectId
return ID
AcDbLine
#include "dbents.h"
3 ChangeColor
ID
Acad::ErrorStatus ChangeColor(AcDbObjectId entId, Adesk::UInt16 colorIndex)
{
AcDbEntity *pEntity;
//
acdbOpenObject(pEntity, entId, AcDb::kForWrite);
//
pEntity->setColorIndex(colorIndex);
41
//
pEntity->close();
return Acad::eOk;
}
acdbOpenObject ID
AcDbEntity::setColorIndex colorIndex AutoCAD
0256 0 256
Acad::ErrorStatus BOOL
Acad::ErrorStatus
BOOL
4 ChangeColor
void ZffCHAP2ChangeColor()
{
//
AcDbObjectId lineId;
lineId = CreateLine();
//
ChangeColor(lineId, 1);
}
CreateLine ChangeColor
AcDbObjectId lineId
ObjectARX
2.2.4
VC++ F5 AutoCAD 2002 ARX
ChangeColor
2.2.5
1
C CreateLine ChangeColor
ZffCHAP2ChangeColor C
42
2.2
C C++
ModifyEntCommands.cpp
CCreateEnt CMofifyEntCreateLine
ChangeColor
2.7
43
2.8
3 CCreateEnt CModifyEnt
#include "StdArx.h"
StdArx.h
#include "dbents.h"
4 CCreateEnt CreateLine
static AcDbObjectId CreateLine();
//
AcDbObjectId CCreateEnt::CreateLine()
//
{
4 CModifyEnt ChangeColor
static Acad::ErrorStatus ChangeColor(AcDbObjectId entId, Adesk::UInt16
colorIndex);
Acad::ErrorStatus CModifyEnt::ChangeColor(AcDbObjectId entId, Adesk::UInt16
colorIndex)
{
}
5 ZffCHAP2ChangeColor
44
2.2
void ZffCHAP2ChangeColor()
{
//
AcDbObjectId lineId;
lineId = CCreateEnt::CreateLine();
//
CModifyEnt::ChangeColor(lineId, 1);
}
45
//
pEntity->close();
return Acad::eOk;
}
AcDbEntity
3 CreateLine
CCreateEnt::CreateLine 0001001000
CCreateEnt
//
AcDbObjectId CCreateEnt::CreateLine(AcGePoint3d ptStart,
AcGePoint3d ptEnd)
{
AcDbLine *pLine = new AcDbLine(ptStart, ptEnd);
//
AcDbObjectId lineId;
lineId = CCreateEnt::PostToModelSpace(pLine);
return lineId;
}
//
AcDbObjectId CCreateEnt::PostToModelSpace(AcDbEntity* pEnt)
{
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
AcDbObjectId entId;
46
2.3
pBlockTableRecord->appendAcDbEntity(entId, pEnt);
pBlockTable->close();
pBlockTableRecord->close();
pEnt->close();
return entId;
}
AddLine
void ZffCHAP2AddLine()
{
AcGePoint3d ptStart(0, 0, 0);
AcGePoint3d ptEnd(100, 100, 0);
AcDbObjectId lineId;
lineId = CCreateEnt::CreateLine(ptStart, ptEnd);
CModifyEnt::ChangeColor(lineId, 1);
CModifyEnt::ChangeLayer(lineId, _T(""));
CModifyEnt::ChangeLinetype(lineId, _T(""));
}
2.3
2.3.1
2.3.2
ObjectARX AcDbCircle
AcDbCircle();
AcDbCircle(const AcGePoint3d& cntr, const AcGeVector3d& nrm, double radius);
C++ C++
47
0000
001
2.3.3
1 VC++ 6.0File/Open Workspace
CreateEnts File/Open
Workspace
// CreateEnt.h
static AcDbObjectId CreateCircle(AcGePoint3d ptCenter,
AcGeVector3d vec, double radius);
// CreateEnt.cpp
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint3d ptCenter,
AcGeVector3d vec, double
radius)
{
AcDbCircle *pCircle = new AcDbCircle(ptCenter, vec, radius);
//
AcDbObjectId circleId;
circleId = CCreateEnt::PostToModelSpace(pCircle);
return circleId;
}
3 CCreateEnt CreateCircle
XOY XOY
//
static AcDbObjectId CreateCircle(AcGePoint3d ptCenter, double radius);
//
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint3d ptCenter, double radius)
{
AcGeVector3d vec(0, 0, 1);
48
2.3
XOY
4 CCalculation
MiddlePoint
AcGePoint2d CCalculation::MiddlePoint(AcGePoint2d pt1, AcGePoint2d pt2)
{
AcGePoint2d pt;
pt[X] = (pt1[X] + pt2[X]) / 2;
pt[Y] = (pt1[Y] + pt2[Y]) / 2;
return pt;
}
AcGePoint3d CCalculation::MiddlePoint(AcGePoint3d pt1, AcGePoint3d pt2)
{
AcGePoint3d pt;
pt[X] = (pt1[X] + pt2[X]) / 2;
pt[Y] = (pt1[Y] + pt2[Y]) / 2;
pt[Z] = (pt1[Z] + pt2[Z]) / 2;
return pt;
}
5 CCreateEnt
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint2d pt1, AcGePoint2d pt2)
{
//
AcGePoint2d pt = CCalculation::MiddlePoint(pt1, pt2);
AcGePoint3d ptCenter(pt[X], pt[Y], 0);
//
double radius = pt1.distanceTo(pt2) / 2;
//
return CCreateEnt::CreateCircle(ptCenter, radius);
}
CCalculation::MiddlePoint
AcGePoint2d::distanceTo
6 VBA
ObjectARX
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint2d pt1, AcGePoint2d pt2,
49
AcGePoint2d pt3)
{
//
double xysm, xyse, xy;
AcGePoint3d ptCenter;
double radius;
xy = pow(pt1[X], 2) + pow(pt1[Y], 2);
xyse = xy - pow(pt3[X], 2) - pow(pt3[Y], 2);
xysm = xy - pow(pt2[X], 2) - pow(pt2[Y], 2);
xy = (pt1[X] - pt2[X]) * (pt1[Y] - pt3[Y]) - (pt1[X] - pt3[X]) * (pt1[Y] pt2[Y]);
//
if (fabs(xy) < 0.000001)
{
AfxMessageBox("");
return 0;
}
//
ptCenter[X] = (xysm * (pt1[Y] - pt3[Y]) - xyse * (pt1[Y] - pt2[Y])) / (2 *
xy);
ptCenter[Y] = (xyse * (pt1[X] - pt2[X]) - xysm * (pt1[X] - pt3[X])) / (2 *
xy);
ptCenter[Z] = 0;
radius = sqrt((pt1[X] - ptCenter[X]) * (pt1[X] - ptCenter[X]) +
(pt1[Y] - ptCenter[Y]) * (pt1[Y] - ptCenter[Y]));
if (radius < 0.000001)
{
AfxMessageBox("");
return 0;
}
return CCreateEnt::CreateCircle(ptCenter, radius);
}
C powfabs sqrt
50
2.3
#include <math.h>
x2y2z2x3
xyzx1y1z1
y3z3
( x x1 ) 2 + ( y y1 ) 2 = ( x x 2 ) 2 + ( y y 2 ) 2 = ( x x3 ) 2 + ( y y 3 ) 2
2 x1 x + x1 2 y1 y + y1 = 2 x 2 x + x 2 2 y 2 y + y 2 = 2 x3 x + x3 2 y 3 y + y 3
2
[
y ) y = [( x
]
)]/ 2
( x 2 x1 ) x + ( y 2 y1 ) y = ( x 2 + y 2 ) ( x1 + y1 ) / 2
( x3 x1 ) x + ( y 3
2
3
+ y 3 ) ( x1 + y1
2
( x 2 x1 )...( y 2 y1 )
( x3 x1 )...( y 3 y1 )
[
x )...[( x
]
)]/ 2
[( x
[( x
]
)]/ 2...( y
+ y2 ) ( x1 + y1 ) / 2...( y 2 y1 )
+ y3 ) ( x1 + y1
3 y1 )
( x 2 x1 )... ( x 2 + y 2 ) ( x1 + y1 ) / 2
( x3
2
3
+ y 3 ) ( x1 + y1
2
7 ObjectARX AcGe
AcGeCircArc3d
AcDbObjectId CCreateEnt::CreateCircle(AcGePoint2d pt1, AcGePoint2d pt2,
AcGePoint2d pt3)
{
//
AcGeCircArc2d geArc(pt1, pt2, pt3);
AcGePoint3d ptCenter(geArc.center().x, geArc.center().y, 0);
return CCreateEnt::CreateCircle(ptCenter, geArc.radius());
}
AcGeCircArc2d
AcGeCircArc2d
#include "gearc3d.h"
51
2.3.4
1 AddCircle
void ZffCHAP2AddCircle()
{
//
AcGePoint3d ptCenter(100, 100, 0);
CCreateEnt::CreateCircle(ptCenter, 20);
//
AcGePoint2d pt1(70, 100);
AcGePoint2d pt2(130, 100);
CCreateEnt::CreateCircle(pt1, pt2);
//
pt1.set(60, 100);
pt2.set(140, 100);
AcGePoint2d pt3(100, 60);
CCreateEnt::CreateCircle(pt1, pt2, pt3);
}
2.9
2.3.5
52
2.4
2.4
2.4.1
2.4.2
ObjectARX AcDbArc
AcDbArc(
const AcGePoint3d& center,
double radius,
double startAngle,
double endAngle);
AcDbArc(
const AcGePoint3d& center,
const AcGeVector3d& normal,
double radius,
double startAngle,
double endAngle);
AcDbArc();
2.4.3
1 CreateEnts CCalculation Pt2dTo3d
{
AcDbArc *pArc = new AcDbArc(ptCenter, vec, radius, startAngle,
endAngle);
AcDbObjectId arcId;
arcId = CCreateEnt::PostToModelSpace(pArc);
return arcId;
}
3 XOY
AcDbObjectId CCreateEnt::CreateArc(AcGePoint2d ptCenter, double radius,
double startAngle, double
endAngle)
{
AcGeVector3d vec(0, 0, 1);
return CCreateEnt::CreateArc(CCalculation::Pt2dTo3d(ptCenter),
vec, radius, startAngle, endAngle);
}
4
AcDbObjectId CCreateEnt::CreateArc(AcGePoint2d ptStart, AcGePoint2d ptOnArc,
AcGePoint2d ptEnd)
{
//
AcGeCircArc2d geArc(ptStart, ptOnArc, ptEnd);
AcGePoint2d ptCenter = geArc.center();
double radius = geArc.radius();
//
AcGeVector2d vecStart(ptStart.x - ptCenter.x, ptStart.y - ptCenter.y);
AcGeVector2d vecEnd(ptEnd.x - ptCenter.x, ptEnd.y - ptCenter.y);
double startAngle = vecStart.angle();
double endAngle = vecEnd.angle();
return CCreateEnt::CreateArc(ptCenter, radius, startAngle, endAngle);
}
AcGeVector2d angle X
5
AcDbObjectId CCreateEnt::CreateArcSCE(AcGePoint2d ptStart, AcGePoint2d
54
2.4
ptCenter,
AcGePoint2d ptEnd)
{
//
double radius = ptCenter.distanceTo(ptStart);
//
AcGeVector2d vecStart(ptStart.x - ptCenter.x, ptStart.y - ptCenter.y);
AcGeVector2d vecEnd(ptEnd.x - ptCenter.x, ptEnd.y - ptCenter.y);
double startAngle = vecStart.angle();
double endAngle = vecEnd.angle();
//
return CCreateEnt::CreateArc(ptCenter, radius, startAngle, endAngle);
}
CreateArc CreateArcSCE
6
AcDbObjectId CCreateEnt::CreateArc(AcGePoint2d ptStart, AcGePoint2d ptCenter,
double angle)
{
//
double radius = ptCenter.distanceTo(ptStart);
//
AcGeVector2d vecStart(ptStart.x - ptCenter.x, ptStart.y - ptCenter.y);
double startAngle = vecStart.angle();
double endAngle = startAngle + angle;
//
return CCreateEnt::CreateArc(ptCenter, radius, startAngle, endAngle);
}
2.4.4
1 CCalculation PI
double CCalculation::PI()
{
return 4 * atan(1.0);
}
55
atan C
#include <math.h>
2 AddArc
void ZffCHAP2AddArc()
{
// XOY
AcGePoint2d ptCenter(50, 50);
CCreateEnt::CreateArc(ptCenter, 100 * sqrt(2) / 2,
5 * CCalculation::PI() / 4, 7 * CCalculation::PI() / 4);
//
AcGePoint2d ptStart(100, 0);
AcGePoint2d ptOnArc(120, 50);
AcGePoint2d ptEnd(100, 100);
CCreateEnt::CreateArc(ptStart, ptOnArc, ptEnd);
//
ptStart.set(100, 100);
ptCenter.set(50, 50);
ptEnd.set(0, 100);
CCreateEnt::CreateArcSCE(ptStart, ptCenter, ptEnd);
//
ptStart.set(0, 100);
ptCenter.set(50, 50);
CCreateEnt::CreateArc(ptStart, ptCenter, CCalculation::PI() / 2);
}
CreateEntsCommand.cpp
#include "Calculation.h"
3AutoCAD 2002 AddArc 2.10
2.10
56
2.5
2.4.5
AcGeVector2d
2.5
2.5.1
2.3
2.5.2
ObjectARX AcDbPolyline AcDb2dPolyline
AcDb3dPolyline AutoCAD AcDbPolyline AcDb3dPolyline
PLINE AcDbPolyline 3DPOLY
AcDb3dPolyline AcDb2dPolyline
AcDbPolyline AcDb3dPolyline
2.5.3
1 CreateEnts CreatePolyline
//
static AcDbObjectId CreatePolyline(AcGePoint2dArray points, double width = 0);
//
AcDbObjectId CCreateEnt::CreatePolyline(AcGePoint2dArray points, double width)
{
int numVertices = points.length();
AcDbPolyline *pPoly = new AcDbPolyline(numVertices);
for (int i = 0; i < numVertices; i++)
{
57
CreatePolyline width 0
C++
AcDbPolyline
AcDbPolyline::AcDbPolyline
AcDbPolyline::addVertexAt
addVertexAt
Acad::ErrorStatus addVertexAt(
unsigned int index,
const AcGePoint2d& pt,
double bulge = 0.,
double startWidth = -1.,
double endWidth = -1);
index 0 pt bulge
startWidth endWidth
0 1 01
1
2
AcDbObjectId CCreateEnt::CreatePolyline(AcGePoint2d ptStart,
AcGePoint2d ptEnd, double width)
{
AcGePoint2dArray points;
points.append(ptStart);
points.append(ptEnd);
return CCreateEnt::CreatePolyline(points, width);
}
AcGePoint2dArray append
58
2.5
removeAt length
3
AcDbObjectId CCreateEnt::Create3dPolyline(AcGePoint3dArray points)
{
AcDb3dPolyline *pPoly3d = new
AcDb3dPolyline(AcDb::k3dSimplePoly, points);
return CCreateEnt::PostToModelSpace(pPoly3d);
}
AcDb3dPolyline AcDb::k3dSimplePoly
4 CModifyEnt Rotate
AcDbEntity *pEnt;
Acad::ErrorStatus es = acdbOpenObject(pEnt, entId, AcDb::kForWrite,
false);
pEnt->transformBy(xform);
pEnt->close();
return es;
}
AcDbEntity::transformBy
AcGeMatrix3d AcGeMatrix3d
setToScalingsetToRotation setToTranslation
transformBy
Move Scale
Acad::ErrorStatus CModifyEnt::Move(AcDbObjectId entId, AcGePoint3d ptBase,
AcGePoint3d ptDest)
59
{
//
AcGeMatrix3d xform;
AcGeVector3d vec(ptDest.x - ptBase.x, ptDest.y - ptBase.y,
ptDest.z - ptBase.z);
xform.setToTranslation(vec);
AcDbEntity *pEnt;
Acad::ErrorStatus es = acdbOpenObject(pEnt, entId, AcDb::kForWrite,
false);
pEnt->transformBy(xform);
pEnt->close();
return es;
}
Acad::ErrorStatus CModifyEnt::Scale(AcDbObjectId entId,
AcGePoint3d ptBase, double scaleFactor)
{
//
AcGeMatrix3d xform;
xform.setToScaling(scaleFactor, ptBase);
AcDbEntity *pEnt;
Acad::ErrorStatus es = acdbOpenObject(pEnt, entId, AcDb::kForWrite,
false);
pEnt->transformBy(xform);
pEnt->close();
return es;
}
60
2.5
{
AcGePoint2d pt;
pt.x = ptCenter.x + radius * cos(i * angle);
pt.y = ptCenter.y + radius * sin(i * angle);
points.append(pt);
}
AcDbObjectId polyId = CCreateEnt::CreatePolyline(points, width);
//
AcDbEntity *pEnt;
acdbOpenAcDbEntity(pEnt, polyId, AcDb::kForWrite);
AcDbPolyline *pPoly = AcDbPolyline::cast(pEnt);
if (pPoly != NULL)
{
pPoly->setClosed(Adesk::kTrue);
}
pEnt->close();
CModifyEnt::Rotate(polyId, ptCenter, rotation);
return polyId;
}
ab
cdabdc
acdbOpenAcDbEntity
AcDbEntity AcDbPolyline
AcDbPolylien
AcDbPolyline *pPoly = AcDbPolyline::cast(pEnt);
cast ObjectARX AcRxObject
pEnt pPoly
if (pEnt->isKindOf(AcDbPolyline::desc()) == Adesk::kTrue)
{
AcDbPolyline *pPoly = AcDbPolyline::cast(pEnt);
if (pPoly != NULL)
{
61
pPoly->setClosed(Adesk::kTrue);
}
}
CCalculation::Min CCalculation::Max
62
2.5
7
AcDbObjectId CCreateEnt::CreatePolyCircle(AcGePoint2d ptCenter,
double radius, double width)
{
//
AcGePoint2d pt1, pt2, pt3;
pt1.x = ptCenter.x + radius;
pt1.y = ptCenter.y;
pt2.x = ptCenter.x - radius;
pt2.y = ptCenter.y;
pt3.x = ptCenter.x + radius;
pt3.y = ptCenter.y;
//
AcDbPolyline *pPoly = new AcDbPolyline(3);
63
addVertexAt
0 1
2.11 0 1
1
2.11
64
2.5
2.5.4
1 CCalculation
//
double CCalculation::RtoG(double angle)
{
return angle * 180 / CCalculation::PI();
}
//
double CCalculation::GtoR(double angle)
{
return angle * CCalculation::PI() / 180;
}
2 AddPolyline
void ZffCHAP2AddPolyline()
{
//
AcGePoint2d ptStart(0, 0), ptEnd(100, 100);
CCreateEnt::CreatePolyline(ptStart, ptEnd, 1);
//
AcGePoint3d pt1(0, 0, 0), pt2(100, 0, 0), pt3(100, 100, 0);
AcGePoint3dArray points;
points.append(pt1);
points.append(pt2);
points.append(pt3);
CCreateEnt::Create3dPolyline(points);
65
//
CCreateEnt::CreatePolygon(AcGePoint2d::kOrigin, 6, 30, 0, 1);
//
AcGePoint2d pt(60, 70);
CCreateEnt::CreateRectangle(pt, ptEnd, 1);
//
pt.set(50, 50);
CCreateEnt::CreatePolyCircle(pt, 30, 1);
//
CCreateEnt::CreatePolyArc(pt, 50, CCalculation::GtoR(45),
CCalculation::GtoR(225), 1);
}
2.12
2.5.5
ObjectARX
66
2.6
2.6
2.6.1
AcDbEllipse
AcDbSpline
2.6.2
AcDbEllipse
1
2.13
2.13
AcDbSpline
2.6.3
1 CreateEnts CreateEllipse
AcDbObjectId CCreateEnt::CreateEllipse(AcGePoint3d ptCenter,
AcGeVector3d vecNormal, AcGeVector3d majorAxis, double
ratio)
{
AcDbEllipse *pEllipse = new AcDbEllipse(ptCenter, vecNormal,
majorAxis, ratio);
return CCreateEnt::PostToModelSpace(pEllipse);
}
AcDbEllipse
67
AcDbEllipse dbelipse.h
2
fabs C
math.h
3
//
static AcDbObjectId CreateSpline(const AcGePoint3dArray& points,
int order = 4, double fitTolerance = 0.0);
//
AcDbObjectId CCreateEnt::CreateSpline(const AcGePoint3dArray& points,
68
2.6
assert assert
true false assert
AcDbSpline order 226
assert
order 2.14
2.14 assert
AcDbSpline dbspline.h
4
//
static AcDbObjectId CreateSpline(const AcGePoint3dArray& points,
const AcGeVector3d& startTangent, const AcGeVector3d&
endTangent,
int order = 4, double fitTolerance = 0.0);
//
AcDbObjectId CCreateEnt::CreateSpline(const AcGePoint3dArray& points,
const AcGeVector3d& startTangent, const AcGeVector3d&
69
endTangent,
int order, double fitTolerance)
{
assert(order >= 2 && order <= 26);
AcDbSpline *pSpline = new AcDbSpline(points, startTangent,
endTangent,
order, fitTolerance);
return CCreateEnt::PostToModelSpace(pSpline);
}
const
const ObjectARX
2.6.4
1 AddEllipse
void ZffCHAP2AddEllipse()
{
//
AcGeVector3d vecNormal(0, 0, 1);
AcGeVector3d majorAxis(40, 0, 0);
AcDbObjectId entId;
entId = CCreateEnt::CreateEllipse(AcGePoint3d::kOrigin, vecNormal,
majorAxis, 0.5);
//
AcGePoint2d pt1(60, 80), pt2(140, 120);
CCreateEnt::CreateEllipse(pt1, pt2);
}
AcGePoint3d::kOrigin 000
2 AddSpline
void ZffCHAP2AddSpline()
70
2.6
{
//
AcGePoint3d pt1(0, 0, 0), pt2(10, 30, 0), pt3(60, 80, 0), pt4(100, 100,
0);
AcGePoint3dArray points;
points.append(pt1);
points.append(pt2);
points.append(pt3);
points.append(pt4);
CCreateEnt::CreateSpline(points);
//
pt2.set(30, 10, 0);
pt3.set(80, 60, 0);
points.removeSubArray(0, 3);
points.append(pt1);
points.append(pt2);
points.append(pt3);
points.append(pt4);
AcGeVector3d startTangent(5, 1, 0);
AcGeVector3d endTangent(5, 1, 0);
CCreateEnt::CreateSpline(points, startTangent, endTangent);
}
3AddEllipseAddSpline 2.15
2.15
2.6.5
71
assert
2.7
2.7.1
AutoCAD REGION
2.7.2
AcDbRegion AutoCAD ObjectARX
AcDbRegion
createFromCurves
createFromCurves
static Acad::ErrorStatus createFromCurves(
const AcDbVoidPtrArray& curveSegments,
AcDbVoidPtrArray& regions);
CurveSegments
regions
AcDbLineAcDbArc
AcDbEllipse
AcDbCircleAcDbSplineAcDb3dPolyline AcDbPolyline
2.7.3
CreateEnts CreateRegion
AcDbObjectIdArray CCreateEnt::CreateRegion(const AcDbObjectIdArray& curveIds)
{
AcDbObjectIdArray regionIds; // ID
AcDbVoidPtrArray curves;
//
AcDbVoidPtrArray regions;
//
AcDbEntity *pEnt;
//
AcDbRegion *pRegion;
// curveIdscurves
72
//
2.7
//
{
for (i = 0; i < regions.length(); i++)
{
delete (AcRxObject*)regions[i];
}
}
//
for (i = 0; i < curves.length(); i++)
{
pEnt = static_cast<AcDbEntity*>(curves[i]);
pEnt->close();
}
73
return regionIds;
}
static_cast<AcDbEntity*>
static_cast C++
static_cast < type-id > ( expression )
expression type-id
ObjectARX cast
createFromCurves
AcDbRegion dbregion.h
2.7.4
1 AddRegion
void ZffCHAP2AddRegion()
{
//
ads_name ss;
int rt = acedSSGet(NULL, NULL, NULL, NULL, ss);
//
AcDbObjectIdArray objIds;
// ID
if (rt == RTNORM)
{
long length;
acedSSLength(ss, &length);
//
//
AcDbObjectIdArray regionIds;
74
2.7
regionIds = CCreateEnt::CreateRegion(objIds);
int number = regionIds.length();
if (number > 0)
{
acutPrintf("\n%d", number);
}
else
{
acutPrintf("\n0");
}
}
acutPrintf acutPrintf
Hello,World C printf
2.16
3 AddRegion
: addregion
: : 6
6
:
Enter
2
Ok
2.7.5
static_cast
75
2.8
2.8.1
AcDbText AcDbMText
CAD
2.8.2
AcDbText
AcDbText( const AcGePoint3d& position,
const char* text,
AcDbObjectId style = AcDbObjectId::kNull,
double height = 0,
double rotation = 0);
position text style
ID AutoCAD height rotation
AcDbMText AutoCAD
setTextStyle setContents
2.8.3
1 CreateEnts CreateText
//
static AcDbObjectId CreateText(const AcGePoint3d& ptInsert,
const char* text, AcDbObjectId style = AcDbObjectId::kNull,
double height = 2.5, double rotation = 0);
//
AcDbObjectId CCreateEnt::CreateText(const AcGePoint3d& ptInsert,
const char* text, AcDbObjectId style,
double height, double rotation)
{
AcDbText *pText = new AcDbText(ptInsert, text, style, height,
rotation);
return CCreateEnt::PostToModelSpace(pText);
76
2.8
2 CreateMText
//
static AcDbObjectId CreateMText(const AcGePoint3d& ptInsert,
const char* text, AcDbObjectId style = AcDbObjectId::kNull,
double height = 2.5, double width = 10);
//
AcDbObjectId CCreateEnt::CreateMText(const AcGePoint3d& ptInsert,
const char* text, AcDbObjectId style,
double height, double width)
{
AcDbMText *pMText = new AcDbMText();
//
pMText->setTextStyle(style);
pMText->setContents(text);
pMText->setLocation(ptInsert);
pMText->setTextHeight(height);
pMText->setWidth(width);
pMText->setAttachment(AcDbMText::kBottomLeft);
return CCreateEnt::PostToModelSpace(pMText);
}
AcDbMText dbmtext.h
2.8.4
1 AddText
void ZffCHAP2AddText()
{
//
AcGePoint3d ptInsert(0, 4, 0);
CCreateEnt::CreateText(ptInsert, "CAD");
//
ptInsert.set(0, 0, 0);
CCreateEnt::CreateMText(ptInsert, "http://www.cadhelp.net");
}
77
4
2AutoCAD 2002 AddText 2.17
2.17
3AutoCAD
AutoCAD
2002 2.18
2.18
4 2.19
2.19
2.8.5
78
2.9
2.9
2.9.1
2.9.2
AcDbHatch AutoCAD
1
2
3
4
5
6
7
8
2.9.3
CreateEnts CreateHatch
ID
pHatch->setElevation(0);
//
pHatch->setAssociative(bAssociative);
//
pHatch->setPattern(AcDbHatch::kPreDefined, patName);
//
es = pHatch->appendLoop(AcDbHatch::kExternal, objIds);
//
es = pHatch->evaluateHatch();
//
AcDbObjectId hatchId;
hatchId = CCreateEnt::PostToModelSpace(pHatch);
//
if (bAssociative)
{
AcDbEntity *pEnt;
for (int i = 0; i < objIds.length(); i++)
{
es = acdbOpenAcDbEntity(pEnt, objIds[i],
AcDb::kForWrite);
if (es == Acad::eOk)
{
//
pEnt->addPersistentReactor(hatchId);
pEnt->close();
}
}
}
return hatchId;
}
ObjectARX appendLoop
80
2.9
Acad::ErrorStatus appendLoop(
Adesk::Int32 loopType,
const AcDbObjectIdArray& dbObjIds);
ID
evaluateHatch
AcDbHatch dbhatch.h
2.9.4
1 AddHatch
void ZffCHAP2AddHatch()
{
//
ads_name ss;
int rt = acedSSGet(NULL, NULL, NULL, NULL, ss);
AcDbObjectIdArray objIds;
// ID
if (rt == RTNORM)
{
long length;
acedSSLength(ss, &length);
for (int i = 0; i < length; i++)
{
ads_name ent;
acedSSName(ss, i, ent);
AcDbObjectId objId;
acdbGetObjectId(objId, ent);
objIds.append(objId);
}
}
acedSSFree(ss);
//
2.20
3 AddHatch
: addhatch
: : 3
:
Enter
2.21
2.21
2.9.5
82
2.10
2.10
2.10.1
12
2.10.2
AcDbAlignedDimension 5
AcDbRotatedDimension 6
AcDbRadialDimension
AcDbDiametricDimension
AcDbOrdinateDimension X
XY
2.10.3
1 CreateEnts CreateEnt CreateDimAligned
//
83
dbdim.h
2 vecOffset
//
static AcDbObjectId CreateDimAligned(const AcGePoint3d& pt1,
const AcGePoint3d& pt2, const AcGePoint3d& ptLine,
const AcGeVector3d& vecOffset = AcGeVector3d::kIdentity,
const char* dimText = NULL);
//
AcDbObjectId CCreateEnt::CreateDimAligned(const AcGePoint3d& pt1,
const AcGePoint3d& pt2, const AcGePoint3d& ptLine,
const AcGeVector3d& vecOffset,
const char* dimText)
{
AcDbAlignedDimension *pDim = new AcDbAlignedDimension(pt1, pt2,
ptLine, dimText, AcDbObjectId::kNull);
AcDbObjectId dimensionId;
dimensionId = CCreateEnt::PostToModelSpace(pDim);
//
AcDbEntity *pEnt;
Acad::ErrorStatus es;
es = acdbOpenAcDbEntity(pEnt, dimensionId, AcDb::kForWrite);
84
2.10
AcDbAlignedDimension *pDimension =
AcDbAlignedDimension::cast(pEnt);
if (pDimension != NULL)
{
//
//
pDimension->setDimtmove(1);
//
AcGePoint3d ptText = pDimension->textPosition();
ptText = ptText + vecOffset;
pDimension->setTextPosition(ptText);
}
pEnt->close();
return dimensionId;
}
3 CreateDimRotated
//
static AcDbObjectId CreateDimRotated(const AcGePoint3d& pt1,
const AcGePoint3d& pt2, const AcGePoint3d& ptLine,
double rotation, const char* dimText = NULL,
AcDbObjectId dimStyle = AcDbObjectId::kNull);
//
AcDbObjectId CCreateEnt::CreateDimRotated(const AcGePoint3d& pt1,
const AcGePoint3d& pt2, const AcGePoint3d& ptLine,
double rotation, const char* dimText,
AcDbObjectId dimStyle)
{
AcDbRotatedDimension *pDim = new
AcDbRotatedDimension(rotation,
pt1, pt2, ptLine, dimText, dimStyle);
return CCreateEnt::PostToModelSpace(pDim);
}
4 CreateDimRadial
//
85
//
static AcDbObjectId CreateDimRadial(const AcGePoint3d& ptCenter,
double radius, double angle, double leaderLength = 5);
//
AcDbObjectId CCreateEnt::CreateDimRadial(const AcGePoint3d& ptCenter,
double radius, double angle, double leaderLength)
{
AcGePoint3d ptChord = CCalculation::PolarPoint(ptCenter, angle,
radius);
return CCreateEnt::CreateDimRadial(ptCenter, ptChord,
leaderLength);
}
CCalculation::PolarPoint
86
2.10
6 CreateDimDiametric
//
static AcDbObjectId CreateDimDiametric(const AcGePoint3d& ptChord1,
const AcGePoint3d& ptChord2, double leaderLength,
const char* dimText = NULL,
AcDbObjectId dimStyle = AcDbObjectId::kNull);
//
AcDbObjectId CCreateEnt::CreateDimDiametric(const AcGePoint3d& ptChord1,
const AcGePoint3d& ptChord2, double leaderLength,
const char* dimText, AcDbObjectId dimStyle)
{
AcDbDiametricDimension *pDim = new
AcDbDiametricDimension(ptChord1,
ptChord2, leaderLength, dimText, dimStyle);
return CCreateEnt::PostToModelSpace(pDim);
}
//
static AcDbObjectId CreateDimDiametric(const AcGePoint3d& ptCenter,
double radius, double angle, double leaderLength = 5);
//
AcDbObjectId CCreateEnt::CreateDimDiametric(const AcGePoint3d& ptCenter,
double radius, double angle, double leaderLength)
{
//
AcGePoint3d ptChord1, ptChord2;
ptChord1 = CCalculation::PolarPoint(ptCenter, angle, radius);
ptChord2 = CCalculation::PolarPoint(ptCenter,
angle + CCalculation::PI(), radius);
return CCreateEnt::CreateDimDiametric(ptChord1, ptChord2,
leaderLength);
}
87
8
//
static AcDbObjectId CreateDim2LineAngular(const AcGePoint3d& ptStart1,
const AcGePoint3d& ptEnd1, const AcGePoint3d& ptStart2,
const AcGePoint3d& ptEnd2, const AcGePoint3d& ptArc,
const char* dimText = NULL,
AcDbObjectId dimStyle = AcDbObjectId::kNull);
//
AcDbObjectId CCreateEnt::CreateDim2LineAngular(const AcGePoint3d& ptStart1,
const AcGePoint3d& ptEnd1, const AcGePoint3d& ptStart2,
const AcGePoint3d& ptEnd2, const AcGePoint3d& ptArc,
const char* dimText, AcDbObjectId dimStyle)
{
AcDb2LineAngularDimension *pDim = new
AcDb2LineAngularDimension(
ptStart1, ptEnd1, ptStart2, ptEnd2, ptArc, dimText, dimStyle);
return CCreateEnt::PostToModelSpace(pDim);
}
//
static AcDbObjectId CreateDim3PtAngular(const AcGePoint3d& ptCenter,
const AcGePoint3d& ptEnd1, const AcGePoint3d& ptEnd2,
const AcGePoint3d& ptArc,
const char* dimText = NULL,
AcDbObjectId dimStyle = AcDbObjectId::kNull);
//
AcDbObjectId CCreateEnt::CreateDim3PtAngular(const AcGePoint3d& ptCenter,
const AcGePoint3d& ptEnd1, const AcGePoint3d& ptEnd2,
const AcGePoint3d& ptArc, const char* dimText,
AcDbObjectId dimStyle)
{
AcDb3PointAngularDimension *pDim = new
AcDb3PointAngularDimension(
ptCenter, ptEnd1, ptEnd2, ptArc, dimText, dimStyle);
return CCreateEnt::PostToModelSpace(pDim);
}
88
2.10
10 CreateDimOrdinate
//
static AcDbObjectId CreateDimOrdinate(Adesk::Boolean xAxis,
const AcGePoint3d& ptStart, const AcGePoint3d& ptEnd,
const char* dimText = NULL,
AcDbObjectId dimStyle = AcDbObjectId::kNull);
//
AcDbObjectId CCreateEnt::CreateDimOrdinate(Adesk::Boolean xAxis,
const AcGePoint3d& ptStart, const AcGePoint3d& ptEnd,
const char* dimText,
AcDbObjectId dimStyle)
{
AcDbOrdinateDimension *pDim = new
AcDbOrdinateDimension(xAxis,
ptStart, ptEnd, dimText, dimStyle);
return CCreateEnt::PostToModelSpace(pDim);
}
11 XY
//
static AcDbObjectIdArray CreateDimOrdinate(const AcGePoint3d& ptDef,
const AcGePoint3d& ptTextX, const AcGePoint3d& ptTextY);
//
AcDbObjectIdArray CCreateEnt::CreateDimOrdinate(const AcGePoint3d& ptDef,
const AcGePoint3d& ptTextX, const AcGePoint3d& ptTextY)
{
AcDbObjectId dimId;
AcDbObjectIdArray dimIds;
dimId = CCreateEnt::CreateDimOrdinate(Adesk::kTrue, ptDef,
ptTextX);
dimIds.append(dimId);
dimId = CCreateEnt::CreateDimOrdinate(Adesk::kFalse, ptDef,
ptTextY);
dimIds.append(dimId);
return dimIds;
}
89
12
//
static AcDbObjectIdArray CreateDimOrdinate(const AcGePoint3d& ptDef,
const AcGeVector3d& vecOffsetX, const AcGeVector3d&
vecOffsetY);
//
AcDbObjectIdArray CCreateEnt::CreateDimOrdinate(const AcGePoint3d& ptDef,
const AcGeVector3d& vecOffsetX, const AcGeVector3d&
vecOffsetY)
{
AcGePoint3d ptTextX = ptDef + vecOffsetX;
AcGePoint3d ptTextY = ptDef + vecOffsetY;
return CCreateEnt::CreateDimOrdinate(ptDef, ptTextX, ptTextY);
}
2.10.4
1 CCalculation RelativePoint
2.10
CCreateEnt::CreateLine(pt3, pt4);
CCreateEnt::CreateLine(pt4, pt5);
CCreateEnt::CreateLine(pt5, pt1);
//
AcGePoint3d ptCenter1, ptCenter2;
ptCenter1 = CCalculation::RelativePoint(pt3, 16, 0);
ptCenter2 = CCalculation::RelativePoint(ptCenter1, 25, 0);
CCreateEnt::CreateCircle(ptCenter1, 3);
CCreateEnt::CreateCircle(ptCenter2, 4);
AcGePoint3d ptTemp1, ptTemp2;
//
ptTemp1 = CCalculation::RelativePoint(pt1, -20, 3);
CCreateEnt::CreateDimRotated(pt1, pt2, ptTemp1, 0);
//
ptTemp1 = CCalculation::RelativePoint(pt1, 4, 10);
CCreateEnt::CreateDimRotated(pt1, pt5, ptTemp1,
CCalculation::PI() / 2);
//
ptTemp1 = CCalculation::RelativePoint(pt3, -3, -6);
CCreateEnt::CreateDimRotated(pt3, pt4, ptTemp1,
7 * CCalculation::PI() / 4);
//
ptTemp1 = CCalculation::RelativePoint(pt2, -3, 4);
CCreateEnt::CreateDimAligned(pt2, pt3, ptTemp1,
AcGeVector3d(4, 10, 0), "new position");
//
ptTemp1 = CCalculation::RelativePoint(pt5, -5, 5);
CCreateEnt::CreateDim3PtAngular(pt5, pt1, pt4, ptTemp1);
//
ptTemp1 = CCalculation::PolarPoint(ptCenter1,
CCalculation::PI() / 4, 3);
CCreateEnt::CreateDimRadial(ptCenter1, ptTemp1, -3);
91
//
ptTemp1 = CCalculation::PolarPoint(ptCenter2,
CCalculation::PI() / 4, 4);
ptTemp2 = CCalculation::PolarPoint(ptCenter2,
CCalculation::PI() / 4, -4);
CCreateEnt::CreateDimDiametric(ptTemp1, ptTemp2, 0);
//
CCreateEnt::CreateDimOrdinate(ptCenter2, AcGeVector3d(0, -10, 0),
AcGeVector3d(10, 0, 0));
}
2.22
2.10.5
dimText
AcDbDimension::setDimensionText
setTextPosition
setDimtmove
AcDbDimension
92
2.11
2.11
2.11.1
AutoCAD
MOVE AcDbText
2.11.2
AutoCAD
acedGrRead
int acedGrRead(
int track,
int * type,
struct resbuf * result);
track
Bit 0 1
acedGrRead type 5result XY
Bit 1 2
Bit 2 4 type
type 0 type 1 type
2
Bit 3 8 Ctrl+C
type result
ptText[Y] = result.resval.rpoint[Y];
//
{
93
}
if (type == 3)
//
{
track = 0;
}
}
2.11.3
1ObjectARXGrReadMFCCreateEnts
CreateEnt.h CreateEnt.cpp ModifyEnt.h ModifyEnt.cpp Calculation.h
Calculation.cppVC++ 6.0 Project/Add To
Project/Files 2.23
2.23
VC
ClassView
CCreateEntCCalculation CModifyEnt
2AddDimension 2.24
94
2.11
2.24 AddDimension
2AddDimension
void ZffCHAP2AddDimension()
{
//
ads_name en;
ads_point pt;
if (acedEntSel(":", en, pt) != RTNORM)
return;
//
AcDbObjectId arcId;
Acad::ErrorStatus es = acdbGetObjectId(arcId, en);
if (es != Acad::eOk)
return;
AcDbEntity *pEnt;
es = acdbOpenAcDbEntity(pEnt, arcId, AcDb::kForRead);
//
if (!pEnt->isKindOf(AcDbArc::desc()))
{
pEnt->close();
95
return;
}
AcDbArc *pArc = AcDbArc::cast(pEnt);
//
AcGePoint3d ptCenter, ptStart, ptEnd, ptMiddle;
ptCenter = pArc->center();
es = pArc->getStartPoint(ptStart);
es = pArc->getEndPoint(ptEnd);
double length;
es = pArc->getDistAtPoint(ptEnd, length);
es = pArc->getPointAtDist(length / 2, ptMiddle);
pEnt->close();
//
CString strLength;
strLength.Format("%.2f", length);
AcDbObjectId dimId;
dimId = CCreateEnt::CreateDim3PtAngular(ptCenter, ptStart,
ptEnd, ptMiddle, strLength);
//
AcGePoint3d ptText;
int track = 1, type; //track=1
struct resbuf result;
//
96
2.11
{
pDim->setTextPosition(ptText);
}
}
pEnt->close();
if (type == 3)
//
{
track = 0;
}
}
}
acedEntSel ads_name
acdbGetObjectId ads_name AcDbObjectId
acdbOpenAcDbEntity
getDistAtPoint getPointAtDist
acedGrRead
acdbOpenAcDbEntity
3 MoveText
void ZffCHAP2MoveText()
{
ads_name entName;
ads_point ptPick, ptBase;
if (acedEntSel("\n", entName, ptPick) !=
RTNORM)
{
return;
}
AcDbObjectId txtId;
AcDbText *pText = NULL;
AcDbEntity *pEnt = NULL;
Acad::ErrorStatus es = acdbGetObjectId(txtId, entName);
if (es != Acad::eOk)
{
97
return;
}
AcGePoint3d ptInsertOld(0, 0, 0);
acdbOpenObject(pEnt, txtId, AcDb::kForWrite);
if (pEnt->isKindOf(AcDbText::desc()))
{
pText = AcDbText::cast(pEnt);
if (pText != NULL)
{
ptInsertOld = pText->position();
}
}
pEnt->close();
if (acedGetPoint(NULL, "\n", ptBase) != RTNORM)
{
return;
}
acedPrompt("\n");
AcGePoint3d ptInsertNew(0, 0, 0);
AcGePoint3d ptPick3d = asPnt3d(ptBase);
//
int track = 1, type; //track=1
struct resbuf result;
//
98
2.11
{
pText = AcDbText::cast(pEnt);
if (pText != NULL)
{
pText->setPosition(ptInsertNew);
}
}
pEnt->close();
if (type == 3)
//
{
track = 0;
}
}
}
2.11.4
1AutoCAD 2002 ARCTEXT
2.25
2.25
2AddDimension
2.26
2.26
3 MoveText
99
: movetext
acedGrRead
2.11.5
acedGrRead
2.12
2.12.1
2.12.2
ObjectARX
//
AcDbBlockTableRecordIterator *pItr;
//
pBlkTblRcd->newIterator(pItr);
AcDbEntity *pEnt;
//
for (pItr->start(); !pItr->done(); pItr->step())
{
//
pItr->getEntity(pEnt, AcDb::kForWrite);
// pEnt
//
pEnt->close();
100
2.12
}
delete pItr;
//
2.12.3
VC++ 6.0 ObjectARX GetEntsOnLayer
GetEnts
void ZffCHAP2GetEnts()
{
//
AcDbLayerTable *pLayerTbl;
acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pLayerTbl, AcDb::kForRead);
if (!pLayerTbl->has(""))
{
acutPrintf("\n\"\"!");
pLayerTbl->close();
return;
}
AcDbObjectId layerId;
// ID
pLayerTbl->getAt("", layerId);
pLayerTbl->close();
//
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
//
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForRead);
pBlkTbl->close();
//
AcDbBlockTableRecordIterator *pItr;
//
pBlkTblRcd->newIterator(pItr);
AcDbEntity *pEnt;
//
101
//
}
}
//
pEnt->close();
}
delete pItr;
//
pBlkTblRcd->close();
}
AcDbLayerTable::has
true false
newIterator
AutoCAD
AcDbEntity layer
acutDelString acutmem.h
}
acutDelString(layerName);
// layer
102
2.12
AcDbEntity layerId ID ID
ObjectARX
2.27
2.27
2.12.4
AutoCAD 2002
GetEnts
2.12.5
AcDbObjectIdArray
AcDbObjectIdArray
AcDbObjectIdArray entIds;
ID
entIds.append(pEnt->objectId());
ID
103
2.13
2.13.1
ObjectARX
2.13.2
ObjectARX AcDb3dSolid AutoCAD
AutoCAD ACIS
2.13
3
AcDb3dSolid extrudeAlongPath
virtual Acad::ErrorStatus extrudeAlongPath(
const AcDbRegion* region,
const AcDbCurve* path);
region path
extrudeAlongPath region path
AcDb3dSolid extrude
4
AcDb3dSolid revolve
virtual Acad::ErrorStatus revolve(
const AcDbRegion* region,
const AcGePoint3d& axisPoint,
const AcGeVector3d& axisDir,
double angleOfRevolution);
region axisPoint
axisDir axisPoint angleOfRevolution
5
AcDb3dSolid booleanOper
virtual Acad::ErrorStatus booleanOper(
AcDb::BoolOperType operation,
AcDb3dSolid* solid);
operation AcDb::kBoolUnite
AcDb::kBoolIntersect AcDb::kBoolSubtractsolid
2.13.3
1 VC++ 6.0 ObjectARX Create3dSolid
AddBox
void ZffCHAP2AddBox()
{
AcDb3dSolid *pSolid = new AcDb3dSolid();
Acad::ErrorStatus es = pSolid->createBox(40, 50, 30);
105
if (es != Acad::eOk)
{
acedAlert("!");
delete pSolid;
return;
}
//
AcGeMatrix3d xform;
AcGeVector3d vec(100, 100, 100);
xform.setToTranslation(vec);
pSolid->transformBy(xform);
//
PostToModelSpace(pSolid);
}
createBox Acad::eOk
ObjectARX
Acad::ErrorStatus
PostToModelSpace
106
2.13
PostToModelSpace ZffCHAP2AddBox
C C++
2 AddCylinder
void ZffCHAP2AddCylinder()
{
//
AcDb3dSolid *pSolid = new AcDb3dSolid();
pSolid->createFrustum(30, 10, 10, 0);
//
PostToModelSpace(pSolid);
}
createFrustum 4 0
3 AddSpire
void ZffCHAP2AddSpire()
{
//
double radius, deltaVertical; //
//
// n+1
//
107
}
//
AcDb3dPolyline *p3dPoly = new
AcDb3dPolyline(AcDb::k3dSimplePoly,
points);
//
AcDbObjectId spireId = PostToModelSpace(p3dPoly);
//
AcGeVector3d vec(0, 1, 0);
//
//
segment
number*segment+1 1
atan(1)/4 4*atan(1)
108
2.13
AcDbVoidPtrArray regions;
//
AcDbEntity *pEnt;
//
AcDbRegion *pRegion;
//
// curveIdscurves
for (int i = 0; i < curveIds.length(); i++)
{
acdbOpenAcDbEntity(pEnt, curveIds.at(i), AcDb::kForRead);
if (pEnt->isKindOf(AcDbCurve::desc()))
{
curves.append(static_cast<void*>(pEnt));
}
}
Acad::ErrorStatus es = AcDbRegion::createFromCurves(curves,
regions);
if (es == Acad::eOk)
{
//
for (i = 0; i < regions.length(); i++)
{
//
pRegion = static_cast<AcDbRegion*>(regions[i]);
pRegion->setDatabaseDefaults();
AcDbObjectId regionId;
regionId = PostToModelSpace(pRegion);
regionIds.append(regionId);
109
}
}
else
//
{
for (i = 0; i < regions.length(); i++)
{
delete (AcRxObject*)regions[i];
}
}
//
for (i = 0; i < curves.length(); i++)
{
pEnt = static_cast<AcDbEntity*>(curves[i]);
pEnt->close();
}
return regionIds;
}
4 RevolveEnt
void ZffCHAP2RevolveEnt()
{
//
AcGePoint3d vertex[5];
vertex[0] = AcGePoint3d(15, 0, 0);
vertex[1] = AcGePoint3d(45, 0, 0);
vertex[2] = AcGePoint3d(35, 9, 0);
vertex[3] = AcGePoint3d(41, 18, 0);
vertex[4] = AcGePoint3d(15, 18, 0);
AcGePoint3dArray points;
for (int i = 0; i <= 4; i++)
{
points.append(vertex[i]);
}
//
AcDb3dPolyline *p3dPoly = new
AcDb3dPolyline(AcDb::k3dSimplePoly,
points, true);
110
2.13
AcGePoint3d::kOrigin AcGeVector3d(0, 1, 0)
AcGePoint3d(10, 10, 0)
5 Boolean
void ZffCHAP2Boolean()
{
//
AcDb3dSolid *pSolid1 = new AcDb3dSolid();
pSolid1->createBox(40, 50, 30);
AcDb3dSolid *pSolid2 = new AcDb3dSolid();
pSolid2->createBox(40, 50, 30);
//
AcGeMatrix3d xform;
AcGeVector3d vec(20, 25, 15);
xform.setToTranslation(vec);
pSolid1->transformBy(xform);
//
AcDbObjectId solidId1 = PostToModelSpace(pSolid1);
AcDbObjectId solidId2 = PostToModelSpace(pSolid2);
111
//
acdbOpenObject(pSolid1, solidId1, AcDb::kForWrite);
acdbOpenObject(pSolid2, solidId2, AcDb::kForWrite);
Acad::ErrorStatus es = pSolid1->booleanOper(AcDb::kBoolUnite,
pSolid2);
assert(pSolid2->isNull());
pSolid2->erase(); //
pSolid2->close(); //
pSolid1->close();
}
assert
FALSE
erase Undo
erase(kfalse)
2.13.4
AutoCAD 2002 ARX AddBox
AddCylinderAddSpireRevolveEntBoolean 2.28
112
2.14
Transform
2.28
2.13.5
createSphere
createToruscreateWedge extrude
2.14 Transform
2.14.1
ObjectARX
acedCommand AutoCAD
AcDbEntity transformBy
AutoCAD
ObjectARX acedCommand
void ZffTransformTestCommand()
{
acedCommand(RTSTR, "_move",
RTNONE);
AfxMessageBox("?");
113
AutoCAD 2002
AutoCAD ObjectARX
transformBy
ObjectARX
acutPrintfacedGetPoint
transformBy
ObjectARX COM
2.14.2
1 transformBy
transformBy AcDbEntity AcGeMatrix3d
AcGeMatrix3d 2.29
2.29
AcGeMatrix3d
setToTranslation
setToRotation
setToScaling
setToMirroring
2
AcDbObject clone
AcDbObject AcDbEntity
AcDbObject
114
2.14
Transform
clone
3 AcAxXXX
ObjectARX AcAx COM
AutoCAD AcAxMoveAcAxRotate AcAxScaleEntity
COM AcAxMove
HRESULT AXAUTOEXP AcAxMove(
AcDbObjectId& objId,
VARIANT fromPoint,
VARIANT toPoint);
VARIANT VARIANT COM
C C++ COM
COM
COM COM
COM COM
COM
COM AcAxMoveAcAxRotate
AcAxScaleEntity COM
2.14.3
1 ObjectARX TransformEntInsert/New Class
New ClassClass TypeGeneric Class
CTransUtil OK
2 CTransUtil Move transformBy
Acad::ErrorStatus CTransUtil::Move(AcDbObjectId entId, const AcGePoint3d
&ptFrom, const AcGePoint3d &ptTo)
{
//
AcGeVector3d vec(ptTo[X] - ptFrom[X], ptTo[Y] - ptFrom[X],
ptTo[Z] - ptFrom[Z]);
AcGeMatrix3d mat;
mat.setToTranslation(vec);
AcDbEntity *pEnt = NULL;
Acad::ErrorStatus es = acdbOpenObject(pEnt, entId,
AcDb::kForWrite);
115
if (es != Acad::eOk)
return es;
es = pEnt->transformBy(mat);
pEnt->close();
return es;
}
transformBy AcGeMatrix3d
AcGeMatrix3d setToTranslation
AcGeVector3d
3 AcMove AcAxMove
BOOL CTransUtil::AcMove(AcDbObjectId entId, const AcGePoint3d &ptFrom,
const AcGePoint3d &ptTo)
{
// AcGePoint3d
VARIANT *pvaFrom = Point3dToVARIANT(ptFrom);
VARIANT *pvaTo = Point3dToVARIANT(ptTo);
BOOL bRet = SUCCEEDED(AcAxMove(entId, *pvaFrom, *pvaTo));
delete pvaFrom;
delete pvaTo;
return bRet;
}
static Point3dToVARIANT
C++ static
VARIANT COleSafeArray
C++
116
2.14
Transform
}
Point3dToVARIANT new
AcMove pvaFrom pvaTo
clone AcDbObject
117
{
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
AcDbObjectId entId;
pBlockTableRecord->appendAcDbEntity(entId, pEnt);
pBlockTable->close();
pBlockTableRecord->close();
pEnt->close();
return entId;
}
5
Acad::ErrorStatus CTransUtil::Rotate(AcDbObjectId entId,
const AcGePoint2d &ptBase,
double angle)
{
//
AcGeMatrix3d mat;
mat.setToRotation(angle, AcGeVector3d::kZAxis,
AcGePoint3d(ptBase[X], ptBase[Y], 0.));
//
AcDbEntity *pEnt = NULL;
Acad::ErrorStatus es = acdbOpenObject(pEnt, entId,
AcDb::kForWrite);
if (es != Acad::eOk)
return es;
es = pEnt->transformBy(mat);
pEnt->close();
118
2.14
Transform
return es;
}
2.14.4
2.14.5
AcAxMove axauto15.lib
119
3.1
3.1.1
AutoCAD
AutoCAD 2002
3.1.2
2.1
AutoCAD
Autodesk
inspector 2002\Release\AsdkInspector.arx3.1
*Model_Space*Paper_Space
*Paper_Space0
12
120
3.1
3.1
AcDbBlockBegin AcDbBlockEnd
*Model_Space
1
2
3
3.1.3
VC++ 6.0 ObjectARX MakeBlkDef
AddBlk
void ZffCHAP3AddBlk()
{
//
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForWrite);
//
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTblRcd = new AcDbBlockTableRecord();
//
char blkName[40];
121
acedGetString
int acedGetString(
int cronly,
122
3.1
cronly Adesk::kTrue
Adesk::kFalseprompt result
dbents.h
3.1.4
1 AutoCAD 2002 AddBlk
Center Enter
Center
2 AutoCAD 2002
3.2
33.3
3.3
3.1.5
AutoCAD
AutoCAD
acedGetString
123
3.2
3.2.1
3.2.2
AutoCAD AutoCAD
ObjectARX AcDbBlockReference
AcDbBlockReference
AcDbBlockReference(
const AcGePoint3d& position,
AcDbObjectId blockTableRec);
position blockTableRec ID
3.2.3
VC++ 6.0 ObjectARX InsertBlkRef
InsertBlk
void ZffCHAP3InsertBlk()
{
//
char blkName[40];
if (acedGetString(Adesk::kFalse, "\n", blkName) !=
RTNORM)
{
return;
}
//
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForWrite);
124
3.2
//
CString strBlkDef;
strBlkDef.Format("%s", blkName);
if (!pBlkTbl->has(strBlkDef))
{
acutPrintf("\n");
pBlkTbl->close();
return;
}
//
ads_point pt;
if (acedGetPoint(NULL, "\n", pt) != RTNORM)
{
pBlkTbl->close();
return;
}
AcGePoint3d ptInsert = asPnt3d(pt);
//
AcDbObjectId blkDefId;
pBlkTbl->getAt(strBlkDef, blkDefId);
//
AcDbBlockReference *pBlkRef = new AcDbBlockReference(ptInsert,
blkDefId);
//
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForWrite);
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId, pBlkRef);
//
pBlkRef->close();
pBlkTblRcd->close();
pBlkTbl->close();
125
AcDbBlockTable::has
acedGetPoint
int acedGetPoint(
const ads_point pt,
const char * prompt,
ads_point result);
ptUCS
NULL
promptNULLresult
acedGetPoint5
ads_point ADS
typedef ads_real ads_point[3];
ads_real
typedef double ads_real;
ads_point ADS
ads_point AcGePoint3d
asPnt3d
ptInsert[X] = pt[X];
ptInsert[Y] = pt[Y];
ptInsert[Z] = pt[Z];
asPnt3d geassign.h
AcGePoint3d ptInsert = asPnt3d(pt);
XY Z ObjectARX
enum { X = 0, Y = 1, Z = 2 };
3.2.4
AutoCAD 2002 InsertBlk
: insertblk
circle
XY Z
1
126
3.3
3.2.5
acedGetPoint
ads_point AcGePoint3d
3.3
3.3.1
AutoCAD INSERT
3.3.2
3.3.3
VC++ 6.0 ObjectARX BlkWithAttribute
AddBlk
void ZffCHAP3AddBlk()
{
//
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForWrite);
//
AcDbBlockTableRecord *pBlkTblRcd;
127
128
3.3
pLine1->close();
pLine2->close();
pCircle->close();
pAttDef->close();
pBlkTblRcd->close();
}
AcDbAttributeDefinition AcDbText
AcDbAttributeDefinition(
const AcGePoint3d& position,
const char* text,
const char* tag,
const char* prompt,
AcDbObjectId style = AcDbObjectId::kNull);
position text tag
prompt style ID
3.3.4
AutoCAD 2002 AddBlk blk
AutoCAD 20023.4
blk
3.4
: INSERT
[(S)/X/Y/Z/(R)/(PS)/PX/PY/PZ/(PR)]:
129
<20>: 40
3.5
3.5
3.3.5
3.4
3.4.1
AutoCAD
3.4.2
1
2
3.4.3
BlkWithAttribute InsertBlk
void ZffCHAP3InsertBlk()
130
3.4
{
//
char blkName[40];
if (acedGetString(Adesk::kFalse, "\n", blkName) !=
RTNORM)
{
return;
}
//
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForWrite);
//
CString strBlkDef;
strBlkDef.Format("%s", blkName);
if (!pBlkTbl->has(strBlkDef))
{
acutPrintf("\n");
pBlkTbl->close();
return;
}
//
ads_point pt;
if (acedGetPoint(NULL, "\n", pt) != RTNORM)
{
pBlkTbl->close();
return;
}
AcGePoint3d ptInsert = asPnt3d(pt);
//
AcDbObjectId blkDefId;
pBlkTbl->getAt(strBlkDef, blkDefId);
//
AcDbBlockReference *pBlkRef = new AcDbBlockReference(ptInsert,
131
blkDefId);
//
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForWrite);
pBlkTbl->close();
AcDbObjectId entId;
pBlkTblRcd->appendAcDbEntity(entId, pBlkRef);
//
AcDbBlockTableRecord *pBlkDefRcd;
acdbOpenObject(pBlkDefRcd, blkDefId, AcDb::kForRead);
if (pBlkDefRcd->hasAttributeDefinitions())
{
AcDbBlockTableRecordIterator *pItr;
pBlkDefRcd->newIterator(pItr);
AcDbEntity *pEnt;
for (pItr->start(); !pItr->done(); pItr->step())
{
pItr->getEntity(pEnt, AcDb::kForRead);
//
AcDbAttributeDefinition *pAttDef;
pAttDef = AcDbAttributeDefinition::cast(pEnt);
if (pAttDef != NULL)
{
//
AcDbAttribute *pAtt = new AcDbAttribute();
//
pAtt->setPropertiesFrom(pAttDef);
//
pAtt->setInvisible(pAttDef->isInvisible());
AcGePoint3d ptBase = pAttDef->position();
ptBase += pBlkRef->position().asVector();
pAtt->setPosition(ptBase);
pAtt->setHeight(pAttDef->height());
pAtt->setRotation(pAttDef->rotation());
132
3.4
// TagPromptTextString
char *pStr;
pStr = pAttDef->tag();
pAtt->setTag(pStr);
free(pStr);
pStr = pAttDef->prompt();
acutPrintf("%s%s", "\n", pStr);
free(pStr);
pAtt->setFieldLength(30);
pAtt->setTextString("40");
//
pBlkRef->appendAttribute(pAtt);
pAtt->close();
}
pEnt->close();
}
delete pItr;
}
//
pBlkRef->close();
pBlkTblRcd->close();
pBlkDefRcd->close();
}
setPropertiesFrom
AcDbAttributeDefinition tag prompt
char *pStr;
// pStr
free(pStr);
133
3.4.4
AutoCAD 2002 AddBlk blk
InsertBlk
: insertblk
blk
3.4.5
setPropertiesFrom
3.5
3.5.1
3.5.2
AcDbBlockTableRecord getPreviewIcon
Acad::ErrorStatus
getPreviewIcon(
PreviewIcon & previewIcon) const;
PreviewIcon ObjectARX
typedef AcArray<Adesk::UInt8> PreviewIcon;
134
3.5
3.5.3
1VC++ 6.0ObjectARXGetBlkPreviewIcon
3.6
3.6
ID
IDD_BLKPREVIEWICON
IDC_BLKDEF_LIST
IDC_BITMAP
IDC_NUM_BLKDEF
IDC_HAS_ATT
IDCANCEL
2ObjectARXObjectARX MFC Support
3.7CacUiDialogCpreviewBlkDlg
Create Class
OK
135
3.7
3VC++ 6.0Insert/Bitmap3.8
BitmapNew
3.8
4ResourceView
Properties3.9IDIDB_BLANK
blank.bmp3030
3.9
136
ID
3.5
5Enter3.10
TypeBitmapImageIDB_BLANK
3.10
6Ctrl+WMFC ClassWizardMember
VariablesMFC3.11
3.11
137
3.12
8ClassViewCpreviewBlkDlg
Add Member Function3.13
OK
3.13
9 BlockIconToBMP
ID
HBITMAP CPreviewBlkDlg::BlockIconToBMP(const AcDbObjectId &blkId, HDC hdc)
{
Acad::ErrorStatus es;
AcDbBlockTableRecord *pBlkTblRcd = NULL; //
AcArray<Adesk::UInt8> icon;
//
138
3.5
//
try
{
es = acdbOpenObject(pBlkTblRcd, blkId, AcDb::kForRead);
if (es != Acad::eOk)
throw 1;
if (!pBlkTblRcd->hasPreviewIcon())
//
{
pBlkTblRcd->close();
return NULL;
}
es = pBlkTblRcd->getPreviewIcon(icon);
if (es != Acad::eOk)
throw 2;
es = pBlkTblRcd->close();
if (es != Acad::eOk)
throw 3;
}
catch (...)
{
pBlkTblRcd->close();
return NULL;
}
// icon
BITMAPINFOHEADER ih;
//
//
139
AcDbBlockTableRecord hasPreviewIcon
getPreviewIcon
10
BOOL CPreviewBlkDlg::OnInitDialog()
{
CAcUiDialog::OnInitDialog();
//
AcDbBlockTable *pBlkTbl;
AcDbBlockTableRecord *pBlkTblRcd;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
//
AcDbBlockTableIterator *pItr;
pBlkTbl->newIterator(pItr);
for (pItr->start(); !pItr->done(); pItr->step())
{
pItr->getRecord(pBlkTblRcd, AcDb::kForRead);
char *pName;
pBlkTblRcd->getName(pName);
CString strName(pName);
acutDelString(pName);
if (strName.Compare(ACDB_MODEL_SPACE) != 0 &&
strName.Compare(ACDB_PAPER_SPACE) != 0 &&
strName.Compare("*Paper_Space0"))
{
m_lstBlkDef.AddString(strName);
}
140
3.5
pBlkTblRcd->close();
}
delete pItr;
pBlkTbl->close();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return
FALSE
}
11
void CPreviewBlkDlg::OnSelchangeBlkdefList()
{
//
CPaintDC dc(this);
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
AcDbObjectId blkTblRcdId;
CString strBlkDefName;
m_lstBlkDef.GetLBText(m_lstBlkDef.GetCurSel(), strBlkDefName);
Acad::ErrorStatus es = pBlkTbl->getAt(strBlkDefName, blkTblRcdId);
HBITMAP hBitmap = BlockIconToBMP(blkTblRcdId, dc.GetSafeHdc());
m_bitmap.SetBitmap(hBitmap);
//
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(strBlkDefName, pBlkTblRcd, AcDb::kForRead);
//
AcDbBlockReferenceIdIterator *pItr;
pBlkTblRcd->newBlockReferenceIdIterator(pItr);
int number = 0;
for (pItr->start(); !pItr->done(); pItr->step())
{
141
number++;
}
m_strBlkRefNum.Format("%d", number);
//
if (pBlkTblRcd->hasAttributeDefinitions())
{
m_strHasAttribute = "";
}
else
{
m_strHasAttribute = "";
}
pBlkTblRcd->close();
pBlkTbl->close();
UpdateData(FALSE);
}
12 PreviewBlkDlg.h
#include "Resource.h"
PreviewBlkDlg.cpp
#include "dbsymtb.h"
#include "acutmem.h"
13 ViewBlk
void ZffCHAP3ViewBlk()
{
//
CAcModuleResourceOverride resOverride;
//
CPreviewBlkDlg dlg;
dlg.DoModal();
}
3.5.4
AutoCAD 2002 ViewBlk
142
3.5
3.14
3.15
3.15
3.5.5
143
AutoCAD AutoCAD
AcDbBlockTable
AcDbTextStyleTable AutoCAD
STYLE
AcDbLinetypeTable AutoCAD LTYPE
getSymbolTable
getBlockTable
getLayerTable
AcDbSymbolTable
add
getAt
has
newIterator
144
4.1
4.1
4.1.1
4.1.2
AcDbLayerTableRecord
setColor
Cstring
CstdioFile WriteString
CstdioFile ReadString
4.1.3
1 VC++ 6.0 ObjectARX OperateLayer
NewLayer
void ZffCHAP4NewLayer()
{
//
char layerName[100];
if (acedGetString(Adesk::kFalse, "\n",
layerName) != RTNORM)
{
return;
}
//
AcDbLayerTable *pLayerTbl;
acdbHostApplicationServices()->workingDatabase()
->getLayerTable(pLayerTbl, AcDb::kForWrite);
145
//
if (pLayerTbl->has(layerName))
{
pLayerTbl->close();
return;
}
//
AcDbLayerTableRecord *pLayerTblRcd;
pLayerTblRcd = new AcDbLayerTableRecord();
pLayerTblRcd->setName(layerName);
//
AcDbObjectId layerTblRcdId;
pLayerTbl->add(layerTblRcdId, pLayerTblRcd);
acdbHostApplicationServices()->workingDatabase()
->setClayer(layerTblRcdId);
pLayerTblRcd->close();
pLayerTbl->close();
}
getLayerTable AcDb::kForWrite
has
AcDbDatabase setClayer
2 LayerColor
void ZffCHAP4LayerColor()
{
//
char layerName[100];
if (acedGetString(Adesk::kFalse, "\n",
layerName) != RTNORM)
{
return;
}
//
146
4.1
AcDbLayerTable *pLayerTbl;
acdbHostApplicationServices()->workingDatabase()
->getLayerTable(pLayerTbl, AcDb::kForRead);
//
if (!pLayerTbl->has(layerName))
{
pLayerTbl->close();
return;
}
//
AcDbLayerTableRecord *pLayerTblRcd;
pLayerTbl->getAt(layerName, pLayerTblRcd, AcDb::kForWrite);
//
AcCmColor oldColor = pLayerTblRcd->color();
int nCurColor = oldColor.colorIndex();
int nNewColor = oldColor.colorIndex();
//
//
AcDbLayerTable getAt
AcDb::kForWrite
AcedSetColorDialog 2
Adesk::Boolean acedSetColorDialog(
int& nColor,
Adesk::Boolean bAllowMetaColor,
int nCurLayerColor);
nColor
bAllowMetaColor
147
nCurLayerColor
AcCmColor
AcCmColor color;
color.setColorIndex(nNewColor);
pLayerTblRcd->setColor(color);
3 DelLayer
void ZffCHAP4DelLayer()
{
//
char layerName[100];
if (acedGetString(Adesk::kFalse, "\n",
layerName) != RTNORM)
{
return;
}
//
AcDbLayerTable *pLayerTbl;
acdbHostApplicationServices()->workingDatabase()
->getLayerTable(pLayerTbl, AcDb::kForRead);
//
if (!pLayerTbl->has(layerName))
{
pLayerTbl->close();
return;
}
//
AcDbLayerTableRecord *pLayerTblRcd;
pLayerTbl->getAt(layerName, pLayerTblRcd, AcDb::kForWrite);
pLayerTblRcd->erase();
//
pLayerTblRcd->close();
pLayerTbl->close();
}
AcDbObject erase
148
4.1
4 ExportLayer
void ZffCHAP4ExportLayer()
{
//
CStdioFile f;
CFileException e;
char *pFileName = "C:\\layers.txt";
if (!f.Open(pFileName, CFile::modeCreate | CFile::modeWrite, &e))
{
acutPrintf("\n");
return;
}
//
AcDbLayerTable *pLayerTbl;
AcDbLayerTableRecord *pLayerTblRcd;
acdbHostApplicationServices()->workingDatabase()
->getLayerTable(pLayerTbl, AcDb::kForRead);
//
AcDbLayerTableIterator *pItr;
pLayerTbl->newIterator(pItr);
for (pItr->start(); !pItr->done(); pItr->step())
{
pItr->getRecord(pLayerTblRcd, AcDb::kForRead);
//
CString strLayerInfo;
//
char *layerName;
pLayerTblRcd->getName(layerName);
strLayerInfo = layerName;
free(layerName);
strLayerInfo += ",";
//
CString strColor;
//
149
strLayerInfo += ",";
CString strLinetype;
//
AcDbLinetypeTableRecord *pLinetypeTblRcd;
acdbOpenObject(pLinetypeTblRcd,
pLayerTblRcd->linetypeObjectId(),
AcDb::kForRead);
char *linetypeName;
pLinetypeTblRcd->getName(linetypeName);
pLinetypeTblRcd->close();
strLinetype = linetypeName;
free(linetypeName);
strLayerInfo += strLinetype;
strLayerInfo += ",";
CString strLineWeight;
//
Cstring Cstring
strLayerInfo += strLineWeight;
CstdioFile WriteString
5 ImportLayer
150
4.1
void ZffCHAP4ImportLayer()
{
//
CStdioFile f;
CFileException e;
char *pFileName = "C:\\layers.txt";
if (!f.Open(pFileName, CFile::modeRead, &e))
{
acutPrintf("\n");
return;
}
//
AcDbLayerTable *pLayerTbl;
AcDbLayerTableRecord *pLayerTblRcd;
acdbHostApplicationServices()->workingDatabase()
->getLayerTable(pLayerTbl, AcDb::kForWrite);
//
CString strLineText;
//
while (f.ReadString(strLineText))
{
//
if (strLineText.IsEmpty())
continue;
//
CStringArray layerInfos;
if (!GetFieldText(strLineText, layerInfos))
continue;
//
AcDbLayerTableRecord *pLayerTblRcd;
AcDbObjectId layerTblRcdId;
if (pLayerTbl->has(layerInfos.GetAt(0)))
{
pLayerTbl->getAt(layerInfos.GetAt(0), layerTblRcdId);
}
151
else
{
pLayerTblRcd = new AcDbLayerTableRecord();
pLayerTblRcd->setName(layerInfos.GetAt(0));
pLayerTbl->add(layerTblRcdId, pLayerTblRcd);
pLayerTblRcd->close();
}
acdbOpenObject(pLayerTblRcd, layerTblRcdId,
AcDb::kForWrite);
//
AcCmColor color;
Adesk::UInt16 colorIndex = atoi(layerInfos.GetAt(1));
color.setColorIndex(colorIndex);
pLayerTblRcd->setColor(color);
//
AcDbLinetypeTable *pLinetypeTbl;
AcDbObjectId linetypeId;
acdbHostApplicationServices()->workingDatabase()
->getLinetypeTable(pLinetypeTbl, AcDb::kForRead);
if (pLinetypeTbl->has(layerInfos.GetAt(2)))
{
pLinetypeTbl->getAt(layerInfos.GetAt(2), linetypeId);
}
else
{
pLinetypeTbl->getAt("Continous", linetypeId);
}
pLayerTblRcd->setLinetypeObjectId(linetypeId);
pLinetypeTbl->close();
//
AcDb::LineWeight lineWeight =
(AcDb::LineWeight)atol(layerInfos.GetAt(3));
pLayerTblRcd->setLineWeight(lineWeight);
152
4.1
pLayerTblRcd->close();
}
pLayerTbl->close();
}
GetFieldText
BOOL GetFieldText(CString strLineText, CStringArray &fields)
{
if (strLineText.Find(",", 0) == -1)
//
{
return FALSE;
}
int nLeftPos = 0, nRightPos = 0;
//
Cstring
Find Mid
153
4.1.4
1AutoCAD 2002NewLayerNewLayer
4.1
NewLayer
4.1
20 DelLayer NewLayer
Enter
AutoCAD NewLayer
3LayerColor04.2
00
154
4.1
4.2
4
4.3
4.3
5ExportLayer
layers.txt4.4
155
4.4
6 ImportLayer
4.1.5
4.2
4.2.1
AutoCAD STYLE
4.2.2
ObjectARX
1
2
3 setName
4 setFileName
5 setXScale
6
156
4.2
4.2.3
VC++ 6.0 ObjectARX AddTextStyle
AddStyle
void ZffCHAP4AddStyle()
{
//
AcDbTextStyleTable *pTextStyleTbl;
acdbHostApplicationServices()->workingDatabase()
->getTextStyleTable(pTextStyleTbl, AcDb::kForWrite);
//
AcDbTextStyleTableRecord *pTextStyleTblRcd;
pTextStyleTblRcd = new AcDbTextStyleTableRecord();
//
pTextStyleTblRcd->setName("");
//
pTextStyleTblRcd->setFileName("simfang.ttf");
//
pTextStyleTblRcd->setXScale(0.7);
//
pTextStyleTbl->add(pTextStyleTblRcd);
pTextStyleTblRcd->close();
pTextStyleTbl->close();
}
pTextStyleTblRcd->setFileName("romans");
4.5
157
4.5
4.2.4
AutoCAD 2002AddStyle
4.6
4.6
4.2.5
158
4.3
4.3
4.3.1
4.3.2
ObjectARX
1
2
3
4.3.3
VC++ 6.0 ObjectARX AddDimStyle
AddDimStyle
void ZffCHAP4AddDimStyle()
{
//
char styleName[100];
if (acedGetString(Adesk::kFalse, "\n",
styleName) != RTNORM)
{
return;
}
//
AcDbDimStyleTable *pDimStyleTbl;
acdbHostApplicationServices()->workingDatabase()
->getDimStyleTable(pDimStyleTbl, AcDb::kForWrite);
if (pDimStyleTbl->has(styleName))
{
pDimStyleTbl->close();
159
return;
}
//
AcDbDimStyleTableRecord *pDimStyleTblRcd;
pDimStyleTblRcd = new AcDbDimStyleTableRecord();
//
pDimStyleTblRcd->setName(styleName);
//
pDimStyleTblRcd->setDimasz(3);
//
pDimStyleTblRcd->setDimexe(3);
//
pDimStyleTblRcd->setDimtad(1);
//
pDimStyleTblRcd->setDimtxt(3);
//
//
pDimStyleTbl->add(pDimStyleTblRcd);
pDimStyleTblRcd->close();
pDimStyleTbl->close();
}
4.3.4
1 AutoCAD 2002 AddDimStyle MyStyle
Enter
2
160
4.3
4.7
3MyStyle
4.8
4.8
4.3.5
AutoCAD
4.9
161
4.9
ObjectARX
ISO-25204.10
4.10
//
AcDbDimStyleTableRecord *pDimStyleTblRcd;
pDimStyleTblRcd = new AcDbDimStyleTableRecord();
// ISO-25
AcDbDimStyleTableRecord *pOldStyle;
pDimStyleTbl->getAt("ISO-25", pOldStyle, AcDb::kForRead);
//
pDimStyleTblRcd->setName(styleName);
pDimStyleTblRcd->setDimtxt(pOldStyle->dimtxt());
pDimStyleTblRcd->setDimasz(pOldStyle->dimasz());
pDimStyleTblRcd->setDimexe(pOldStyle->dimexe());
pDimStyleTblRcd->setDimtad(pOldStyle->dimtad());
162
4.4
4.4
4.4.1
AutoCAD ZOOM
PAN VIEW
4.4.2
ObjectARX AcDbViewTableRecord AutoCAD
AcDbAbstractViewTableRecord
acedSetCurrentView
ObjectARX
VIEWMODE
VIEWCTRUCS
LENSLENGTH
TARGET UCS
VIEWDIRUCS
VIEWSIZE
SCREENSIZEX Y
VIEWTWIST
TILEMODE
CVPORT
FRONTZ
BACKZ
setCenterPointsetHeight setWidth
DCS WCSUCS
DCS AutoCAD
acedTrans
int acedTrans(
const ads_point pt,
const struct resbuf * from,
const struct resbuf * to,
int disp,
ads_point result);
163
pt from pt to
result disp pt disp 0pt
disp 0pt
from to from to
4.4.3
1 VC++ 6.0 ObjectARX ChangeView
ZoomScale
void ZffCHAP4ZoomScale()
{
//
ads_real scale;
if (acedGetReal("\n", &scale) != RTNORM)
return;
//
AcDbViewTableRecord view = GetCurrentView();
//
view.setWidth(view.width() / scale);
view.setHeight(view.height() / scale);
//
acedSetCurrentView(&view, NULL);
}
GetCurrentView
164
4.4
ChangeViewCommands.cpp
C
GetCurrentView
AcDbViewTableRecord GetCurrentView()
{
AcDbViewTableRecord view;
struct resbuf rb;
struct resbuf wcs, ucs, dcs; //
wcs.restype = RTSHORT;
wcs.resval.rint = 0;
ucs.restype = RTSHORT;
ucs.resval.rint = 1;
dcs.restype = RTSHORT;
dcs.resval.rint = 2;
//
acedGetVar("VIEWMODE", &rb);
view.setPerspectiveEnabled(rb.resval.rint & 1);
view.setFrontClipEnabled(rb.resval.rint & 2);
view.setBackClipEnabled(rb.resval.rint & 4);
view.setFrontClipAtEye(!(rb.resval.rint & 16));
// UCS
acedGetVar("VIEWCTR", &rb);
acedTrans(rb.resval.rpoint, &ucs, &dcs, 0, rb.resval.rpoint);
view.setCenterPoint(AcGePoint2d(rb.resval.rpoint[X],
rb.resval.rpoint[Y]));
//
acedGetVar("LENSLENGTH", &rb);
view.setLensLength(rb.resval.rreal);
// UCS
acedGetVar("TARGET", &rb);
acedTrans(rb.resval.rpoint, &ucs, &wcs, 0, rb.resval.rpoint);
view.setTarget(AcGePoint3d(rb.resval.rpoint[X],
rb.resval.rpoint[Y], rb.resval.rpoint[Z]));
165
// UCS
acedGetVar("VIEWDIR", &rb);
acedTrans(rb.resval.rpoint, &ucs, &wcs, 1, rb.resval.rpoint);
view.setViewDirection(AcGeVector3d(rb.resval.rpoint[X],
rb.resval.rpoint[Y], rb.resval.rpoint[Z]));
//
acedGetVar("VIEWSIZE", &rb);
view.setHeight(rb.resval.rreal);
double height = rb.resval.rreal;
// X Y
acedGetVar("SCREENSIZE", &rb);
view.setWidth(rb.resval.rpoint[X] / rb.resval.rpoint[Y] * height);
//
acedGetVar("VIEWTWIST", &rb);
view.setViewTwist(rb.resval.rreal);
//
acedGetVar("TILEMODE", &rb);
int tileMode = rb.resval.rint;
//
acedGetVar("CVPORT", &rb);
int cvport = rb.resval.rint;
//
bool paperspace = ((tileMode == 0) && (cvport == 1)) ? true : false;
view.setIsPaperspaceView(paperspace);
if (!paperspace)
{
//
acedGetVar("FRONTZ", &rb);
view.setFrontClipDistance(rb.resval.rreal);
//
acedGetVar("BACKZ", &rb);
view.setBackClipDistance(rb.resval.rreal);
166
4.4
}
else
{
view.setFrontClipDistance(0.0);
view.setBackClipDistance(0.0);
}
return view;
}
acedSetCurrentView
ObjectARX
2 ZoomWindow
void ZffCHAP4ZoomWindow()
{
//
ads_point pt1, pt2;
if (acedGetPoint(NULL, "\n", pt1) != RTNORM)
return;
if (acedGetCorner(pt1, "\n", pt2) != RTNORM)
return;
struct resbuf wcs, ucs, dcs; //
wcs.restype = RTSHORT;
wcs.resval.rint = 0;
ucs.restype = RTSHORT;
ucs.resval.rint = 1;
dcs.restype = RTSHORT;
dcs.resval.rint = 2;
acedTrans(pt1, &ucs, &dcs, 0, pt1);
acedTrans(pt2, &ucs, &dcs, 0, pt2);
AcDbViewTableRecord view = GetCurrentView();
//
view.setCenterPoint(AcGePoint2d((pt1[X] + pt2[X]) / 2,
(pt1[Y] + pt2[Y]) / 2));
167
//
view.setHeight(fabs(pt1[Y] - pt2[Y]));
view.setWidth(fabs(pt1[X] - pt2[X]));
//
acedSetCurrentView(&view, NULL);
}
3 ZoomExtents
void ZffCHAP4ZoomExtents()
{
AcDbBlockTable *pBlkTbl;
AcDbBlockTableRecord *pBlkTblRcd;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForRead);
pBlkTbl->close();
//
AcDbExtents extent;
extent.addBlockExt(pBlkTblRcd);
pBlkTblRcd->close();
//
ads_point pt[7];
pt[0][X] = pt[3][X] = pt[4][X] = pt[7][X] = extent.minPoint().x;
pt[1][X] = pt[2][X] = pt[5][X] = pt[6][X] = extent.maxPoint().x;
pt[0][Y] = pt[1][Y] = pt[4][Y] = pt[5][Y] = extent.minPoint().y;
pt[2][Y] = pt[3][Y] = pt[6][Y] = pt[7][Y] = extent.maxPoint().y;
pt[0][Z] = pt[1][Z] = pt[2][Z] = pt[3][Z] = extent.maxPoint().z;
pt[4][Z] = pt[5][Z] = pt[6][Z] = pt[7][Z] = extent.minPoint().z;
// DCS
struct resbuf wcs, dcs; //
wcs.restype = RTSHORT;
wcs.resval.rint = 0;
dcs.restype = RTSHORT;
dcs.resval.rint = 2;
168
4.4
AcDbExtents addBlockExt
WCS 8
169
DCS
4.4.4
1AutoCAD 2002
4.11
4.11
2ZoomScale22
4.12
4.12 2
3ZoomWindow4.13
170
4.4
4.13
4ZoomExtents4.14
ZOOMEExtents
4.14
4.4.5
AcDbEntity getGeomExtents
AcDbExtents addExt
AutoCAD
171
4.5
4.5.1
4 ADS 4
4.5.2
ObjectARX AcDbViewportTableRecord AcDbViewport
AcDbViewportTableRecord AutoCAD
AcDbViewport AutoCAD
1 setLowerLeftCorner setUpperRightCorner
setName
4
2
3
AcDbViewport
4.5.3
1 VC++ 6.0 ObjectARX Viewports
Create4VPorts4
void ZffCHAP4Create4VPorts()
{
//
AcDbViewportTable *pVPortTbl;
acdbHostApplicationServices()->workingDatabase()
->getViewportTable(pVPortTbl, AcDb::kForWrite);
//
AcGePoint2d pt1, pt2;
AcDbViewportTableRecord *pVPortTblRcd1=new
AcDbViewportTableRecord;
pt1.set(0, 0);
172
4.5
pt2.set(0.5, 0.5);
pVPortTblRcd1->setLowerLeftCorner(pt1);
pVPortTblRcd1->setUpperRightCorner(pt2);
pVPortTblRcd1->setName("4VPorts");
AcDbViewportTableRecord *pVPortTblRcd2=new
AcDbViewportTableRecord;
pt1.set(0.5, 0);
pt2.set(1, 0.5);
pVPortTblRcd2->setLowerLeftCorner(pt1);
pVPortTblRcd2->setUpperRightCorner(pt2);
pVPortTblRcd2->setName("4VPorts");
AcDbViewportTableRecord *pVPortTblRcd3=new
AcDbViewportTableRecord;
pt1.set(0, 0.5);
pt2.set(0.5, 1);
pVPortTblRcd3->setLowerLeftCorner(pt1);
pVPortTblRcd3->setUpperRightCorner(pt2);
pVPortTblRcd3->setName("4VPorts");
AcDbViewportTableRecord *pVPortTblRcd4=new
AcDbViewportTableRecord;
pt1.set(0.5, 0.5);
pt2.set(1, 1);
pVPortTblRcd4->setLowerLeftCorner(pt1);
pVPortTblRcd4->setUpperRightCorner(pt2);
pVPortTblRcd4->setName("4VPorts");
pVPortTbl->add(pVPortTblRcd1);
pVPortTbl->add(pVPortTblRcd2);
pVPortTbl->add(pVPortTblRcd3);
pVPortTbl->add(pVPortTblRcd4);
pVPortTbl->close();
pVPortTblRcd1->close();
pVPortTblRcd2->close();
pVPortTblRcd3->close();
pVPortTblRcd4->close();
173
//
struct resbuf rb;
acedGetVar("TILEMODE", &rb);
if (rb.resval.rint == 1)
//
{
acedCommand(RTSTR, ".-VPORTS", RTSTR, "R",
RTSTR, "4VPorts", RTNONE);
}
//
else
{
2 CreateVPortInSpace
AcDbViewport
void ZffCHAP4CreateVPortInSpace()
{
//
Acad::ErrorStatus es =
acdbHostApplicationServices()->layoutManager()
->setCurrentLayout("1");
if (es != Acad::eOk)
{
return;
}
//
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
//
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_PAPER_SPACE, pBlkTblRcd,
AcDb::kForWrite);
pBlkTbl->close();
174
4.5
//
AcDbViewport *pViewport = new AcDbViewport();
pViewport->setCenterPoint(AcGePoint3d(100, 50, 0));
pViewport->setHeight(80);
pViewport->setWidth(120);
//
AcDbObjectId viewportId;
pBlkTblRcd->appendAcDbEntity(viewportId, pViewport);
pViewport->close();
pBlkTblRcd->close();
//
AcDbViewport *pVP;
acdbOpenObject(pVP, viewportId, AcDb::kForWrite);
pViewport->setOn();
acedSetCurrentVPort(pVP);
pVP->close();
}
setOn
4.5.4
1AutoCAD 2002Create4VPorts4.15
4.15
2CreateVPortInSpace4.16
175
4.16
4.5.5
4.6 UCS
4.6.1
AutoCAD UCS
UCS UCS
UCS UCS UCS ObjectARX
WCS
4.6.2
ObjectARX UCS AutoCAD UCS
X Y UCS AcDbUCSTableRecord setOriginsetXAxis
setYAxis X Y
acedSetCurrentUCS UCS AcGeMatrix3d
UCS WCS UCS
UCS WCS acedSetCurrentUCS
ObjectARXWCS
176
4.6
UCS
UCSacedTransUCSWCS
4.4
4.6.3
1 VC++ 6.0 ObjectARX OperateUCS
NewUcs UCS UCS
void ZffCHAP4NewUCS()
{
// UCS
AcDbUCSTable *pUcsTbl;
acdbHostApplicationServices()->workingDatabase()
->getUCSTable(pUcsTbl, AcDb::kForWrite);
// UCS
AcGePoint3d ptOrigin(0, 0, 0);
AcGeVector3d vecXAxis(1, 1, 0);
AcGeVector3d vecYAxis(-1, 1, 0);
// UCS
AcDbUCSTableRecord *pUcsTblRcd = new AcDbUCSTableRecord();
// UCS
Acad::ErrorStatus es = pUcsTblRcd->setName("NewUcs");
if (es != Acad::eOk)
{
delete pUcsTblRcd;
pUcsTbl->close();
return;
}
pUcsTblRcd->setOrigin(ptOrigin);
pUcsTblRcd->setXAxis(vecXAxis);
pUcsTblRcd->setYAxis(vecYAxis);
// UCSUCS
es = pUcsTbl->add(pUcsTblRcd);
if (es != Acad::eOk)
{
delete pUcsTblRcd;
pUcsTbl->close();
177
return;
}
//
pUcsTblRcd->close();
pUcsTbl->close();
}
void ZffCHAP4SetCurUcs()
{
// UCS
char ucsName[40];
if (acedGetString(NULL, "\n", ucsName) !=
RTNORM)
return;
// UCS
AcDbUCSTable *pUcsTbl;
acdbHostApplicationServices()->workingDatabase()
->getUCSTable(pUcsTbl, AcDb::kForRead);
if (!pUcsTbl->has(ucsName))
{
pUcsTbl->close();
return;
}
AcDbUCSTableRecord *pUcsTblRcd;
pUcsTbl->getAt(ucsName, pUcsTblRcd, AcDb::kForRead);
// UCS
AcGeMatrix3d mat;
AcGeVector3d vecXAxis, vecYAxis, vecZAxis;
vecXAxis = pUcsTblRcd->xAxis();
vecYAxis = pUcsTblRcd->yAxis();
vecZAxis = vecXAxis.crossProduct(vecYAxis);
mat.setCoordSystem(pUcsTblRcd->origin(), vecXAxis,
vecYAxis, vecZAxis);
// UCSUCS
178
4.6
UCS
pUcsTblRcd->close();
pUcsTbl->close();
// UCS
acedSetCurrentUCS(mat);
}
3 MoveUcsOrigin UCS
void ZffCHAP4MoveUcsOrigin()
{
// UCS
AcGeMatrix3d mat;
Acad::ErrorStatus es = acedGetCurrentUCS(mat);
// UCS
AcGePoint3d ptOrigin;
AcGeVector3d vecXAxis, vecYAxis, vecZAxis;
mat.getCoordSystem(ptOrigin, vecXAxis, vecYAxis, vecZAxis);
// UCS
AcGeVector3d vec(100, 100, 0);
ptOrigin += vec;
//
mat.setCoordSystem(ptOrigin, vecXAxis, vecYAxis, vecZAxis);
// UCS
acedSetCurrentUCS(mat);
}
4 RotateUcs UCS Z 60
void ZffCHAP4RotateUcs()
{
// UCS
AcGeMatrix3d mat;
Acad::ErrorStatus es = acedGetCurrentUCS(mat);
179
// UCS
AcGePoint3d ptOrigin;
AcGeVector3d vecXAxis, vecYAxis, vecZAxis;
mat.getCoordSystem(ptOrigin, vecXAxis, vecYAxis, vecZAxis);
// Z60
vecXAxis.rotateBy(60 * atan(1) * 4 / 180, vecZAxis);
vecYAxis.rotateBy(60 * atan(1) * 4 / 180, vecZAxis);
//
mat.setCoordSystem(ptOrigin, vecXAxis, vecYAxis, vecZAxis);
// UCS
acedSetCurrentUCS(mat);
}
5 AddEntInUcs UCS
void ZffCHAP4AddEntInUcs()
{
//
struct resbuf wcs, ucs;
wcs.restype = RTSHORT;
wcs.resval.rint = 0;
ucs.restype = RTSHORT;
ucs.resval.rint = 1;
//
ads_point pt1, pt2;
if (acedGetPoint(NULL, "", pt1) != RTNORM)
return;
if (acedGetPoint(pt1, "", pt2) != RTNORM)
return;
// WCS
acedTrans(pt1, &ucs, &wcs, 0, pt1);
acedTrans(pt2, &ucs, &wcs, 0, pt2);
//
AcDbLine *pLine = new AcDbLine(asPnt3d(pt1), asPnt3d(pt2));
180
4.6
UCS
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForWrite);
pBlkTbl->close();
pBlkTblRcd->appendAcDbEntity(pLine);
pLine->close();
pBlkTblRcd->close();
}
4.6.4
1 AutoCAD 2002 NewUcs
UCS UCS
: ucs
UCS : **
[(N)/(M)/(G)/(P)/(R)/(S)/(D)/(A)/?/
(W)] <>: ?
UCS
UCS <*>:
Enter
UCS : **
:
"NewUcs"
= <0.00000.00000.0000>X = <0.70710.70710.0000>
Y = <-0.70710.70710.0000>Z = <0.00000.00001.0000>
[(N)/(M)/(G)/(P)/(R)/(S)/(D)/(A)/?/
(W)] <>: **
// WCS
acedTrans(pt1, &ucs, &wcs, 0, pt1);
acedTrans(pt2, &ucs, &wcs, 0, pt2);
4.6.5
UCS WCS
UCS
UCS
182
5.1
acedCommand
5 ADSRX
ADS AutoCAD AutoCAD R10 Autodesk
ObjectARX Autodesk
C
ObjectARX ADS
ADSRX ObjectARX
AutoCAD
DCL DCL MFC
MFC
5.1 acedCommand
5.1.1
ObjectARX acedCommand acedCmd AutoCAD
AutoCAD
5.1.2
1acedCommand
acedCommand
int acedCommand(int rtype, ... unnamed);
ARX5.1
0RTNONERTNONE
183
ADSRX
5.1
acedCommand
AutoCAD 0010
acedCommand(RTSTR, "Circle",
//
RTSTR, 0,0,0,
//
RTSTR, 10,
//
RTNONE);
//
AddCircle1 acedCommand
2acedCmd
acedCmd
int acedCmd(const struct resbuf * rbp);
resbuf acutBuildList
acedCommand resbuf
acedCmd acedCommand AddCircle2
acedCmd
3resbuf
resbuf ObjectARX
struct resbuf {
struct resbuf *rbnext; //
184
5.1
acedCommand
short restype;
union ads_u_val resval;
};
ads_u_val
union ads_u_val {
ads_real rreal;
ads_real rpoint[3];
short rint; // shortint
char *rstring;
long rlname[2];
long rlong;
struct ads_binary rbinary;
};
resbuf rbnext
rbnext NULL
resbuf acutRelRb
EntInfo
restypeads_u_val5.1
5.2
5.2
acutRelRb
acutNewRb
acutRelRb
5.1.3
1 VC++ 6.0 ObjectARX Resbuf
AddCircle1 acedCommand
void ZffCHAP5AddCircle1()
185
ADSRX
{
// ADS
ads_point ptCenter = {0, 0, 0};
//
//
// acedCommand
acedCommand(RTSTR, "Circle",
//
RTPOINT, ptCenter, //
RTREAL, radius,
RTNONE);
//
//
2 AddCircle2 acedCmd
void ZffCHAP5ADDCIRCLE2()
{
struct resbuf *rb; //
int rc = RTNORM; //
//
ads_point ptCenter = {30, 0, 0};
ads_real radius = 10;
rb = acutBuildList(RTSTR, "Circle",
RTPOINT, ptCenter,
RTREAL, radius,
RTNONE);
//
if (rb != NULL)
{
rc = acedCmd(rb);
}
//
if (rc != RTNORM)
{
acutPrintf("\n!");
}
186
5.1
acedCommand
acutRelRb(rb);
//
acedCommand(RTSTR, "Zoom", RTSTR, "E", RTNONE);
}
acutBuildList acedCmd
acedCommand acutBuildList
acutRelRb
acedCommand AutoCAD Zoom
3 EntInfo
void ZffCHAP5EntInfo()
{
//
ads_name entName;
ads_point pt;
if (acedEntSel("\n:", entName, pt) != RTNORM)
return;
struct resbuf *rbEnt;
//
//
//
//
acutPrintf("\n:%s", rb->resval.rstring);
break;
187
ADSRX
case 10: //
acutPrintf("\n:(%.2f, %.2f, %.2f)",
rb->resval.rpoint[X],
rb->resval.rpoint[Y],
rb->resval.rpoint[Z]);
break;
case 40: //
acutPrintf("\n:%.4f", rb->resval.rreal);
break;
case 210: //
acutPrintf("\n:(%.2f, %.2f, %.2f)",
rb->resval.rpoint[X],
rb->resval.rpoint[Y],
rb->resval.rpoint[Z]);
break;
default:
break;
}
// switch
rb = rb->rbnext;
}
//
// while
if (rbEnt != NULL)
{
acutRelRb(rbEnt);
}
}
acedEntSel ads_name
acdbEntGet
rbEnt
rbrb->restypeacutPrintfrb->resval
DXF
AutoCADacad_dev.chm5.3
188
5.1
5.3
acedCommand
DXF
rb = rb->rbnext rb
acutRelRb
rb rbEnt acutRelRb
rbEnt
5.1.4
1AutoCAD 2002ARXAddCircle1
AddCircle2F2
AutoCAD5.4
189
ADSRX
5.4
2EntInfo5.5
5.5
5.1.5
acedCommand acedCmd AutoCAD
ObjectARX
acedEntSel aced ADSRX
RTNORM ADSRX
RTNORM
RTERROR
RTCAN Esc
RTREJAutoCAD
RTFAIL AutoLISP
RTKWORD
190
5.2
5.2
5.2.1
ObjectARX acedGetStringacedGetPoint
acedGetIntacedGetKword acedGetReal
acedGetPoint
AutoCAD PLINE
: _pline
:
0.0000
[(A)/(H)/(L)/(U)/(W)]:
[(A)/(C)/(H)/(L)/(U)/(W)]:
[(A)/(H)/(L)/(U)/(W)]:
AutoCAD
5.2.2
Enter Esc
void ZffCHAP5AddPolyBasic()
{
int index = 2;
//
ads_point ptStart;
//
if (acedGetPoint(NULL, "\n", ptStart) != RTNORM)
return;
ads_point ptPrevious, ptCurrent; //
acdbPointSet(ptStart, ptPrevious);
AcDbObjectId polyId;
// ID
191
ADSRX
if (index == 2)
{
//
AcDbPolyline *pPoly = new AcDbPolyline(2);
AcGePoint2d ptGe1, ptGe2;
//
ptGe1[X] = ptPrevious[X];
ptGe1[Y] = ptPrevious[Y];
ptGe2[X] = ptCurrent[X];
ptGe2[Y] = ptCurrent[Y];
pPoly->addVertexAt(0, ptGe1);
pPoly->addVertexAt(1, ptGe2);
//
polyId = PostToModelSpace(pPoly);
}
else if (index > 2)
{
//
AcDbPolyline *pPoly;
acdbOpenObject(pPoly, polyId, AcDb::kForWrite);
AcGePoint2d ptGe;
//
ptGe[X] = ptCurrent[X];
ptGe[Y] = ptCurrent[Y];
pPoly->addVertexAt(index - 1, ptGe);
pPoly->close();
}
index++;
acdbPointSet(ptCurrent, ptPrevious);
}
}
1
2
3 Enter Esc
192
5.2
4 Enter Esc
3
2 acedGetPoint
acedGetPoint acedGetPoint
acedInitGet acedGetPoint
acedGetPoint
void ZffCHAP5GetPoint()
{
int rc;
//
char kword[20]; //
ads_point pt;
acedInitGet(RSG_NONULL, "Keyword1 keyWord2");
rc = acedGetPoint(NULL, "[Keyword1/keyWord2]:", pt);
switch (rc)
{
case RTKWORD: //
if (acedGetInput(kword) != RTNORM)
return;
if (strcmp(kword, "Keyword1") == 0)
acedAlert("Keyword1!");
else if (strcmp(kword, "keyWord2") == 0)
acedAlert("keyWord2!");
break;
case RTNORM:
acutPrintf("(%.2f, %.2f, %.2f)",
pt[X], pt[Y], pt[Z]);
}
// switch
acedGetPoint
RTKWORD acedGetInput
Keyword1 keyWord2
K W
5.2.3
1 VC++ 6.0 ObjectARX AddPolyDynamic
193
ADSRX
AddPoly AddPolyDynamicCommands.cpp
GetWidth
ads_real GetWidth()
{
ads_real width = 0;
if (acedGetReal("\n:", &width) == RTNORM)
{
return width;
}
else
{
return 0;
}
}
2 GetWidth GetColorIndex
int GetColorIndex()
{
int colorIndex = 0;
if (acedGetInt("\n(0256):", &colorIndex) !=
RTNORM)
return 0;
//
while (colorIndex < 0 || colorIndex > 256)
{
acedPrompt("\n.");
if (acedGetInt("\n(0256):", &colorIndex) !=
RTNORM)
return 0;
}
return colorIndex;
}
GetWidth
0256
3 AddPoly
194
5.2
void ZffCHAP5AddPoly()
{
int colorIndex = 0;
//
//
ads_real width = 0;
int index = 2;
//
ads_point ptStart;
//
//
if (acedGetPoint(NULL, "\n:", ptStart) != RTNORM)
return;
ads_point ptPrevious, ptCurrent; //
acdbPointSet(ptStart, ptPrevious);
// ID
AcDbObjectId polyId;
//
acedInitGet(NULL, "W C O");
int rc = acedGetPoint(ptPrevious,
//
{
char kword[20];
if (acedGetInput(kword) != RTNORM)
return;
if (strcmp(kword, "W") == 0)
{
width = GetWidth();
}
else if (strcmp(kword, "C") == 0)
{
colorIndex = GetColorIndex();
}
else if (strcmp(kword, "O") == 0)
{
return;
}
195
ADSRX
else
{
acutPrintf("\n.");
}
}
else if (rc == RTNORM)
//
{
if (index == 2)
{
//
AcDbPolyline *pPoly = new AcDbPolyline(2);
AcGePoint2d ptGe1, ptGe2;
//
ptGe1[X] = ptPrevious[X];
ptGe1[Y] = ptPrevious[Y];
ptGe2[X] = ptCurrent[X];
ptGe2[Y] = ptCurrent[Y];
pPoly->addVertexAt(0, ptGe1);
pPoly->addVertexAt(1, ptGe2);
//
pPoly->setConstantWidth(width);
pPoly->setColorIndex(colorIndex);
//
polyId = PostToModelSpace(pPoly);
}
else if (index > 2)
{
//
AcDbPolyline *pPoly;
acdbOpenObject(pPoly, polyId, AcDb::kForWrite);
AcGePoint2d ptGe;
//
ptGe[X] = ptCurrent[X];
ptGe[Y] = ptCurrent[Y];
pPoly->addVertexAt(index - 1, ptGe);
//
pPoly->setConstantWidth(width);
196
5.2
pPoly->setColorIndex(colorIndex);
pPoly->close();
}
index++;
acdbPointSet(ptCurrent, ptPrevious);
}
//
acedInitGet(NULL, "W C O");
rc = acedGetPoint(ptPrevious,
"\n [(W)/(C)]<(O)>:", ptCurrent);
}
}
acedGetPoint
5.2.4
AutoCAD 2002 ARX AddPoly
: addpoly
:
[(W)/(C)]<(O)>:
[(W)/(C)]<(O)>:w
:2
[(W)/(C)]<(O)>:c
(0256):1
[(W)/(C)]<(O)>:
[(W)/(C)]<(O)>:o
2
197
ADSRX
5.2.5
1
acedGetInt
int acedGetInt(const char * prompt, int * result);
prompt NULL
acedGetReal
acedGetString
int acedGetString(int cronly, const char * prompt, char * result);
cronly 0 1
acedGetDist
acedGetCorner
acedGetPoint
acedGetAngle ANGBASE
acedInitGetacedGetKword acedGetInput
2 acedGetFileD
acedGetFileD AutoCAD
void ZffCHAP5SelectFile()
{
const char* title = "";
const char* path = "C:\\";
struct resbuf *fileName;
198
5.3
fileName = acutNewRb(RTSTR);
if (acedGetFileD(title, path, "dwg;dxf", 0, fileName) == RTNORM)
{
acedAlert(fileName->resval.rstring);
}
acutRelRb(fileName);
}
5.6
5.6
AutoCAD
5.3
5.3.1
ObjectARX AutoCAD
acedGetXX AutoCAD acedEntSel
acedEntSel
199
ADSRX
5.3.2
1
AutoCAD ads_name
acedSSAdd acedSSGet acedSSGet
PICKFIRST
AutoCAD Crossing
Crossing
PolygonFenceLastPrevious
Window
Window Polygon
2
acedSSAdd
acedSSDel
acedSSAdd
int acedSSAdd(const ads_name ename, const ads_name sname, ads_name result);
ename sname result
ename sname acedSSAdd
ename sname
ename sname
ename
ename sname ename
sname
acedSSDel
int acedSSDel(const ads_name ename, const ads_name ss);
ename ss
3
acedSSGet
int acedSSGet (const char *str,
200
5.3
acedSSGet
NULL
pt1 pt1
NULL
AllLast Previous
:$
Prompts supplied
:?
Other callbacks
CP
:D
Duplicates OK
:E
Everything in aperture
PickFirst
:K
Keyword callbacks
:S
WP
201
ADSRX
0 30
//
strcpy(sbuf, "CIRCLE");
rb.resval.rstring = sbuf;
rb.rbnext = NULL; //
//
acedSSGet("X", NULL, NULL, &rb, ssname);
acedSSFree(ssname);
acutRelRb
acutBuildList
0
struct resbuf *rb; //
ads_name ssname;
rb = acutBuildList(RTDXF0, "LINE",
8, "0",
//
//
RTNONE);
// 0
acedSSGet("X", NULL, NULL, rb, ssname);
acutRelRb(rb);
acedSSFree(ssname);
DXF 0 acutBuildList 0
RTDXF0 0
DXF
0Line
Arc
1
2
202
5.3
8
10
60
0 1
62
5.7
DXF
5.3.3
1
VC++ 6.0 ObjectARX SelectionSet
CreateSSet
203
ADSRX
void ZffCHAP5CreateSSet()
{
ads_name sset; //
//
acedSSGet("A", NULL, NULL, NULL, sset);
//
acedSSFree(sset);
}
2
1 SelectEnt
void ZffCHAP5SelectEnt()
{
ads_point pt1, pt2, pt3, pt4;
struct resbuf *pointlist;
//
ads_name ssname;
//
pt1[X] = pt1[Y] = pt1[Z] = 0.0;
pt2[X] = pt2[Y] = 5.0; pt2[Z] = 0.0;
// PICKFIRST
//
acedSSGet(NULL, NULL, NULL, NULL, ssname);
// PickFirst
acedSSGet("I", NULL, NULL, NULL, ssname);
//
acedSSGet("P", NULL, NULL, NULL, ssname);
//
acedSSGet("L", NULL, NULL, NULL, ssname);
// (5,5)
acedSSGet(NULL, pt2, NULL, NULL, ssname);
// (0,0)(5,5)
acedSSGet("W", pt1, pt2, NULL, ssname);
204
5.3
//
pt3[X] = 10.0; pt3[Y] = 5.0; pt3[Z] = 0.0;
pt4[X] = 5.0; pt4[Y] = pt4[Z] = 0.0;
pointlist = acutBuildList(RTPOINT, pt1, RTPOINT, pt2,
RTPOINT, pt3, RTPOINT, pt4, 0);
acedSSGet("WP", pointlist, NULL, NULL, ssname);
// (0,0)(5,5)
acedSSGet("C", pt1, pt2, NULL, ssname);
//
acedSSGet("CP", pointlist, NULL, NULL, ssname);
acutRelRb(pointlist);
//
pt4[Y] = 15.0; pt4[Z] = 0.0;
pointlist = acutBuildList(RTPOINT, pt1, RTPOINT, pt2,
RTPOINT, pt3, RTPOINT, pt4, 0);
acedSSGet("F", pointlist, NULL, NULL, ssname);
acutRelRb(pointlist);
acedSSFree(ssname);
}
acedSSGet CP WP
acutBuildList acedSSGet
205
ADSRX
5.8
3ClassViewCPubFunctionAdd Member
Function 5.9
OKPolyToGeCurve
5.9
CPubFunction::PolyToGeCurve
4 PolyToGeCurve
pPline pGeCurve
206
5.3
int nSegs;
//
//
AcGeVoidPointerArray geCurves;
//
nSegs = pPline->numVerts() - 1;
//
for (int i = 0; i < nSegs; i++)
{
if (pPline->segType(i) == AcDbPolyline::kLine)
{
pPline->getLineSegAt(i, line);
pLine = new AcGeLineSeg2d(line);
geCurves.append(pLine);
}
else if (pPline->segType(i) == AcDbPolyline::kArc)
{
pPline->getArcSegAt(i, arc);
pArc = new AcGeCircArc2d(arc);
geCurves.append(pArc);
}
}
//
if (pPline->isClosed() && pPline->segType(nSegs) ==
AcDbPolyline::kArc)
{
pPline->getArcSegAt(nSegs, arc);
pArc = new AcGeCircArc2d(arc);
pArc->setAngles(arc.startAng(), arc.endAng() (arc.endAng() - arc.startAng()) / 100);
geCurves.append(pArc);
}
207
ADSRX
//
if (geCurves.length() == 1)
{
pGeCurve = (AcGeCurve2d *)geCurves[0];
}
else
{
pGeCurve = new AcGeCompositeCurve2d(geCurves);
}
//
if (geCurves.length() > 1)
{
for (i = 0; i < geCurves.length(); i++)
{
delete geCurves[i];
}
}
return true;
}
*& 2.1
segType
AcGeLineSeg2d AcGeCircArc2d
if (geCurves.length() == 1)
{
pGeCurve = (AcGeCurve2d *)geCurves[0];
}
208
5.3
else
{
pGeCurve = new AcGeCompositeCurve2d(geCurves);
}
1 delete new
3 CPubFunction SelectEntInPoly
4 pPline
ObjectIdArray ObjectId selectMode
CPWPapproxEps
//
//
{
pPline->setClosed(!bClosed);
}
209
ADSRX
//
CPubFunction::PolyToGeCurve(pPline, pGeCurve);
//
AcGePoint2dArray SamplePtArray;
//
AcGeDoubleArray ParamArray;
//
//
// PolyToGeCurve
//
AcGeTol tol;
tol.setEqualPoint(0.01);
AcGePoint2d ptFirst = SamplePtArray[0];
AcGePoint2d ptLast = SamplePtArray[SamplePtArray.length() - 1];
if (ptFirst.isEqualTo(ptLast))
{
SamplePtArray.removeLast();
}
//
struct resbuf *rb;
rb = CPubFunction::BuildRbFromPtArray(SamplePtArray);
// acedSSGet
ads_name ssName;
//
210
//
5.3
}
// ObjectIdArray
long length;
acedSSLength(ssName, &length);
for (i = 0; i < length; i++)
{
// ObjectId
ads_name ent;
acedSSName(ssName, i, ent);
AcDbObjectId objId;
acdbGetObjectId(objId, ent);
//
AcDbEntity *pEnt;
Acad::ErrorStatus es = acdbOpenAcDbEntity(pEnt, objId,
AcDb::kForRead);
//
if (es == Acad::eWasOpenForWrite)
{
continue;
}
ObjectIdArray.append(pEnt->objectId());
pEnt->close();
}
//
acutRelRb(rb);
acedSSFree(ssName);
//
//
return true;
}
selectMode ObjectIdArray
PolyToGeCurve
AcGeCurve2d getSamplePoints
211
ADSRX
AcDbPolyline
getSamplePoints
void getSamplePoints(
double fromParam,
double toParam,
double approxEps,
AcGePoint3dArray& pointArray,
AcGeDoubleArray& paramArray) const;
fromParamtoParamapproxEps
pointArrayfromParamtoParam
paramArraypointArray[2]
Autodesk[3] 5.10
5.10
5.11AB
CD
5.11
212
5.3
acedSSGet
BuildRbFromPtArray
ObjectId
ObjectId
acdbOpenAcDbEntity Acad::eWasOpenForWrite
4 BuildRbFromPtArray
arrPoints
//
//
i1
{
adsPt[X] = arrPoints[i].x;
adsPt[Y] = arrPoints[i].y;
//
nextRb->rbnext = acutBuildList(RTPOINT, adsPt, RTNONE);
213
ADSRX
nextRb = nextRb->rbnext;
}
return retRb;
}
5 SelectEntInPoly
void ZffCHAP5SelectEntInPoly()
{
//
ads_name entName;
ads_point pt;
if (acedEntSel("\n:", entName, pt) != RTNORM)
return;
AcDbObjectId entId;
acdbGetObjectId(entId, entName);
//
AcDbEntity *pEnt;
acdbOpenObject(pEnt, entId, AcDb::kForWrite);
if (pEnt->isKindOf(AcDbPolyline::desc()))
{
AcDbPolyline *pPoly = AcDbPolyline::cast(pEnt);
AcDbObjectIdArray ObjectIdArray; // ID
CPubFunction::SelectEntInPoly(pPoly, ObjectIdArray, "CP", 1);
acutPrintf("\n%d.", ObjectIdArray.length());
}
pEnt->close();
}
3
1 Filter1
void ZffCHAP5Filter1()
{
struct resbuf *rb; //
214
5.3
ads_name ssname;
rb = acutBuildList(RTDXF0, "TEXT",
//
8, "0,1",
1, "*cadhelp*",
//
//
RTNONE);
//
acedSSGet("X", NULL, NULL, rb, ssname);
long length;
acedSSLength(ssname, &length);
acutPrintf("\n:%d", length);
acutRelRb(rb);
acedSSFree(ssname);
}
0 1
cadhelp 0, 1
*mjtd**
cadhelp
AutoCAD 5.12
5.12
2 Filter2
Filter1
rb = acutBuildList(-4, "<OR",
//
215
ADSRX
RTDXF0, "TEXT",
//
RTDXF0, "MTEXT",
//
-4, "OR>",
//
RTNONE);
DXF4 <
> 5.13
5.13
3 Filter3
Filter1
rb = acutBuildList(RTDXF0, "CIRCLE",
//
-4, ">=",
//
40, 30,
//
RTNONE);
30 40
DXF4
5.14AutoCAD
5.14
216
5.3
4 Filter4
rb = acutBuildList(RTDXF0, "CIRCLE", //
-4, ">,>,*",
//
10, pt1,
//
-4, "<,<,*",
//
10, pt2,
//
RTNONE);
pt1 pt2
10
7 Filter5
rb = acutBuildList(1001, "XData", //
RTNONE);
Xdata
5.3.4
AutoCAD 2002 ARX
5.15
00100100
217
ADSRX
5.15
Test2
void ZffCHAP5TEST2()
{
ads_name ssname;
ads_point pt1, pt2;
pt1[X] = pt1[Y] = pt1[Z] = 0;
pt2[X] = pt2[Y] = 100;
pt2[Z] = 0;
// pt1pt2
acedSSGet("C", pt1, pt2, NULL, ssname);
long length;
acedSSLength(ssname, &length);
acutPrintf("\n:%d", length);
acedSSFree(ssname);
}
5.16
5.17Test2
5.18
5.17
218
5.3
5.18
4 3
acedSSGet A
5.3.5
//
AcGePoint2d ptMin, ptMax;
if (!CPubFunction::GetViewPortBound(ptMin, ptMax))
{
return;
}
//
CPubFunction::ZoomExtents();
//
//
CPubFunction::WindowZoom(ptMin, ptMax, 1);
GetViewPortBound
WCS ZoomExtents WindowsZoom
CPubFunction static
::
GetViewPortBound
bool CPubFunction::GetViewPortBound(AcGePoint2d &ptMin, AcGePoint2d &ptMax)
{
219
ADSRX
//
//
double viewHeight;
struct resbuf rbViewSize;
//
220
5.3
VIEWSIZESCREEN VIEWCTR
ZoomExtents 4.4
void CPubFunction::ZoomExtents()
{
AcDbBlockTable *pBlkTbl;
AcDbBlockTableRecord *pBlkTblRcd;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForRead);
pBlkTbl->close();
//
AcDbExtents extent;
extent.addBlockExt(pBlkTblRcd);
pBlkTblRcd->close();
//
ads_point pt[7];
pt[0][X] = pt[3][X] = pt[4][X] = pt[7][X] = extent.minPoint().x;
pt[1][X] = pt[2][X] = pt[5][X] = pt[6][X] = extent.maxPoint().x;
pt[0][Y] = pt[1][Y] = pt[4][Y] = pt[5][Y] = extent.minPoint().y;
pt[2][Y] = pt[3][Y] = pt[6][Y] = pt[7][Y] = extent.maxPoint().y;
pt[0][Z] = pt[1][Z] = pt[2][Z] = pt[3][Z] = extent.maxPoint().z;
pt[4][Z] = pt[5][Z] = pt[6][Z] = pt[7][Z] = extent.minPoint().z;
// DCS
struct resbuf wcs, dcs; //
wcs.restype = RTSHORT;
wcs.resval.rint = 0;
dcs.restype = RTSHORT;
221
ADSRX
dcs.resval.rint = 2;
acedTrans(pt[0], &wcs, &dcs, 0, pt[0]);
acedTrans(pt[1], &wcs, &dcs, 0, pt[1]);
acedTrans(pt[2], &wcs, &dcs, 0, pt[2]);
acedTrans(pt[3], &wcs, &dcs, 0, pt[3]);
acedTrans(pt[4], &wcs, &dcs, 0, pt[4]);
acedTrans(pt[5], &wcs, &dcs, 0, pt[5]);
acedTrans(pt[6], &wcs, &dcs, 0, pt[6]);
acedTrans(pt[7], &wcs, &dcs, 0, pt[7]);
// DCS
double xMax = pt[0][X], xMin = pt[0][X];
double yMax = pt[0][Y], yMin = pt[0][Y];
for (int i = 1; i <= 7; i++)
{
if (pt[i][X] > xMax)
xMax = pt[i][X];
if (pt[i][X] < xMin)
xMin = pt[i][X];
if (pt[i][Y] > yMax)
yMax = pt[i][Y];
if (pt[i][Y] < yMin)
yMin = pt[i][Y];
}
AcDbViewTableRecord view = GetCurrentView();
//
view.setCenterPoint(AcGePoint2d((xMin + xMax) / 2,
(yMin + yMax) / 2));
//
view.setHeight(fabs(yMax - yMin));
view.setWidth(fabs(xMax - xMin));
//
Acad::ErrorStatus es = acedSetCurrentView(&view, NULL);
}
GetCurrentView
222
5.3
AcDbViewTableRecord CPubFunction::GetCurrentView()
{
AcDbViewTableRecord view;
struct resbuf rb;
struct resbuf wcs, ucs, dcs; //
wcs.restype = RTSHORT;
wcs.resval.rint = 0;
ucs.restype = RTSHORT;
ucs.resval.rint = 1;
dcs.restype = RTSHORT;
dcs.resval.rint = 2;
// ""
acedGetVar("VIEWMODE", &rb);
view.setPerspectiveEnabled(rb.resval.rint & 1);
view.setFrontClipEnabled(rb.resval.rint & 2);
view.setBackClipEnabled(rb.resval.rint & 4);
view.setFrontClipAtEye(!(rb.resval.rint & 16));
// UCS
acedGetVar("VIEWCTR", &rb);
acedTrans(rb.resval.rpoint, &ucs, &dcs, 0, rb.resval.rpoint);
view.setCenterPoint(AcGePoint2d(rb.resval.rpoint[X],
rb.resval.rpoint[Y]));
//
acedGetVar("LENSLENGTH", &rb);
view.setLensLength(rb.resval.rreal);
// UCS
acedGetVar("TARGET", &rb);
acedTrans(rb.resval.rpoint, &ucs, &wcs, 0, rb.resval.rpoint);
view.setTarget(AcGePoint3d(rb.resval.rpoint[X],
rb.resval.rpoint[Y], rb.resval.rpoint[Z]));
// UCS
acedGetVar("VIEWDIR", &rb);
223
ADSRX
224
5.3
{
view.setFrontClipDistance(0.0);
view.setBackClipDistance(0.0);
}
return view;
}
WindowZoom
Acad::ErrorStatus CPubFunction::WindowZoom(const AcGePoint2d &ptMin,
const AcGePoint2d &ptMax, double scale)
{
AcDbViewTableRecord view;
AcGePoint2d ptCenter2d((ptMin[X] + ptMax[X]) / 2,
(ptMin[Y] + ptMax[Y]) / 2);
view.setCenterPoint(ptCenter2d);
view.setWidth((ptMax[X] - ptMin[X]) / scale);
view.setHeight((ptMax[Y] - ptMin[Y]) / scale);
Acad::ErrorStatus es = acedSetCurrentView(&view, NULL);
return es;
}
WCS XOY
DXF
void ZffCHAP5EntInfo()
{
acDocManager->sendStringToExecute(acDocManager->curDocumen
t(),
"(entget(car(entsel))) "); //
225
ADSRX
EntInfo
50500 30 EntInfo
5.19
5.19
DXF
.
0. CIRCLE 067. 0 678.
0 8 10
40
OK
226
6.1
6.1
6.1.1
6.1.2
AutoCAD
AutoCAD
16K
AcDbObject setXData
virtual Acad::ErrorStatus
AcDbObject::setXData(const resbuf* xdata);
AcDbObject xData
virtual resbuf*
AcDbObject::xData(const char* regappName = NULL) const;
31
acdbRegApp
227
6.1.3
1 VC++ 6.0 ObjectARX Xdata
AddXData
void ZffCHAP5AddXData()
{
//
ads_name en;
ads_point pt;
if (acedEntSel("\n", en, pt) != RTNORM)
return;
AcDbObjectId entId;
Acad::ErrorStatus es = acdbGetObjectId(entId, en);
//
struct resbuf* pRb;
char appName[] = {"XData"};
char typeName[] = {""};
//
acdbRegApp("XData");
//
pRb = acutBuildList(AcDb::kDxfRegAppName, appName,
//
AcDb::kDxfXdAsciiString, typeName,
//
AcDb::kDxfXdInteger32, 2,
//
AcDb::kDxfXdReal, 3.14,
//
AcDb::kDxfXdWorldXCoord, pt,
RTNONE);
//
AcDbEntity *pEnt;
acdbOpenAcDbEntity(pEnt, entId, AcDb::kForWrite);
228
//
6.1
//
{
acutRelRb(pTemp);
acutPrintf("\n");
}
else
{
pEnt->setXData(pRb);
}
pEnt->close();
acutRelRb(pRb);
}
AcDb::kDxfRegAppName AcDb::kDxfXd
2 ViewXData
void ZffCHAP5ViewXData()
{
//
ads_name en;
ads_point pt;
if (acedEntSel("\n", en, pt) != RTNORM)
return;
AcDbObjectId entId;
Acad::ErrorStatus es = acdbGetObjectId(entId, en);
//
AcDbEntity *pEnt;
acdbOpenAcDbEntity(pEnt, entId, AcDb::kForRead);
struct resbuf *pRb;
pRb = pEnt->xData("XData");
229
pEnt->close();
if (pRb != NULL)
{
//
struct resbuf *pTemp;
pTemp = pRb;
//
pTemp = pTemp->rbnext;
acutPrintf("\n%s",
pTemp->resval.rstring);
pTemp = pTemp->rbnext;
acutPrintf("\n%d", pTemp->resval.rint);
pTemp = pTemp->rbnext;
acutPrintf("\n%.2f",
pTemp->resval.rreal);
pTemp = pTemp->rbnext;
acutPrintf("\n(%.2f, %.2f, %.2f)",
pTemp->resval.rpoint[X], pTemp->resval.rpoint[Y],
pTemp->resval.rpoint[Z]);
acutRelRb(pRb);
}
else
{
acutPrintf("\n");
}
}
AcDbObject xData
6.1.4
1 AutoCAD 2002 LINE AddXData
2 AddXData
230
6.2
3 ViewXData
4 ViewXData
: VIEWXDATA
2
3.14
(561.77, 302.57, 0.00)
6.1.5
6.2
6.2.1
Autodesk
ID
231
6.2.2
createExtensionDictionary
extensionDictionary
AcDbDictionary setAt AcDbXrecord
AcDbXrecord acutBuildList
setFromRbChain
extensionDictionary
getAt
AcDbXrecord
rbChain
2
AutoCAD
AutoCAD
AcDbDatabase getNamedObjectsDictionary
setAt getAt
6.2.3
1 VC++ 6.0 ObjectARX Xrecord
AddXRecord
void ZffCHAP5AddXRecord()
{
//
ads_name en;
ads_point pt;
if (acedEntSel("\n", en, pt) != RTNORM)
return;
232
6.2
// ID
AcDbObjectId entId;
AcDbXrecord setFromRbChain
Acad::ErrorStatus setFromRbChain(
const resbuf& pRb,
AcDbDatabase* auxDb = NULL);
233
pRb *pRb
2 ViewXRecord
Xrecord
void ZffCHAP5VIEWXRECORD()
{
//
ads_name en;
ads_point pt;
if (acedEntSel("\n", en, pt) != RTNORM)
return;
AcDbObjectId entId;
Acad::ErrorStatus es = acdbGetObjectId(entId, en);
// ObjectId
AcDbEntity *pEnt;
acdbOpenAcDbEntity(pEnt, entId, AcDb::kForRead);
AcDbObjectId dictObjId = pEnt->extensionDictionary();
pEnt->close();
//
if (dictObjId == AcDbObjectId::kNull)
{
acutPrintf("\n!");
return;
}
// XRecord
AcDbDictionary *pDict;
AcDbXrecord *pXrec;
acdbOpenObject(pDict, dictObjId, AcDb::kForRead);
pDict->getAt("XRecord", (AcDbObject*&)pXrec, AcDb::kForRead);
pDict->close();
//
struct resbuf *pRb;
pXrec->rbChain(&pRb);
pXrec->close();
234
6.2
if (pRb != NULL)
{
//
struct resbuf *pTemp;
pTemp = pRb;
acutPrintf("\n%s",
pTemp->resval.rstring);
pTemp = pTemp->rbnext;
acutPrintf("\n%d", pTemp->resval.rint);
pTemp = pTemp->rbnext;
acutPrintf("\n%.2f",
pTemp->resval.rreal);
pTemp = pTemp->rbnext;
acutPrintf("\n(%.2f, %.2f, %.2f)",
pTemp->resval.rpoint[X], pTemp->resval.rpoint[Y],
pTemp->resval.rpoint[Z]);
acutRelRb(pRb);
}
}
AcDbXrecord rbChain
Acad::ErrorStatus rbChain(
resbuf** ppRb,
AcDbDatabase* auxDb = NULL) const;
void ZffCHAP5AddNameDict()
{
//
char entType[] = {""};
struct resbuf *pRb;
235
//
AcDbDictionary *pNameObjDict, *pDict;
acdbHostApplicationServices()->workingDatabase()
->getNamedObjectsDictionary(pNameObjDict,
AcDb::kForWrite);
//
AcDbObjectId dictObjId;
if (pNameObjDict->getAt("MyDict", (AcDbObject*&)pDict,
AcDb::kForWrite) == Acad::eKeyNotFound)
{
pDict = new AcDbDictionary;
pNameObjDict->setAt("MyDict", pDict, dictObjId);
pDict->close();
}
pNameObjDict->close();
//
AcDbObjectId xrecObjId;
AcDbXrecord *pXrec = new AcDbXrecord;
acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
pDict->setAt("XRecord", pXrec, xrecObjId);
pDict->close();
//
ads_point pt;
pt[X] = 100;
pt[Y] = 100;
pt[Z] = 0;
pRb = acutBuildList(AcDb::kDxfText, entType,
AcDb::kDxfInt32, 12,
AcDb::kDxfReal, 3.14,
AcDb::kDxfXCoord, pt,
RTNONE);
pXrec->setFromRbChain(*pRb);
pXrec->close();
acutRelRb(pRb);
}
236
6.2
4 ViewNameDict
void ZffCHAP5ViewNameDict()
{
//
AcDbDictionary *pNameObjDict, *pDict;
Acad::ErrorStatus es;
acdbHostApplicationServices()->workingDatabase()
->getNamedObjectsDictionary(pNameObjDict,
AcDb::kForRead);
es = pNameObjDict->getAt("MyDict", (AcDbObject*&)pDict,
AcDb::kForRead);
pNameObjDict->close();
//
if (es == Acad::eKeyNotFound)
return;
//
AcDbXrecord *pXrec;
pDict->getAt("XRecord", (AcDbObject*&)pXrec, AcDb::kForRead);
pDict->close();
//
struct resbuf *pRb;
pXrec->rbChain(&pRb);
pXrec->close();
if (pRb != NULL)
{
//
struct resbuf *pTemp;
pTemp = pRb;
acutPrintf("\n%s",
pTemp->resval.rstring);
pTemp = pTemp->rbnext;
237
acutPrintf("\n%d", pTemp->resval.rint);
pTemp = pTemp->rbnext;
acutPrintf("\n%.2f",
pTemp->resval.rreal);
pTemp = pTemp->rbnext;
acutPrintf("\n(%.2f, %.2f, %.2f)",
pTemp->resval.rpoint[X], pTemp->resval.rpoint[Y],
pTemp->resval.rpoint[Z]);
acutRelRb(pRb);
}
}
6.2.4
1 AutoCAD 2002 ARX AddXRecord
2ViewXRecord
6.1
6.1
3AddNameDict
ViewNameDict
6.2
6.2
ViewXRecordViewNameDict
238
6.3
6.3
6.3
6.2.5
AutoCAD
6.3
6.3.1
AutoCAD Group
ObjectARX
239
6.3.2
ObjectARX
AcDbDatabase
getGroupDictionary
ACAD_GROUP
getAt
AcDbDictionary *pNameDict;
acdbHostApplicationServices()->workingDatabase()
->getNamedObjectsDictionary(pNameDict, AcDb::kForRead);
pNameDict->getAt("ACAD_GROUP", (AcDbObject*&)pGroupDict,
AcDb::kForWrite);
pNameDict->close();
6.3.3
1 VC++ 6.0 ObjectARX Group
AddGroup
void ZffCHAP6AddGroup()
{
//
ads_name sset;
acutPrintf("\n:");
if (acedSSGet(NULL, NULL, NULL, NULL, sset) != RTNORM)
return;
long length;
acedSSLength(sset, &length);
AcDbObjectIdArray objIds;
for (long i = 0; i < length; i++)
{
// ObjectId
ads_name ent;
acedSSName(sset, i, ent);
AcDbObjectId objId;
acdbGetObjectId(objId, ent);
//
240
6.3
AcDbEntity *pEnt;
acdbOpenObject(pEnt, objId, AcDb::kForRead);
objIds.append(pEnt->objectId());
pEnt->close();
}
acedSSFree(sset);
//
char groupName[] = {"MyGroup"};
CreateGroup(objIds, groupName);
}
CreateGroup ObjectId
2 DelGroupMyGroup
void ZffCHAP6DelGroup()
{
//
AcDbDictionary *pGroupDict;
acdbHostApplicationServices()->workingDatabase()
->getGroupDictionary(pGroupDict, AcDb::kForWrite);
241
if (pGroupDict->has("MyGroup"))
{
pGroupDict->remove("MyGroup");
}
pGroupDict->close();
}
6.3.4
1 AutoCAD 2002 ARX AddGroup
Enter
2Group6.4
MyGroup
6.4
3 DelGroup MyGroup
Group
MyGroup
6.3.5
242
6.4
6.4
6.4.1
6.4.2
ACAD_MLINESTYLE AcDbMlineStyle
AcDbMlineStyle
AcDbMlineStyle
1
AcDbMlineStyle *pMlStyle = new AcDbMlineStyle;
2 initMlineStyle
3 setName
4 addElement
Acad::ErrorStatus addElement(
int& index,
double offset,
const AcCmColor & color,
AcDbObjectId linetypeId,
bool checkIfReferenced = true);
index 0offset color
linetypeId checkIfReferenced
AcDbMlineStyle
setElement setFillColor
6.4.3
1 VC++ 6.0 ObjectARX MlineStyle
AddMlStyle
void ZffCHAP6AddMlStyle()
{
//
Acad::ErrorStatus es;
243
es = acdbHostApplicationServices()->workingDatabase()
->loadLineTypeFile("CENTER", "acadiso.lin");
es = acdbLoadLineTypeFile("HIDDEN", "acadiso.lin",
acdbHostApplicationServices()->workingDatabase());
// AcDbMlineStyle
AcDbMlineStyle *pMlStyle = new AcDbMlineStyle;
pMlStyle->initMlineStyle();
pMlStyle->setName("NewStyle");
int index;
//
AcCmColor color; //
AcDbObjectId linetypeId;
// ID
//
color.setColorIndex(1);
//
GetLinetypeId("CENTER", linetypeId);
pMlStyle->addElement(index, 0, color, linetypeId);
//
color.setColorIndex(5);
//
GetLinetypeId("HIDDEN", linetypeId);
pMlStyle->addElement(index, 0.5, color, linetypeId);
//
pMlStyle->addElement(index, -0.5, color, linetypeId);
//
AcDbDictionary *pDict;
acdbHostApplicationServices()->workingDatabase()
->getMLStyleDictionary(pDict, AcDb::kForWrite);
AcDbObjectId mlStyleId;
es = pDict->setAt("NewStyle", pMlStyle, mlStyleId);
pDict->close();
pMlStyle->close();
}
244
6.4
GetLinetypeId ObjectId
2 DelMlStyle AddMlStyle
void ZffCHAP6DelMlStyle()
{
//
AcDbDictionary *pDict;
acdbHostApplicationServices()->workingDatabase()
->getGroupDictionary(pDict, AcDb::kForWrite);
if (pDict->has("NewStyle"))
{
pDict->remove("NewStyle");
}
pDict->close();
}
3 InitApplication
245
void InitApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_INIT
AddCommand("ZFFCHAP6", "ADDMLSTYLE", "ADDMLSTYLE",
ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, ZffCHAP6AddMlStyle);
AddCommand("ZFFCHAP6", "DELMLSTYLE", "DELMLSTYLE",
ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, ZffCHAP6DelMlStyle);
//}}AFX_ARX_INIT
//
acutPrintf("\nAddMlStyle,");
acutPrintf("\nDelMlStyle,");
}
6.4.4
1AutoCAD 2002ARXAutoCAD
6.5
6.5
2 AddMlStyle NewStyle
: _mline
: = = 20.00 = STANDARD
[(J)/(S)/(ST)]: st STEnter
[?]: ?
:
---------------- -----------------246
6.4
NEWSTYLE
STANDARD
[?]: newstyle
: = = 20.00 = NEWSTYLE
[(J)/(S)/(ST)]:
:
[(U)]:
[(C)/(U)]: c
6.6
6.6
3 DelMlStyle NewStyle
6.4.5
247
7
AcDbDatabase AutoCAD AcDbDatabase
AcDbDatabase
DWG
AcDbDatabaseAcApDocument
AutoCAD MDI
AcApDocument AcApDocument
MFC
AcApDocument
AcDbDatabase
7.1
7.1.1
AutoCAD
createDwg
AcDbLineAcDbCircle
11
248
7.1
7.1.2
saveAs dwg
readDwgFile
7.1
AutoCAD
Sub GetAcadPath()
MsgBox Application.FullName
End Sub
249
DWORD dwRet
= ::GetModuleFileName(acedGetAcadWinApp()->m_hInstance,
acadPath.GetBuffer(_MAX_PATH) , _MAX_PATH);
acadPath.ReleaseBuffer();
_MAX_PATH Windows Windows
Windows
regedit
3
readDwgFile AcDbDatabase
applyPartialOpenFilters closeInput
applyPartialOpenFilters
Acad::ErrorStatus applyPartialOpenFilters(
const AcDbSpatialFilter* pSpatialFilter,
const AcDbLayerFilter* pLayerFilter);
pSpatialFilter pLayerFilter
7.1.3
1VC++ 6.0ObjectARXCreateDatabase
Use MFC
MFC 7.2
250
7.1
7.2
MFC
2 CreateDwg AutoCAD
void ZffCHAP7CreateDwg()
{
//
AcDbDatabase *pDb = new AcDbDatabase();
AcDbBlockTable *pBlkTbl;
pDb->getSymbolTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForWrite);
pBlkTbl->close();
//
AcDbCircle *pCir1 = new AcDbCircle(AcGePoint3d(1,1,1),
AcGeVector3d(0,0,1), 1.0);
AcDbCircle *pCir2 = new AcDbCircle(AcGePoint3d(4,4,4),
AcGeVector3d(0,0,1), 2.0);
pBlkTblRcd->appendAcDbEntity(pCir1);
pCir1->close();
251
pBlkTblRcd->appendAcDbEntity(pCir2);
pCir2->close();
pBlkTblRcd->close();
CString acadPath;
GetAcadPath(acadPath);
// acad.exe
// "acad.exe"AutoCAD
acadPath = acadPath.Left(acadPath.GetLength() - 8);
CString filePath = acadPath + "test.dwg";
// saveAsdwg
pDb->saveAs(filePath.GetBuffer(0));
filePath.ReleaseBuffer();
delete pDb;
// pDb
filePath
AcDbDatabase saveAs const char*
CString GetBuffer(0) CString
saveAs GetBuffer ReleaseBuffer
GetAcadPath AutoCAD
acad.exe
bool GetAcadPath(CString &acadPath)
{
DWORD dwRet
= ::GetModuleFileName(acedGetAcadWinApp()->m_hInstance,
acadPath.GetBuffer(_MAX_PATH) , _MAX_PATH);
acadPath.ReleaseBuffer();
if (dwRet == 0)
{
return false;
}
else
{
return true;
252
7.1
}
}
DWORD Win32 32
void ZffCHAP7ReadDwg()
{
// kFalse
//
AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);
// AcDbDatabase::readDwgFile()dwg
CString acadPath;
GetAcadPath(acadPath);
// "acad.exe"
acadPath = acadPath.Left(acadPath.GetLength() - 8);
CString filePath = acadPath + "test.dwg";
pDb->readDwgFile(filePath.GetBuffer(0));
filePath.ReleaseBuffer();
//
bool bRet = PartialOpenDatabase(pDb);
//
AcDbBlockTable *pBlkTbl;
pDb->getSymbolTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd,
AcDb::kForRead);
pBlkTbl->close();
AcDbBlockTableRecordIterator *pBlkTblRcdItr;
pBlkTblRcd->newIterator(pBlkTblRcdItr);
//
AcDbEntity *pEnt;
for (pBlkTblRcdItr->start(); !pBlkTblRcdItr->done();
253
pBlkTblRcdItr->step())
{
pBlkTblRcdItr->getEntity(pEnt,
AcDb::kForRead);
acutPrintf(": %s\n",
(pEnt->isA())->name());
pEnt->close();
//
}
pBlkTblRcd->close();
delete pBlkTblRcdItr;
delete pDb;
}
PartialOpenDatabase
PartialOpenDatabase
bool PartialOpenDatabase(AcDbDatabase *pDb)
{
if (pDb == NULL)
return false;
//
ads_point pt1, pt2;
pt1[X] = 0.0;
pt1[Y] = 0.0;
pt1[Z] = 0.0;
pt2[X] = 100.0;
pt2[Y] = 100.0;
pt2[Z] = 0.0;
//
AcGeVector3d normal;
//
254
7.1
// WCS
rbTo.restype = RT3DPOINT;
rbTo.resval.rpoint[0] = normal[0];
rbTo.resval.rpoint[1] = normal[1];
rbTo.resval.rpoint[2] = normal[2];
acedTrans(pt1, &rbFrom, &rbTo, FALSE, pt1);
acedTrans(pt2, &rbFrom, &rbTo, FALSE, pt2);
//
AcGePoint2dArray array;
array.append(AcGePoint2d(pt1[0], pt1[1]));
array.append(AcGePoint2d(pt2[0], pt2[1]));
AcDbSpatialFilter spatialFilter;
spatialFilter.setDefinition(
array,
normal,
pt1[Z],
ACDB_INFINITE_XCLIP_DEPTH,
-ACDB_INFINITE_XCLIP_DEPTH,
Adesk::kTrue);
//
AcDbLayerFilter layerFilter;
layerFilter.add("Circle");
layerFilter.add("Line");
//
Acad::ErrorStatus es;
es = pDb->applyPartialOpenFilters(&spatialFilter, &layerFilter);
if ((es == Acad::eOk) && pDb->isPartiallyOpened())
{
pDb->closeInput();
return true;
}
else
{
255
return false;
}
}
0001001000VIEWDIR
AcGeVector3d
ECS acedTrans
pt1 pt2 WCS ECS AcGePoint2dArray
AcDbSpatialFilter setDefinition
Acad::ErrorStatus setDefinition(
const AcGePoint2dArray& pts,
const AcGeVector3d& normal,
double elevation,
double frontClip,
double backClip,
Adesk::Boolean enabled);
pts
normal elevation normal
pts frontClip backClip
enabled
PartialOpenDatabase setDefinition
spatialFilter.setDefinition(
array,
normal,
pt1[Z],
ACDB_INFINITE_XCLIP_DEPTH,
-ACDB_INFINITE_XCLIP_DEPTH,
Adesk::kTrue);
arraynormal pt[Z]
ACDB_INFINITE_XCLIP_DEPTH ObjectARX
1.0e+300 pt1pt2
AcDbLayerFilter
7.1.4
1 AutoCAD 2002 ARX CreateDwg
test.dwg ZOOM E
256
7.1
2CircleLine,
7.3
7.3
3Rectangle00100100
LineCircle
LineCircle 7.4
test.dwg
7.4
4ReadDwg 7.5
257
7.5
1
2
Circle Line
7.1.5
AutoCAD
CString
7.2
7.2.1
Windows
AutoCAD
ObjectARX
AcDbDatabase wblock insert
7.2.2
1wblock
AcDbDatabase wblock
Acad::ErrorStatus wblock(
AcDbDatabase*& pOutputDb,
const AcDbObjectIdArray& outObjIds,
const AcGePoint3d& basePoint);
Acad::ErrorStatus wblock(AcDbDatabase*& pOutputDb);
Acad::ErrorStatus wblock(AcDbDatabase*& pOutputDb, AcDbObjectId blockId);
AutoCAD WBLOCK
258
7.2
outObjIds AcDbEntity
wblock
2insert
insert
Acad::ErrorStatus insert(
AcDbObjectId& blockId,
const char* pBlockName,
AcDbDatabase* pDb,
bool preserveSourceDatabase = true);
Acad::ErrorStatus insert(
const AcGeMatrix3d& xform,
AcDbDatabase* pDb,
bool preserveSourceDatabase = true);
Acad::ErrorStatus insert(
AcDbObjectId& blockId,
const char* pSourceBlockName,
const char* pDestinationBlockName,
AcDbDatabase* pDb,
bool preserveSourceDatabase = true);
pDestinationBlockName
pSourceBlockName
pDestinationBlockName
3
wblock insert
wblock
insert
wblock
259
7.2.3
VC++ 6.0 ObjectARX Wblock
ImportBlkDef
void ZffCHAP7ImportBlkDef()
{
//
AcDbDatabase pExternalDb(Adesk::kFalse); //
struct resbuf *rb;
rb = acutNewRb(RTSTR);
if (RTNORM != acedGetFileD("", NULL, "dwg", 0,
rb))
{
acutRelRb(rb);
//
return;
}
if (Acad::eOk != pExternalDb.readDwgFile(rb->resval.rstring))
{
acedAlert("DWG!");
acutRelRb(rb);
//
return;
}
acutRelRb(rb);
// Blk
AcDbBlockTable* pBlkTbl;
if (Acad::eOk != pExternalDb.getBlockTable(pBlkTbl, AcDb::kForRead))
{
acedAlert( "!" );
return;
}
AcDbBlockTableRecord* pBlkTblRcd;
Acad::ErrorStatus es = pBlkTbl->getAt(_T("Blk"), pBlkTblRcd, AcDb::kForRead);
pBlkTbl->close();
if (Acad::eOk != es) {
acedAlert("!");
return;
}
260
7.2
//
AcDbBlockReferenceIdIterator *pItr;
if (Acad::eOk != pBlkTblRcd->newBlockReferenceIdIterator(pItr))
{
acedAlert("!");
pBlkTblRcd->close();
return;
}
// ObjectId
//
AcDbObjectIdArray list;
//
// list
if (Acad::eOk != pExternalDb.wblock( pTempDb, list, AcGePoint3d::kOrigin ))
{
acedAlert("wblock!");
return;
}
//
if (Acad::eOk != acdbHostApplicationServices()->workingDatabase()
->insert(AcGeMatrix3d::kIdentity, pTempDb))
acedAlert("insert!");
261
delete pTempDb;
//
ads_name lastEnt;
if (acdbEntLast(lastEnt) != RTNORM)
{
acedAlert("!");
return;
}
AcDbObjectId entId;
es = acdbGetObjectId(entId, lastEnt);
AcDbEntity *pEnt;
es = acdbOpenAcDbEntity(pEnt, entId, AcDb::kForWrite);
pEnt->erase();
pEnt->close();
}
list Blk
AcGePoint3d::kOrigin AcGeMatrix3d::kIdentity
0 4 3 AcGeMatrix3d
7.2.4
1 AutoCAD 2002 ARX
Blk Blk test.dwg
2ImportBlkDef 7.6
test.dwg
7.6
262
7.3
3Insert 7.7
BlkBlk
7.7
7.2.5
wblock
insert
acdbEntLast acdbGetObjectId
AcGePoint3d::kOrigin AcGeMatrix3d::kIdentity
7.3
7.3.1
AutoCAD
ObjectARX docsamps\longtrans
263
7.3.2
1 AcDbObjectIdArray ObjectId
2 checkOut
3
4 checkIn
7.3.3
VC++ 6.0 ObjectARX LongTransaction
BlockEditBlk
void ZffCHAP7BlockEdit()
{
//
AcDbBlockTable *pBlkTbl;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlkTbl, AcDb::kForRead);
AcDbBlockTableRecord *pBlkTblRcd; // Blk
pBlkTbl->getAt("Blk", pBlkTblRcd, AcDb::kForWrite);
AcDbObjectIdArray objIdArray;
//
AcDbBlockTableRecordIterator *pItr;
//
pBlkTblRcd->newIterator(pItr);
// objIdArray
for (pItr->start(); !pItr->done(); pItr->step())
{
AcDbEntity *pEnt;
pItr->getEntity(pEnt, AcDb::kForRead);
if (pEnt->isKindOf(AcDbCircle::desc()))
{
objIdArray.append(pEnt->objectId( ));
}
264
7.3
pEnt->close();
}
delete pItr;
pBlkTblRcd->close();
//
AcDbBlockTableRecord *pModelSpaceRcd;
pBlkTbl->getAt(ACDB_MODEL_SPACE, pModelSpaceRcd,
AcDb::kForWrite);
pBlkTbl->close();
AcDbObjectId id = pModelSpaceRcd->objectId();
//
ObjectId
pModelSpaceRcd->close();
//
AcDbObjectId transId;
// ObjectId
AcDbIdMapping errorMap;
// ObjectId
//
acapLongTransactionManagerPtr()->checkOut(transId, objIdArray,
id, errorMap);
//
AcDbObject *pObj;
//
265
pWorkSetIter->step())
{
AcDbEntity *pEnt;
acdbOpenObject(pEnt, pWorkSetIter->objectId(),
AcDb::kForWrite);
pEnt->setColorIndex(1);
pEnt->close();
}
delete pWorkSetIter;
}
pObj->close();
}
//
char strInput[100];
acedGetString(0, "\nEnter...",
strInput);
//
acapLongTransactionManagerPtr()->checkIn(transId, errorMap);
}
7.3.4
1 AutoCAD 2002 ARX
Blk
Blk
2BlockEditObjectIdArray
7.8
266
7.4
7.8
3 Enter
7.3.5
AutoCAD
7.4
7.4.1
AutoCAD AutoCAD
ObjectARX
ObjectARX
7.4.2
AcDbDatabaseSummaryInfo
acdbGetSummaryInfo
acdbPutSummaryInfo
DWGPROPS
DWGPROPS
267
7.4.3
VC++ 6.0 ObjectARX SummaryInfo
SaveSummaryInfo
void ZffCHAP7SaveSummaryInfo()
{
// acsiobj.arx
if (!acrxDynamicLinker->loadModule("acsiobj.arx", 0))
{
acedAlert("SummaryInfo!");
return;
}
//
if (HasSummaryInfo())
return;
AcDbDatabase *pDb;
pDb = acdbHostApplicationServices()->workingDatabase();
//
AcDbDatabaseSummaryInfo *pInfo;
Acad::ErrorStatus es;
es = acdbGetSummaryInfo(pDb, pInfo);
pInfo->setAuthor("Afanto");
pInfo->setComments("The drawing is used for the ARX book.");
pInfo->addCustomSummaryInfo("Size", "A4");
pInfo->addCustomSummaryInfo("Language", "Chinese");
pInfo->setHyperlinkBase("http://www.cadhelp.net");
pInfo->setKeywords("ObjectARX");
pInfo->setLastSavedBy("cadhelp");
pInfo->setRevisionNumber("Version 1.0");
pInfo->setSubject("Development");
pInfo->setTitle("Development of ObjectARX");
//
es = acdbPutSummaryInfo(pInfo);
}
HasSummaryInfo
268
7.4
bool HasSummaryInfo()
{
AcDbDictionary *pDict;
acdbHostApplicationServices()->workingDatabase()
->getNamedObjectsDictionary(pDict, AcDb::kForRead);
// "DWGPROPS"
if (!pDict->has("DWGPROPS"))
{
pDict->close();
return false;
}
pDict->close();
return true;
}
7.4.4
AutoCAD 2002ARXSaveSummaryInfo
7.9
7.9
269
7.4.5
acdbGetSummaryInfo
AcDbDatabaseSummaryInfo acdbPutSummaryInfo
270
8.1
8 ObjectARX MFC
ObjectARX MFC
ObjectARX ObjectARX MFC
AutoCAD
ObjectARX
MFC
8.1
8.1.1
ObjectARX MFC ObjectARX AcUi
MFC ObjectARX
AutoCAD
MFC ObjectARX
ObjectARX AutoCAD
AutoCAD
8.1.2
ObjectARX
CDialog CDialog DoModal
ObjectARX AcUi AutoCAD
MFC AutoCAD
ObjectARX ObjectARX
8.1.3
1 MFC
1VC++ 6.0ObjectARXModalDialog
MFCInsert/ResourceInsert Resource
271
ObjectARX MFC
8.1DialogNew
8.1
2Enter
8.2IDIDIDD_MFC_MODALCaption
MFCFont
9
8.2
ID
272
8.1
8.3
4View/ClassWizardCtrl+W
8.4IDD_MFC_MODAL
8.4
273
ObjectARX MFC
8.5
8.6
7 MfcModal
void ZffCHAP12MfcModal()
274
8.1
{
// MFC
CMfcDialog theDialog;
if (theDialog.DoModal() == IDOK)
{
AfxMessageBox(_T(""));
}
}
8 ZffCHAP12MfcModal ModalDialogCommands.cpp
CMfcDialog
#include "MfcDialog.h"
CMfcDialog MfcDialog.h
#include "Resource.h"
2 ObjectARX MFC
1 ID IDD_ARX_MODAL
ObjectARX MFC 9
OK Cancel
2 2 4 4 8.7
2 IDIDC_BUTTON_POINTIDC_BUTTON_ANGLE4
ID IDC_EDIT_XPT IDC_EDIT_YPT IDC_EDIT_ZPT
IDC_EDIT_ANGLE
8.7
2 StylesOwner draw
8.8
275
ObjectARX MFC
8.8
Owner draw
3ObjectARXObjectARX
MFC Support 8.9NameCArxDialog
CAcUiDialogCreate ClassCArxDialog
OK
8.9
ObjectARX
4Ctrl+WMFC
ClassWizard Member Variables
IDC_BUTTON_ANGLE 8.10Add Member Variable
CategoryAutoCAD ControlVariable type
CAcUiPickButtonm_btnAngleOK
276
8.1
8.10
CArxDialog m_btnAngle
5 2 4
8.11
8.11
6Message MapsIDCArxDialog
WM_INITDIALOGOnInitDialog
OnClose
277
ObjectARX MFC
OnButtonAngle OnButtonPoint 4
OnKillfoucsEditAngleOnKillfoucsEditXPtOnKillfoucsEditYPtOnKillfoucsEditZPt
8.12OKMFC ClassWizard
8.12
7 CArxDialog 4
CString m_strAngle;
CString m_strZPt;
CString m_strYPt;
CString m_strXPt;
8 OnInitDialog
BOOL CArxDialog::OnInitDialog()
{
CAcUiDialog::OnInitDialog();
//
m_editXPt.SetRange(-100.0, 100.0);
m_editYPt.SetRange(-100.0, 100.0);
m_editZPt.SetRange(-100.0, 100.0);
278
8.1
//
m_editAngle.SetRange(0.0, 90.0);
//
m_btnPick.AutoLoad();
m_btnAngle.AutoLoad();
//
m_strAngle = "0.0";
m_strXPt = "0.0";
m_strYPt = "0.0";
m_strZPt = "0.0";
//
DisplayPoint();
DisplayAngle();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return
FALSE
}
SetRange Validate
AutoLoad
DisplayPoint DisplayAngle
void CArxDialog::DisplayPoint()
{
//
m_editXPt.SetWindowText(m_strXPt);
m_editXPt.Convert(); //
m_editYPt.SetWindowText(m_strYPt);
m_editYPt.Convert();
m_editZPt.SetWindowText(m_strZPt);
m_editZPt.Convert();
}
void CArxDialog::DisplayAngle()
{
//
m_editAngle.SetWindowText(m_strAngle);
279
ObjectARX MFC
m_editAngle.Convert();
}
void CArxDialog::OnButtonPoint()
{
// AutoCAD
BeginEditorCommand();
//
ads_point pt;
if (acedGetPoint(NULL, "\n:", pt) == RTNORM)
{
//
CompleteEditorCommand();
m_strXPt.Format("%.2f", pt[X]);
m_strYPt.Format("%.2f", pt[Y]);
m_strZPt.Format("%.2f", pt[Z]);
//
DisplayPoint();
}
else
{
//
CancelEditorCommand();
}
}
BeginEditorCommand AutoCAD
CompleteEditorCommand AutoCAD
CancelEditorCommand AutoCAD
AutoCAD
10
void CArxDialog::OnButtonAngle()
{
280
8.1
// AutoCAD
BeginEditorCommand();
//
ads_point pt;
acdbDisToF(m_strXPt, -1, &pt[X]);
acdbDisToF(m_strYPt, -1, &pt[Y]);
acdbDisToF(m_strZPt, -1, &pt[Z]);
//
double angle;
const double PI = 4 * atan(1);
if (acedGetAngle(pt, "\n:", &angle) == RTNORM)
{
//
CompleteEditorCommand();
//
m_strAngle.Format("%.2f", angle * (180.0/PI));
//
DisplayAngle();
}
else
{
//
CancelEditorCommand();
}
}
acdbDisToF
int acdbDisToF(
const char * str,
int unit,
ads_real * v);
281
ObjectARX MFC
void CArxDialog::OnKillfocusEditAngle()
{
//
m_editAngle.Convert();
m_editAngle.GetWindowText(m_strAngle);
}
void CArxDialog::OnKillfocusEditXpt()
{
//
m_editXPt.Convert();
m_editXPt.GetWindowText(m_strXPt);
}
void CArxDialog::OnKillfocusEditYpt()
{
//
m_editYPt.Convert();
m_editYPt.GetWindowText(m_strYPt);
}
void CArxDialog::OnKillfocusEditZpt()
{
//
m_editZPt.Convert();
m_editZPt.GetWindowText(m_strZPt);
}
Convert GetWindowText
m_strXPt
12 AutoCAD
void CArxDialog::OnClose()
{
// AutoCAD
double x = atof(m_strXPt);
double y = atof(m_strYPt);
double z = atof(m_strZPt);
acutPrintf("\n(%.2f, %.2f, %.2f).", x, y, z);
282
8.1
CAcUiDialog::OnClose();
}
atof CString
const char*
13 ArxModal
void ZffCHAP12ArxModal()
{
//
CAcModuleResourceOverride resOverride;
// ObjectARX
CArxDialog theDialog;
theDialog.DoModal();
}
ObjectARX
AutoCAD
CAcModuleResourceOverride resOverride;
14 ZffCHAP12ArxModal CArxDialog
#include ArxDialog.h
8.1.4
1AutoCAD 2002ARXMfcModal
8.13
8.13 MFC
2 8.14
283
ObjectARX MFC
8.14
3ArxModal 8.15
:
8.15 ObjectARX
4
(517.14, 233.77, 0.00).
8.1.5
AutoCAD
AutoCAD
CString double
8.2
8.2.1
AutoCAD
AutoCAD8.16
284
8.2
8.16
8.2.2
ObjectARX
DestroyWindow PostNcDestroy
8.2.3
1VC++ 6.0ObjectARXModelessDialog
MFC8.17
285
ObjectARX MFC
8.17
ID IDD_DIALOG_MODELESS ID
IDC_BUTTON_PICK_ST IDC_BUTTON_PICK_ENStyles
Owner draw ID IDD_BUTTON_LINE
IDC_BUTTON_CLOSE(&C) ID
IDC_EDIT_STXIDC_EDIT_STYIDC_EDIT_STZIDC_EDIT_ENXIDC_EDIT_ENY
IDC_EDIT_ENZ
2 ObjectARX ObjectARX MFC Support
CAcUiDialog CModelessDlg
3Ctrl+WMFC ClassWizardMember Variables
IDIDC_EDIT_ENX8.18Category
ValueVariable typeCStringm_strEnX
OKm_strEnX
8.18 CString
45
8.19
286
8.2
8.19
5
CacUiPickButton
6MFC ClassWizardMessage Maps
Object IDs
IDMessagesBN_CLICKED
OK
7 PostNcDestroy
OverWriteOverLoadObject IDs
CModelessDlgMessagesWM_CLOSE
WM_INITIDIALOG
8.20
287
ObjectARX MFC
8.20
ObjectARX
OnAcadKeepFocus
8 ModelessDialog.cpp acrxEntryPoint
pDialog ModelessDlg.h pDialog
_hdllInstance
#include "ModelessDlg.h"
HINSTANCE _hdllInstance =NULL ;
CModelessDlg *pDialog = NULL;
//
9 ObjectARX ModelessDlg
ModelessDlg.h pDialog
#include "StdAfx.h"
#include "StdArx.h"
#include "ModelessDlg.h"
extern CModelessDlg *pDialog;
// This is command 'MODELESSDLG'
void ZffCHAP12ModelessDlg()
{
288
8.2
CAcModuleResourceOverride resOverride;
//
if (pDialog == NULL)
{
pDialog = new CModelessDlg(acedGetAcadFrame());
pDialog->Create(IDD_DIALOG_MODELESS);
pDialog->ShowWindow(SW_SHOW);
}
else
{
pDialog->ShowWindow(SW_SHOW);
}
}
CAcModuleResourceOverride resOverride;
pDialog
NULL Create ShowWindow
Esc
pDialog NULL
pDialog NULL
ShowWindow
10
BOOL CModelessDlg::OnInitDialog()
{
CAcUiDialog::OnInitDialog();
//
m_btnPickEnd.AutoLoad();
m_btnPickStart.AutoLoad();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return
FALSE
}
CModelessDlg CAcUiDialog
11
289
ObjectARX MFC
DestroyWindow
void CModelessDlg::OnButtonClose()
{
//
DestroyWindow();
}
DestroyWindow CWindow MFC CAcUiDialog
CModelessDlg
12
PostNcDestroy
void CModelessDlg::PostNcDestroy()
{
//
delete this;
if (pDialog != NULL)
{
pDialog = NULL;
}
CAcUiDialog::PostNcDestroy();
}
pDialog ModelessDlg.cpp
heap
static
13
DestroyWindow
void CModelessDlg::OnClose()
290
8.2
{
CAcUiDialog::OnClose();
//
DestroyWindow();
}
14 AutoCAD
ModelessDialog.cpp
CloseDialog
BOOL CloseDialog()
{
if (pDialog == NULL)
{
return TRUE;
}
BOOL bRet = pDialog->DestroyWindow();
if (bRet)
{
pDialog = NULL;
}
return bRet;
}
UnloadApplication CloseWindow
void UnloadApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_EXIT
acedRegCmds->removeGroup("ZFFCHAP12");
//}}AFX_ARX_EXIT
// TODO: clean up your application
CloseDialog();
//
15
291
ObjectARX MFC
void CModelessDlg::OnButtonPickEn()
{
// AutoCAD
BeginEditorCommand();
//
ads_point pt;
if (acedGetPoint(NULL, "\n:", pt) == RTNORM)
{
//
CompleteEditorCommand();
m_strEnX.Format("%.2f", pt[X]);
m_strEnY.Format("%.2f", pt[Y]);
m_strEnZ.Format("%.2f", pt[Z]);
}
else
{
//
CancelEditorCommand();
}
//
UpdateData(FALSE);
}
void CModelessDlg::OnButtonPickSt()
{
// AutoCAD
BeginEditorCommand();
//
ads_point pt;
if (acedGetPoint(NULL, "\n:", pt) == RTNORM)
{
//
CompleteEditorCommand();
m_strStX.Format("%.2f", pt[X]);
m_strStY.Format("%.2f", pt[Y]);
m_strStZ.Format("%.2f", pt[Z]);
292
8.2
}
else
{
//
CancelEditorCommand();
}
//
UpdateData(FALSE);
}
16
void CModelessDlg::OnButtonLine()
{
//
AcGePoint3d ptStart(atof(m_strStX), atof(m_strStY), atof(m_strStZ));
AcGePoint3d ptEnd(atof(m_strEnX), atof(m_strEnY), atof(m_strEnZ));
//
acDocManager->lockDocument(curDoc());
AcDbLine *pLine = new AcDbLine(ptStart, ptEnd);
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlockTable, AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
AcDb::kForWrite);
AcDbObjectId lineId;
pBlockTableRecord->appendAcDbEntity(lineId, pLine);
pBlockTable->close();
pBlockTableRecord->close();
pLine->close();
//
acDocManager->unlockDocument(curDoc());
293
ObjectARX MFC
acDocManager->lockDocument(curDoc());
acDocManager->unlockDocument(curDoc());
acDocManager curDoc
8.2.4
1AutoCAD 2002ARXModelessDlg
8.21
8.21
8.2.5
Esc
294