Add layer description
Hi,
I have wrote a function to create new layer. It create layer with name, color and off status set. But fail to add description to new layer.
I have wrote a function to create new layer. It create layer with name, color and off status set. But fail to add description to new layer.
bool newLayer( const ACHAR * name, const ACHAR * description, Adesk::UInt32 color, bool isOff )After running this code in BricsCAD I get this output:
{
Acad::ErrorStatus es = Acad::eOk;
AcDbLayerTableRecord * pLayerTableRecord = new AcDbLayerTableRecord;
es = pLayerTableRecord->setName( name );
if ( es != Acad::eOk )
{
acutPrintf( _T( "\nERROR: Could not add layer name! Error code: %s" ), acadErrorStatusText( es ) );
delete pLayerTableRecord;
return false;
}
if ( description != nullptr )
{
es = pLayerTableRecord->setDescription( description );
if ( es != Acad::eOk )
{
acutPrintf( _T( "\nERROR: Could not add layer description! Error code: %s" ), acadErrorStatusText( es ) );
acutPrintf( _T( "\nLayer description: %s" ), description );
}
}
AcCmColor colorObject;
if ( colorObject.setColorIndex( color ) == Acad::eOk )
pLayerTableRecord->setColor( colorObject );
pLayerTableRecord->setIsOff( isOff );
AcDbLayerTable * pLayerTable = nullptr;
es = acdbHostApplicationServices( )->workingDatabase( )->getSymbolTable( pLayerTable, AcDb::kForWrite );
if ( es != Acad::eOk )
{
acutPrintf( _T( "\nERROR: Could not open SymbolTable! Error code: %s" ), acadErrorStatusText( es ) );
delete pLayerTableRecord;
return false;
}
es = pLayerTable->add( pLayerTableRecord );
pLayerTable->close( );
if ( es != Acad::eOk )
{
acutPrintf( _T( "\nERROR: Could not add new layer to SymbolTable! Error code: %s" ), acadErrorStatusText( es ) );
delete pLayerTableRecord;
return false;
}
pLayerTableRecord->close( );
acutPrintf( _T( "\nLayer %s %s" ), name, _T( " have been created." ) );
return true;
}
ERROR: Could not add layer description! Error code: eNullObjectPointerWhy pLayerTableRecord->setDescription( description ); returns eNullObjectPointer? As second line in output shows variable description is set to Place holder description.
Layer description: Place holder description.
Layer MyLayerName have been created.
0
Comments
-
Hi Donatas,
interestingly, the behaviour is the same in AutoCAD/ARX ...
reason is, that the "layer description" property is stored as XData, and XData on a database object require that the object is database-resident.
> Layer description: Place holder description.
which version of BricsCAD do you use ? In my testing on V22, the (input) string is not changed at all.
So easiest solution :
first add the new layer to the LayerTable, then assign all the propertiesbool newLayer(const ACHAR* name, const ACHAR* description, Adesk::UInt16 color, bool isOff) { AcDbLayerTable* pLayerTable = nullptr; Acad::ErrorStatus es = acdbCurDwg()->getSymbolTable(pLayerTable, AcDb::kForWrite); if (es != Acad::eOk) { acutPrintf(_T("\nERROR: Could not open SymbolTable! Error code: %ls"), acadErrorStatusText(es)); return false; } AcDbLayerTableRecord* pLayerTableRecord = new AcDbLayerTableRecord(); es = pLayerTable->add(pLayerTableRecord); pLayerTable->close(); if (es != Acad::eOk) { acutPrintf(_T("\nERROR: Could not add new layer to SymbolTable! Error code: %ls" ), acadErrorStatusText(es)); delete pLayerTableRecord; return false; } es = pLayerTableRecord->setName(name); if (es != Acad::eOk) { acutPrintf(_T("\nERROR: Could not add layer name! Error code: %ls"), acadErrorStatusText(es)); } if (description != nullptr) { es = pLayerTableRecord->setDescription(description); if (es != Acad::eOk) { acutPrintf(_T("\nERROR: Could not add layer description! Error code: %ls"), acadErrorStatusText(es)); acutPrintf(_T("\nLayer description: %ls"), description); } } AcCmColor colorObject; if (colorObject.setColorIndex(color) == Acad::eOk) pLayerTableRecord->setColor(colorObject); pLayerTableRecord->setIsOff(isOff); pLayerTableRecord->close(); acutPrintf(_T("\nLayer %ls %ls"), name, _T(" have been created.")); return true; }
many greetings !0 -
😳
Thanks. This is new for me. So, I need to first add it to database.
I use BricsCAD Platinum 20.
I had BricsCAD 20, upgraded it to Platinum and after 1-2 months found out Bricsys merged Platinum into BricsCAD. It would been better if I extended my license0