Read and set Dimension style from current drawing file.

Read and set Dimension style from current drawing file.

jlobo2
Advocate Advocate
2,787 Views
20 Replies
Message 1 of 21

Read and set Dimension style from current drawing file.

jlobo2
Advocate
Advocate

How do I read, from a Dimension Style table in the current drawing, and set it to an object to be used later for drawing?

 

The code below, returns object id as null. Am I missing something here?

Thank You for your help in advance.

 

AcDbDimStyleTable *pDimensionStyleTbl;

theDb->getSymbolTable(pDimensionStyleTbl, AcDb::kForRead);
pDimensionStyleTbl->getAt(_T("_STANDARD"), idDimensionStyleStandard);

 

 

0 Likes
Accepted solutions (2)
2,788 Views
20 Replies
Replies (20)
Message 2 of 21

Alexander.Rivilis
Mentor
Mentor

@jlobo2 

You have to use AcDbDatabase::dimStyleTableId for get AcDbObjectId of AcDbDimStyleTable

Also you have to check name _STANDARD (maybe STANDARD without underscore)

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 21

jlobo2
Advocate
Advocate

Thank You for your response.

 

The underscore, is the part of the name in the current drawing.

Not sure, what did you mean by AcDbDatabase::dimStyleTableId ?

 

	AcDbDatabase::dimStyleTableId *tempDb;

 

 

0 Likes
Message 4 of 21

Alexander.Rivilis
Mentor
Mentor
Accepted solution

@jlobo2 

Sample code:

 

static void ADSKMyGroupMyCommand() {
  Acad::ErrorStatus es;
  AcDbDatabase *pCurDb = acdbCurDwg();
  AcDbObjectId idDimStyleTable = pCurDb->dimStyleTableId();
  AcDbDimStyleTablePointer pDimStyleTable(idDimStyleTable, AcDb::kForRead);
  if ((es = pDimStyleTable.openStatus()) == Acad::eOk)
  {
    AcDbObjectId idDimStyleTableRecord;
    if ((es = pDimStyleTable->getAt(_T("_STANDARD"), idDimStyleTableRecord)) == Acad::eOk)
    {
      acutPrintf(_T("\nidDimStyleTableRecord=%x"), idDimStyleTableRecord.asOldId());
    }
    else
    {
      acutPrintf(_T("\npDimStyleTable->getAt() = %s"), acadErrorStatusText(es));
    }
  }
  else
  {
    acutPrintf(_T("\npDimStyleTable.openStatus() = %s"), acadErrorStatusText(es));
  }

}

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 5 of 21

jlobo2
Advocate
Advocate

@Alexander.Rivilis  Thank You for your response.

 

I am receiving an error with  AcDbDimStyleTablePointer pDimStyleTable(idDimStyleTable, AcDb::kForRead);

saying, that it's an undeclared identifier.

 

Which libraries are you using? I am using Object ARX, in Visual Studio. I only have the options below with the 

AcDbDimStyleTable

 

DimensionStyle.jpg

 

0 Likes
Message 6 of 21

Alexander.Rivilis
Mentor
Mentor

Ok. Add line on top of file:

#include "dbobjptr.h"

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 7 of 21

jlobo2
Advocate
Advocate

@Alexander.Rivilis  Thank You, but the id is still NULL. Not sure why.

0 Likes
Message 8 of 21

Alexander.Rivilis
Mentor
Mentor

Attach your dwg-file. What ObjectARX SDK version you use?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 9 of 21

jlobo2
Advocate
Advocate

We are using ObjectArx 2018 version. we have a template file setup. So all we are trying to do is read data from the template drawing file and use the data while drawing a new one.

0 Likes
Message 10 of 21

Alexander.Rivilis
Mentor
Mentor
Accepted solution

@jlobo2 wrote:

We are using ObjectArx 2018 version. we have a template file setup. So all we are trying to do is read data from the template drawing file and use the data while drawing a new one.


I've created new dwg-file, created new Dimension Style with name _STANDARD and exec my code in this drawing - no error and valid AcDbObjectId:

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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

Message 11 of 21

jlobo2
Advocate
Advocate

Ok. 

 

Am sure we are missing some files.

