Author Topic: Attributes and Fields  (Read 1514 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Attributes and Fields
« on: February 19, 2017, 07:56:34 AM »
Hi everyone,


I have a few copies of the same block and I was trying to link 2 (source and dest) attribute values (from diffrent blockrefs), using field(s):
Code - Auto/Visual Lisp: [Select]
  1. (setq sAtt (vlax-ename->vla-object (car (nentsel "\nSelect source attribute: "))))
  2. (setq dAtt (vlax-ename->vla-object (car (nentsel "\nSelect dest attribute: "))))
  3. (vla-put-TextString dAtt (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vlax-get sAtt 'ObjectId)) ">%).TextString>%"))
At first it sounded like an easy task, but it didn't work.

Soo... I created another copy of that block, and manually linked (no lisp) his attribute to the source one - and it worked (the handmade one).
Then from the properties of that "handmade" field I got the field textstring which was: " %<\AcObjProp Object(%<\_ObjId 140701967863360>%).TextString>% "
and tried directly assigning the same content (to the 3rd block):
Code - Auto/Visual Lisp: [Select]
  1.   (vlax-ename->vla-object (car (nentsel "\nSelect dest attribute reference: ")))
  2.   "%<\AcObjProp Object(%<\_ObjId 140701967863360>%).TextString>%"
  3. )
So the above failed.

Then I decided to check if the ObjId should be linked to the attribute reference (see the comments):

Code - Auto/Visual Lisp: [Select]
  1. %<\AcObjProp Object(%<\_ObjId 140701967863360>%).TextString>% ; extracted from the "handmade" field - that works
  2. _$ (vla-get-ObjectId (vlax-ename->vla-object (car (nentsel "\nSelect source attribute reference:"))))
  3. 42 ; this Id doesn't match the Id from the "handmade" field
  4. "284" ; but the handle from the field's ID matches
  5. _$ (vla-get-Handle (vlax-ename->vla-object (car (nentsel "\nSelect source attribute reference: "))))
  6. "284" ; to the handle of the selected source attribute ref
  7. _$
I have no idea whats wrong  :cry:
Heres the test drawing:
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Attributes and Fields
« Reply #1 on: February 19, 2017, 08:16:37 AM »
When populating attribute references with field expressions, you usually need to regenerate the drawing or use the UPDATEFIELD command for the field value to be displayed.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Attributes and Fields
« Reply #2 on: February 19, 2017, 08:26:51 AM »
Thanks for the input, Lee...
However that was not the problem - I did found the solution:
Code - Auto/Visual Lisp: [Select]
  1. (vla-put-TextString dAtt (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vlax-get sAtt 'ObjectId)) ">%).TextString>%")) ; doesn't work
Code - Auto/Visual Lisp: [Select]
  1. (vla-put-TextString dAtt (strcat "%<\\AcObjProp Object(%<\\_ObjId " (itoa (vla-get-ObjectId sAtt)) ">%).TextString>%")) ; works
Seems like vlax-get/vlax-put must be avoided when populating with FIELDS, and use vla-get-*/vla-put-* instead.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: Attributes and Fields
« Reply #3 on: February 19, 2017, 09:03:13 AM »
I'm glad you were able to find the source of the problem. :-)

Be careful when using this technique to obtain the ObjectID when working with 32-bit/64-bit systems, as alternative methods must be used to obtain the ObjectID in order to account for the 32-bit upper limit for signed integers in AutoLISP. You may wish to refer to my LM:objectid function as part of my Area Field to Attribute program as an example of how I account for this.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Attributes and Fields
« Reply #4 on: February 19, 2017, 10:09:13 AM »
I have some experience with fields, and I keep such subfunction somewhere in my library, although I've forgot to use it.
Thanks again! :)
Hopefully this thread will help for anyone that gets stuck on the same problem.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg