TheSwamp

Code Red => ARX Programming => Topic started by: gilseorin on March 23, 2007, 05:40:29 AM

Title: Usage Of Function
Post by: gilseorin on March 23, 2007, 05:40:29 AM
Hi, all.
I need your help.
Would you show me the usage of function?
My code is as follows:

void DrawLine() {

 ads_point pt1, pt2;
if(acedGetPoint(NULL,"\nSpecify Start Point : ",pt1) != RTNORM) return;
if(acedGetPoint(pt1,"\nSpecify End Point : ",pt2) != RTNORM) return;
AcGePoint3d startPt=asPnt3d(pt1);
AcGePoint3d endPt=asPnt3d(pt2);

AcDbLine *pLine=new AcDbLine(startPt,endPt);
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();

AcDbLayerTable *pLayerTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTable, AcDb::kForWrite);
AcDbLayerTableRecord *pLayerTableRecord =new AcDbLayerTableRecord;
pLayerTableRecord->setName("MyLayer");
pLayerTable->add(pLayerTableRecord);
pLayerTable->close();

AcCmColor color;
color.setColorIndex(2);
pLayerTableRecord->setColor(color);

pLayerTableRecord->close();

pLine->setLayer("MyLayer");
pLine->setColorIndex(256);
}


I wish to convert the blue part to the fuction.
Thanks in advance.
Title: Re: Usage Of Fuction
Post by: MickD on March 23, 2007, 07:14:50 PM
how about something like this -
Code: [Select]
public void setAttributes(AcDbEntity * ent, char * layerName)
{
    AcDbLayerTable *pLayerTable;
    acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTable, AcDb::kForWrite);
    AcDbLayerTableRecord *pLayerTableRecord =new AcDbLayerTableRecord;
    pLayerTableRecord->setName(layerName);
    pLayerTable->add(pLayerTableRecord);
    pLayerTable->close();

    AcCmColor color;
    color.setColorIndex(2);
    pLayerTableRecord->setColor(color);

    pLayerTableRecord->close();

    ent->setLayer(layerName);
    ent->setColorIndex(256);
}

not tested, but you should get the idea ;)
Title: Re: Usage Of Function
Post by: gilseorin on March 24, 2007, 03:45:38 AM
Code: [Select]
char *layerName="MyLayer";
void setAttributes(AcDbEntity &pLine, char &layerName);
pLine->close();

Code: [Select]
void setAttributes(AcDbEntity * ent, char * layerName)
{
      -------
       ent->close();
}

Thank you so much, MickD.
Stupid question, but how should I call your function?
I tried on and on, but failed.