In the code -  AcDbDatabase *pCurDb = acdbCurDwg(); gives us an error, acdbCurrDwg is undefined.

Which header file should we include for this one?

0 Likes
Message 12 of 21

Alexander.Rivilis
Mentor
Mentor

@jlobo2 wrote:

Ok. 

 

Am sure we are missing some files.

In the code -  AcDbDatabase *pCurDb = acdbCurDwg(); gives us an error, acdbCurrDwg is undefined.

Which header file should we include for this one?


Add:

#include "migrtion.h"

or replace acdbCurDwg() with acdbHostApplicationServices()->workingDatabase()

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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

Message 13 of 21

jlobo2
Advocate
Advocate

ok,

  1. now the error message is 
    Error (active)		identifier "acdbHostApplicationServices" is undefined	
  2.  So, the first code snippet I posted, works on AutoCAD 2018 on Windows 8, but fails to work on AutoCAD 2018 on Windows 10. Any idea why?
0 Likes
Message 14 of 21

Alexander.Rivilis
Mentor
Mentor

@jlobo2 wrote:

ok,

  1. now the error message is 
    Error (active)		identifier "acdbHostApplicationServices" is undefined	
  2.  So, the first code snippet I posted, works on AutoCAD 2018 on Windows 8, but fails to work on AutoCAD 2018 on Windows 10. Any idea why?

No ideas. You have to debug your code.

P.S.: Error is due to your not include dbapserv.h

Best solution is create new project with ObjectARX Wizard 2018

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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

Message 15 of 21

jlobo2
Advocate
Advocate

Yes, I believe that's the way to go. Was just debugging and bug fixing code for my colleague, who is no more with the company. I really appreciate your help. It saved me lot of research time.

0 Likes
Message 16 of 21

jlobo2
Advocate
Advocate

@Alexander.Rivilis 

 

I have this code in C#.NET to access the DimStyles on a different project.

It works well with users in one country, but not with another country.

Am I missing anything here?

 

DimStyleTable pDimensionStyleTbl;

using (Transaction acTrans = theDb.TransactionManager.StartTransaction())
{
      pDimensionStyleTbl = acTrans.GetObject(theDb.DimStyleTableId,
      OpenMode.ForRead) as DimStyleTable;
      idDimensionStyleStandard = pDimensionStyleTbl["Standard"];
}

pDimensionStyleTbl.Dispose();
0 Likes
Message 17 of 21

Alexander.Rivilis
Mentor
Mentor

@jlobo2 wrote:

@Alexander.Rivilis 

 

I have this code in C#.NET to access the DimStyles on a different project.

It works well with users in one country, but not with another country.

Am I missing anything here?

 

DimStyleTable pDimensionStyleTbl;

using (Transaction acTrans = theDb.TransactionManager.StartTransaction())
{
      pDimensionStyleTbl = acTrans.GetObject(theDb.DimStyleTableId,
      OpenMode.ForRead) as DimStyleTable;
      idDimensionStyleStandard = pDimensionStyleTbl["Standard"];
}

pDimensionStyleTbl.Dispose();

Maybe "Standard" is renamed? If is easy rename dimstyle "Standard" to any other name with _RENAME command.

using (Transaction acTrans = theDb.TransactionManager.StartTransaction())
{
      DimStyleTable pDimensionStyleTbl = acTrans.GetObject(theDb.DimStyleTableId,
      OpenMode.ForRead) as DimStyleTable;
      try {
        idDimensionStyleStandard = pDimensionStyleTbl["Standard"];
      } catch {};
      acTrans.Commit();
}

 

 

 

 

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 18 of 21

jlobo2
Advocate
Advocate

SpainStandardDimStyle.jpg

   I thought so, but its named as Standard.

0 Likes
Message 19 of 21

Alexander.Rivilis
Mentor
Mentor

@jlobo2 wrote:

 

   I thought so, but its named as Standard.


What value of idDimensionStyleStandard after code execution?

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | 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 20 of 21

jlobo2
Advocate
Advocate

@Alexander.Rivilis  Any help to the question below. i would really appreciate it.

Make Dimensions Annotative from a Template in the drawing

 

The dimensions are not being annotative.AnnotativeScaleDimensions.jpg

0 Likes