Author Topic: how do I attach a dictionary to an entity?  (Read 4592 times)

0 Members and 1 Guest are viewing this topic.

danadrian.baluta@yahoo.co

  • Guest
how do I attach a dictionary to an entity?
« on: March 04, 2015, 11:43:37 AM »
I'm trying to create a dictionary attached to an entity, but I couldn't find a function like dictadd.
Should I just edit the dictinary's assoc 330 and, instead of the main dictionary, place the entity that I want to be the parent of my dictionary?

Thank you,
Adrian

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: how do I attach a dictionary to an entity?
« Reply #1 on: March 04, 2015, 12:21:12 PM »
I find this a little easier with VLISP.  Start with the owning object's extension dictionary, which can then host other extension dictionaries and XRecords (although I rarely do the latter), with those dictionaries able to host *other* dictionaries and XRecords.  By keeping your information in specific, discrete dictionaries instead of at the root extension dictionary, you can avoid tripping over other data - including your own.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

danadrian.baluta@yahoo.co

  • Guest
Re: how do I attach a dictionary to an entity?
« Reply #2 on: March 05, 2015, 04:59:04 AM »
Thank you for pointing me to the right direction. I was looking for a way to create the extended dictionary, but there was no command.
After reading your advice, i looked only in vlisp and found out that
Code: [Select]
vla-GetExtensionDictionary, when called, automatically creates an extended dictionary if it doesn't find one.
Hope this will be useful for others as it was for me.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: how do I attach a dictionary to an entity?
« Reply #3 on: March 05, 2015, 06:48:12 AM »
Hi,

Here's a way using Vanilla AutoLISP:

