// cmdcount_findfile: return int representing whether file was found (RTNORM) // or not. Looks in the directory where .cfg/.ini files // live. If it doesn't find the file there, it looks along // the AutoCAD search path, according to acedFindFile(). int cmdcount_findfile (const char *fname, char *result) { char statFilePath[MAX_PATH_LENGTH]; #ifdef OEM // OEM doesn't support environment the "ACADCFG" env. variable. So, we'll look // in the exedir instead resbuf tmpResult; if (acedGetVar(/*NOXLATE*/"EXEDIR", &tmpResult) != RTNORM) { sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1", PRODUCTL, getProductName()); acrx_abort(abort_msg); } strcpy(statFilePath, tmpResult.resval.rstring); #else if (acedGetEnv(/*NOXLATE*/"ACADCFG", statFilePath) != RTNORM) { sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1", PRODUCTL, getProductName()); acrx_abort(abort_msg); } #endif if (statFilePath[strlen(statFilePath) - 1] != '\\') strcat(statFilePath, "\\"); strcat(statFilePath, fname); if (fopen(statFilePath, /*NOXLATE*/"r") != NULL) { strcpy(result, statFilePath); return RTNORM; } else return acedFindFile(fname, result); }
void jig3d() { try { struct resbuf rb; acedGetVar("cvport", &rb); if (rb.resval.rint==1) throw CmdException("3djig cannot be used in layout mode"); ads_name ename; ads_point pt; int rt; if ((rt = acedEntSel("Select object:",ename,pt))==RTCAN) return; if (rt!=RTNORM) throw CmdException(Acad::eInvalidInput,"Invalid selection. Try again!"); AcDbObjectId id; acdbGetObjectId(id,ename); Jig3d jig; jig.init(id, asPnt3d(pt), rb.resval.rint); jig.engage(); } catch(CmdException e) { const char* strDesc = e.description(); if (strDesc == NULL) strDesc = "No description."; acutPrintf("ERROR:%s (es=%s)",strDesc,acadErrorStatusText(e.errorStatus())); } }
BOOL TWBlockRefenceTool::Insert( IN const CString& strBlockName, IN const AcGePoint3d& PtIns, IN double dScale, IN double dRat, AcDbDatabase* pDb /*= NULL */ ) { /* 使用简单的实现方法 */ ads_name entPre = { 0, 0 }; ads_entlast( entPre ); resbuf rbOld; resbuf rbNew; rbNew.restype = RTSHORT; rbNew.resval.rint = 0; acedGetVar( _T("ATTREQ"), &rbOld ); acedSetVar( _T("ATTREQ"), &rbNew ); ads_command( RTSTR, _T("insert"), RTSTR, strBlockName, RT3DPOINT, asDblArray(PtIns), RTREAL, 1.0, RTSTR, _T(""), RTREAL, 0.0, 0 ); acedSetVar( _T("ATTREQ"), &rbOld ); ads_name ent = { 0 ,0 }; ads_entlast( ent ); //判定是否正确生成块参照 if( ads_name_equal(ent, entPre) ) return FALSE; acdbGetObjectId( m_IdblockRef, ent ); return IsValid(); }
//----------------------------------------------------------------------------- // Uses acedGetVar() to get the sysvars. // int getIntSysVar(char* pszVarName) { struct resbuf rb; acedGetVar(pszVarName,&rb); return(rb.resval.rint); }
// GETcURtIME: return double representing Julian Date, values of which // may be directly subtracted for elapsed time measurement. double getCurTime() { resbuf currentTime; if (acedGetVar(/*NOXLATE*/"DATE", ¤tTime) != RTNORM) { // This should never happen. sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1", PRODUCTL, getProductName()); acrx_abort(abort_msg); } return currentTime.resval.rreal; }
/* Utility function to replace hardcoded references to acad.exe, acadnt.cfg, etc. Pass in the extension of the desired file and get back the product specific file name. */ TCHAR *getProgramFiles(TCHAR *ext) { struct resbuf result; static char program[13]; if (acedGetVar(/*NOXLATE*/"PROGRAM", &result) != RTNORM) { /* If we can't get the "PRODUCT" name, assume "acad" */ sprintf(program, /*NOXLATE*/"acad%.*s", 8, ext); } else { sprintf(program, /*NOXLATE*/"%.*s%.*s", 4, result.resval.rstring, 8, ext); acdbFree (result.resval.rstring) ; } return program; }
void printCurrentDateTime(FILE* statFile) { resbuf tempRes; int jtd_day; double jtd_msec; int ctd_year, ctd_month, ctd_day, ctd_hour, ctd_minute, ctd_second; double rem; long t, j, y, d; // Get Julian date and convert it to calendar time and date // As in Calendar Time and Date, in case you were wondering what // the "ctd_" prefix used pervasively in this routine stands for. if (acedGetVar(/*NOXLATE*/"DATE", &tempRes) != RTNORM) { sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 2", PRODUCTL, getProductName()); acrx_abort(abort_msg); } jtd_day = (int)tempRes.resval.rreal; jtd_msec = tempRes.resval.rreal - (int)tempRes.resval.rreal; j = jtd_day - 1721119L; t = 4 * j - 1; y = t / 146097L; j = t - 146097L * y; d = j / 4; j = (4 * d + 3) / 1461; d = (4 * d - 1461L * j + 7) / 4; ctd_month = (5 * d - 3) / 153; ctd_day = ((5 * d) - 3 - 153 * ctd_month + 5) / 5; ctd_year = (short)((100 * y) + j); if (ctd_month >= 10) { ctd_month -= 9; ctd_year++; } else ctd_month += 3; ctd_hour = (short)(jtd_msec * 24); rem = (jtd_msec * 24) - ctd_hour; ctd_minute = (short)(rem * 60); rem = (rem * 60) - ctd_minute; ctd_second = (short)(rem * 60); // print current date and time fprintf(statFile, "%0*d/%0*d/%0*d %0*d:%0*d:%0*d", 2, ctd_month, 2, ctd_day, 4, ctd_year, 2, ctd_hour, 2, ctd_minute, 2, ctd_second); }
char *getProductName( ) { /* Save the Product Name is a static variable, so that we only need to actually get it the first time we execute. */ if (product[0] == NULL) { struct resbuf result; if (acedGetVar(/*NOXLATE*/"PRODUCT", &result) != RTNORM) /* If we can't get the "PRODUCT" name, assume "AutoCAD" */ strcpy(product, /*NOXLATE*/"AutoCAD"); else strcpy(product, result.resval.rstring); } return product; }
// cmdcount_findfile: Searches for the stat file as follows: // 1. Searches the location of StatPath. // 2. If this key is not present it searches MyDocuments // 3. It searches the AutoCAD search path. // Note that MyDocuments and StatPath are mutually exclusive. int cmdcount_findfile (const TCHAR *fname, TCHAR *result, bool returnDefault) { TCHAR statFilePath[MAX_PATH_LENGTH] = "\0"; TCHAR buf[512]; _tcscpy(buf,acrxProductKey()); _tcscat(buf,/*NOXLATE*/_T("\\Applications\\AcadCmdCount")); HKEY hKey; if (ERROR_SUCCESS==RegOpenKeyEx(HKEY_CURRENT_USER,buf,0,KEY_QUERY_VALUE,&hKey)) { DWORD dwType = 0; DWORD dwDataSize = sizeof(buf); if (ERROR_SUCCESS == RegQueryValueEx(hKey, _T(/*MSG0*/"StatPath"), NULL, &dwType, (LPBYTE)buf, &dwDataSize)) { _tcscpy(statFilePath,buf); } RegCloseKey(hKey); } if (statFilePath[0]==0) { resbuf rb; if (acedGetVar(/*NOXLATE*/"MYDOCUMENTSPREFIX", &rb) != RTNORM) { sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1", PRODUCTL, getProductName()); acrx_abort(abort_msg); } _tcscpy(statFilePath,rb.resval.rstring); acdbFree(rb.resval.rstring); } if (statFilePath[strlen(statFilePath) - 1] != '\\') strcat(statFilePath, "\\"); strcat(statFilePath, fname); FILE* f; if ((f = fopen(statFilePath, /*NOXLATE*/"r")) != NULL) { fclose(f); strcpy(result, statFilePath); return RTNORM; } else { int ret = acedFindFile(fname, result); if (ret!=RTNORM && returnDefault) { ret= RTNORM; strcpy(result,statFilePath); } return ret; } }
// The following defines the constructor that accepts a point to be used as the // centerpoint of the ellipse and the current UCS normal // vector to be used as the normal for the ellipse. It // also initializes the radius ratio to a small value so // that during selection of the major axis, the ellipse // will appear as a line. The prompt counter is also // initialized to 0. // AsdkEllipseJig::AsdkEllipseJig( const AcGePoint3d& pt, const AcGeVector3d& normal) : mCenterPt(pt), mNormal(normal), mRadiusRatio(0.00001), mPromptCounter(0) { // Calculate a proper initial offset for the major axis from the current view extents. // struct resbuf rb; memset (&rb, 0, sizeof (struct resbuf)); acedGetVar (_T("VIEWSIZE"), &rb); double majorAxisInitialOffset = rb.resval.rreal/1000.0; mMajorAxis = AcGeVector3d(majorAxisInitialOffset,0,0); // Offset the major axis a bit from the center point. }
void Additional_Class::Close_ORTHOMODE( void ) { resbuf var; if(RTNORM == acedGetVar(_T("ORTHOMODE"), &var)) { if( var.resval.rint == 1) { var.resval.rint = 0; acedSetVar(_T("ORTHOMODE"), &var); return; } else { return; } } return; }
void XAcDocOp::openDocCallBack(void *pData) { if(pData == NULL || !AfxIsValidAddress(pData , sizeof(_CREATEDOCUMENTINFO))) return; CString strFilePathName; if(pData == NULL || !AfxIsValidAddress(pData , sizeof(_CREATEDOCUMENTINFO))) return; Acad::ErrorStatus es; try { _CREATEDOCUMENTINFO *pCreateInfo; pCreateInfo = (_CREATEDOCUMENTINFO*)pData; strFilePathName = pCreateInfo->pszName; strFilePathName.Trim(); //判断当前是否处于SDI模式 BOOL bIsSDIMode = FALSE; resbuf *pRb; pRb = acutNewRb(RTSHORT); if(acedGetVar("SDI" , pRb) == RTNORM && pRb->resval.rint == 1) //是SDI模式 { pCreateInfo->bActiveOldDoc = FALSE; //不能切换到先前的文档 if(curDoc() != NULL) es = acDocManager->closeDocument(curDoc()); //关闭当前文档 } acutRelRb(pRb); es = acDocManager->appContextOpenDocument(strFilePathName); if(pCreateInfo->bActiveOldDoc && pCreateInfo->pOldDoc != NULL) acDocManager->activateDocument(pCreateInfo->pOldDoc); } catch (...) { } }
Adesk::Boolean updateCumulativeStats() { // If anything is going on in any document, now is NOT a good // time to accumulate stats, because each command/LISP expression // in progress has pointers into session stats. // This could be fixed with more recoding than I have time to do // now. WCA 7/15/98 for (int i = docData.length() - 1; i >= 0; i--) { // Make sure our info is up to date. if (docData[i].doc == curDocGlobals.doc) docData[i] = curDocGlobals; if ((docData[i].cmdIndex > 0) || (docData[i].lispRcd != NULL)) return Adesk::kFalse; } if (!readCumulativeStats()) { acutPrintf("\nWarning: Could not find Command Statistics file.\n"); acutPrintf("Will try to create it.\n"); } AcRxDictionaryIterator* iter; // Loop over current session stats, and merge them into cumulative stats. for (iter = sessionStats->newIterator(); !iter->done(); iter->next()) { AsdkCommandRecord* sessionCmdRcd = (AsdkCommandRecord*) iter->object(); AsdkCommandRecord* cumulativeCmdRcd = (AsdkCommandRecord*) cumulativeStats->at(iter->key()); if (!cumulativeCmdRcd) // First time, add it. cumulativeStats->atPut(iter->key(), new AsdkCommandRecord(sessionCmdRcd->count, sessionCmdRcd->elapsedTime)); else { // Not the first time, so bump it. cumulativeCmdRcd->count += sessionCmdRcd->count; cumulativeCmdRcd->elapsedTime += sessionCmdRcd->elapsedTime; } } delete iter; // Now that it has been added in, wipe out the current session Stats; delete sessionStats; sessionStats = initStatDictionary(); // Open the cumulative stat file, creating it if necessary. char statFilePath[MAX_PATH_LENGTH]; int ret = cmdcount_findfile(statFileName, statFilePath,true); assert(ret==RTNORM);//this should always succeed // Open the file FILE* statFile = fopen(statFilePath, /*NOXLATE*/"w"); if (statFile == NULL) { // Bad permission in our chosen directory. Give up. acedAlert("Warning: Could not create Command Statistics file."); return Adesk::kTrue; } // Print version number of STATFILE fprintf(statFile, "v%04.1f\n", STAT_FILENAME_VERSION); // Print create date of STATFILE if (!*createDate) { fprintf(statFile, "Created: "); printCurrentDateTime(statFile); fprintf(statFile, "\n"); } else fprintf(statFile, "%s\n", createDate); // Print date last modified for STATFILE fprintf(statFile, "Last Modified: "); printCurrentDateTime(statFile); fprintf(statFile, "\n"); resbuf tempRes; // Print LOGINNAME if (acedGetVar(/*NOXLATE*/"LOGINNAME", &tempRes) != RTNORM) { sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1", PRODUCTL, getProductName()); acrx_abort(abort_msg); } fprintf(statFile, /*NOXLATE*/"LOGINNAME: %s\n", tempRes.resval.rstring); acdbFree (tempRes.resval.rstring) ; // Print ACAD serial number if (acedGetVar(/*NOXLATE*/"_PKSER", &tempRes) != RTNORM) { sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1", PRODUCTL, getProductName()); acrx_abort(abort_msg); } fprintf(statFile, /*NOXLATE*/"%.*s Serial Number: %s\n", PRODUCTL, getProductName(), tempRes.resval.rstring); acdbFree (tempRes.resval.rstring) ; // Print ACAD version if (acedGetVar(/*NOXLATE*/"_VERNUM", &tempRes) != RTNORM) { sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1", PRODUCTL, getProductName()); acrx_abort(abort_msg); } fprintf(statFile, /*NOXLATE*/"%.*s version: %s\n", PRODUCTL, getProductName(), tempRes.resval.rstring); acdbFree (tempRes.resval.rstring) ; for (iter = cumulativeStats->newIterator(AcRx::kDictSorted); !iter->done(); iter->next()) { // Write out the command string. fprintf(statFile, "%s", iter->key()); // Try for reasonable text alignment, such as allowing 24 chars // for the command name. But have at least 1 space as a delimiter. int nbrOfSpaces = 24 - strlen(iter->key()); do fprintf(statFile, " "); while (--nbrOfSpaces > 0); // Now the count and elapsed time in seconds (assume 1 billion seconds // maximum, which should exceed a typical beta survey period). fprintf(statFile, "%7i %12.2f\n", ((AsdkCommandRecord*) iter->object())->count, ((AsdkCommandRecord*) iter->object())->elapsedTime); } fclose(statFile); delete iter; return Adesk::kTrue; }
Acad::ErrorStatus selectEntity(const AcDb::SubentType& subType, AcDbFullSubentPath& subPath) { Acad::ErrorStatus acadReturnValue = Acad::eOk; int errStat = RTERROR; ads_name sset; AcGePoint3d pickPnt; struct resbuf org_osnap; acedGetVar(ACRX_T("OSMODE"), &org_osnap); struct resbuf new_osnap = org_osnap; new_osnap.resval.rint = 0; acedSetVar(ACRX_T("OSMODE"), &new_osnap); while ((errStat != RTNORM) && (errStat != RTCAN) && (errStat != RTREJ) && (errStat != RTNONE)) { ads_name ent_name; switch(subType) { case AcDb::kNullSubentType: errStat = acedEntSel(ACRX_T("\n Pick a solid\n"), ent_name, asDblArray(pickPnt)); break; case AcDb::kFaceSubentType: errStat = acedEntSel(ACRX_T("\n Pick a face\n"), ent_name, asDblArray(pickPnt)); break; case AcDb::kEdgeSubentType: errStat = acedEntSel(ACRX_T("\n Pick an edge\n"), ent_name, asDblArray(pickPnt)); break; default: acutPrintf(ACRX_T("\n getPath: unsupported subentity type: %d\n"), subType); return Acad::eInvalidInput; } if (errStat == RTERROR) { struct resbuf buf_errno; acedGetVar(ACRX_T("ERRNO"), &buf_errno); if (buf_errno.resval.rint == OL_ENTSELNULL) errStat = RTNONE; } } if (errStat == RTNORM) { errStat = acedSSGet(NULL, asDblArray(pickPnt), NULL, NULL, sset); } acedSetVar(ACRX_T("OSMODE"), &org_osnap); if (errStat != RTNORM) return Acad::eAmbiguousInput; // Get the entity name struct resbuf* rb; errStat = acedSSNameX(&rb, sset, 0L); if (errStat != RTNORM) { acedSSFree(sset); return Acad::eAmbiguousInput; } // Free the selection set acedSSFree(sset); // The selected entity is the final entry in the resbuf int i; struct resbuf* pTemp; for (i=1, pTemp=rb; i<3; i++, pTemp=pTemp->rbnext) ; ads_name ename; ads_name_set(pTemp->resval.rlname, ename); // Get the GsMarker pTemp = pTemp->rbnext; short marker = pTemp->resval.rint; // Free the rb resbuf entity acutRelRb(rb); // Get the object ID of the selected entity AcDbObjectId objId; acadReturnValue = acdbGetObjectId(objId, ename); if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n acdbGetObjectId failed\n")); return acadReturnValue; } // Use an existing transaction if there is one; // else open a new one Adesk::Boolean ownTransaction = Adesk::kFalse; acadReturnValue = dbOpenTransaction(ownTransaction); if (acadReturnValue != Acad::eOk) { acutPrintf(ACRX_T("\n Error in dbOpenTransaction:")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } // Open the object for read-only AcDbObject* pObj = NULL; acadReturnValue = actrTransactionManager->getObject( pObj, objId, AcDb::kForRead); if (acadReturnValue != Acad::eOk) { dbAbortTransaction(ownTransaction); acutPrintf(ACRX_T("\n Error in getPath:")); errorReport((AcBr::ErrorStatus)acadReturnValue); return acadReturnValue; } if (AcDbBlockReference::cast(pObj) != NULL) { acadReturnValue = extractSolidFromBlock(ename, subType, marker, pickPnt, subPath); if (acadReturnValue != Acad::eOk) { dbCloseTransaction(ownTransaction); acutPrintf(ACRX_T("\n extractSolidFromBlock failed\n")); return acadReturnValue; } } else { AcDbObjectIdArray objIdList; objIdList.append(objId); acadReturnValue = makeSubentPath(pObj, objIdList, subType, marker, pickPnt, subPath); if (acadReturnValue != Acad::eOk) { dbCloseTransaction(ownTransaction); acutPrintf(ACRX_T("\n makeSubentPath failed\n")); return acadReturnValue; } } // Close the transaction dbCloseTransaction(ownTransaction); return acadReturnValue; }
// 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(); }
// Invoked by the command - DRAGPOLY // void dragPolyCommand() { int nSides = 0; ads_point center, startPt, normal; if (acedGetPoint(NULL, "\nLocate center of polygon: ", center) != RTNORM) 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, msg, 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); AsdkPolyJig* pJig = new AsdkPolyJig(); pJig->acquire(cen, norm, nameBuf, tsId, elev); delete pJig; }
// 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); }
// commandStats: Print out current Session and Cumulative Stats void initStats() { cmdr = new AsdkCommandReactor(); statFileName[0] = EOS; // Define dictionary to delete all its entries when it is deleted. sessionStats = initStatDictionary(); acedEditor->addReactor(cmdr); acedRegCmds->addCommand(/*NOXLATE*/"ASDK_COMMAND_STATS", /*NOXLATE*/"ASDK_CMDSTAT", "CMDSTAT", ACRX_CMD_MODAL, &commandStats); acedRegCmds->addCommand(/*NOXLATE*/"ASDK_COMMAND_STATS", /*NOXLATE*/"ASDK_CMDCOUNT", "CMDCOUNT", ACRX_CMD_MODAL, &cmdCommandCount); bStatsFileUpdatePending = Adesk::kFalse; // Initialize Global struct array docData.setLogicalLength(0); // Fill array from existing documents AcApDocumentIterator* pDocIter = acDocManager->newAcApDocumentIterator(); for (;!pDocIter->done(); pDocIter->step()) // add an entry for the document, if some other notification hasn't // already done so. lookupDoc(pDocIter->document()); delete pDocIter; // Establish current document, if there is one yet. if ((docData.length() > 0) && (acDocManager->curDocument() != NULL)) curDocGlobals = docData[lookupDoc(acDocManager->curDocument())]; else curDocGlobals.doc = NULL; pDocReactor = new AsdkDocReactor; acDocManager->addReactor(pDocReactor); resbuf tempRes; int i, j; // set the statFileName to be <LOGINNAME>.txt // remove blanks and tabs from LOGINNAME, so we have a more // reasonable statFileName. if (acedGetVar(/*NOXLATE*/"LOGINNAME", &tempRes) != RTNORM) { sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1", PRODUCTL, getProductName()); acrx_abort(abort_msg); } strcpy(statFileName, tempRes.resval.rstring); acdbFree (tempRes.resval.rstring) ; for (i = 0, j = 0; (statFileName[i] != EOS) && (j < LOGINNAME_LENGTH); i++) { if ((statFileName[i] != ' ') && (statFileName[i] != '\t')) { statFileName[j] = statFileName[i]; j++; } } statFileName[j] = EOS; strcat(statFileName, /*NOXLATE*/".txt"); }
void printAll() { int rc; char blkName[50]; rc = acedGetString(Adesk::kTrue, "Enter Block Name <CR for current space>: ", blkName); if (rc != RTNORM) return; if (blkName[0] == '\0') { if (acdbHostApplicationServices()->workingDatabase()->tilemode() == Adesk::kFalse) { struct resbuf rb; acedGetVar("cvport", &rb); if (rb.resval.rint == 1) { strcpy(blkName, ACDB_PAPER_SPACE); } else { strcpy(blkName, ACDB_MODEL_SPACE); } } else { strcpy(blkName, ACDB_MODEL_SPACE); } } AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(blkName, pBlockTableRecord, AcDb::kForRead); pBlockTable->close(); AcDbBlockTableRecordIterator *pBlockIterator; pBlockTableRecord->newIterator(pBlockIterator); for (; !pBlockIterator->done(); pBlockIterator->step()) { AcDbEntity *pEntity; pBlockIterator->getEntity(pEntity, AcDb::kForRead); AcDbHandle objHandle; pEntity->getAcDbHandle(objHandle); char handleStr[20]; objHandle.getIntoAsciiBuffer(handleStr); const char *pCname = pEntity->isA()->name(); acutPrintf("Object Id %lx, handle %s, class %s.\n", pEntity->objectId(), handleStr, pCname); pEntity->close(); } delete pBlockIterator; pBlockTableRecord->close(); acutPrintf("\n"); }
void asdktest4 () { //----- Select the entities ads_name ss, en ; if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM ) return ; //----- Append entity IDs to the collector long n ; AcDbObjectId id ; AsdkHlrCollector collector ; acedSSLength (ss, &n) ; for ( int i =0 ; i < n ; i++ ) { acedSSName (ss, i, en) ; acdbGetObjectId (id, en) ; collector.addEntity (id) ; } acedSSFree (ss) ; //----- Get current viewport settings struct resbuf rb; acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb); ads_point tarPt; acdbUcs2Wcs (rb.resval.rpoint, tarPt, Adesk::kFalse) ; //----- Ask if non-visible edges should be created int hidLines =AfxMessageBox (ACRX_T("Would you like to see hidden lines?"), MB_YESNO) ; int honorInt =AfxMessageBox (ACRX_T("Would you like to honor internal visibility of polyface meshes or ACIS objects?"), MB_YESNO) ; int meshSils =AfxMessageBox (ACRX_T("Would you like to calculate silhouettes of polyface meshes?"), MB_YESNO) ; int unit =AfxMessageBox (ACRX_T("Would you like to unit solid before processing?"), MB_YESNO) ; //----- *** First view will be front view *** //----- Process hidden line removal AsdkHlrEngine hlrFront ( asPnt3d (tarPt), AcGeVector3d (0, -1, 0),//AcGeVector3d (0, 0, -1), kProject| kEntity | kBlock | kReuse //----- Do not use 'kCleanup' | (honorInt == IDYES ? kHonorInternals : 0) | (hidLines == IDYES ? kShowAll : 0) | (meshSils == IDYES ? kMeshSilhouettes : 0) | (unit == IDYES ? kUnite : 0) ) ; hlrFront.run (collector) ; AddEntityToLayer (collector, ACRX_T("FontView")) ; //----- *** Second view will be left view *** //----- Process hidden line removal AsdkHlrEngine hlrLeft ( asPnt3d (tarPt), AcGeVector3d (1, 0, 0),//, AcGeVector3d (1, 0, 0), kProject| kEntity | kBlock | kReuse //----- Do not use 'kCleanup' | (honorInt == IDYES ? kHonorInternals : 0) | (hidLines == IDYES ? kShowAll : 0) | (meshSils == IDYES ? kMeshSilhouettes : 0) | (unit == IDYES ? kUnite : 0) ) ; hlrLeft.run (collector) ; AddEntityToLayer (collector, ACRX_T("LeftView")) ; //----- *** Third view will be top view *** //----- Process hidden line removal AsdkHlrEngine hlrTop ( asPnt3d (tarPt), AcGeVector3d (0, 0, 1),//, AcGeVector3d (0, -1, 0), kProject| kEntity | kBlock | kReuse //----- Do not use 'kCleanup' | (honorInt == IDYES ? kHonorInternals : 0) | (hidLines == IDYES ? kShowAll : 0) | (meshSils == IDYES ? kMeshSilhouettes : 0) | (unit == IDYES ? kUnite : 0) ) ; hlrTop.run (collector) ; AddEntityToLayer (collector, ACRX_T("TopView")) ; }
//在CAD中根据一个文件名打开一个文档,返回一个状态和输出打开的文档 Acad::ErrorStatus XAcDocOp::openAcDocument(CString strFilePathName , AcApDocument *&pDoc , BOOL bKeepOldActive , BOOL bAutoCloseOnlyReadWarning) { AcApDocuments arrDocs , arrDocs1; Acad::ErrorStatus es; strFilePathName.Trim(); if(strFilePathName.GetLength() == 0) return Acad::eFileNotFound; pDoc = NULL; //先获取现今的所有文档 es = enumAcDocument(arrDocs); if(es != Acad::eOk) return es; if(acDocManager->isApplicationContext()) { AcApDocument *pOldDoc = NULL; //判断当前是否处于SDI模式 BOOL bIsSDIMode = FALSE; resbuf *pRb; pRb = acutNewRb(RTSHORT); if(acedGetVar("SDI" , pRb) == RTNORM && pRb->resval.rint == 1) //是SDI模式 { bKeepOldActive = FALSE; //不能切换到先前的文档 if(curDoc() != NULL) es = acDocManager->closeDocument(curDoc()); //关闭当前文档 } acutRelRb(pRb); if(bKeepOldActive) pOldDoc = curDoc(); if(bAutoCloseOnlyReadWarning) //自动关闭只读提示对话框 AutoCloseOnlyReadWarningDlg(); es = acDocManager->appContextOpenDocument(strFilePathName); if(es != Acad::eOk) return es; if(bKeepOldActive && pOldDoc != NULL) acDocManager->activateDocument(pOldDoc); } else { _CREATEDOCUMENTINFO createInfo; ::ZeroMemory(&createInfo , sizeof(_CREATEDOCUMENTINFO)); _tcscpy(createInfo.pszName , strFilePathName); if(bKeepOldActive) { createInfo.bActiveOldDoc = TRUE; createInfo.pOldDoc = curDoc(); } if(bAutoCloseOnlyReadWarning) //自动关闭只读提示对话框 AutoCloseOnlyReadWarningDlg(); acDocManager->executeInApplicationContext(openDocCallBack , (void *)&createInfo); } //再一次获取所有文档 es = enumAcDocument(arrDocs1); if(es != Acad::eOk) return es; if(arrDocs.GetSize() == arrDocs1.GetSize()) //创立失败 return Acad::eCreateFailed; BOOL bFind; for(int i = 0 ; i < arrDocs1.GetSize() ; i++) { bFind = FALSE; for(int j = 0 ; j < arrDocs.GetSize() ; j++) { if(arrDocs.GetAt(j) == arrDocs1.GetAt(i)) { bFind = TRUE; break; } } if(!bFind) { pDoc = arrDocs1.GetAt(i); return Acad::eOk; //检查名字是否相等 CString strName; strName = pDoc->fileName(); ASSERT(strName.Compare(strFilePathName) == 0); } } return Acad::eCreateFailed; }
void asdktest1 () { //----- Select the entities ads_name ss, en ; if ( acedSSGet (NULL, NULL, NULL, NULL, ss) != RTNORM ) return ; //----- Append entity IDs to the collector long n ; AcDbObjectId id ; AsdkHlrCollector collector ; collector.setDeleteState (true) ; acedSSLength (ss, &n) ; for ( int i =0 ; i < n ; i++ ) { acedSSName (ss, i, en) ; acdbGetObjectId (id, en) ; collector.addEntity (id) ; } acedSSFree (ss) ; //----- Get current viewport settings struct resbuf rb; acedGetVar(ACRX_T(/*NOXLATE*/"viewdir"), &rb); ads_point dirPt; acdbUcs2Wcs (rb.resval.rpoint, dirPt, Adesk::kTrue) ; acedGetVar(ACRX_T(/*NOXLATE*/"target"), &rb); ads_point tarPt; acdbUcs2Wcs (rb.resval.rpoint, tarPt, Adesk::kFalse) ; //----- Ask if non-visible edges should be created int hidLines =AfxMessageBox (ACRX_T("Would you like to see hidden lines?"), MB_YESNO) ; int honorInt =AfxMessageBox (ACRX_T("Would you like to honor internal visibility of polyface meshes or ACIS objects?"), MB_YESNO) ; int meshSils =AfxMessageBox (ACRX_T("Would you like to calculate silhouettes of polyface meshes?"), MB_YESNO) ; int unit =AfxMessageBox (ACRX_T("Would you like to unit solid before processing?"), MB_YESNO) ; //----- Process hidden line removal AsdkHlrEngine hlr ( asPnt3d (tarPt), asVec3d (dirPt), kEntity | kBlock | kSubentity | kProgress | (honorInt == IDYES ? kHonorInternals : 0) | (hidLines == IDYES ? kShowAll : 0) | (meshSils == IDYES ? kMeshSilhouettes : 0) | (unit == IDYES ? kUnite : 0) ) ; hlr.setAcisConversionProgressCallBack (progress1) ; hlr.setAhlProgressCallBack (progress2) ; hlr.setAcadConversionProgressCallBack (progress3) ; acedSetStatusBarProgressMeter (ACRX_T("HLR running: "), 0, 300) ; hlr.run (collector) ; acedRestoreStatusBar () ; //----- Assign color to the resulting entities //----- red for visible edges //----- blue for non-visible edges //----- yellow for internal edges 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 ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) { acutPrintf (_T("Failed to add entity to current space.\n")) ; break ; } if ( acdbOpenAcDbEntity (pEnt, id, AcDb::kForRead) != Acad::eOk ) { acutPrintf (_T("Failed to open last added outputed curve.\n")) ; break ; } //----- Entity originator path for block reference entities AcDbObjectIdArray ids =p->getObjectIds () ; if ( ids.logicalLength () > 0 ) { acutPrintf (ACRX_T("\n%lx, "), pEnt->objectId ().asOldId ()) ; if ( p->getSubentId ().type () != AcDb::kNullSubentType ) acutPrintf (ACRX_T("[%ld, %ld], "), p->getSubentId ().type (), p->getSubentId ().index ()) ; for ( int j =0 ; j < ids.logicalLength () ; j++ ) acutPrintf (ACRX_T("%lx, "), ids.at (j).asOldId ()) ; AcDbObjectId id =ids.last () ; if ( !id.isNull () ) { AcDbEntity *ent =NULL ; acdbOpenAcDbEntity (ent, id, AcDb::kForRead) ; id =ent->linetypeId () ; ent->close () ; if ( pEnt->upgradeOpen () == Acad::eOk ) pEnt->setLinetype (id) ; } } pEnt->close () ; } }