void Additional_Class::SetLayerIsOff( CString strLayerName)
{
	AcDbLayerTable *pLayTbl = NULL; 
	acdbCurDwg()->getLayerTable(pLayTbl, AcDb::kForWrite); 
	if(!pLayTbl->has(strLayerName)) 
	{ 
		pLayTbl->close(); //该图层不存在 
		return; 
	} 

	AcDbLayerTableRecord *pLayTblRec = NULL; 
	AcDbObjectId objId; 
	pLayTbl->getAt(strLayerName, pLayTblRec, AcDb::kForWrite); 
	pLayTbl->close(); 

	//pLayTblRec->isInUse();
	
	if (pLayTblRec==NULL) 
	{ 
		return; 
	} 
	bool tempBool = pLayTblRec->isOff();
	if (tempBool == false)
	{
		pLayTblRec->setIsOff(true); 
	}
	else
	{
		pLayTblRec->setIsOff(false);
	}
	pLayTblRec->close(); 
	return; 
}
Beispiel #2
0
//把一层设置为OFF or ON
void CArxHelper::SetOneLayer(const TCHAR *name,int flag,bool YN)
	//flag 1:isoff 2:isfrozen 3:islocked
{
	AcDbLayerTable *pLayerTable;
	acdbCurDwg()->getLayerTable(pLayerTable,AcDb::kForRead);

	if(!pLayerTable->has(name))
	{
		pLayerTable->close();
		return;
	}

	AcDbObjectId id;
	pLayerTable->getAt(name,id);
	AcDbLayerTableRecord *pLayerTableRecord;
	acdbOpenObject(pLayerTableRecord,id,AcDb::kForWrite);

	switch(flag)
	{
	case 1:
		pLayerTableRecord->setIsOff(YN);
		break;
	case 2:
		pLayerTableRecord->setIsFrozen(YN);
		break;
	case 3:
		pLayerTableRecord->setIsLocked(YN);
		break;
	}

	pLayerTableRecord->close();
	pLayerTable->close();
}
Beispiel #3
0
bool CLayerState::set(void)
{
	AcDbLayerTableRecord* pLayer = NULL;
	if (Acad::eOk != acdbOpenObject(pLayer, m_idLayer, AcDb::kForWrite))
		return false;

	pLayer->setIsOff(m_bOff);
	pLayer->setIsFrozen(m_bFrozen);
	pLayer->setIsLocked(m_bLocked);
	pLayer->close();
	return true;
}
// This function creates a new AcDbLayerTableRecord, fills
// it in, and adds it to the layer table
// 
// THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
//
void
addLayer()
{
    AcDbLayerTable *pLayerTbl;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pLayerTbl, AcDb::kForWrite);

    if (!pLayerTbl->has(_T("ASDK_TESTLAYER"))) {
        AcDbLayerTableRecord *pLayerTblRcd
            = new AcDbLayerTableRecord;
        pLayerTblRcd->setName(_T("ASDK_TESTLAYER"));
        pLayerTblRcd->setIsFrozen(0);// layer to THAWED
        pLayerTblRcd->setIsOff(0);   // layer to ON
        pLayerTblRcd->setVPDFLT(0);  // viewport default
        pLayerTblRcd->setIsLocked(0);// un-locked

        AcCmColor color;
        color.setColorIndex(1); // set color to red
        pLayerTblRcd->setColor(color);

        // For linetype, we need to provide the object ID of
        // the linetype record for the linetype we want to
        // use.  First, we need to get the object ID.
	//
        AcDbLinetypeTable *pLinetypeTbl;
        AcDbObjectId ltId;
        acdbHostApplicationServices()->workingDatabase()
            ->getSymbolTable(pLinetypeTbl, AcDb::kForRead);
        if ((pLinetypeTbl->getAt(_T("DASHED"), ltId))
            != Acad::eOk)
        {
            acutPrintf(_T("\nUnable to find DASHED")
                _T(" linetype. Using CONTINUOUS"));
            
            // CONTINUOUS is in every drawing, so use it.
            //
            pLinetypeTbl->getAt(_T("CONTINUOUS"), ltId);
        }
        pLinetypeTbl->close();

        pLayerTblRcd->setLinetypeObjectId(ltId);
        pLayerTbl->add(pLayerTblRcd);
        pLayerTblRcd->close();
        pLayerTbl->close();
    } else {
        pLayerTbl->close();
        acutPrintf(_T("\nlayer already exists"));
    }
}
Beispiel #5
0
static void CheakLayerExit(CString layerName,int colorIndx, AcDb::LineWeight lineWeigt)
{
	//int colorIndx = 7;		//默认的颜色为白色
	//AcDb::LineWeight lineWeigt = AcDb::kLnWt000;

	//lineWeigt = AcDb::kLnWt030;
	AcDbLayerTable* pLayerTbl = NULL;
	// 获取当前的数据库
	AcDbDatabase*pDB=acdbHostApplicationServices()->workingDatabase();
	// 因为要创建新的图层,所以先要以写的方式获取图层表
	pDB->getSymbolTable(pLayerTbl,AcDb::kForWrite);
	// 检查图层是否存在
	if (!pLayerTbl->has(layerName)) {
		// 初始化一个新的对象,并且设置它的属性
		AcDbLayerTableRecord *pLayerTblRcd = new AcDbLayerTableRecord;
		pLayerTblRcd->setName(layerName);
		pLayerTblRcd->setIsFrozen(0); // 图层设置为THAWED(解冻的)
		pLayerTblRcd->setIsOff(0); // 图层设置为ON(开着的)
		pLayerTblRcd->setIsLocked(0); // 图层 un-locked(解锁的)
		AcCmColor color;
		color.setColorIndex(colorIndx); // 图层的颜色设置
		pLayerTblRcd->setColor(color);
		pLayerTblRcd->setLineWeight(lineWeigt);
		// 增加一个新的图层到容器(表)中
		pLayerTbl->add(pLayerTblRcd);
		// 把新建的图层关闭(不要删除它)
		pLayerTblRcd->close();
		// 关闭容器(表)
		pLayerTbl->close();
	}
	else {
		// 如果这个图层已经存在,仅仅需要关闭表继续就是
		AcDbLayerTableRecord *pLayerTblRcd;
		pLayerTbl->getAt(layerName, pLayerTblRcd, AcDb::kForWrite);
		AcCmColor color;
		color.setColorIndex(colorIndx); // 图层的颜色设置
		pLayerTblRcd->setColor(color);
		pLayerTblRcd->setLineWeight(lineWeigt);
		pLayerTblRcd->close();
		pLayerTbl->close();
		//acutPrintf(_T("\nMYLAYER already exists"));
	}

}
Beispiel #6
0
Acad::ErrorStatus TWArxLayer::Create( OUT AcDbObjectId& IdLayer ) const
{
	if( m_strName.IsEmpty() ) return Acad::eInvalidInput;

	AcDbDatabase* pDb = GetWorkingDB();

	Acad::ErrorStatus es = Acad::eKeyNotFound;

	AcDbLayerTable* pLayerTb = NULL;
	es = pDb->getLayerTable( pLayerTb,AcDb::kForRead );
	if( pLayerTb == NULL ) return es;
	
	es = pLayerTb->getAt( m_strName, IdLayer );
	if( es == Acad::eOk )
	{
		pLayerTb->close();
		return es;
	}

	es = pLayerTb->upgradeOpen();

	AcDbLayerTableRecord* pLtr = new AcDbLayerTableRecord;
	pLtr->setName( m_strName );
	pLtr->setIsFrozen( m_bIsFrozen );
	pLtr->setIsLocked( m_bIsLocked );
	pLtr->setIsOff( m_bIsOff );

	es = pLayerTb->add( IdLayer, pLtr );
	pLayerTb->close();

	if( es == Acad::eOk )
	{
		pLtr->close();
		return es;
	}

	TWFreePtr( pLtr );
	return es;
}
void CLayerTreeDlg::ShowLayer(HTREEITEM hItem, BOOL bShow)
{
	CString sLayerName = m_tree.GetItemText(hItem);

	HTREEITEM hChild = m_tree.GetNextItem(hItem,TVGN_CHILD);

	// 只有树叶才有对应的图层
	if (hChild == NULL)
	{
		ShowLayer(sLayerName, bShow);
		//如果是面层,还要把它的填充图层打开
		CString sHatchLayer;
		sHatchLayer.Format("%s_填充",sLayerName);
		bool hasHatch = false;
		acDocManager->lockDocument(acDocManager->curDocument());
		AcDbLayerTable * pLayerTbl = NULL;
		Acad::ErrorStatus es =
		acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl,AcDb::kForRead);
		if (pLayerTbl->has(sHatchLayer))
		{
			AcDbLayerTableRecord * pLayerTbRcd = NULL;
			es = pLayerTbl->getAt(sHatchLayer,pLayerTbRcd,AcDb::kForWrite);
			pLayerTbRcd->setIsOff(bShow == 0);
			pLayerTbRcd->close();
			hasHatch = true;
		}
		pLayerTbl->close();
		acDocManager->unlockDocument(acDocManager->curDocument());
	}

	while(hChild != NULL)
	{
		ShowLayer(hChild, bShow);
		hChild = m_tree.GetNextItem(hChild,TVGN_NEXT);
	}
}
Beispiel #8
0
void CreateLayer()
{
	Acad::ErrorStatus es;
	ACHAR szNewName[255];
	_tcscpy(szNewName, _T("NewLayer"));

	AcDbDatabase* pCurDb = acdbHostApplicationServices()->workingDatabase();
	if (pCurDb == NULL)
	{
		acutPrintf(_T("\nError:Current database is NULL!"));
		return;
	}

	AcDbLayerTableRecord* pNewLayer = new AcDbLayerTableRecord;
	es = pNewLayer->setName(szNewName);
	if (es != Acad::eOk)
	{
		acutPrintf(_T("\nFailed setName of the layer!"));
		delete pNewLayer;
		return;
	}

	AcCmColor cmColor;
	cmColor.setColorIndex(1);
	pNewLayer->setColor(cmColor);

	pNewLayer->setIsFrozen(false);
	pNewLayer->setIsOff(false);
	pNewLayer->setVPDFLT(false);
	pNewLayer->setIsLocked(false);

	bool bStat = false;
	AcDbLayerTable* pLayerTbl = NULL;
	es = pCurDb->getLayerTable(pLayerTbl, AcDb::kForWrite);
	if (es == Acad::eOk)
	{
		if (pLayerTbl->has(szNewName))
		{
			acutPrintf(_T("\nThe Layer \"%s\" has existed!"), szNewName);
			delete pNewLayer;
		}
		else
		{
			es = pLayerTbl->add(pNewLayer);
			if (es == Acad::eOk)
			{
				bStat = true;
				pNewLayer->close();
			}
			else
			{
				acutPrintf(_T("\nFailed to add a new layer in LayerTable!"));
				delete pNewLayer;
			}
		}

		pLayerTbl->close();
	}

	if (bStat)
	{
		acutPrintf(_T("\nCreated the new layer: \"%s\" successfully!"), szNewName);
	}
	else
	{
		acutPrintf(_T("\nFailed to create the layer: \"%s\""), szNewName);
	}
}