예제 #1
2
void addXData()
{
	// Get an Entity.
	ads_name mnEnt;
    ads_point ptSel;
    int nRet = acedEntSel(_T("\nSelect an Entity: "), mnEnt, ptSel);
	if (nRet != RTNORM)
		return;
	AcDbObjectId oid;
	
    Acad::ErrorStatus retStat;
    retStat = acdbGetObjectId(oid, mnEnt);
    if (retStat != Acad::eOk)
		return;

    AcDbObject* pObj = NULL;

    if ((retStat = acdbOpenObject(pObj, oid, AcDb::kForRead)) != Acad::eOk)
    {
        return;
    }
	// Get new XData.
	TCHAR appName[132] = {0};
	TCHAR resString[200] = {0};

    acedGetString(NULL, _T("\nEnter application name: "), appName);
    acedGetString(NULL, _T("\nEnter string to be added: "), resString);

    // XData
    resbuf *pRb = NULL;
	resbuf *pTemp = NULL;
    
    pRb = pObj->xData(appName);

    if (pRb != NULL)
	{
        for (pTemp = pRb; pTemp->rbnext != NULL; pTemp = pTemp->rbnext);
    }
	else
	{
        acdbRegApp(appName);
        pRb = acutNewRb(AcDb::kDxfRegAppName);
        pTemp = pRb;
        pTemp->resval.rstring = (TCHAR*)malloc((_tcslen(appName) + 1) * sizeof(TCHAR));
        _tcscpy(pTemp->resval.rstring, appName);
    }

    pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);
    pTemp = pTemp->rbnext;
    pTemp->resval.rstring = (TCHAR*)malloc((_tcslen(resString) + 1) * sizeof(TCHAR));
    _tcscpy(pTemp->resval.rstring, resString);

	// Set XData.
    pObj->upgradeOpen();
    pObj->setXData(pRb);
    
    pObj->close();
    acutRelRb(pRb);
}
// This is the main function of this app.  It allows the
// user to select an entity.  It then checks to see if the
// entity is a 2d-polyline.  If so, then it calls iterate
// passing in the objectId of the pline.
// 
void
listPline()
{
    int rc;
    ads_name en;
    AcGePoint3d pt;
    rc = acedEntSel(_T("\nSelect a polyline: "), en,
        asDblArray(pt));

    if (rc != RTNORM) {
        acutPrintf(_T("\nError during object selection"));
        return;
    }

    AcDbObjectId eId;
    acdbGetObjectId(eId, en);

    AcDbObject *pObj;
    acdbOpenObject(pObj, eId, AcDb::kForRead);
    if (pObj->isKindOf(AcDb2dPolyline::desc())) {
        pObj->close();
        iterate(eId);
    } else {
        pObj->close();
        acutPrintf(_T("\nSelected entity is not an AcDb2dPolyline. \nMake sure the setvar PLINETYPE is set to 0 before createing a polyline"));
    }
}
예제 #3
0
AcDbObject* ZcEntityReactor::selectObject(AcDb::OpenMode openMode)
{
	int nRet = 0;
	ads_name en;
	ads_point pt;

	nRet = acedEntSel(_T("\nSelect an entity:"), en, pt);
	if (nRet != RTNORM)
	{
		return NULL;
	}

	AcDbObjectId eId;
	Acad::ErrorStatus retStat;
	retStat = acdbGetObjectId(eId, en);
	if (retStat != Acad::eOk)
	{
		acutPrintf(_T("\nacdbGetObjectId failed!"));
		return NULL;
	}

	AcDbObject* obj = NULL;
	if ((retStat = acdbOpenObject(obj, eId, openMode)) != Acad::eOk)
	{
		acutPrintf(_T("\nOpen Failed!"));
		return NULL;
	}

	return obj;
}
예제 #4
0
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()));
    }
}
예제 #5
0
// The selectObject() function prompts the user to select an 
// entity or enter an object's handle.  It then proceeds to 
// open the object/entity and return a pointer to it.
// 
AcDbObject*
selectObject(AcDb::OpenMode openMode)
{
    ads_name en;
    ads_point pt;
    char handleStr[132];
    AcDbObjectId eId;

    Acad::ErrorStatus retStat;
    int ss;

    // Allow user to either pick an entity,
    // or type in the object handle.
    //
    acedInitGet(RSG_OTHER, "_Handle Handle");
    ss = acedEntSel("\nSelect an Entity or enter"
        " 'H' to enter its handle:  ", en, pt);

    switch (ss) {
    case RTNORM:   // got it!
        break;
    case RTKWORD:
        if ((acedGetString(Adesk::kFalse,
            "Enter Valid Object Handle: ",
            handleStr) == RTNORM)
            && (acdbHandEnt(handleStr, en) == RTNORM))
        {
            break;
        }
    // Fall-through intentional
    //
    default:
        acutPrintf("Nothing Selected, Return Code==%d\n",
            ss);
        return NULL;
    }

    // Now, exchange the ads_name for the object Id...
    //
    retStat = acdbGetObjectId(eId, en);
    if (retStat != Acad::eOk) {
        acutPrintf("\nacdbGetObjectId failed");
        acutPrintf("\nen==(%lx,%lx), retStat==%d\n",
            en[0], en[1], eId);
        return NULL;
    }

    AcDbObject* pObj;

    if ((retStat = acdbOpenObject(pObj, eId, openMode))
        != Acad::eOk)
    {
        acutPrintf("acdbOpenEntity failed: ename:"
            "(%lx,%lx), mode:%d retStat:%d", en[0],
            en[1], openMode, retStat);
        return NULL;
    }
    return pObj;
}
예제 #6
0
    //-------------------------------------------------------------------------------------------
    //
    //  功能: 将从AcDbObject派生数据库对象保存到实体的扩展词典中
    //
    //  作者:Qin H.X.
    //
    // 日期:200709
    //
    //  历史:
    //          2007.10.08 修改 by Qin H.X.
    //
    //----------------------------------------------------------------------------------------------
    // - CSCH081.AddAttribute command (do not rename)
    static void CSCH081AddAttribute(void)
    {
        AcDbObjectId dictObjId,eId, attId;
        AcDbDictionary* pDict;
        //选择管道(多义线)
        ads_name en;
        ads_point pt;
        if (  acedEntSel(_T("\n选择管道(多义线): "), en, pt)!= RTNORM)
        {
            acutPrintf(_T("\n选择失败,退出: "));
            return ;
        }
        // 打开对象
        acdbGetObjectId(eId, en);
        AcDbEntity * pEnt;
        acdbOpenObject(pEnt, eId,  AcDb::kForWrite);
        if(!pEnt->isKindOf (AcDbPolyline::desc ()))
        {
            acutPrintf(_T("\n选择的不是管道(多义线),退出: " ));
            return ;
        }

        // 判断实体的扩展词典是否创建,如果没有则创建
        dictObjId = pEnt->extensionDictionary();
        if(	dictObjId ==  AcDbObjectId::kNull )
        {
            pEnt->createExtensionDictionary();
        }

        // 获取实体的扩展词典
        dictObjId = pEnt->extensionDictionary();
        pEnt->close();

        // 	判断词典中的属性是否创建
        CPipeAttribute* pAttribute;
        acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
        pDict->getAt (_T("属性"),attId);
        if(attId!= AcDbObjectId::kNull )//如果已经创建则输出数据
        {
            acdbOpenObject(pAttribute, attId, AcDb::kForRead);
            acutPrintf(_T("\n管径:%4.2f " ),pAttribute->m_dRadius);
            acutPrintf(_T("\n壁厚:%4.2f " ),pAttribute->m_dThickness );
            acutPrintf(_T("\n埋深:%4.2f " ),pAttribute->m_dDeep );
            acutPrintf(_T("\n材质:%s " ),pAttribute->m_cMaterial  );
        }
        else
        {
            //没有则创建属性
            pAttribute = new CPipeAttribute();
            pDict->setAt(_T("属性"), pAttribute, attId);
        }
        //关闭对象
        pDict->close();
        pAttribute->close();

    }