Code - Auto/Visual Lisp: [Select]
  1. ;; gc:GetOrCreateExtDict (gile)
  2. ;; Returns the ename of the entity extension dictionary.
  3. ;; The dictionary is created if it didn't already exist.
  4. ;;
  5. ;; Argument : ent (ENAME)
  6.  
  7. (defun gc:GetOrCreateExtDict (ent / dict)
  8.   (cond
  9.     ((cdadr (member '(102 . "{ACAD_XDICTIONARY") (entget ent))))
  10.     ((setq dict (entmakex '((0 . "DICTIONARY") (100 . "AcDbDictionary")))
  11.            elst (entget ent)
  12.      )
  13.      (entmod
  14.        (vl-list*
  15.          (car elst)
  16.          (cadr elst)
  17.          '(102 . "{ACAD_XDICTIONARY")
  18.          (cons 360 dict)
  19.          '(102 . "}")
  20.          (cddr elst)
  21.        )
  22.      )
  23.      dict
  24.     )
  25.   )
  26. )
« Last Edit: March 05, 2015, 06:57:00 AM by gile »
Speaking English as a French Frog

danadrian.baluta@yahoo.co

  • Guest
Re: how do I attach a dictionary to an entity?
« Reply #4 on: March 05, 2015, 07:27:36 AM »
Thank you for the suggestion.
I did it this way:
Code: [Select]
(setq window1 (car (entsel)))
(setq newdict (vla-GetExtensionDictionary (vlax-ename->vla-object window1)))
(setq xrlist (list '(0 . "XRECORD") '(100 . "AcDbXrecord") '(280 . 1) '(1040 . -1.0)))
(setq xname (entmakex xrlist))
(SETQ DICTENT (vlax-vla-object->ename newdict))
(dictadd DICTENT "SCHEME_1" xname)

But I still get an error message: bad DXF group: (1040 . -1.0)
1040 code is for floating numbers. Why do I get this error?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: how do I attach a dictionary to an entity?
« Reply #5 on: March 05, 2015, 08:47:18 AM »
But I still get an error message: bad DXF group: (1040 . -1.0)
1040 code is for floating numbers. Why do I get this error?

DXF Group 1040 is reserved for use in xdata - I would suggest using DXF Groups 40-48.

danadrian.baluta@yahoo.co

  • Guest
Re: how do I attach a dictionary to an entity?
« Reply #6 on: March 05, 2015, 09:23:42 AM »
Thank you, Lee Mac, for the answer.
I already have the entities from an old project and they look like this:
Code - Auto/Visual Lisp: [Select]
  1. ((-1 . <Entity name: 7ffffb59cc0>) (0 . XRECORD) (5 . 28FA4) (102 . {ACAD_REACTORS) (330 . <Entity name: 7ffffb59cb0>) (102 . }) (330 . <Entity name: 7ffffb59cb0>) (100 . AcDbXrecord) (280 . 1) (1040 . -1.0))
when I use entget.
and the extension dicctionary looks like this:
Code - Auto/Visual Lisp: [Select]
  1. ((-1 . <Entity name: 7ffffb59cb0>) (0 . DICTIONARY) (330 . <Entity name: 7ffffb59c70>) (5 . 28FA3) (100 . AcDbDictionary) (280 . 1) (281 . 1) (3 . PROP) (360 . <Entity name: 7ffffb59cc0>))
Any idea how were they created?
I need to be able to add a new entity that has the same structure.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: how do I attach a dictionary to an entity?
« Reply #7 on: March 05, 2015, 11:29:05 AM »
A Test shows that BricsCAD (V14) accepts gc 1040 in xrecords. This may also apply to other ODA based .dwg editors.

@ Adrian Baluta:
The entity lists in your last post should have double quotes in a number of places.

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: how do I attach a dictionary to an entity?
« Reply #8 on: March 05, 2015, 11:51:52 AM »
Maybe Adrian used my old version of code posted here :

http://www.theswamp.org/index.php?topic=47878.msg529338#msg529338

Firstly it had (princ) so output was without double quotes... In some point of time, I've silently updated my code with (print) function instead, also with correct output shown grey after the code that has double quotes...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

danadrian.baluta@yahoo.co

  • Guest
Re: how do I attach a dictionary to an entity?
« Reply #9 on: March 05, 2015, 12:01:33 PM »
Thank you, roy_043
I guess this explains the mistery. I can't verify with what application were the entities made, but, at least, now I have a logical explanation.

And indeed, when using princ you don't get double quotes. You get them only when the entity comes as a value returned by a function.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: how do I attach a dictionary to an entity?
« Reply #10 on: March 05, 2015, 12:24:48 PM »
And indeed, when using princ you don't get double quotes. You get them only when the entity comes as a value returned by a function.

Or when using (prin1)  :wink:

A Test shows that BricsCAD (V14) accepts gc 1040 in xrecords. This may also apply to other ODA based .dwg editors.

Thank you for the information roy  :-)

TMoses

  • Guest
Re: how do I attach a dictionary to an entity?
« Reply #11 on: March 14, 2015, 10:27:48 AM »
Indeed, BricsCAD actually allows DXF group codes >= 999 to be used for XRecords;
this is not compatible with AutoCAD AutoLISP, so we actually fixed that.

Nevertheless, once such DXF items with code >= 999 are present in database, AutoCAD perfectly supports them (no error in audit/recover); can be saved + reloaded as dwg + dxf files, no problems at all;
even more, ARX allows such codes for XRecords, even when the docs states differently about this (terribly outdated).

In conclusion, it seems safest to stick with DXF codes as documented for XRecords (below 500).
I hope this explains a bit more ...
many greetings !

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: how do I attach a dictionary to an entity?
« Reply #12 on: March 14, 2015, 01:37:12 PM »
Thank you for your valuable input Torsten - it's great to see you around these parts! :)

TMoses

  • Guest
Re: how do I attach a dictionary to an entity?
« Reply #13 on: March 14, 2015, 10:07:11 PM »
Dear Lee :-)

it is my pleasue to kill all the dirty bugs ... I just fixed another problem with (acet-sys-control-down) and (acet-sys-shift-down) as Roy posted in another thread (unfortunately 1 year ago).

So I could really encourage everyone to send us the bug reports at Bricsys site :-)
Wish you a nice weekend & warm regards !