// 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"));
    }
}
Пример #2
0
AcDbObjectId CArxHelper::SetLayer(TCHAR* layerName)
{
	AcDbObjectId layerId = NULL;
	AcDbLayerTable *pLayerTbl;
	acdbCurDwg()->getLayerTable(pLayerTbl,AcDb::kForWrite);

	AcDbLayerTableIterator *pItr;
	pLayerTbl->newIterator(pItr);

	for(;!pItr->done();pItr->step())
	{
		AcDbLayerTableRecord *pLayer;
		pItr->getRecord(pLayer,AcDb::kForRead);

		TCHAR *str=NULL;
		pLayer->getName(str);
		if(_tcscmp(layerName,str)==0)
			layerId=pLayer->id();
		if(str!=NULL) delete []str;

		pLayer->close();

		if(layerId!=NULL)
			break;
	}

	delete pItr;
	pItr = NULL;

	if(layerId==NULL)
	{
		AcDbLayerTableRecord *pLayerTblRcd=new AcDbLayerTableRecord();
		Acad::ErrorStatus es = pLayerTblRcd->setName(layerName);
		if (es != Acad::eOk)
			pLayerTblRcd->setName(_T("0"));

		pLayerTbl->add(layerId,pLayerTblRcd);

		pLayerTblRcd->close();
	}

	pLayerTbl->close();

	acdbCurDwg() ->setClayer(layerId);

	return layerId;
}
Пример #3
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"));
	}

}
Пример #4
0
	//-------------------------------------------------------------------------------------------
	// 
	//  功能: 向层表中添加记录(创建新层)
	//                 
	//
	//  作者:Qin H.X.
	//
	// 日期:200709
	//
	//  历史:无
	//
	//----------------------------------------------------------------------------------------------
	// - CGDCH03.AddLayer command (do not rename)
	static void CGDCH03AddLayer(void)
	{
		//先声明一个空的层表指针
		AcDbLayerTable *pLayerTbl;  
		//通过当前图形数据库获取层表对象指针
		//打开层表为写入状态
		acdbHostApplicationServices()->workingDatabase()  ->getSymbolTable(pLayerTbl, AcDb::kForWrite); 

		//判断层是否已经存在
		if(!pLayerTbl->has(_T("MyLayer"))) {   
			//新层表记录
			AcDbLayerTableRecord *pLayerTblRcd=  new AcDbLayerTableRecord;
			pLayerTblRcd->setName(_T("MyLayer"));   //设定图层名
			pLayerTblRcd->setIsFrozen(0);   // 图层解冻
			pLayerTblRcd->setIsOff(0);      // 打开图层
			pLayerTblRcd->setVPDFLT(0);   // 使用默认视口
			pLayerTblRcd->setIsLocked(0);   // 图层解锁
			// AcCmColor是ACAD颜色管理类
			AcCmColor color;    
			color.setColorIndex(1);  
			// 图层颜色为红色    
			pLayerTblRcd->setColor(color);  
			// 为给新图层设置线型,要得到线型表记录的ID。
			//  以下的代码演示如何得到并操作记录ID
			AcDbLinetypeTable *pLinetypeTbl;
			AcDbObjectId ltId;
			acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLinetypeTbl, AcDb::kForRead);
			if ((pLinetypeTbl->getAt(_T("DASHED"), ltId))!= Acad::eOk)	{  
				acutPrintf(_T("\n未发现DASHED线型使用CONTINUOUS线型"));
				// 每一个不完全空的图形数据库的线型表中都有线型名为CONTINUOUS 的默认记录
				pLinetypeTbl->getAt(_T("CONTINUOUS"), ltId);
			}
			pLinetypeTbl->close();
			pLayerTblRcd->setLinetypeObjectId(ltId);
			pLayerTbl->add(pLayerTblRcd);
			pLayerTblRcd->close();
			pLayerTbl->close();
		} else {
			pLayerTbl->close();
			acutPrintf(_T("\n层已经存在"));
		}

	}
