コード例 #1
0
ファイル: complex.cpp プロジェクト: kevinzhwl/ObjectARXMod
void
makeABlock()
{
     // Create and name a new block table record.
     //
     AcDbBlockTableRecord *pBlockTableRec
         = new AcDbBlockTableRecord();
     pBlockTableRec->setName("ASDK-NO-ATTR");

     // Get the block table.
     //
     AcDbBlockTable *pBlockTable = NULL;
     acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForWrite);

     // Add the new block table record to the block table.
     //
     AcDbObjectId blockTableRecordId;
     pBlockTable->add(blockTableRecordId, pBlockTableRec);
     pBlockTable->close();

     // Create and add a line entity to the component's
     // block record.
     //
     AcDbLine *pLine = new AcDbLine();
     AcDbObjectId lineId;

     pLine->setStartPoint(AcGePoint3d(3, 3, 0));
     pLine->setEndPoint(AcGePoint3d(6, 6, 0));
     pLine->setColorIndex(3);

     pBlockTableRec->appendAcDbEntity(lineId, pLine);
     pLine->close();
     pBlockTableRec->close();
}
コード例 #2
0
ファイル: lab2main.cpp プロジェクト: kevinzhwl/ObjectARXMod
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
}