Author Topic: New to ARX need your Help!  (Read 2202 times)

0 Members and 1 Guest are viewing this topic.


  • Guest
New to ARX need your Help!
« on: November 22, 2009, 04:53:09 PM »
thanks for you time.

I'm new to Arx, and I need your help to accomplish a little work.

I need to elaborate many dwg file, I normally do it via vba or via using AutoCAD.Interop.AcadApplication,
but this time I decide to use arx to build a dll for AutoCAD.

I watched some tutorials, where I learned some things, now I can:
- iterate through layers and blocks
- Create new layers, blocks, and entities
- open, "watch" and close all the .dwg in a specific folder
- and other little things

but i need to know how to:
- iterate through all entities
- change entities layer if doesn't match some characteristics
- save and close the active document

vba example

Dim ntt As AcadEntity
Sub main()
    For Each ntt In ThisDrawing.Modelspace
        If Not GoodLay(ntt.layer) Then
            UniformLayers (ntt)
        End If
    Next ntt
End Sub

Function UniformLayers(ntt As AcadEntity) As Boolean
    Select Case ntt.layer
        Case "0"
        Case "GoodName1", "GoodName2", "..."
            'do something
        Case Else
            ntt.layer = "0"
    End Select
End Function

Hope someone can tel me how to do this.

Tnx again
« Last Edit: November 22, 2009, 05:05:22 PM by Ricky_76 »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7096
  • AKA Daniel
Re: New to ARX need your Help!
« Reply #1 on: December 01, 2009, 02:41:36 AM »
here is a sample of how to iterate though the database, hope it helps you

Code: [Select]

 static void doit ()
    AcDbObjectIdArray ids;
    AcDbDatabase *pDb = new AcDbDatabase(false);
    if(pDb->readDwgFile(_T("PathToMyDwg"),_SH_DENYRW)== eOk)
    delete pDb;
  static int iterEnts (AcDbDatabase *pDb, AcDbObjectIdArray &ids)
    int cnt = 0;
    AcDbBlockTableRecord *pRec;
    if(acdbOpenAcDbObject((AcDbObject *&) pRec,
      pDb->currentSpaceId(), AcDb::kForRead) == Acad::eOk)
      AcDbBlockTableRecordIterator *pIter;
      if(pRec->newIterator(pIter) == Acad::eOk)
        for(pIter->start(); !pIter->done(); pIter->step())
          AcDbObjectId objId;
          AcDbEntity *pEnt;
          if(pIter->getEntity(pEnt, AcDb::kForRead) == Acad::eOk)
            AcDbPoint *pPoint = AcDbPoint::cast(pEnt);
              if(_tcsicmp(pPoint->layer(), _T("TESTLAYER")) == 0)
        delete pIter;
    return cnt;