예제 #7
0
bool Additional_Class::Select_Entity_Ent( CString ScreenPrint, ads_name &RtEntity, ads_point &RtPoint )
{
	if (acedEntSel(ScreenPrint, RtEntity, RtPoint)!= RTNORM)
	{
		//acutPrintf(_T(ZYUtils::LoadString(IDS_INPUTFACTOR)));
// 		this->SetError("USER SELECT ENTITY ERROR!", "Select_Entity_Ent");
// 		m_ErrorList.push_back(m_Error);
		return false;
	}
	return true;
}
예제 #8
0
void selectObject(AcDbObjectId& eID)
{
	ads_name en;
	ads_point pt;
	int nReturn;
	nReturn = acedEntSel(_T("\nSelecteaza polilinia de contur: "), en, pt);
	if (nReturn != RTNORM)
		return;
	if (acdbGetObjectId(eID, en) != Acad::eOk)
		return;
}
예제 #9
0
AcDbObjectIdArray Additional_Class::Select_Entitys( CString ScreenPrint )
{
	AcDbObjectIdArray resArray;
	//ads_name &RtEntity = NULL;
	AcDbEntity *pEnt;
	AcDbPoint RtPoint;
	ads_name ss;
	ads_point ff;
	//acedGetPoint(NULL,"ss",ff);
	//ff = asPnt3d(RtPoint.x, RtPoint.y, RtPoint.z);
	acedEntSel(ScreenPrint, ss, ff);
	//Select_Entity_Ent("ss",pEnt,RtPoint);
	return resArray;
}
예제 #10
0
void printXData()
{
	// Get an Entity.
	ads_name mnEnt;
    ads_point ptSel;
    int nRet = acedEntSel(_T("\nSelect an Entity: "), mnEnt, ptSel);
	if (nRet != RTNORM)
		return;
	AcDbObjectId oid;
	
    Acad::ErrorStatus retStat;
    retStat = acdbGetObjectId(oid, mnEnt);
    if (retStat != Acad::eOk)
		return;

    AcDbObject* pObj = NULL;

    if ((retStat = acdbOpenObject(pObj, oid, AcDb::kForRead)) != Acad::eOk)
    {
        return;
    }

    // Get the application name for the xdata.
    //
	TCHAR appname[133] = {0};
    if (acedGetString(NULL, _T("\nEnter the Xdata application name: "), appname) != RTNORM)
    {
        return;
    }

    // Get the xdata for the application name.
    //
    resbuf *pRb = pObj->xData(appname);

    if (pRb != NULL)
	{
        printXDList(pRb);
        acutRelRb(pRb);
    }
	else
	{
        acutPrintf(_T("\nNo xdata for appname: %s."), appname);
    }
    pObj->close();
}
예제 #11
0
void
getExtDictOfObject(AcDbDictionary*& pExtDict)
{
    ads_name ename;
    ads_point pt;

    ADSOK(acedEntSel("Select employee:",ename,pt));
    //do a quick check
    //a more comprehensive check could include 
    //whether we already have the detail object on this candidate
    AcDbObjectId idO;
    ARXOK(acdbGetObjectId(idO,ename));
    AcDbObject* pO;
    ARXOK(actrTransactionManager->getObject(pO,idO,AcDb::kForRead));
    if (!pO->isKindOf(AcDbBlockReference::desc()))
        throw Acad::eNotThatKindOfClass;        
    if ((idO = pO->extensionDictionary())==AcDbObjectId::kNull)
        throw Acad::eKeyNotFound;
    //make sure that you open erased extension dictionaries
    ARXOK(actrTransactionManager->getObject((AcDbObject*&)pExtDict,idO,AcDb::kForWrite, Adesk::kTrue));
    if (pExtDict->isErased())
        ARXOK(pExtDict->erase(Adesk::kFalse));

}
예제 #12
0
ArxDbgUiPrBase::Status
ArxDbgUiPrEntity::go()
{
    CString prompt;
    int result;
    int errNum;
    ads_point adsPt;
    ads_name ent;
    AcDbObjectId tmpId;
    AcDbEntity* tmpEnt;
    Acad::ErrorStatus es;

    prompt.Format(_T("\n%s: "), message());

    while (1) {
        acedInitGet(0, keyWords());
        result = acedEntSel(prompt, ent, adsPt);

        if (result == RTNORM) {
            ArxDbgUtils::enameToObjId(ent, tmpId);
            es = acdbOpenAcDbEntity(tmpEnt, tmpId, AcDb::kForRead);
            if (es == Acad::eOk) {
                    // if its correct class and we are not filtering locked layers its ok,
                    // or if we are filtering locked layers and this one isn't on a locked layer
                if (correctClass(tmpEnt)) {     // correctClass() will print error msg
                    if ((!m_filterLockedLayers) ||
                        (ArxDbgUtils::isOnLockedLayer(tmpEnt, true) == false)) {    // isOnLockedLayer() will print error msg
                        tmpEnt->close();
                        m_pickPt = asPnt3d(adsPt);
                        m_objId = tmpId;
                        return ArxDbgUiPrBase::kOk;
                    }
                }
                tmpEnt->close();    // close and loop again until they get it right!
            }
            else {
                ASSERT(0);
                ArxDbgUtils::rxErrorMsg(es);
                return ArxDbgUiPrBase::kCancel;
            }
        }
        else if (result == RTERROR) {
            getSysVar(AcadVar::adserr, errNum);
            if (errNum == OL_ENTSELPICK)            // picked but didn't get anything
                acutPrintf(_T("\nNothing selected."));
            else if (errNum == OL_ENTSELNULL) {     // hit RETURN or SPACE
                if (m_allowNone)
                    return ArxDbgUiPrBase::kNone;      // prompt specifically wants to know about None
                else
                    return ArxDbgUiPrBase::kCancel;    // prompt wants to bail on None
            }
            else
                acutPrintf(_T("\nNothing selected."));
        }
        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;
    }
}
예제 #13
0
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));
    }
}
예제 #14
0
void ModifyEntityLayer()
{
	int nRet = 0;
	ads_name entName;
	ads_point ptPick;
	nRet = acedEntSel(_T("\nSelect an entity to change it's layer:"), entName, ptPick);
	if (nRet != RTNORM)
	{
		acutPrintf(_T("\nFailed to select!"));
		return;
	}

	Acad::ErrorStatus es;
	AcDbObjectId objId;
	AcDbEntity* pEnt = NULL;
	acdbGetObjectId(objId, entName);
	es = acdbOpenAcDbEntity(pEnt, objId, AcDb::kForWrite);
	if (es != Acad::eOk)
	{
		acutPrintf(_T("\nFailed to open entity!"));
		return;
	}

	ACHAR szNewName[255];
	_tcscpy(szNewName, _T("NewLayer"));
	bool bHasDone = false;

	AcDbDatabase* pCurDb = acdbHostApplicationServices()->workingDatabase();
	if (pCurDb == NULL)
	{
		acutPrintf(_T("\nError:Current database is NULL!"));
		return;
	}

	AcDbObjectId layerId;
	AcDbLayerTable* pLayerTbl = NULL;
	es = pCurDb->getLayerTable(pLayerTbl, AcDb::kForRead);
	if (es == Acad::eOk)
	{
		if (pLayerTbl->has(szNewName))
		{
			es = pLayerTbl->getAt(szNewName, layerId);
			if (es == Acad::eOk)
			{
				es = pEnt->setLayer(layerId);
				if (es == Acad::eOk)
				{
					bHasDone = true;
				}
			}
		}

		pLayerTbl->close();
	}

	pEnt->close();

	if (bHasDone)
	{
		acutPrintf(_T("\nThe layer of entity has modified to layer:\"%s\""), szNewName);
	}
	else
	{
		acutPrintf(_T("\nFailed to modify the layer of entity to layer:\"%s\""), szNewName);
	}

}
예제 #15
0
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;
}
예제 #16
0
void 
polyeditCommand()
{
	Adesk::Boolean interrupted = Adesk::kFalse;
	Adesk::Boolean	    done;
    Acad::ErrorStatus es = Acad::eOk;
    AcDbFullSubentPath nullSub;
	AcGePoint2d   savedCenter;
	AcGePoint2d   savedStartPoint;
	int	     savedNumSides;
	AcGeVector3d  savedNormal;
	char	     savedName[133];
    double savedElevation;
    
    // Select an AsdkPoly entity.
    
    AsdkPoly	 *poly = NULL;
    AcDb3dSolid  *solid = NULL;
    AcDbObjectId  objId;
    
    ads_name	  ename;
    ads_point     ptres;

    AcDbEntity* ent;

	ads_name ss ;
	if ( acedSSGet ("_I", NULL, NULL, NULL, ss) == RTNORM ) {
		long n ;
		acedSSLength (ss, &n) ;
		switch ( n ) {
			case 0:
				//----- Not possible, but ?
				break ;
			case 1:
				acedSSName (ss, 0, ename) ;

				AOK(acdbGetObjectId(objId, ename));
        
				AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead));
				assert(ent != NULL);
        
				poly = AsdkPoly::cast(ent);
				if (poly == NULL) {
					acutPrintf("\nNot a polygon.");
					AOK(ent->close());
				}
				break ;
			default:
				//----- If more than one entity selected, fallback in standard selection mode
				break ;
		}
		acedSSFree (ss) ;
	}

	while ( poly == NULL ) {

		switch (acedEntSel("\nSelect a poly: ", ename, ptres)) {
        
		case RTNORM:
        
			AOK(acdbGetObjectId(objId, ename));
        
			AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead));
			assert(ent != NULL);
        
			poly = AsdkPoly::cast(ent);
			if (poly == NULL) {
				acutPrintf("\nNot a polygon.");
				AOK(ent->close());
				continue;
			}
        
			break;
        
		case RTNONE:
		case RTCAN:
			return;
		default:
			continue;
		}
		break;
	}

    // Now we have a polygon. Start editing it.
    
    char option[256];
    
    done = Adesk::kFalse;
    interrupted = Adesk::kFalse;
    
    while (!done && !interrupted) {
        
        AOK(getEditOption(option,interrupted));
        
        if (strcmp(option, "Grow") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(growPoly(poly));
            
        } else if (strcmp(option, "Shrink") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(shrinkPoly(poly));
            
        } else if (strcmp(option, "More") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(morePoly(poly));
            
        } else if (strcmp(option, "Less") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(lessPoly(poly));
            
        } else if (strcmp(option, "Thicken") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(thickenPoly(poly, ent, savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation));
            
            solid = AcDb3dSolid::cast(ent);
            assert(solid != NULL);
            poly = NULL;
            
            
            solid->draw();
            
        } else if (strcmp(option, "Flatten") == 0) {
            
            if (!ent->isKindOf(AcDb3dSolid::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(flattenPoly(solid,ent,savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation));
            
            poly = AsdkPoly::cast(ent);
            assert(poly != NULL);
            solid = NULL;
            
            
        } else if (strcmp(option, "Name") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            Acad::ErrorStatus es;
            if ((es = namePoly(poly)) != Acad::eOk) {
                acutPrintf("\nError setting Poly's name. Error: %s",
                    acadErrorStatusText(es));
                done = Adesk::kTrue;
                continue;
            }
            if ((es = stylePoly(poly)) != Acad::eOk) {
                acutPrintf("\nError setting Poly's text style. Error: %s",
                    acadErrorStatusText(es));
                done = Adesk::kTrue;
                continue;
            }
        } else if (strcmp(option, "EXit") == 0) {
            done = Adesk::kTrue;
        } else {
            done = Adesk::kTrue;
        }
        
    }
    
    // Close the entity corresponding to the open for read right
    // after selection.
    
    AOK(ent->close());
}
예제 #17
0
    //-------------------------------------------------------------------------------------------
	// 
	//  功能: 第二条直线的起点移动到第一条直线的中点位置,
	//                 并通过构造旋转矩阵使得第二条直线和第一条直线垂直
	//
	//  作者:Qin H.X.
	//
	// 日期:200709
	//
	//  历史:无
	//
	//----------------------------------------------------------------------------------------------
	// - CGDCH06.TransformLine command (do not rename)
	static void CGDCH06TransformLine(void)
	{


		ads_name      ename1,ename2;
		ads_point     pickpt;
		if (acedEntSel(_T("\n选择直线1: "), ename1, pickpt)  != RTNORM)
		{
			acutPrintf(_T("\n选择直线1失败"));
			return ;
		}
		if (acedEntSel(_T("\n选择直线2: "), ename2, pickpt)  != RTNORM)
		{
			acutPrintf(_T("\n选择直线2失败"));
			return ;
		}	

		AcDbObjectId IdLine1,IdLine2;

		acdbGetObjectId(IdLine1, ename1);		
		acdbGetObjectId(IdLine2, ename2);
		//直线对象
		AcDbLine *pLine1 = NULL;			
		AcDbLine *pLine2 = NULL;	
		//以读方式打开实体
		if(Acad::eOk == acdbOpenObject(pLine1, IdLine1, AcDb::kForRead))
		{
			if(Acad::eOk == acdbOpenObject(pLine2, IdLine2, AcDb::kForRead))
			{

				// 计算第一条直线的中点
				AcGePoint3d ptMid; 
				ptMid.x =  0.5*(pLine1->endPoint ().x + pLine1->startPoint ().x);
				ptMid.y=  0.5*(pLine1->endPoint ().y + pLine1->startPoint ().y);
				ptMid.z =  0.5*(pLine1->endPoint ().z + pLine1->startPoint ().z);	

				// 第二条直线起点到第一条直线的向量
				AcGeVector3d vecMove = ptMid -  pLine2->startPoint ();
				// 构造平移矩阵
				AcGeMatrix3d  mat,mat1;
				mat = mat.translation (vecMove);
				//  修改第二条直线
				pLine2->upgradeOpen ();
				pLine2->transformBy (mat);
				//计算两条直线的夹角
				AcGeVector3d  vec1 = pLine1->endPoint ()- pLine1->startPoint ();
				AcGeVector3d  vec2 = pLine2->endPoint ()- pLine2->startPoint ();
				double dAng;
				dAng = vec1.angleTo(vec2);
				AcGeVector3d vecZ(0.0,0.0,1.0);
				//计算旋转角度
				double dRot;
				if(dAng<0.5*PI)
				{
					dRot = 0.5*PI  - dAng;
				}
				else
				{
					dRot =dAng  -  0.5*PI ;
				}
				// 构造旋转矩阵
				mat1  = mat1.rotation (dRot,vecZ,pLine2->startPoint ());
				//对直线进行旋转变换
				pLine2->transformBy (mat1);
				pLine2->setColorIndex (1);
				//关闭实体
				pLine2->close();
				acutPrintf(_T("\n 操作完成 。"));

			}
			//关闭实体
			pLine1->close();	

		}


		// Add your code for command CGDCH06.TransformLine here
	}
예제 #18
0
    //-------------------------------------------------------------------------------------------
	// 
	//  功能: 求直线的交点和夹角
	//
	//  作者:Zhao C.X.
	//
	// 日期:200709
	//
	//  历史:
	//          调整部分代码 BY	Qin H.X.
	//
	//----------------------------------------------------------------------------------------------
	// - CGDCH06.GetIntersect command (do not rename)
	static void CGDCH06GetIntersect(void)
	{

	ads_name      ename1,ename2;
    ads_point     pickpt;
    if (acedEntSel(_T("\n选择直线1: "), ename1, pickpt)  != RTNORM)
    {
        acutPrintf(_T("\n选择直线1失败"));
        return ;
    }
    if (acedEntSel(_T("\n选择直线2: "), ename2, pickpt)  != RTNORM)
    {
        acutPrintf(_T("\n选择直线2失败"));
        return ;
    }	
	
	AcDbObjectId IdLine1,IdLine2;

	acdbGetObjectId(IdLine1, ename1);		
	acdbGetObjectId(IdLine2, ename2);
	//直线对象
	AcDbLine *pLine1 = NULL;			
	AcDbLine *pLine2 = NULL;	
	//以读方式打开实体
	if(Acad::eOk == acdbOpenObject(pLine1, IdLine1, AcDb::kForRead))
	{
		if(Acad::eOk == acdbOpenObject(pLine2, IdLine2, AcDb::kForRead))
		{
			//创建几何直线
			AcGeLineSeg3d geLineSeg1, geLineSeg2;
			geLineSeg1.set(pLine1->startPoint(), pLine1->endPoint());	
			geLineSeg2.set(pLine2->startPoint(), pLine2->endPoint());

			//求直线的交点
			AcGePoint3d ptIntersect;	
			//如果两条直线有交点
			if (geLineSeg1.intersectWith(geLineSeg2, ptIntersect))	
			{
				acutPrintf(_T("\n两直线的交点:(%0.2f, %0.2f, %0.2f)"), ptIntersect.x, ptIntersect.y,ptIntersect.z);
			}
			else
			{
				acutPrintf(_T("\n直线没有交点。"));
			}

			///求直线的夹角
			AcGeVector3d vect1, vect2;	
			vect1 = geLineSeg1.direction();
			vect2 = geLineSeg2.direction();
			double dAngle;
			dAngle = vect1.angleTo(vect2);
			dAngle *= 180.0 / PI;
			pLine2->close();
			acutPrintf(_T("\n直线的夹角为:%0.0f度"), dAngle);

		}
			//关闭实体
		pLine1->close();	

	}

	}
예제 #19
-7
// This function has the user select an entity and then
// calls the reflectedEnergy() function in the protocol
// extension class attached to that entity's class.
// 
void
energy()
{
    AcDbEntity *pEnt;
    AcDbObjectId pEntId;
    ads_name en;
    ads_point pt;

    if (acedEntSel("\nSelect an Entity:  ", en, pt)
        != RTNORM)
    {
        acutPrintf("Nothing Selected\n");
        return;
    }
    acdbGetObjectId(pEntId, en);
    acdbOpenObject(pEnt, pEntId, AcDb::kForRead);

    // call the protocol extension class's method
    //
    double eTemp = ACRX_X_CALL(pEnt,
        AsdkEntTemperature)->reflectedEnergy(pEnt);

    acutPrintf("\nEnergy == %f\n", eTemp);
    pEnt->close();
}