- UID
- 55031
- 积分
- 995
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-6-3
- 最后登录
- 1970-1-1
|
发表于 2003-7-30 13:48:09
|
显示全部楼层
1.ads_setvar("clayer",&clyr);
ads_setvar 是用来设置系统变量的函数,也就是将系统变量clayer(当前图层)设置为clyr里面存储的值。
2.给你一个关于图层操作的例子看看!
(引至《autoCAD2000 objectarx 编程指南》)
-----------------
Adesk::Boolean getNewLyrLtId(AcDbObjectId& ltypeId)
{
// We know that the linetype 'CONTINUOUS' exists
// so give the user a choice of pressing [ENTER]
// for 'CONTINUOUS' linetype or a listing option
// to show all the linetype available or input a
// linetype name.
char kw[20];
char linType[50];
char *pLtName;
AcDbDatabase *pCurDb = NULL;
AcDbLinetypeTable *pltTable;
AcDbLinetypeTableRecord *pLtTableRcd;
AcDbLinetypeTableIterator *pLtIterator;
int rc;
pCurDb = acdbHostApplicationServices()->workingDatabase();
acedInitGet(NULL, "Name List Continuous");
rc = acedGetKword("\nLinetype - [Name/List/Continuous]<Continuous>: ", kw);
switch(rc)
{
case RTCAN:
acutPrintf("\nUser canceled.");
return Adesk::kFalse;
case RTERROR:
acutPrintf("\nFailed in getNewLyrLtId() function. ");
return Adesk::kFalse;
break;
case RTNONE:
pCurDb->getLinetypeTable(pltTable, AcDb::kForRead);
pltTable->getAt("CONTINUOUS", ltypeId);
pltTable->close();
return Adesk::kTrue;
break;
case RTNORM:
if(strcmp(kw, "Name") == 0)
{
rc = acedGetString(0, "\nEnter linetype string name: ", linType);
switch(rc)
{
case RTCAN:
case RTERROR:
acutPrintf("\nError in retreiving linetype name.");
return Adesk::kFalse;
break;
case RTNORM:
if(linType[0] == '\0')
{
acutPrintf("\nNo layer name given.");
return Adesk::kFalse;
}
// Check to see if the linetype
// exists
pCurDb->getLinetypeTable(pltTable, AcDb::kForRead);
if(pltTable->has(linType))
{
// Retreive the AcDbObjecId of the layer table record
pltTable->getAt(linType, ltypeId);
pltTable->close();
return Adesk::kTrue;
}
acutPrintf("\nLinetype '%s' does not exist using CONTINUOUS. ",
linType);
pltTable->getAt("CONTINUOUS", ltypeId);
pltTable->close();
return Adesk::kTrue;
break;
}// switch
}// if
else if(strcmp(kw, "List") == 0)
{
// Here we will use a Linetype Table Iteraror
// to list out all the available linetype
// and then ask the user to enter a
// valid name for one of the layers
acutPrintf("\nThe following linetypes are available. ");
pCurDb->getLinetypeTable(pltTable, AcDb::kForRead);
pltTable->newIterator(pLtIterator);
for(; !pLtIterator->done(); pLtIterator->step())
{
// get the current linetype record from the iterator,
// opened for read
pLtIterator->getRecord(pLtTableRcd, AcDb::kForRead);
// get the linetype name from the linetype record
// and store it in pLtName
pLtTableRcd->getName(pLtName);
// close the linetype record
pLtTableRcd->close();
acutPrintf("\nLinetype name: %s", pLtName);
delete [] pLtName;
}// for
// Don't forget to delete the iterator
// that's your responsibility
delete pLtIterator;
rc = acedGetString(0, "\n\nEnter linetype string name: ", linType);
switch(rc)
{
case RTCAN:
case RTERROR:
acutPrintf("\nError in retreiving linetype name.");
return Adesk::kFalse;
break;
case RTNORM:
if(linType[0] == '\0')
{
acutPrintf("\nNo layer name given.");
return Adesk::kFalse;
}
// Check to see if the linetype
// exists
pCurDb->getLinetypeTable(pltTable, AcDb::kForRead);
if(pltTable->has(linType))
{
// Retreive the AcDbObjecId of the layer table record
pltTable->getAt(linType, ltypeId);
pltTable->close();
return Adesk::kTrue;
}
acutPrintf("\nLinetype '%s' does not exist using CONTINUOUS. ",
linType);
pltTable->getAt("CONTINUOUS", ltypeId);
pltTable->close();
return Adesk::kTrue;
break;
}// switch
}
else if(strcmp(kw, "Continuous") == 0)
{
// Remember the CONTINUOUS linetype always
// exists in a drawing file.
pCurDb->getLinetypeTable(pltTable, AcDb::kForRead);
pltTable->getAt("CONTINUOUS", ltypeId);
pltTable->close();
return Adesk::kTrue;
}
else
{
return Adesk::kFalse;
}
break;
}// switch
return Adesk::kFalse;
}
// This function called by 'cnl()' which is found on
// Ch4_1Commands.cpp
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);
}
} |
|