Acad::ErrorStatus
ArxDbgUtils::addNewLayer(LPCTSTR layerName, AcDbDatabase* db)
{
	ASSERT(db != NULL);

        // if layer already exists, then just return
    AcDbLayerTable* layTbl;
	Acad::ErrorStatus es = db->getSymbolTable(layTbl, AcDb::kForRead);
	if (es != Acad::eOk)
		return es;

    if (layTbl->has(layerName)) {
        layTbl->close();
        return Acad::eOk;
    }
        // upgrade to write
    es = layTbl->upgradeOpen();
    if (es != Acad::eOk) {
        ASSERT(0);
        layTbl->close();
        return es;
    }
        // make sure the name gets set ok
    AcDbLayerTableRecord* newRec = new AcDbLayerTableRecord;
    es = newRec->setName(layerName);
    if (es != Acad::eOk) {
        delete newRec;
        layTbl->close();
        return Acad::eInvalidInput;
    }
        // look up value for default linetype CONTINUOUS,
        // AcDbLayerTableRecord doesn't set this automatically (at least it didn't in Sedona)
    newRec->setLinetypeObjectId(db->continuousLinetype());

    es = layTbl->add(newRec);
    if (es != Acad::eOk)
        delete newRec;
    else
        newRec->close();

    layTbl->close();
    return es;
}
Пример #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;
}
Пример #7
0
void Additional_Class::SetCurLayler( CString LaylerName )
{
	AcDbDatabase *pCurDb = NULL;
	pCurDb = acdbHostApplicationServices()->workingDatabase();
	/*pCurDb->setClayer()*/

	int n = 0;//判断是否找到图层
	//////////////////////////////////////////////////////////////////////////
	AcDbLayerTable *pLayerTbl;
	acdbHostApplicationServices()->workingDatabase()
		->getSymbolTable(pLayerTbl, AcDb::kForWrite);

	// 建立图层遍历器
	AcDbLayerTableIterator *pLayerIterator;
	pLayerTbl->newIterator(pLayerIterator);
	//
	AcDbLayerTableRecord *pLayerTableRcd;
	
	ACHAR *pLtName;
	ACHAR *pLtNameTT;
	CString pLtNameStr;
	for (; !pLayerIterator->done(); pLayerIterator->step()) 
	{
		pLayerIterator->getRecord(pLayerTableRcd, AcDb::kForWrite);
		pLayerTableRcd->getName(pLtName);
		pLayerTableRcd->close();
		pLtNameStr = pLtName;
		if (pLtNameStr == LaylerName)
		{
			pCurDb->setClayer(pLayerTableRcd->id());
			free(pLtName);
			n = 1;//如果图层找到,则将n赋值为1
			delete pLayerIterator;
			pLayerTbl->close();
			return;
		}
		else
		{
			free(pLtName);
		}
	}

	if (n == 0)
	{
		// 新建图层
		AcDbLayerTableRecord *pLayerTableRecordTT = new AcDbLayerTableRecord;
		pLayerTableRecordTT->setName(LaylerName);
		AcDbObjectId pLayerId;
		pLayerTbl->add(pLayerId, pLayerTableRecordTT);
		pLayerTableRecordTT->getName(pLtNameTT);
		pLayerTableRecordTT->close();
		//struct resbuf pResult;
		//::acedGetVar(_T("CLAYER"),&pResult);//取得当前图层
		//char *p = (LPSTR)(LPCTSTR)LaylerName;
		//pResult.resval.rstring = pLtNameTT;
		//int s=acedSetVar(_T("CLAYER"), &pResult);//将输入的图层设为当前层
		//相当于命令 CLAYER LAYERNAME
		//acutPrintf(_T("\nLinetype name is:  %s"), pResult.resval.rstring);
		//acutPrintf(_T("\nLinetype name is:  %d"), s);
		
		n = 1;//如果图层找到,则将n赋值为1
		delete pLayerIterator;
		pLayerTbl->close();
		struct resbuf pResults;
		::acedGetVar(_T("CLAYER"),&pResults);//取得当前图层
		//pLtNameTT = "0";
		pResults.resval.rstring = pLtNameTT;
		::acedSetVar(_T("CLAYER"), &pResults);//将输入的图层设为当前层
		free(pLtNameTT);
	}
	
	// acutPrintf(_T("\nLinetype name"));
	// acutPrintf(_T("\nLinetype name is:  %s"), pResult.resval.rstring);
}
Пример #8
0
void CMyDlg::OnCreateLine() 
{	
	// TODO: Add your control notification handler code here
	acDocManager->lockDocument(curDoc());

	int i;
	int m, n;

	char *buf = (char*)malloc(20);
	
	AcDbObjectId LineId;
	AcDbLine *pLine = NULL;
	//块表
	AcDbBlockTable *pTb = NULL;
	//块表记录
	AcDbBlockTableRecord *pTbr = NULL;
	//层表
	AcDbLayerTable *pLyr = NULL;
	//层表记录
	AcDbLayerTableRecord* pLyrr = NULL;
	//图形数据库
	AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
	
	Acad::ErrorStatus es;
	
	CListCtrl *pListCtr = (CListCtrl *)GetDlgItem( IDC_LIST1 );
	
	//设置随机数种子
	srand(time(NULL));
	
	//更新数据
	UpdateData(TRUE);

	m_VecSize += m_Edit5;
	m_xVec.resize(m_VecSize);
	m_yVec.resize(m_VecSize);

	//acutPrintf("%d\n", m_Edit1);
	
	es = pDb->getLayerTable(pLyr, AcDb::kForWrite);	//以写的方式打开层表
	es = pDb->getBlockTable(pTb, AcDb::kForRead);	//以读的方式打开块表
	es = pTb->getAt(ACDB_MODEL_SPACE, pTbr, AcDb::kForWrite);//以写的方式打开块表记录
	
	//创建图层GalLineTest
	if (!pLyr->has("GalLineTest"))
	{
		pLyrr = new AcDbLayerTableRecord;	//创建层记录
		pLyrr->setName("GalLineTest");		//设置名字
		//pLyrr->setColor(color);			//设置颜色
		//pLyrr->setLineWeight(lnWt);		//设置线宽
		
		if (Acad::eOk != pLyr->add(pLyrr))	//添加该层记录到层表
		{
			//添加失败
			delete pLyrr;		//释放内存
			pLyr->close();		//关闭层表
		}
		//关闭层表记录
		pLyrr->close();
	}
	//关闭层表
	pLyr->close();
	
	//生成点坐标
	for (i = 0; i < m_Edit5; ++i)
	{
		if ((m_Edit2 != 0) && (m_Edit4 != 0))
		{
			m_xVec[i] = rand() % m_Edit2 + m_Edit1;
			m_yVec[i] = rand() % m_Edit4 + m_Edit3;
		}
		else
		{
			m_xVec[i] = 0;
			m_yVec[i] = 0;
		}
	}
	
	//遍历点坐标
	for (m = 0; m < m_Edit5; ++m)
	{
		for (n = (m+1); n < m_Edit5; ++n)
		{
			if ((m_xVec[m] != m_xVec[n]) && (m_yVec[m] != m_yVec[n]))
			{
				AcGePoint3d ptStart(m_xVec[m], m_yVec[m], 0);
				AcGePoint3d ptEnd(m_xVec[n], m_yVec[n], 0);
				pLine = new AcDbLine(ptStart, ptEnd);
				//pLine->setColor();
				pLine->setLayer("GalLineTest");
				//创建线段
				es = pTbr->appendAcDbEntity(LineId, pLine);
				if (Acad::eOk == es)
				{
					++m_lLineCnt;
				}
				//acutPrintf("%d\n", LineId);
				sprintf(buf, "%d", LineId);			
				m_ListCtr.InsertItem(m_Row, buf);
				
				buf = itoa(pLine->colorIndex(), buf, 10);
				m_ListCtr.SetItemText(m_Row, 1, buf);
				
				buf = itoa(LineLength(m_xVec[m], m_yVec[m],
									m_xVec[n], m_yVec[n]), buf, 10);
				m_ListCtr.SetItemText(m_Row, 2, buf);
				
				++m_Row;
				pLine->close();	//关闭实体
			}
		}
	}
	pTbr->close();	//关闭块表记录
	pTb->close();	//关闭块表

	acDocManager->unlockDocument(curDoc());
	free(buf);
}
Пример #9
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);
	}
}
// This command demonstrates the use of kCleanup / kReuse flags
void AddEntityToLayer (AsdkHlrCollector &collector, ACHAR *layerName) {
    //----- Check layer
    if ( layerName != NULL && *layerName != ACRX_T('\0') ) {
        AcDbDatabase *pDb =acdbHostApplicationServices ()->workingDatabase () ;
        AcDbLayerTable *pLayerTable ;
        pDb->getLayerTable (pLayerTable, AcDb::kForRead) ;
        if ( !pLayerTable->has (layerName) ) {
            AcDbLayerTableRecord *pLayerRecord =new AcDbLayerTableRecord ;
            pLayerRecord->setName (layerName) ;
            pLayerTable->upgradeOpen () ;
            pLayerTable->add (pLayerRecord) ;
            pLayerTable->downgradeOpen () ;
            pLayerRecord->close () ;
            pLayerTable->close () ;
            applyCurDwgLayerTableChanges () ;
        } else {
            pLayerTable->close () ;
        }
    } else {
        layerName =NULL ;
    }
    //----- Assign color to the resulting entities
    //----- red for visible edges
    //----- blue for non-visible edges
    //----- yellow for internal edges
    int n =collector.mOutputData.logicalLength () ;
    for ( int i =0 ; i < n ; i++ ) {
        AsdkHlrData *p =collector.mOutputData [i] ;

        AcDbEntity *pEnt =p->getResultEntity () ;
        AsdkHlrData::Visibility vis =p->getVisibility () ;
        if ( vis == AsdkHlrData::kVisible ) {
            pEnt->setColorIndex (1) ; //----- Read
        } else if ( vis == AsdkHlrData::kInternallyHidden ) {
            if ( p->getHlrVisibility () == AsdkHlrData::kVisible )
                pEnt->setColorIndex (2) ; //----- Yellow
            else
                pEnt->setColorIndex (3) ; //----- Green
        } else {
            pEnt->setColorIndex (5) ; //----- Blue
        }
        if ( layerName != NULL )
            pEnt->setLayer (layerName) ;
        AcDbObjectId id ;
        if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) {
            acutPrintf (_T("Failed to add entity to current space.\n")) ;
            break ;
        }

        //----- Entity originator path for block reference entities
        AcDbObjectIdArray ids =p->getObjectIds () ;
        if ( ids.logicalLength () > 0 ) {
            acutPrintf (ACRX_T("\n%ld, "), pEnt->objectId ().asOldId ()) ;
            for ( int j =0 ; j < ids.logicalLength () ; j++ ) {
                acutPrintf (ACRX_T("%ld, "), ids.at (j).asOldId ()) ;
            }
        }

        pEnt->close () ;
    }
}