기본 콘텐츠로 건너뛰기

1월, 2006의 게시물 표시

어떤 좌표에 위치한 엔터티 구하기

샘플 코드 int ArxGetEntUnderPos(AcDbObjectIdArray& ids , const AcGePoint3d& pt) { ads_point ptUnder = {pt.x, pt.y, pt.z}; ads_name ss; int res; if (RTNORM != (res = acedSSGet(":E", ptUnder, NULL, NULL, ss))) { // There is probably nothing under the cursor, // so return and let AutoCAD process the message return RTFAIL; } long length = 0L; acedSSLength(ss, &length); if (0 == length) { // There is nothing under the cursor, // so there is no need to show the context menu. // Let AutoCAD process the message. acedSSFree(ss); return RTFAIL; } ads_name ename; for(int i = 0;i < length;i++) { acedSSName(ss, i, ename); AcDbObjectId entId; if(Acad::eOk != acdbGetObjectId(entId, ename)) continue; ids.append(entId); } acedSSFree(ss); return RTNORM; }

WBLOCK 예제

현재 열려진 Database를 사용하지 않고. 임의의 Database를 생성하여 블럭을 만들 Entity들을 추가한 후 블럭을 만든다. 이런 방법을 사용하면 현재의 Drawing,에 Entity들을 그리지 않고서도 블럭을 만들기가 가능합니다. void Command_Block() { AcDbDatabase* pDatabase = new AcDbDatabase; AcGePoint3d ptStart; ptStart.x = ptStart.y = ptStart.z = 0; AcGePoint3d ptEnd; ptEnd.x = ptEnd.y = ptEnd.z = 100; AcDbLine* pLine = new AcDbLine(ptStart , ptEnd); AcDbBlockTable *pBlockTable; Acad::ErrorStatus es; es = pDatabase->getBlockTable(pBlockTable, AcDb::kForRead); if (es != Acad::eOk) { ads_alert("Failed to get the block table!"); pBlockTable->close(); return; } AcDbBlockTableRecord *pBlockRec; es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockRec, AcDb::kForWrite); if (es != Acad::eOk) { ads_alert("Failed to get the block table record!"); pBlockRec->close(); return; } AcDbObjectId retId; if(pBlockRec->appendAcDbEntity(retId, pLine) != Acad::eOk) { ads_alert("Can't add entity to the blockTableR

메뉴 생성 예

아래는 메뉴를 생성하는 샘플코드입니다. try { CComPtr pDisp; pDisp = acedGetAcadWinApp()->GetIDispatch(TRUE); CComPtr pComApp; HRESULT hr = pDisp->QueryInterface(IID_IAcadApplication,(void**)&pComApp); if(FAILED(hr)) return; CComPtr pMenuGrps = NULL; if(FAILED(pComApp->get_MenuGroups(&pMenuGrps))) return; CComPtr pMenuGrp = NULL; if(FAILED(pMenuGrps->Item(_variant_t((short)0),&pMenuGrp))) return; CComPtr pPopupMenus = NULL; //add a menu item to the first loaded menu group by name "AddedFromArx" if(FAILED(pMenuGrp->get_Menus(&pPopupMenus))) return; CComPtr pPopupMenu = NULL; if(FAILED(pPopupMenus->Add(_bstr_t("PWPID"),&pPopupMenu))) return; CComPtr pPopupMenuItem = NULL; pPopupMenu->AddMenuItem(_variant_t((short)0),_bstr_t("New Project"),_bstr_t("PWPID_NEWPROJECT\n"),&pPopupMenuItem); pPopupMenu->AddMenuItem(_variant_t((short)1),_bstr_t("Open Project"),_bstr_t("PWPID_OPENPRO

메뉴 제거 예

aaa라는 메뉴를 제거한다. try{ CComPtr pDisp; pDisp = acedGetAcadWinApp()->GetIDispatch(TRUE); CComPtr pComApp; HRESULT hr = pDisp->QueryInterface(IID_IAcadApplication,(void**)&pComApp); if(FAILED(hr)) return; CComPtr pMenuGrps = NULL; if(FAILED(pComApp->get_MenuGroups(&pMenuGrps))) return; CComPtr pMenuGrp = NULL; if(FAILED(pMenuGrps->Item(_variant_t((short)0),&pMenuGrp))) return; CComPtr pPopupMenus = NULL; //add a menu item to the first loaded menu group by name "AddedFromArx" if(FAILED(pMenuGrp->get_Menus(&pPopupMenus))) return; //_variant_t index=1L; //pPopupMenus->RemoveMenuFromMenuBar(index); CComPtr pPopupMenu = NULL; long lCount=0L; pPopupMenus->get_Count(&lCount); for(long l=0;l < lCount;l++){ pPopupMenus->Item(_variant_t((long)l),&pPopupMenu); BSTR name; pPopupMenu->get_Name(&name)

Entity 생성 예

샘플 코드 #include BOOL purePaperSpace() { struct resbuf res; int tilemode, cvport; ads_getvar("tilemode", &res); tilemode = res.resval.rint; ads_getvar("cvport", &res); cvport = res.resval.rint; if(tilemode == 0 && cvport == 1) return TRUE; else return FALSE; } // Helper to posts an entity to the database Adesk::Boolean PostToDb(AcDbEntity* pEnt, AcDbObjectId& objId) { AcDbBlockTable *pBlockTable; Acad::ErrorStatus es; es = acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead); if (es != Acad::eOk) { ads_alert("Failed to get the block table!"); pBlockTable->close(); return Adesk::kFalse; } AcDbBlockTableRecord *pBlockRec; if(purePaperSpace()) es = pBlockTable->getAt(ACDB_PAPER_SPACE, pBlockRec, AcDb::kForWrite); else es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockRec, AcDb::kForWrite); if (es != Acad::eOk) { ads_alert("Failed to get the block table record!"); pBlockRec-&g

Rectangle Jig Class

샘플 코드 // AsdkRectangleJig.h: interface for the AsdkRectangleJig class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_ASDKRECTANGLEJIG_H__B797B881_525A_491D_B14C_F2B9ACA711A8__INCLUDED_) #define AFX_ASDKRECTANGLEJIG_H__B797B881_525A_491D_B14C_F2B9ACA711A8__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include #include #include // asDblArray() #include // acdbWcs2Ecs() & acdbUcs2Ecs() #include // lwpoly stuff. #include "DataMgr.h" #include "ViewCreator.h" //----------------------------------------------------------------------------- // class CRectInfo { public: CRectInfo(); AcGePoint3d m_topLeftCorner; // First point selection. double m_first; // First Chamfer distance. double m_second; // Second Chamfer distance. double m_bulge; // Bulge value. double m_elev;

explode block reference

샘플 코드 /* objIds : 블럭이 explode되고나서 생성되는 entity의 object id들 pBlkRef : block reference bErase : 블럭을 지울것인가 말것인가? */ bool explodeBlockReference(AcDbObjectIdArray& objIds,AcDbBlockReference *pBlkRef,const bool bErase) { assert(pBlkRef && "pBlkRef is NULL"); bool bRet=false; if(pBlkRef) { CString rLayer=pBlkRef->layer(); AcDbVoidPtrArray entitySet; // explode the block, this will return a load of pre-transfromed entities for our perusal USES_OKEYS; try { ARXOK(pBlkRef->explode(entitySet)); } catch(const char* ex) { ARXERROR(ex); return bRet; } if(true == bErase) pBlkRef->erase(); pBlkRef->close(); AcDbDatabase *pDb=acdbHostApplicationServices()->workingDatabase(); AcDbBlockTable *pBT; pDb->getSymbolTable(pBT, AcDb::kForRead); AcDbBlockTableRecord *pBTR; pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForWrite); pBT->close(); // loop round getting each entity for (long i=0l; i<entitySet.len

single documet off

샘플 코드 void DisableSinglenullMode(){ CWinApp* pWinApp = acedGetAcadWinApp(); if(!pWinApp) return; CComPtr<IDispatch> pDisp = pWinApp->GetIDispatch(TRUE); if(!pDisp) return; CComPtr<IAcadApplication> pComApp; HRESULT hr = pDisp->QueryInterface(IID_IAcadApplication,(void**)&pComApp); if(FAILED(hr)) return; CComPtr<IAcadPreferences> pPreferences; pComApp->get_Preferences(&pPreferences); CComPtr<IAcadPreferencesSystem> pPreferSystem; pPreferences->get_System(&pPreferSystem); _variant_t b(VARIANT_FALSE); pPreferSystem->put_SinglenullMode(b); }