Howto modify DXF codes inside custom entities

Howto modify DXF codes inside custom entities

kuang_hf
Enthusiast Enthusiast
3,439 Views
16 Replies
Message 1 of 17

Howto modify DXF codes inside custom entities

kuang_hf
Enthusiast
Enthusiast

Hi there,

We have drawings with some kind of custom entities from third party and a plugin arx to show them. I want to change some properties like layer, text style in these custom entities. Here is my code snippet:

ads_point pt;
int ret = acedEntSel(_T("Select an entity:\n"), ent, pt);
struct resbuf *ebuf = acdbEntGet(ent);
if (ebuf)
{
  struct resbuf *eb = ebuf;
  while (eb)
  {
    if (eb->restype == 7) // text style
    {
      ACHAR *pStyle = eb->resval.rstring;
      eb->resval.rstring = (ACHAR*)acad_malloc(20);
      _tcscpy(eb->resval.rstring, _T("test")); // assume a text style named 'test' already exists
      int ret;
      if ((ret=acdbEntMod(ebuf)) != RTNORM)
      {
        acutRelRb(ebuf);
        return ; // Error
      }
    }
    eb = eb->rbnext;
  }
  acutRelRb(ebuf);
}

My problem is, if I select the custom entity, as soon as I call acdbEntMod, acad crashes...  But if I select a standard entity like dbtext, the code runs ok. So what's wrong with it?

BTW, I notice acad has a standard checking function, which can successfully change the text style of that custom entity. So it's feasible.  But how does acad change it?

 

0 Likes
Accepted solutions (1)
3,440 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable

Maybe  Like  follow,  you can try.

if (eb->restype ==RTSHORT && eb->resval.rint ==7) // text style
{
eb=eb->rbnext;
...
}

0 Likes
Message 3 of 17

Alexander.Rivilis
Mentor
Mentor

If this custom entity is derived from AcDbText or AcDbMText you can use setTextStyle method instead  of changing value of DXF group 7.

For changing layer you can use setLayer method

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

kuang_hf
Enthusiast
Enthusiast

Deal alexander:

Unfortunately the custom entity is not derived from AcDbText(I see it from exported dxf), and we don't have the dbx module file. What else can we do?

0 Likes
Message 5 of 17

Alexander.Rivilis
Mentor
Mentor

@kuang_hf wrote:

Deal alexander:

Unfortunately the custom entity is not derived from AcDbText(I see it from exported dxf), and we don't have the dbx module file. What else can we do?


If you have not dbx-module this custom entity have to become proxy-entity. So you can not do anything with it.

Start this command in AutoCAD commandline, select your custom entity and post result to forum (as text):

