how to read shapenames

how to read shapenames

Anonymous
Not applicable
1,062 Views
2 Replies
Message 1 of 3

how to read shapenames

Anonymous
Not applicable

     a shx file in a dwg is an AcDbTextStyleTableRecord in dwg, is there any way to get all shape names in this shx file with AcDbTextStyleTableRecord, not read the binary file. 

0 Likes
Accepted solutions (1)
1,063 Views
2 Replies
Replies (2)
Message 2 of 3

Alexander.Rivilis
Mentor
Mentor
Accepted solution
static void ShapeNames(void)
{
  struct SHAPESTRUCT {
    unsigned short iShapeNumber;     // shape number
    unsigned short iDefBytes;        // number of data bytes in shape, 2000 max
    unsigned char *lpszShapeName;    // pointer to shapename
    unsigned char *lpszSpecBytes;    // pointer to shape specification bytes
  };
  char SHAPE10[] = "AutoCAD-86 shapes 1.0";
  char SHAPE11[] = "AutoCAD-86 shapes 1.1";
  resbuf *rbfile = NULL;
  if (RTNORM == acedGetFileNavDialog("Select shape file","","shx","ShapeNames",0,&rbfile))
  {
    FILE *fshx = fopen(rbfile->resval.rstring,"rb"); acutRelRb(rbfile);
    if (fshx) {
      char desc[32];
      fread (desc,sizeof(desc),1,fshx);
      if (!strstr(desc,SHAPE10) && !strstr(desc,SHAPE11)) {
        acutPrintf("\nIt is not shape file!");
        fclose(fshx);
        return;
      }
      fseek (fshx, (long)0x1c, SEEK_SET);
      unsigned short iNumShapes = 0;
      fread (&iNumShapes, sizeof (iNumShapes), 1, fshx);
      SHAPESTRUCT *lpShapeList, *lpShape;
      lpShapeList = (SHAPESTRUCT *)calloc(iNumShapes, sizeof (*lpShapeList));
      for (int i=0; i < iNumShapes; i++) {
        lpShape = lpShapeList + i;
        fread(&(lpShape->iShapeNumber), sizeof (lpShape->iShapeNumber), 1, fshx);
        fread(&(lpShape->iDefBytes), sizeof (lpShape->iDefBytes), 1, fshx);
      }
      if (lpShapeList->iShapeNumber != 0) { // it is shape file
        for (int i = 0; i < iNumShapes; i++) {
          lpShape = lpShapeList + i;
          lpShape->lpszShapeName = (unsigned char *)(malloc (lpShape->iDefBytes));
          fread (lpShape->lpszShapeName, sizeof (*lpShape->lpszShapeName), lpShape->iDefBytes, fshx);
          acutPrintf("\nShape N%d = %s", i, lpShape->lpszShapeName);
          free(lpShape->lpszShapeName);
        }
      } else {
        acutPrintf("\nIt is not shape file!");
      }
      free(lpShapeList);
      fclose(fshx);
    }
  }
}

This code was written 5 years ago (before UNICODE "revolution" in AutoCAD). That is why you have to rewrite this code using UNICODE. 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 3 of 3

Alexander.Rivilis
Mentor
Mentor

Sample code for ObjectARX SDK 2007...2012:

static void ShapeNames(void)
{
    typedef struct {
        Adesk::UInt16 iShapeNumber;     // shape number
        Adesk::UInt16 iDefBytes;        // number of data bytes in shape, 2000 max
        Adesk::UInt8  *lpszShapeName;    // pointer to shapename
        Adesk::UInt8  *lpszSpecBytes;    // pointer to shape specification bytes
    } SHAPESTRUCT;

    Adesk::UInt8  SHAPE10[] = "AutoCAD-86 shapes 1.0";
    Adesk::UInt8  SHAPE11[] = "AutoCAD-86 shapes 1.1";
    resbuf *rbfile = NULL;
    if (RTNORM == acedGetFileNavDialog(_T("Select shape file"),_T(""),_T("shx"),_T("ShapeNames"),0,&rbfile))
    {
        FILE *fshx = _tfopen(rbfile->resval.rstring,_T("rb")); acutRelRb(rbfile);
        if (fshx) {
            Adesk::UInt8 desc[32];
            fread (desc,sizeof(desc),1,fshx);
            if (!strstr((char *)desc, (char *)SHAPE10) && !strstr((char *)desc, (char *)SHAPE11)) {
                acutPrintf(_T("\nIt is not shape file!"));
                fclose(fshx);
                return;
            }
            fseek (fshx, (long)0x1c, SEEK_SET);
            Adesk::UInt16 iNumShapes = 0;
            fread (&iNumShapes, sizeof (iNumShapes), 1, fshx);
            SHAPESTRUCT *lpShapeList, *lpShape;
            lpShapeList = (SHAPESTRUCT *)calloc(iNumShapes, sizeof (*lpShapeList));
            for (int i=0; i < iNumShapes; i++) {
                lpShape = lpShapeList + i;
                fread(&(lpShape->iShapeNumber), sizeof (lpShape->iShapeNumber), 1, fshx);
                fread(&(lpShape->iDefBytes), sizeof (lpShape->iDefBytes), 1, fshx);
            }
            if (lpShapeList->iShapeNumber != 0) { // it is shape file
                for (int i = 0; i < iNumShapes; i++) {
                    lpShape = lpShapeList + i;
                    lpShape->lpszShapeName = (unsigned char *)(malloc (lpShape->iDefBytes));
                    fread (lpShape->lpszShapeName, sizeof (*lpShape->lpszShapeName), lpShape->iDefBytes, fshx);
                    AcString sname = lpShape->lpszShapeName;
                    acutPrintf(_T("\nShape N%d = %s"), i, sname.kACharPtr());
                    free(lpShape->lpszShapeName);
                }
            } else {
                acutPrintf(_T("\nIt is not shape file!"));
            }
            free(lpShapeList);
            fclose(fshx);
        }
    }
}

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes