Author Topic: Reading an attribute from a block in an xref.  (Read 2534 times)

0 Members and 1 Guest are viewing this topic.

mr_nick

  • Guest
Reading an attribute from a block in an xref.
« on: December 13, 2006, 04:45:58 AM »
Is there a way to get the attribute info from a block within an xref without using nentselp? I know the name of the block so want to programatically extract the info without having to go clicking on stuff.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Reading an attribute from a block in an xref.
« Reply #1 on: December 13, 2006, 11:09:54 AM »
Yes.  You will have to step through the xref's block definition until you find the block(s?) in question.  Then you can step through it to all the attribute information you want.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

mr_nick

  • Guest
Re: Reading an attribute from a block in an xref.
« Reply #2 on: December 13, 2006, 11:15:17 AM »
I've been working on that theory but for some reason, when I extract the attribute information I get the default value returned and not the actual value. Are you able to offer any pointers? I'm up to my elbows in snippets of code and it's all getting a bit messy!! :lol:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Reading an attribute from a block in an xref.
« Reply #3 on: December 13, 2006, 11:23:29 AM »
Here is how I would do it.  Code written on the fly, untested, but should give you the idea of what I mean.
Code: [Select]
(setq Sel (ensel "\n Select xref: "))
(setq BlkName "YourBlocksName")
(setq BlkCol (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-Acad-Object))))
(setq BlkObj (vla-Item BlkCol (cdr (assoc 2 (entget (car Sel))))))
(vlax-for Obj BlkObj
 (if
  (and
   (= (vla-get-ObjectName Obj) "AcDbBlockReference")
   (= (vla-get-Name Obj) BlkName)
  )
  (foreach Att (vlax-invoke Obj 'GetAttributes)
   (prompt (strcat "\n Tag name: " (vla-get-TagString Att) "  Value: " (vla-get-TextString Att)))
  )
 )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

mr_nick

  • Guest
Re: Reading an attribute from a block in an xref.
« Reply #4 on: December 13, 2006, 11:32:41 AM »
FANTASTIC!!

Does exactly what I wanted. I'm trying to figure out where my code was tripping over because the theory looks very similar.

Your input is very much appreciated :-D

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Reading an attribute from a block in an xref.
« Reply #5 on: December 13, 2006, 11:39:13 AM »
You're welcome.  If you want to paste your code, I/we can take a look at it and see if different eyes can see it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

mr_nick

  • Guest
Re: Reading an attribute from a block in an xref.
« Reply #6 on: December 13, 2006, 11:55:59 AM »
Having had a look, where you use the foreach loop, I had used a mapcar/lambda loop and this appears to be where I'd fudged it. Too many hours spinning too many plates!!  :ugly:

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Reading an attribute from a block in an xref.
« Reply #7 on: December 13, 2006, 12:06:14 PM »
If I wanted to output a list, I would use the mapcar lambda combo, but since I just wanted to output it to the command line, I used foreach.  Usually I would output a list of (TagName . AttValue).  To do that, you would just use something like
Code: [Select]
(mapcar
 '(lambda (x)
  (cons (vla-get-TagString x) (vla-get-TextString x))
 )
 (vlax-invoke BlkObj 'GetAttributes)
)

Hope this is helping.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

mr_nick

  • Guest
Re: Reading an attribute from a block in an xref.
« Reply #8 on: December 14, 2006, 03:41:18 AM »
Spotted it!!

I was using the wrong variable in this line:

(vlax-invoke BlkObj 'GetAttributes)

A good nights sleep seems to have removed the 'see what you want to see' goggles which seem to afflict me when I've been looking at a problem too long!


Thanks for the assistance - couldn't have cracked this without you  :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Reading an attribute from a block in an xref.
« Reply #9 on: December 14, 2006, 11:00:42 AM »
Glad you found where the problem was.

Thanks for the assistance - couldn't have cracked this without you  :-)
You're welcome.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.