Example #1
0
// Accesses the xrecord associated with the key XRECADS in
// the dictionary associated the key TEST_DICT.  Then
// lists out the contents of this xrecord using the
// printList function.
// 
int
listXrecord()
{
    struct resbuf *pObj;
    ads_name dictName;

    // Get the entity name of the ASDK_DICT dictionary in
    // the named object dictionary and place it in dictName.
    //
    acdbNamedObjDict(dictName);
    pObj = acdbDictSearch(dictName, "ASDK_DICT", 0);
    if (pObj) {
        // The entity name is always returned in first resbuf.
        //
        ads_name_set(pObj->resval.rlname, dictName);
    }

    // Get the xrecord associated with the key XRECADS.
    //
    pObj = acdbDictSearch(dictName, "XRECADS", 0);

    if (pObj) {
        printList(pObj);
        acutRelRb(pObj);
    }
    acedRetVoid();
    return RTNORM;
}
Example #2
0
/* Get the entities out of a block and add them to the appropriate
 * lists: if a block, back to blockList - if an entity onto the
 * the entity list according to samplemode.
 */
static int SampleBlock(DLL_LIST blist)

{
    ADSResBuf *ri, *rb1, *rb2, *edata;
    char layer[64], type[16];
    ads_name ename;
    ads_namep blent;
    DLL_LIST newList = NULL;

#ifdef DEBUG
    fprintf(stderr, "SampleBlock(%p)\n", blist);
#endif
    blent = DllFirst(blist, NULL);
    rb1 = ads_entget(blent);
    rb2 = ads_tblsearch("BLOCK", RBSearch(rb1, 2)->resval.rstring, 1);
    ads_relrb(rb1);
    ads_name_set(RBSearch(rb2, -2)->resval.rlname, ename);
    ads_relrb(rb2);
    do {
        edata = ads_entget(ename);
        ri = RBSearch(edata, 0);
        if (strcmp(ri->resval.rstring, "INSERT") == 0) {
            if (!(newList = DllCopyList(blist, entListsSetup,
                    CopyNameProc, NULL, NULL)))
                return 0;
            (void)DllPushF(newList, NewADSName(ename), NULL);
            AddToBlockList(newList);
            ads_relrb(edata);
            continue;
        }
        if (strcmp(ri->resval.rstring, "ENDBLK") == 0) {
            ads_relrb(edata);
            break;
        }
        if (!IsValidEntType(GetEntType(edata, type))) {
            ads_relrb(edata);
            continue;
        }
        if (!(newList = DllCopyList(blist, entListsSetup, CopyNameProc,
                NULL, NULL)))
            return 0;
        if (!DllPushF(newList, NewADSName(ename), NULL))
            return 0;
        switch (options.exportMode) {
			case EXP_BYCOLOR:
				AddEntToColorLists(newList, GetColorVal(edata, newList, 0));
				break;
			case EXP_BYLAYER:
				GetLayerVal(layer, edata, newList, 0);
				AddEntToLayerLists(newList, layer);
				break;
			default:
				ads_fail("SampleBlock: bad export mode\n");
        }
        ads_relrb(edata);
        if (ads_usrbrk())
            return 0;
    } while (ads_entnext(ename, ename) == RTNORM);
    return 1;
}
Example #3
0
/* alloc space and copy name
 */
ads_namep NewADSName(ads_name name)

{
    ads_namep namep;

    if ((namep = malloc(sizeof(ads_name))) == NULL)
        ads_fail("NewADSName: can't alloc name.\n");
    ads_name_set(name, namep);
    return namep;
}
Example #4
0
// Creates an AsdkOwnerDemo object (pObjC) and adds data to
// it.  Next AsdkOwnerDemo pObjC is created and set to be
// the owner of pObjC.  Next AsdkOwnerDemo pObjA is created
// and set to own pObjB.  Finally pObjA is added to a
// dictionary in the named object dictionary.  Technically
// we could just add pObjA to the named object dictionary
// itself,  but that's bad form since it will tend to
// clutter up the named object dictionary.
// 
// THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
//
int 
createObjs()
{
    struct resbuf *pList;
    ads_name enameA, enameB, enameC,
        namedObj, enameTestDict;

    // Create a resbuf list of objC's info and data.  This
    // will include a "dummy" ownership group of 0 since
    // this object won't own any others. The group 70 is the
    // "dummy" integer data value.
    // 
    pList = acutBuildList(RTDXF0, "ASDKOWNERDEMO", 100,
        "AsdkOwnerDemo", 70, 3, 0);

    // Create the object "C" with no owner set.  The
    // object's new entity name will be placed into the
    // objC argument.
    //
    acdbEntMakeX(pList, enameC);
    acutRelRb(pList);

    // Create a resbuf list of objB's info and data.  This
    // will include an ownership group with the entity name
    // of objC.  The group 70 is the "dummy" integer data
    // value.
    // 
    pList = acutBuildList(RTDXF0, "ASDKOWNERDEMO",
        100, "AsdkOwnerDemo", 70, 2, 360, enameC, 0);

    // Create the object "B" with no owner set.  The
    // object's new entity name will be placed into the objC
    // argument
    // 
    acdbEntMakeX(pList, enameB);
    acutRelRb(pList);

    // Create a resbuf list of objA's info and data.  This
    // will include an ownership group with the entity name
    // of objB.  The group 70 is the "dummy" integer data
    // value.
    // 
    pList = acutBuildList(RTDXF0, "ASDKOWNERDEMO",
        100, "AsdkOwnerDemo", 70, 1, 360, enameB, 0);

    // Create the object "A" with no owner set.  The
    // object's new entity name will be placed into the objC
    // argument
    // 
    acdbEntMakeX(pList, enameA);
    acutRelRb(pList);

    // Add object A to a dictionary so it has an owner.

    // Look for the dictionary associated with the key
    // "ASDK_DICT".  If it is not found,  create it and add
    // it to the named object dictionary.
    // 
    acdbNamedObjDict(namedObj);
    if ((pList = acdbDictSearch(namedObj, "ASDK_DICT", 0))
        == NULL)
    {
        pList = acutBuildList(RTDXF0, "DICTIONARY",
            100, "AcDbDictionary", 0);
        acdbEntMakeX (pList, enameTestDict);
        acdbDictAdd(namedObj, "ASDK_DICT", enameTestDict);
    } else {
        // The entity name is always returned in the first resbuf.
        //
        ads_name_set(enameTestDict, pList->resval.rlname);
    }

    // Now add object A to the ASDK_DICT dictionary
    // so it has an owner.
    //
    acdbDictAdd(enameTestDict, "OBJA", enameA);
    acutRelRb(pList);

    acedRetVoid();
    return RTNORM;
}
Example #5
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;
}