void CmdHelper::DrawDipGraph23() { int coal_id = -1; if(RTNORM != acedGetInt(NULL, &coal_id)) return; if(coal_id == -1) return; int tech_id = -1; if(RTNORM != acedGetInt(NULL, &tech_id)) return; if(tech_id == -1) return; cbm::Coal coal; SQLClientHelper::GetCoalById(coal, coal_id); if( coal.id < 0 ) return; cbm::DesignWorkSurfTechnology ws_tech; SQLClientHelper::GetDesignWorkSurfTechnologyById(ws_tech, tech_id); if(ws_tech.id < 0 ) return; //交互选择基点坐标 AcGePoint3d pt; ArxUtilHelper::PromptPt( _T( "请选择一点:" ), pt ); //绘制倾向剖面图 //P23::DipGraph graph( coal, ws_tech ); //graph.setPoint( pt ); //graph.draw(); }
void CmdHelper::DrawHeadGraph12() { int coal_id = -1; if(RTNORM != acedGetInt(NULL, &coal_id)) return; if(coal_id == -1) return; int tech_id = -1; if(RTNORM != acedGetInt(NULL, &tech_id)) return; if(tech_id == -1) return; cbm::Coal coal; SQLClientHelper::GetCoalById(coal, coal_id); if( coal.id < 0 ) return; cbm::DesignDrillingSurfTechnology tws_tech; SQLClientHelper::GetDesignDrillingSurfTechnologyById(tws_tech, tech_id); if(tws_tech.id < 0 ) return; //交互选择基点坐标 AcGePoint3d pt; ArxUtilHelper::PromptPt( _T( "请选择一点:" ), pt ); //绘制走向剖面图 //P12::HeadGraph graph( coal, tws_tech ); //graph.setPoint( pt ); //graph.draw(); }
void CmdHelper::GeneratePore32() { int coal_id = -1; if(RTNORM != acedGetInt(NULL, &coal_id)) return; if(coal_id == -1) return; int tech_id = -1; if(RTNORM != acedGetInt(NULL, &tech_id)) return; if(tech_id == -1) return; cbm::Coal coal; SQLClientHelper::GetCoalById(coal, coal_id); if( coal.id < 0 ) return; cbm::DesignGoafTechnology goaf_tech; SQLClientHelper::GetDesignGoafTechnologyById(goaf_tech, tech_id); if(goaf_tech.id < 0 ) return; std::vector<cbm::DesignGoafPore> close_pores; SQLClientHelper::GetDesignGoafPoreListByForeignKey(close_pores, "design_goaf_technology_id", goaf_tech.id); if(close_pores.empty()) return; // 生成钻孔坐标数据文件(测试用) P32::PoreHelper ph(coal, goaf_tech, close_pores); ph.cacl(); AfxMessageBox(_T("\n生成钻孔数据成功!")); }
void CmdHelper::DrawDipGraph32() { int coal_id = -1; if(RTNORM != acedGetInt(NULL, &coal_id)) return; if(coal_id == -1) return; int tech_id = -1; if(RTNORM != acedGetInt(NULL, &tech_id)) return; if(tech_id == -1) return; cbm::Coal coal; SQLClientHelper::GetCoalById(coal, coal_id); if( coal.id < 0 ) return; cbm::DesignGoafTechnology goaf_tech; SQLClientHelper::GetDesignGoafTechnologyById(goaf_tech, tech_id); if(goaf_tech.id < 0 ) return; std::vector<cbm::DesignGoafPore> close_pores; SQLClientHelper::GetDesignGoafPoreListByForeignKey(close_pores, "design_goaf_technology_id", goaf_tech.id); if(close_pores.empty()) return; //交互选择基点坐标 AcGePoint3d pt; ArxUtilHelper::PromptPt( _T( "请选择一点:" ), pt ); //绘制倾向剖面图 //P32::DipGraph graph( coal, goaf_tech, close_pores ); //graph.setPoint( pt ); //graph.draw(); }
void CmdHelper::DrawEvalUnitGraph() { //int coal_id = -1; //if(RTNORM != acedGetInt(NULL, &coal_id)) return; //if(coal_id == -1) return; int eval_unit_partition_id = -1; if(RTNORM != acedGetInt(NULL, &eval_unit_partition_id)) return; if(eval_unit_partition_id == -1) return; //cbm::Coal coal; //SQLClientHelper::GetCoalById(coal, coal_id); //if( coal.id < 0 ) return; cbm::DesignEvalUnitPartition deup; SQLClientHelper::GetDesignEvalUnitPartitionById(deup, eval_unit_partition_id); if(deup.id < 0 ) return; acutPrintf(_T("\n巷道宽度:%.3f"), deup.w); //交互选择基点坐标 AcGePoint3d pt; ArxUtilHelper::PromptPt( _T( "请选择一点:" ), pt ); //绘制煤层赋存图 EvalUnitGraph graph( deup ); graph.setPoint( pt ); graph.draw(); }
// // NAME: selectDocument // // REMARKS: Simple utility to have the user choose an open document to // perform some action on. // // // // RETURNS: // void static AcApDocument* selectDocument() { AcApDocument* documentArray[10]; AcApDocument* pDoc; AcApDocumentIterator* pDocIter; int nDocs = 0;; pDocIter = acDocManager->newAcApDocumentIterator(); for ( ; !pDocIter->done(); pDocIter->step(), nDocs++) { pDoc = pDocIter->document(); documentArray[nDocs] = pDoc; acutPrintf("%d. %s\n", nDocs + 1, pDoc->fileName()); } delete pDocIter; acedInitGet(RSG_NOZERO | RSG_NONEG, NULL); int iSelection; int inputStatus = acedGetInt("Which document should this command execute in: ", &iSelection); if (inputStatus == RTNORM && iSelection <= nDocs) { return documentArray[iSelection - 1]; } else { return NULL; } }
// ----- zhfzhftool._moblkatt command (do not rename) static void zhfzhftool_moblkatt(void) { // Add your code for command zhfzhftool._moblkatt here //批量修改块属性 int iMode = 0 ; if(RTNORM==acedGetInt(_T("\nInput int(0:全图修改/1:选择修改):"), &iMode)) { CUserTools::SetBlkAtt(iMode) ; } }
//----------------------------------------------------------------------------- //----- This is used as the key for our custom //----- dictionary. Note the registered developer id 'OARX' //----- at the beginning void lab9Command () { OarxEmployee *p =NULL ; try { //----- Start transaction for the db operations in this command actrTransactionManager->startTransaction () ; //----- Prompt the use for the an id int id ; ADSOK ( acedGetInt ("Enter employee's ID:", &id) ) ; //----- Before continuing, we should verify if that Employee is already registered if ( EmployeeService->isEmployeeExist (id) != Adesk::kTrue ) { //----- Continue data acquisition int cubeNumber ; char strFirstName [133] ; char strLastName [133] ; AcGePoint3d position ; ADSOK ( acedGetInt ("Enter cube number:", &cubeNumber) ) ; ADSOK ( acedGetString (0, "Enter employee's first name:", strFirstName) ) ; ADSOK ( acedGetString (0, "Enter employee's last name:", strLastName) ) ; ADSOK ( acedGetPoint (asDblArray (position), NULL, asDblArray (position)) ) ; p =EmployeeService->createEmployee (id, position, cubeNumber,strFirstName, strLastName) ; if ( p == NULL ) throw Acad::eOutOfMemory ; } //----- Stop transaction actrTransactionManager->endTransaction () ; } catch (const Acad::ErrorStatus es) { if ( p != NULL && p->objectId () == AcDbObjectId::kNull ) delete p ; //----- Abort, rollback all db operations actrTransactionManager->abortTransaction () ; //----- Check if the user has cancelled us, then we don't report anything if ( es != Acad::eUserBreak ) acutPrintf ("***Error: %s\n", acadErrorStatusText (es)) ; } }
void CmdHelper::GeneratePore23() { int coal_id = -1; if(RTNORM != acedGetInt(NULL, &coal_id)) return; if(coal_id == -1) return; int tech_id = -1; if(RTNORM != acedGetInt(NULL, &tech_id)) return; if(tech_id == -1) return; cbm::Coal coal; SQLClientHelper::GetCoalById(coal, coal_id); if( coal.id < 0 ) return; cbm::DesignWorkSurfTechnology ws_tech; SQLClientHelper::GetDesignWorkSurfTechnologyById(ws_tech, tech_id); if(ws_tech.id < 0 ) return; // 生成钻孔坐标数据文件(测试用) P23::PoreHelper ph(coal, ws_tech); ph.cacl(); AfxMessageBox(_T("\n生成钻孔数据成功!")); }
// Used to set the AsdkPoly static variable mUseDragData for determining // whether AsdkPoly will use the no-clone-for-dragging mechanism or not. // void setUseDragData() { int val, status; for(;;) { acutPrintf("\nNew value for USEDRAGDATA <%s>: ", AsdkPoly::useDragData() ? "1" : "0"); status = acedGetInt(NULL, &val); if (status != RTNORM) break; if (val != 0 && val != 1) { acutPrintf("\nValue must be 0 or 1"); continue; } AsdkPoly::setUseDragData(val == 1 ? true : false); break; } }
ArxDbgUiPrBase::Status ArxDbgUiPrInt::go() { CString prompt; int initFlag; // set up prompt prompt.Format(_T("\n%s: "), message()); // set up init flag if (m_intType == kNoZero) initFlag = RSG_NONULL+RSG_NOZERO; else if (m_intType == kNoNeg) initFlag = RSG_NONULL+RSG_NONEG; else if (m_intType == kNoNegNoZero) initFlag = RSG_NONULL+RSG_NOZERO+RSG_NONEG; else if (m_intType == kNoNegNoZeroAllowNone) initFlag = RSG_NOZERO+ RSG_NONEG; else initFlag = RSG_NONULL; while (1) { acedInitGet(initFlag, keyWords()); int result = acedGetInt(prompt, &m_value); if (result == RTNORM) { if (inRange()) return ArxDbgUiPrBase::kOk; } else if (result == RTKWORD) { acedGetInput(m_keyWordPicked.GetBuffer(512)); m_keyWordPicked.ReleaseBuffer(); return ArxDbgUiPrBase::kKeyWord; } else if (result == RTNONE) { return ArxDbgUiPrBase::kNone; } else return ArxDbgUiPrBase::kCancel; } }
// get yes or no choice from the user bool getYorN(char *msg) { int res, retcode; char kw[4]; acutPrintf("\n %s [Yes/No]", msg); do { acedInitGet(RSG_NONULL, "Yes No"); retcode = acedGetInt(NULL, &res); switch (retcode) { case RTKWORD: if(acedGetInput(kw) != RTNORM) { acutPrintf("\nError getting Yes/No choice"); return false; } if(strcmp(kw, "Yes") == 0) { return true; } else if(strcmp(kw, "No") == 0) { return false; } else { acutPrintf("\nKeyword Error!!"); return false; } break; default: acutPrintf("\n Enter <Yes/No> :"); break; } } while(retcode != RTKWORD); return true; }
void PDFConverter(BOOL bDwg) { // test(); resbuf* rb = getFileNameInput(); resbuf* pRb = rb; AcStringArray arrFileName; while (pRb) { arrFileName.append(pRb->resval.rstring); pRb = pRb->rbnext; } acutRelRb(rb); rb = NULL; int page = 0; if (arrFileName.length() == 1) { acedInitGet(4, NULL); // use resource for multi langeage. // modify by yhl, 2016/6/29. CString strPrompt; CAcModuleResourceOverride rs; strPrompt.LoadString(IDS_ASKFORPAGENUMBER); int rc = acedGetInt(strPrompt, &page); // int rc = acedGetInt(_T("\nPlease input the page number, 0 for all <1>: "), &page); if (RTNONE == rc) { page = 1; } else if (RTNORM != rc) { return; } } for (int i=0; i<arrFileName.length(); i++) { convertFile(arrFileName[i], page, bDwg); } }
void CmdHelper::DrawOccurrenceGraph() { int mine_id = -1; if(RTNORM != acedGetInt(NULL, &mine_id)) return; if(mine_id == -1) return; cbm::Mine mine; SQLClientHelper::GetMineById(mine, mine_id); if( mine.id < 0 ) return; // 煤层走向长度比例因子,控制显示效果 double factor = 1.0; if(RTNORM != acedGetReal(NULL, &factor)) return; //交互选择基点坐标 AcGePoint3d pt; ArxUtilHelper::PromptPt( _T( "请选择一点:" ), pt ); //绘制煤层赋存图 OccurrenceGraph graph( mine, factor ); graph.setPoint( pt ); graph.draw(); }
Acad::ErrorStatus newLine() { //Mark the leftmost cubicle as unusable by putting a red diagonal //line from the lower left to upper right corners //Use the first parameter of acedGetPoint to rubberband to the second point //Prompt the user to select the line's endpoints ads_point pt1, pt2; int retval; //{{BEGIN_LEVEL_ADVANCED try { //get the first point from the user. Do not specify a base point. //... //{{BEGIN_LEVEL_INTERMEDIATE if ((retval = acedGetPoint(NULL, "\nSelect lower left: ", pt1)) != RTNORM) throw retval; //{{END_LEVEL_INTERMEDIATE //get the second point from the user, using the first point as a base point. //... //{{BEGIN_LEVEL_INTERMEDIATE if ((retval = acedGetPoint(pt1, "\nSelect upper right: ", pt2)) != RTNORM) throw retval; //{{END_LEVEL_INTERMEDIATE } catch (int e) { if (e == RTCAN) return Acad::eUserBreak; if (e == RTERROR) return Acad::eInvalidInput; } //{{END_LEVEL_ADVANCED //Instantiate an AcDbLine pointer. Use the two user-chosen //points as endpoints. //Since AcDbLine's constructor uses AcGePoint2d, but acedGetPoint returns ads_point, //you must find a way to translate old style to new style. This can be done either by //assigning each array member individually, or by calling asPnt3d() from geassign.h //{{BEGIN_LEVEL_ADVANCED //... //{{BEGIN_LEVEL_INTERMEDIATE AcDbLine* pLine = new AcDbLine(asPnt3d(pt1), asPnt3d(pt2)); //{{END_LEVEL_INTERMEDIATE //Make sure you created the line... if (!pLine) { acedAlert("Not enough memory to create a Line!"); return Acad::eOutOfMemory; } //{{END_LEVEL_ADVANCED //Prompt the user to enter a new color //Then change the color property of the new line to this value. //{{BEGIN_LEVEL_ADVANCED //... //{{BEGIN_LEVEL_INTERMEDIATE int color; acedGetInt("\nEnter AutoCAD color number: ", &color); if (pLine->setColorIndex(color) != Acad::eOk) { acutPrintf("\nInvalid color chosen.\n"); } //{{END_LEVEL_INTERMEDIATE //{{END_LEVEL_ADVANCED //Post the new entity to the database //{{BEGIN_LEVEL_ADVANCED AcDbObjectId id; return postToDatabase(pLine, id); //{{END_LEVEL_ADVANCED }
void lineContainment() { AcBr::ErrorStatus returnValue = AcBr::eOk; // Select the entity by type AcBrEntity* pEnt = NULL; AcDb::SubentType subType = AcDb::kNullSubentType; returnValue = selectEntityByType(pEnt, subType); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in selectEntityByType:"); errorReport(returnValue); delete pEnt; return; } // Query the line by AutoCAD pick AcGePoint3d startPt, endPt; int hitCount = 0; acutPrintf("\n Pick line for containment test, by selecting two points: \n"); acedGetPoint(NULL, "\n Pick origin of line: \n", asDblArray(startPt)); acedGetPoint(NULL, "\n Pick another point on line: \n", asDblArray(endPt)); acedGetInt("\n Number of hits wanted: ", &hitCount); // Query the line type const AcGeLinearEnt3d* line = NULL; char opt[128]; while (Adesk::kTrue) { acutPrintf("\nEnter Line Type: "); acedInitGet(NULL, "Infinite Ray Segment"); if (acedGetKword("Infinite/Ray/<Segment>: ", opt) == RTCAN) return; // Map the user input to a valid line type if ((strcmp(opt, "Segment") == 0) || (strcmp(opt, "") == 0)) { line = new AcGeLineSeg3d(startPt, endPt); break; } else if (strcmp(opt, "Ray") == 0) { line = new AcGeRay3d(startPt,endPt); break; } else if (strcmp(opt, "Infinite") == 0) { line = new AcGeLine3d(startPt, endPt); break; } } if (line == NULL) { acutPrintf("\n lineContainment: unable to allocate memory for line\n"); delete pEnt; return; } Adesk::UInt32 numHitsWanted = (Adesk::UInt32)hitCount; Adesk::UInt32 numHitsFound = 0; AcBrHit* hits = NULL; returnValue = pEnt->getLineContainment(*line, numHitsWanted, numHitsFound, hits); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrEntity::getLineContainment:"); errorReport(returnValue); delete pEnt; return; } acutPrintf("\n Number of hits found: %d", numHitsFound); for (Adesk::UInt32 i = 0; i < numHitsFound; i++) { AcBrEntity* entityAssociated = NULL; returnValue = hits[i].getEntityAssociated(entityAssociated); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrHit::getEntityAssociated:"); errorReport(returnValue); delete entityAssociated; break; } if (!pEnt->isEqualTo(entityAssociated)) { acutPrintf("\n lineContainment: Hit owner is not the entity we checked line containment against!"); delete entityAssociated; break; } AcGePoint3d pt; returnValue = hits[i].getPoint(pt); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrHit::getPoint:"); errorReport(returnValue); break; } AcBrEntity* entityHit = NULL; returnValue = hits[i].getEntityHit(entityHit); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrHit::getEntityHit:"); errorReport(returnValue); delete entityHit; break; } AcBrEntity* entityEntered = NULL; returnValue = hits[i].getEntityEntered(entityEntered); if (returnValue != AcBr::eOk) { acutPrintf("\n Error in AcBrHit::getEntityEntered:"); errorReport(returnValue); delete entityHit; delete entityEntered; break; } lnContainmentReport(i, pt, entityHit, entityEntered); delete entityHit; delete entityEntered; } delete pEnt; delete[] hits; return; }
void refEditApiExample() { AcDbObjectId transId; AcDbDatabase* pDb; char *fname; struct resbuf *rb; // Get a dwg file from the user. // rb = acutNewRb(RTSTR); int stat = acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb); if ((stat != RTNORM) || (rb == NULL)) { acutPrintf("\nYou must pick a drawing file."); return; } fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1); strcpy(fname, rb->resval.rstring); acutRelRb(rb); // Open the dwg file. // pDb = new AcDbDatabase(Adesk::kFalse); if (pDb->readDwgFile(fname) != Acad::eOk) { acutPrintf("\nSorry, that draing is probably already open."); return; } // Get the Block Table and then the model space record. // AcDbBlockTable *pBlockTable; pDb->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pOtherMsBtr; pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb::kForRead); pBlockTable->close(); // Create an iterator. // AcDbBlockTableRecordIterator *pIter; pOtherMsBtr->newIterator(pIter); // Set up an object ID array. // AcDbObjectIdArray objIdArray; // Iterate over the model space BTR. Look specifically // for lines and append their object ID to the array. // for (pIter->start(); !pIter->done(); pIter->step()) { AcDbEntity *pEntity; pIter->getEntity(pEntity, AcDb::kForRead); // Look for only AcDbLine objects and add them to the // object ID array. // if (pEntity->isKindOf(AcDbLine::desc())) { objIdArray.append(pEntity->objectId()); } pEntity->close(); } delete pIter; pOtherMsBtr->close(); if (objIdArray.isEmpty()) { acad_free(fname); acutPrintf("\nYou must pick a drawing file that contains lines."); return; } // Now get the current database and the object ID for the // current database's model space BTR. // AcDbBlockTable *pThisBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pThisBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pThisMsBtr; pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr, AcDb::kForWrite); pThisBlockTable->close(); AcDbObjectId id = pThisMsBtr->objectId(); pThisMsBtr->close(); // Create the long transaction. This will check all the entities // out of the external database. // AcDbIdMapping errorMap; acapLongTransactionManagerPtr()->checkOut(transId, objIdArray, id, errorMap); // Now modify the color of these entities. // int colorIndex; acedGetInt("\nEnter color number to change entities to: ", &colorIndex); AcDbObject* pObj; if (acdbOpenObject(pObj, transId, AcDb::kForRead) == Acad::eOk) { // Get a pointer to the transaction. // AcDbLongTransaction* pLongTrans = AcDbLongTransaction::cast(pObj); if (pLongTrans != NULL) { // Get a work set iterator. // AcDbLongTransWorkSetIterator* pWorkSetIter; pLongTrans->newWorkSetIterator(pWorkSetIter); // Iterate over the entities in the work set and change the color. // for (pWorkSetIter->start(); !pWorkSetIter->done(); pWorkSetIter->step()) { AcDbEntity *pEntity; acdbOpenAcDbEntity(pEntity, pWorkSetIter->objectId(), AcDb::kForWrite); pEntity->setColorIndex(colorIndex); pEntity->close(); } delete pWorkSetIter; } pObj->close(); } // Pause to see the change. // char str[132]; acedGetString(0, "\nSee the new colors. Press return to check the object into the original database", str); // Check the entities back in to the original database. // acapLongTransactionManagerPtr()->checkIn(transId, errorMap); // Save the original database, since we have made changes. // pDb->saveAs(fname); // Close/Delete the database // delete pDb; pDb = NULL; acad_free(fname); }
// Invoked by the command - POLY // void polyCommand() { int nSides = 0; while (nSides < 3) { acedInitGet(INP_NNEG, ""); switch (acedGetInt("\nEnter number of sides: ", &nSides)) { case RTNORM: if (nSides < 3) acutPrintf("\nNeed at least 3 sides."); break; default: return; } } ads_point center, startPt, normal; if (acedGetPoint(NULL, "\nLocate center of polygon: ", center) != RTNORM) return; startPt[0] = center[0]; startPt[1] = center[1]; startPt[2] = center[2]; while (asPnt3d(startPt) == asPnt3d(center)) { switch (acedGetPoint(center, "\nLocate start point of polygon: ", startPt)) { case RTNORM: if (asPnt3d(center) == asPnt3d(startPt)) acutPrintf("\nPick a point different from the center."); break; default: return; } } char nameBuf[133]; if (acedGetString(Adesk::kTrue, "\nEnter polygon name: ", nameBuf) != RTNORM) return; AcDbObjectId tsId = 0; char styleBuf[133], msg[133]; // Get default text style struct resbuf result ; if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) { acutPrintf("\nError while reading default AutoCAD text style setting"); return ; } strcpy (styleBuf, result.resval.rstring) ; sprintf (msg, "\nEnter text style <%s>: ", result.resval.rstring) ; acdbFree (result.resval.rstring) ; if (acedGetString(Adesk::kTrue, "\nEnter text style: ", styleBuf) != RTNORM) return; if ( styleBuf[0] == '\0' ) { // Get default text style struct resbuf result ; if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) { acutPrintf("\nError while reading default AutoCAD text style setting"); return ; } strcpy (styleBuf, result.resval.rstring) ; acdbFree (result.resval.rstring) ; } if ( rx_getTextStyleId(styleBuf, acdbHostApplicationServices()->workingDatabase(), tsId) != Acad::eOk) { acutPrintf("\nInvalid text style name"); return; } // Set the normal to the plane of the polygon to be the same as the // z direction of the current ucs, i.e. (0, 0, 1) since we also got the // center and start point in the current UCS. (acedGetPoint() returns in // the current UCS.) normal[X] = 0.0; normal[Y] = 0.0; normal[Z] = 1.0; acdbUcs2Wcs(normal, normal, Adesk::kTrue); acdbUcs2Ecs(center, center,normal, Adesk::kFalse); acdbUcs2Ecs(startPt, startPt,normal, Adesk::kFalse); double elev = center[2]; AcGePoint2d cen = asPnt2d(center), start = asPnt2d(startPt); AcGeVector3d norm = asVec3d(normal); AsdkPoly* poly = new AsdkPoly; if (poly==NULL){ acutPrintf("\nOut of memory."); return; } if (poly->set(cen, start, nSides, norm, nameBuf, tsId, elev)!=Acad::eOk){ delete poly; acutPrintf("\nCannot create AsdkPoly with given parameters."); return; } poly->setDatabaseDefaults(acdbHostApplicationServices()->workingDatabase()); postToDb(poly); }
// input may either return RTNORM (from command line) or RTMODELESS (from OPM) // if it is RTMODELSS, the entity already has that value set. // if it not RTMODELSS, we process as before, setting the value on m_pPoly void CPolyCommand::getInput() { ads_point tmpc; char tmpBuf[133]; if (!m_pPolyCmd->GotNumSides()) { int nSides; acedInitGet(INP_NNEG, ""); if ((m_retval = acedGetInt("\nEnter number of sides: ", &nSides)) == RTNORM) { if (nSides < 3) { acutPrintf("\nNeed at least 3 sides."); return; } m_pPoly->put_NumSides(nSides); } } else if (!m_pPolyCmd->GotCenter()) { if ((m_retval = acedGetPoint(NULL, "\nLocate center of polygon: ", tmpc)) == RTNORM) { AcAxPoint2d pt2d(tmpc[0],tmpc[1]); m_pPoly->put_Center(*pt2d.asVariantPtr()); } } else if (!m_pPolyCmd->GotStartPoint()) { AcAxPoint2d pt2dCtr(0.0,0.0); VARIANT *pVar = pt2dCtr.asVariantPtr(); m_pPoly->get_Center(pVar); pt2dCtr = pVar; ads_point cp = { pt2dCtr.x, pt2dCtr.y }; if ((m_retval = acedGetPoint(cp, "\nLocate start point of polygon: ", tmpc)) == RTNORM) { AcAxPoint2d pt2d(tmpc[0],tmpc[1]); if (pt2dCtr == pt2d) { acutPrintf("\nPick a point different from the center."); return; } m_pPoly->put_StartPoint(*pt2d.asVariantPtr()); } } else if (!m_pPolyCmd->GotTextString()) { if ((m_retval = acedGetString(Adesk::kTrue, "\nEnter polygon name: ",tmpBuf)) == RTNORM) { m_pPoly->put_TextString(_bstr_t(tmpBuf)); } } else if (!m_pPolyCmd->GotTextStyleName()) { if ((m_retval = acedGetString(Adesk::kTrue, "\nEnter text style: ", tmpBuf)) == RTNORM) { AcDbObjectId tsId; if (tmpBuf[0] == '\0' ) { // Get default text style struct resbuf result ; if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) { acutPrintf( "\nError while reading default AutoCAD text style setting"); fail(); return; } strcpy (tmpBuf, result.resval.rstring) ; acdbFree (result.resval.rstring) ; } if ( rx_getTextStyleId(tmpBuf, acdbHostApplicationServices()->workingDatabase(), tsId) != Acad::eOk) { acutPrintf("\nInvalid text style name"); fail(); return; } m_pPoly->put_TextStyleName(_bstr_t(tmpBuf)); } } else m_bDone = true; if (m_retval != RTNORM && m_retval != RTMODELESS) fail(); }
void addEmpCommand() { AcDbDictionary* pEmployeeDict=NULL; EmployeeDetails* pEmployeeDetails=NULL; EmployeeEntry* pEmployeeEntry=NULL; //this cannot really happen but... if (acdbHostApplicationServices()->workingDatabase()==NULL) return; try { //start transaction for the db operations in this command actrTransactionManager->startTransaction(); //get the data from the user ads_name ename; ads_point pt; ADSOK(acedEntSel("Select employee:",ename,pt)); //do a quick check //a more comprehensive check could include //a check to see if we already have the detail object on this candidate AcDbObjectId idO; ARXOK(acdbGetObjectId(idO,ename)); AcDbObject* pO; ARXOK(actrTransactionManager->getObject(pO,idO,AcDb::kForWrite)); if (!pO->isKindOf(AcDbBlockReference::desc())) throw Acad::eNotThatKindOfClass; //go on getting user input int id; ADSOK(acedGetInt("Enter employee ID:",&id)); int cubeNumber; ADSOK(acedGetInt("Enter cube number:",&cubeNumber)); char strFirstName[133]; ADSOK(acedGetString(0,"Enter employee first name:",strFirstName)); char strLastName[133]; ADSOK(acedGetString(0,"Enter employee last name:",strLastName)); //create an EmployeeDetails object and set its fields if ((pEmployeeDetails= new EmployeeDetails)==NULL) throw Acad::eOutOfMemory; ARXOK(pEmployeeDetails->setID(id)); ARXOK(pEmployeeDetails->setCubeNumber(cubeNumber)); ARXOK(pEmployeeDetails->setFirstName(strFirstName)); ARXOK(pEmployeeDetails->setLastName(strLastName)); //get hold of the extension dictionary if ((idO = pO->extensionDictionary())==AcDbObjectId::kNull){ ARXOK(pO->createExtensionDictionary()); idO = pO->extensionDictionary(); } AcDbDictionary* pExtDict; //make sure you open erased extension dictionaries //you may need to unerase them ARXOK(actrTransactionManager->getObject((AcDbObject*&)pExtDict,idO,AcDb::kForWrite,Adesk::kTrue)); //add the EmployeeDetails to the extension dictionary addDictAndEntry(DICT,pExtDict,DETAILS,pEmployeeDetails); //create the EmployeeEntry and set the id it holds to //point to the corresponding EmployeeDetails if ((pEmployeeEntry= new EmployeeEntry)==NULL) throw Acad::eOutOfMemory; ARXOK(pEmployeeEntry->setEmployee(pEmployeeDetails->objectId())); //get hold of the NOD AcDbDictionary* pNOD; ARXOK(getNOD(pNOD,AcDb::kForWrite)); //create string key from the employee id char strID[33]; sprintf(strID,"%d",id); //set the EmployeeEntry to the NOD addDictAndEntry(DICT,pNOD,strID,pEmployeeEntry); actrTransactionManager->endTransaction(); } catch (const Acad::ErrorStatus es) { //we have run into some error //do the proper cleanup. a smart pointer could check these in its //destructor and then we wouldn't need this but we I don't want to //complicate the picture with that yet. if (pEmployeeDict!=NULL && pEmployeeDict->objectId()==AcDbObjectId::kNull) delete pEmployeeDict; if (pEmployeeDetails!=NULL && pEmployeeDetails->objectId()==AcDbObjectId::kNull) delete pEmployeeDetails; if (pEmployeeEntry!=NULL && pEmployeeEntry->objectId()==AcDbObjectId::kNull) delete pEmployeeEntry; //abort, rollback all db operations actrTransactionManager->abortTransaction(); //check if the user has cancelled us, then we don't report //anything if (es!=Acad::eUserBreak) acutPrintf("***Error: %s\n",acadErrorStatusText(es)); } }