|
// Date: Nov 18, 2003
#include
#include
#include
#include
#include
#include
#include
// Header file for SHBrowseForFolder API function.
#include
#include
//#define MAX_PATH 500;;
int dofun();
int funcload();
// FUNCLOAD -- Define this application's external functions.
// Return RTERROR on error, else RTNORM.
static int funcload()
{
if(!acedDefun("EXP_NEWLAYER", 0))
return RTERROR;
if(!acedDefun("EXP_BROWSEFOLDER", 1))
return RTERROR;
}
void createNewLayer(char* lyrname, Adesk::UInt16 clr, AcDbObjectId ltypeId, Adesk::Boolean current)
{
// We need to check if the layer name exists
// If the layer name exists, apply the color
// linetype id and whither to make it current
// or not. In order to be current it cannot be
// frozen, so we need to check for this also.
// If the layer name does not exist we just create
// a new layer with the properties contained in the arguments
AcDbLayerTable *pLyrTable;
AcDbLayerTableRecord *pLyrTblRecord;
AcDbObjectId recId;
AcCmColor color;
color.setColorIndex(clr); // set color to parameter clr
AcDbDatabase *pCurDb = NULL;
pCurDb = acdbHostApplicationServices()->workingDatabase();
pCurDb->getLayerTable(pLyrTable, AcDb::kForRead);
// Check to see if the layer name exists
if(pLyrTable->has(lyrname))
{
pLyrTable->getAt(lyrname, pLyrTblRecord, AcDb::kForWrite, Adesk::kFalse);
// pLyrTblRecord now points at the layer table record
// which was opened for write
pLyrTblRecord->setIsFrozen(Adesk::kFalse);
pLyrTblRecord->setColor(color);
pLyrTblRecord->setLinetypeObjectId(ltypeId);
}
else
{
// Note how we can change the open mode
// of the layer table from AcDb::kForRead
// to AcDb::kForWrite
pLyrTable->upgradeOpen();
pLyrTblRecord = new AcDbLayerTableRecord;
pLyrTblRecord->setName(lyrname);
pLyrTblRecord->setColor(color);
pLyrTblRecord->setLinetypeObjectId(ltypeId);
pLyrTable->add(pLyrTblRecord);
}
// Get the layer Table ObjectId
recId = pLyrTblRecord->objectId();
pLyrTblRecord->close();
pLyrTable->close();
// Set the layer current if current
// is equal to Adesk::kTrue
// pCurDb is point to the current
// drawing database
// The database AcDbDatabase has a number of
// query and edit functions for the header variables
if(current)
{
pCurDb->setClayer(recId);
}
}
// DOFUN -- Execute external function (called upon an RQSUBR request).
// Return value from the function executed, RTNORM or RTERROR.
static int dofun()
{
//char *lyrname = 0;
char* lyrname = 0;
int col = 0;
char *ltype = 0;
AcDbObjectId ltypeObjId;
Adesk::Boolean current = 0;
struct resbuf *rb;
struct resbuf *rbTrav;
struct resbuf *res_list;
int val;
int i = 0;
// Declared variable for calling EXP_BROWSEFOLDER function
char path[MAX_PATH];
BROWSEINFO bi = {0};
ITEMIDLIST *pidl;
char *title = 0;
// Get the function code and check that it's within range.
if((val = acedGetFunCode()) restype)
{
case RTSTR:
if(i == 0)
lyrname = rbTrav->resval.rstring;
else if(i == 2)
ltype = rbTrav->resval.rstring;
break;
case RTSHORT:
if(i == 1)
col = rbTrav->resval.rint;
else if(i == 3)
current = rbTrav->resval.rint;
break;
default:
break;
} // switch
rbTrav = rbTrav->rbnext;
i += 1;
} // while
if((lyrname == NULL))
lyrname = "NONE_NAME";
if((ltype == NULL)||(strcmp(ltype, "") == 0))
ltype = "CONTINUOUS";
AcDbLinetypeTable *pLinetypeTbl;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLinetypeTbl, AcDb::kForRead);
pLinetypeTbl->getAt(ltype,ltypeObjId);
createNewLayer(lyrname,col,ltypeObjId,current);
// The following code frament constructs a list to return to AutoLISP
res_list = acutBuildList(
RTSTR, lyrname,
RTSHORT, col,
RTSTR, ltype,
RTSHORT, current,
0);
if(res_list == NULL)
{
acdbFail("Couldn't create list!\n");
return NULL;
}
acedRetList(res_list);
if(res_list != NULL)
acutRelRb(res_list);
break;
// other function codes.
//
case 1:
while(rbTrav)
{
switch(rbTrav->restype)
{
case RTSTR:
if (i == 0)
{
title = rbTrav->resval.rstring;
}
break;
default:
break;
} // switch
rbTrav = rbTrav->rbnext;
i += 1;
} // while
if( title != NULL)
{
//bi.pszDisplayName = title;
bi.lpszTitle = title;
bi.ulFlags = BIF_RETURNONLYFSDIRS;
}
else
{
//bi.pszDisplayName = title;
bi.lpszTitle = "Select a directory";
bi.ulFlags = BIF_RETURNONLYFSDIRS;
}
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
pidl = SHBrowseForFolder( &bi );
if( pidl!= NULL)
{
// 获取目录路径
SHGetPathFromIDList(pidl, path);
//const char * pPath=(char*)path;
//如何转换lpwstr宽字节,到一般的字符串。
//MessageBox(NULL,cString,"ok",MB_OK);
//释放内存
IMalloc *imalloc = 0;
if(SUCCEEDED(SHGetMalloc(&imalloc)))
{
imalloc->Free(pidl);
imalloc->Release();
}
}
if( path )
acedRetStr(path);
break;
// Other function codes.
default:
break;
} // switch
return 0;
}
// DLL Entry Point -- This function replaces main() for an ObjectARX program.
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
switch(msg)
{
case AcRx::kInitAppMsg:
acrxDynamicLinker->unlockApplication(pkt);
acrxRegisterAppMDIAware(pkt);
break;
case AcRx::kInvkSubrMsg:
dofun();
break;
case AcRx::kLoadDwgMsg:
funcload();
break;
default:
break;
}
return AcRx::kRetOK;
}
nfcaatym3am.gif
|
|