?? acrxentrypoint.cpp
字號:
// (C) Copyright 2002-2005 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//-----------------------------------------------------------------------------
//----- acrxEntryPoint.h
//-----------------------------------------------------------------------------
#include "StdAfx.h"
#include "resource.h"
#include "WidthSetup.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("MSL")
double thick_width(0), thin_width(0);
//-----------------------------------------------------------------------------
//----- ObjectARX EntryPoint
class CToPline6App : public AcRxArxApp {
private:
public:
CToPline6App () : AcRxArxApp () {}
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
// TODO: Load dependencies here
// You *must* call On_kInitAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
// TODO: Add your initialization code here
return (retCode) ;
}
virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
// TODO: Add your code here
// You *must* call On_kUnloadAppMsg here
AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
// TODO: Unload dependencies here
return (retCode) ;
}
virtual void RegisterServerComponents () {
}
// ----- MSLToPline6.widthsetup command
static void MSLToPline6widthsetup(void)
{
// Add your code for command MSLToPline6.topline here
CWidthSetup setupdialog;
setupdialog.DoModal();
thick_width = setupdialog.thick_width;
thin_width = setupdialog.thin_width;
acutPrintf("%f,%f\n",thick_width,thin_width);
//檢查每個實體的線型,對于實線,用粗線; 點畫線,虛線等用細線
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices() -> workingDatabase() -> getSymbolTable(pBlockTable,AcDb::kForRead);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable -> getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForRead);
pBlockTable -> close();
AcDbBlockTableRecordIterator *pBlockIterator;
pBlockTableRecord -> newIterator(pBlockIterator);
char *LayerName;
AcDbLayerTable * pLayerTbl;//定義層表指針
AcDbLayerTableRecord * pLayerTblRcd; //定義層表記錄指針
AcDbLinetypeTable *pLinetypeTbl; //定義線型表指針
AcDbObjectId ContinuousId;
//以讀方式打開層表,獲得層表指針
acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForRead);
//以讀方式打開線型表,獲得線型指針
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLinetypeTbl,AcDb::kForRead);
pLinetypeTbl -> getAt("CONTINUOUS",ContinuousId); //獲得實線的Id
pLinetypeTbl -> close();
for(; !pBlockIterator -> done(); pBlockIterator -> step()) {
//AcDbPolyline *pEntity;
AcDbEntity *pEntity;
AcDbPolyline *pPolyline = NULL;
AcDbObject *pObj;
pBlockIterator -> getEntity(pEntity, AcDb::kForRead);
const char *linetype = pEntity -> linetype();
if(strcmp(linetype,"ByLayer")==0) { //若某實體的線型為ByLayer
//1.獲得該實體所在層的層名
LayerName = pEntity -> layer();
//2.利用層名獲得層表記錄指針pLayerTblRcd
if (pLayerTbl->getAt(LayerName,pLayerTblRcd,AcDb::kForRead)==Acad::eOk)
{
AcDbObjectId linetypeId = pLayerTblRcd -> linetypeObjectId();
if(linetypeId == ContinuousId) { //若該層為實線,即continuous,該實體為粗線
ads_name ent;
if(Acad::eOk != acdbGetAdsName(ent,pEntity->objectId())) return;
pEntity ->close();
acedCommand(RTSTR,"PEDIT",RTENAME,ent,RTSTR,"W",RTREAL,thick_width,RTSTR,"",0);
}
else {
ads_name ent;
if(Acad::eOk != acdbGetAdsName(ent,pEntity->objectId())) return;
pEntity ->close();
acedCommand(RTSTR,"PEDIT",RTENAME,ent,RTSTR,"W",RTREAL,thin_width,RTSTR,"",0);
}
}
}
else if(strcmp(linetype,"ByBlock")==0) { //若某實體的線型為ByBlock
}
else if(strcmp(linetype,"Continuous")==0) {
ads_name ent;
if(Acad::eOk != acdbGetAdsName(ent,pEntity->objectId())) return;
pEntity ->close();
acedCommand(RTSTR,"PEDIT",RTENAME,ent,RTSTR,"W",RTREAL,thick_width,RTSTR,"",0);
}
else {
ads_name ent;
if(Acad::eOk != acdbGetAdsName(ent,pEntity->objectId())) return;
pEntity ->close();
acedCommand(RTSTR,"PEDIT",RTENAME,ent,RTSTR,"W",RTREAL,thin_width,RTSTR,"",0);
}
AcDb::LineWeight lineweight = pEntity -> lineWeight();
acutPrintf("linetype %s.\n", linetype);
acutPrintf("Line Weight %d\n",lineweight);
pEntity -> close();
pLayerTbl ->close();
}
delete pBlockIterator;
pBlockTableRecord -> close();
acutPrintf("\n");
}
// - MSLToPline6.topline command (do not rename)
static void MSLToPline6topline(void)
{
// Add your code for command MSLToPline6.topline here
//首先獲取當前圖形中的所有實體
struct resbuf rb1,rb2;
ads_point LeftDownPts,RightUpPts;
ads_name ssname;
int rt;
acedCommand(RTSTR,"ZOOM",RTSTR,"ALL",0);
acedGetVar("EXTMAX",&rb1); //獲取當前圖形右上角點坐標
acedGetVar("EXTMIN",&rb2); //獲取當前圖形左下角點坐標
ads_point_set(rb1.resval.rpoint,RightUpPts);
ads_point_set(rb2.resval.rpoint,LeftDownPts);
double deltax = (RightUpPts[X] - LeftDownPts[X]) / 10;
double deltay = (RightUpPts[Y] - LeftDownPts[Y]) / 10;
RightUpPts[X] += deltax;
RightUpPts[Y] += deltay;
LeftDownPts[X] -= deltax;
LeftDownPts[Y] -= deltay;
rt=acedSSGet("C",RightUpPts,LeftDownPts,NULL,ssname);
if(rt!=RTNORM) {
acdbFail("實體選擇集構造失敗");
return;
}
//為了利用boundary命令獲取外邊界輪廓,構造一包圍盒
ads_point pts;
pts[X] = LeftDownPts[X] + 1;
pts[Y] = LeftDownPts[Y] + 1;
acedCommand(RTSTR,"_RECTANG",RT3DPOINT,LeftDownPts,RT3DPOINT,RightUpPts,0);
//獲取圖形中的最后一個實體
ads_name LastName;
if(acdbEntLast(LastName) != RTNORM) {
acdbFail("No entities in drawing\n");
return ;
}
acedCommand(RTSTR,"-BOUNDARY",RTSTR,"A",RTSTR,"I",RTSTR,"Y",RTSTR,"O",RTSTR,"P",RTSTR,"",RT3DPOINT,pts,RTSTR,"",0);
acedCommand(RTSTR,"ERASE",RTENAME,LastName,RTSTR,"",0); //刪除包圍盒
if(acdbEntLast(LastName) != RTNORM) {
acdbFail("No entities in drawing\n");
return ;
}
acedCommand(RTSTR,"ERASE",RTENAME,LastName,RTSTR,"",0); //刪除沿包圍盒生成的多段線
//將其他剩余實體生成不合并的多段線
acedCommand(RTSTR,"PEDIT",RTSTR,"M",RTSTR,"C",RT3DPOINT,RightUpPts,RT3DPOINT,LeftDownPts,RTSTR,"",RTSTR,"Y",RTSTR,"",0);
//將指定內孔生成合并的多段線
/*acutPrintf("用鼠標點選內孔:");
acedCommand(RTSTR,"-BOUNDARY",RTSTR,"A",RTSTR,"O",RTSTR,"P",RTSTR,"",0);*/
}
} ;
//-----------------------------------------------------------------------------
IMPLEMENT_ARX_ENTRYPOINT(CToPline6App)
ACED_ARXCOMMAND_ENTRY_AUTO(CToPline6App, MSLToPline6, widthsetup, widthsetup, ACRX_CMD_TRANSPARENT, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CToPline6App, MSLToPline6, topline, topline, ACRX_CMD_TRANSPARENT, NULL)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -