#include "StdAfx.h" #include "StdArx.h" // The one and only document manager object // You can use the DocVars object to retrieve // document specific data throughout your application AsdkDataManager DocVars; // // Implementation of the document data class. // CDocData::CDocData() { // NOTE: DO NOT edit the following lines. //{{AFX_ARX_DATA_INIT(CDocData) //}}AFX_ARX_DATA_INIT // TODO: add your own initialization. } CDocData::CDocData(const CDocData &data) { // NOTE: DO NOT edit the following lines. //{{AFX_ARX_DATA_INIT2(CDocData) //}}AFX_ARX_DATA_INIT2 // TODO: add your own initialization. } CDocData::~CDocData() { // NOTE: DO NOT edit the following lines. //{{AFX_ARX_DATA_DEL(CDocData) //}}AFX_ARX_DATA_DEL // TODO: clean up. } const TCHAR * GetRegLocation() { return _T("Software\\SHSware\\R2012"); } double DocGetPScale() { return 100.0; } BOOL SetLayerLocked(const TCHAR* szLayerName, BOOL bLock) { AcDbLayerTable *pLayertable = NULL; AcDbLayerTableRecord *pLayerRec = NULL; acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead); if(!pLayertable) return FALSE; if((pLayertable->getAt(szLayerName, pLayerRec, AcDb::kForWrite)) == Acad::eOk) { if(bLock) pLayerRec->setIsLocked(true); // 打开 else pLayerRec->setIsLocked(false); // 关 pLayerRec->close(); pLayertable->close(); } else pLayertable->close(); return TRUE; } BOOL SetLayer0UnLocked() { AcDbLayerTable *pLayertable = NULL; AcDbLayerTableRecord *pLayerRec = NULL; acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead); if(!pLayertable) return FALSE; if((pLayertable->getAt(_T("0"), pLayerRec, AcDb::kForRead)) == Acad::eOk) { if(pLayerRec->isLocked() && pLayerRec->upgradeOpen()==Acad::eOk) { pLayerRec->setIsLocked(false); // 关 pLayerRec->downgradeOpen(); } pLayerRec->close(); } pLayertable->close(); return TRUE; } void SetBlkAttrText(Entity entBlk, const TCHAR*szText, const TCHAR*szTag, double nHeight, BOOL bVisible, BOOL bDown) { SetLayer0UnLocked(); AcDbBlockReference *pBlockRef = NULL;// 定义块表指针 AcDbObjectId eId; acdbGetObjectId(eId, entBlk); acdbOpenObject(pBlockRef, eId, AcDb::kForRead); if(!pBlockRef) return; AcDbObjectIterator *pIterator; pIterator = pBlockRef -> attributeIterator(); for (pIterator -> start(); !pIterator -> done(); pIterator -> step()) { //遍历块中实体 AcDbObjectId att_id; att_id = pIterator -> objectId(); AcDbEntity *pEnt; AcDbAttribute *pAtt; acdbOpenAcDbEntity(pEnt, att_id, AcDb::kForWrite); pAtt = AcDbAttribute::cast(pEnt); if(pAtt != NULL) { TCHAR *cname = pAtt->tag();//得到标记 if(_tcsicmp(cname, szTag) == 0){ if(!bVisible) pAtt->setInvisible(Adesk::kTrue); else{ pAtt->setTextString(szText); pAtt->setHeight(nHeight*DocGetPScale()); pAtt->setInvisible(Adesk::kFalse); if(bDown){ pAtt->setHorizontalMode(AcDb::kTextLeft); pAtt->setVerticalMode(AcDb::kTextTop); } } } delete[] cname; } pEnt->close(); } delete pIterator; pBlockRef->close(); } CString GetArxDir() { TCHAR szPath[MAX_PATH]; ::GetModuleFileName(_hdllInstance, szPath, MAX_PATH); CString sPath(szPath); sPath = sPath.Left(sPath.ReverseFind(_T('\\'))); return sPath; } CString GetSysDir() { CString arx = GetArxDir(); CString sys = arx.Left(arx.ReverseFind(_T('\\'))); return sys + _T("\\sys"); }