You can put the New() method and custom properties to work by adding a specialized tool with custom behavior. In the previous procedure, you created a command tool that launches the LINE command. The following procedure shows how to add a tool that uses ObjectARX functionality to create a line. It also uses the tool's properties to define the endpoints of the line.
Basic steps for adding this tool include
double m_StartX;
STDMETHOD(get_StartX)(/*out, retval*/ DOUBLE* pVal); STDMETHOD(put_StartX)(/*in*/ DOUBLE newVal);
STDMETHODIMP CSimpleTool:get_StartX(DOUBLE* pVal) { (*pVal) = m_StartX; return S_OK; } STDMETHODIMP CSimpleTool:put_StartX(DOUBLE newVal) { m_StartX = newVal; return S_OK; }
StartY StartZ EndX EndY EndZ
Now that new properties are available, you can use the corresponding member variables to implement the line creation routine.
STDMETHODIMP CSimpleTool::executeCallback() { }
AcGePoint3d ptStart(m_StartX, m_StartY, m_StartZ); AcGePoint3d ptEnd(m_EndX, m_EndY, m_EndZ);
AcDbLine* pLine = new AcDbLine(ptStart, ptEnd);
AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close(); AcDbObjectId lineId; pBlockTableRecord->appendAcDbEntity(lineId, pLine); pBlockTableRecord->close(); pLine->close();
return S_OK;
Here is the finished executeCallback() function:
STDMETHODIMP CSimpleTool::executeCallback() { AcGePoint3d ptStart(m_StartX, m_StartY, m_StartZ); AcGePoint3d ptEnd(m_EndX, m_EndY, m_EndZ); AcDbLine* pLine = new AcDbLine(ptStart, ptEnd); AcDbBlockTable *pBlockTable; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord; pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite); pBlockTable->close(); AcDbObjectId lineId; pBlockTableRecord->appendAcDbEntity(lineId, pLine); pBlockTableRecord->close(); pLine->close(); return S_OK; }
To link the executeCallback() functionality to a tool, you call the CreateToolATC() method in the CREATESIMPLE command.
tool.CreateToolATC(pPalette);
When your new tool appears in the Tool Palettes window, right-click it and select Properties. Notice that the newly added start point and endpoint properties appear. If you modify their values in this UI, the tool will use the revised values when it constructs its next line.