(entget (car (entsel)) '("*"))

 

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

kuang_hf
Enthusiast
Enthusiast

The command result:

命令: (entget (car (entsel)) '("*"))
选择对象: ((-1 . <图元名: 7ffffb05a40>) (0 . "TCH_TEXT") (330 . <图元名: 7ffffb03820>) (5
. "21B4") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "PUB_TITLE") (62 .
0) (100 . "TDbEntity") (46 . 0.0) (47 . 100.0) (68 . 1) (100 . "TDbText") (10
-95621.2 -323770.0 0.0) (40 . 3.0) (1 . "test string") (50 . 0.0) (7 .
"CJ-ST") (70 . 0) (72 . 7))

I also think it maybe impossible to change anything of it. But acad's standard check function can change the custom entities' text style and layer according a dws file.  That's what I'm wondering...

0 Likes
Message 7 of 17

Alexander.Rivilis
Mentor
Mentor

You can change layer of this entity with AcDbEntity::setLayer method. As far as this entity is not derived from AcDbText or AcDbMText you can not use AcDbText::setTextStyle or AcDbMText::setTextStyle methods. If there is a COM-wrapper for this entity you can try use it:

(vlax-dump-object (vlax-ename->vla-object (car (entsel))) t)

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

kuang_hf
Enthusiast
Enthusiast

The command result is :

no function definition: VLAX-ENAME->VLA-OBJECT.  😞

 

0 Likes
Message 9 of 17

Alexander.Rivilis
Mentor
Mentor
(vl-load-com)

This line can be executed once before executing

(vlax-dump-object (vlax-ename->vla-object (car (entsel))) t)

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

kuang_hf
Enthusiast
Enthusiast

选择对象: ; IComLineText: IComLineText Interface
;特性值:
; Alignment = "左下(BL)"
; Application (RO) = #<VLA-OBJECT IAcadApplication 0000000140607198>
; Document (RO) = #<VLA-OBJECT IAcadDocument 0000000028bad400>
; Handle (RO) = "21B4"
; HasExtensionDictionary (RO) = 0
; Height = "3.0"
; Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 00000000315d3a48>
; Layer = "PUB_TITLE"
; LayoutRotation = 0.0
; Linetype = "ByLayer"
; LinetypeScale = 1.0
; Lineweight = -1
; Material = "ByLayer"
; ObjectID (RO) = 42
; ObjectID32 (RO) = 42
; ObjectName (RO) = "TDbText"
; OwnerID (RO) = 43
; OwnerID32 (RO) = 43
; PlotStyleName = "ByBlock"
; Rotation = 0.0
; Scale = 100.0
; Text = "^C1^C~^C7^C轴立面图"
; TextStyle = "CJ-ST"
; TrueColor = #<VLA-OBJECT IAcadAcCmColor 00000000315d3c80>
; Visible = -1
;支持的方法:
; ArrayPolar (3)
; ArrayRectangular (6)
; Copy ()
; Delete ()
; GetBoundingBox (2)
; GetExtensionDictionary ()
; GetXData (3)
; Highlight (1)
; IntersectWith (2)
; Mirror (2)
; Mirror3D (3)
; Move (2)
; Rotate (2)
; Rotate3D (3)
; ScaleEntity (2)
; SetXData (2)
; TransformBy (1)
; Update ()
T

 

Seem to have no proper COM methods?

0 Likes
Message 11 of 17

Alexander.Rivilis
Mentor
Mentor
Accepted solution

Try this code:

(vla-put-TextStyle (vlax-ename->vla-object (car (entsel))) "test")

Textstyle "test" have to be in this dwg-file before this call.

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

kuang_hf
Enthusiast
Enthusiast

It works!!!

Thanks for your help, Alexander. You're so welcome. BTW, can it be finished in C++ code?

0 Likes
Message 13 of 17

Alexander.Rivilis
Mentor
Mentor

@kuang_hf wrote:

It works!!!

Thanks for your help, Alexander. You're so welcome. BTW, can it be finished in C++ code?


It is possible but very complicated. It's easier to do this with VisualLisp.

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

kuang_hf
Enthusiast
Enthusiast

Thanks again.

0 Likes
Message 15 of 17

kuang_hf
Enthusiast
Enthusiast

Dear Alexander,

Sorry to bother you again.  The custom entities I mentioned above is from a third party company, and they provide two kinds of plug-ins.  The first one is full functional, which can let you edit properties, copy, delete their custom entities. The second is a restricted one, which can let you copy and delete their entities, but editing is not allowed.  If I install the first one, I can change entities' text style as you provided. But if I install the second 'restricted' one,  vlax-dump-object command fails with 'Automation error'. Seems that this kind of plug-in does not provide COM interfaces. BUT in this case, acad still can change the text style through 'Standard Check' function!  Is there another way to fulfill this, like modify hard pointers etc., or there are other kinds of COM interface ? 

0 Likes
Message 16 of 17

Alexander.Rivilis
Mentor
Mentor

@kuang_hf 

Sorry. I have not any idea.

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

kuang_hf
Enthusiast
Enthusiast

Dear Alexander,

I got a better method. Derive a filer from AcDbDwgFiler,  and use dwgOutFields to read the fields from an entity, and use dwgInFields to replace the specified ID.  Sample:

AcDbEntity * pEnt;
if (acdbOpenObject(pEnt, id, AcDb::kForWrite) == Acad::eOk)

{

MyFiler filer(); // this filer will do some replacing job in readXXX functions
pEnt->dwgOutFields(&filer);
pEnt->dwgInFields(&filer);

pEnt->close();

}