Author Topic: Getting the ID of Attribute ??????  (Read 3502 times)

0 Members and 1 Guest are viewing this topic.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Getting the ID of Attribute ??????
« on: November 27, 2006, 12:35:50 PM »
First of all this is my 3rd attempt at Visual Lisp that I am trying to learn which might as well be Greek.

I am trying to pull a value from specific attribute (1 0f 3) in a block and feed that value to an attribute of a different block (different name than the first) I want the user to select the desired Room Tag block, the routine to pull the room number value from that block and feed that value to a user selected Door Tag block.  The bocks and attributes are known.  When feeding in the value to the door tag block, I would like to incorporate the use of the field so there would be a link.

Code: [Select]
(DEFUN C:test ()
  (princ)
  (vl-cmdf ".undo" "m")
  ;;
  (setvar "cmdecho" 1)
;;;Prompts for user selection of Room Name Block.
  (setq RoomTag (vla-get-objectid
  (vlax-ename->vla-object
    (car (entsel "\n Select Room Name Block "))
  )
)
  )
  ;;
  ;;;Extract Value of Attribute < RM_NO > from Room Tag
  (setq RmNo (vla-get-objectid
       ????????

;;;Prompts for user selection of Door Tag Block and passes value to block.        
  (vla-put-TextString
    (vlax-ename->vla-object
      (car (entsel "\n Select Door Tag Block "))
    )
    (strcat
      "%<\AcObjProp Object(%<\_ObjId"
      (itoa RmNo)
      ">%).TextString \f "
      %tc1
      ">%"
    )
  )

  (setvar "cmdecho" 1)
)
;; End of Lisp

The problem that I am having is there is a different ID number (?? Lack of a better term) for each attribute.  How do I extract ID number that from user a selected block?.

Quote
  ;;;Extract Value of Attribute < RM_NO > from Room Tag
  (setq RmNo (vla-get-objectid
          ?? ?? ??
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting the ID of Attribute ??????
« Reply #1 on: November 27, 2006, 12:47:33 PM »
Once you get your block, then you can get the attributes from it, and  then make an associated list of the the 'tag' and 'value'.
Code: [Select]
(setq AttList
 (mapcar
  '(lambda (x)
   (cons
    (vla-get-TagString x)
    (vla-get-TextString x)
   )
  )
  (vlax-invoke RoomTag 'GetAttributes)
 )
)
Then to populate the other attribute with the information you want, I would step through the list of attributes returned by
Code: [Select]
(vlax-invoke BlkObj 'GetAttributes)You will have to change your code a little as you need to select the second block, and then pass the 'vla object' to the function above, or you can pick the attribute itself with 'nentsel', but for that to work there has to be a string there aready.

Hope that makes some sense.
Tim

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

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Getting the ID of Attribute ??????
« Reply #2 on: November 27, 2006, 01:21:29 PM »
Hope that makes some sense.
Ahhhh No.  You were a F16 that just flew over my head.  I heard you & saw you but that was about it.  :-)

Once you get your block, then you can get the attributes from it, and  then make an associated list of the the 'tag' and 'value'.
Code: [Select]
(setq AttList
 (mapcar
  '(lambda (x)
   (cons
    (vla-get-TagString x)
    (vla-get-TextString x)
   )
  )
  (vlax-invoke RoomTag 'GetAttributes)
 )
)

Then to populate the other attribute with the information you want, I would step through the list of attributes returned by
Code: [Select]
(vlax-invoke BlkObj 'GetAttributes)
I am confused.
Why do I need to get a list of ALL the attributes of the block? I only want one attribute and it's value.  So why do I step thru them all?  Or is that the way it is done?  (Just asking to understand  :-))

You will have to change your code a little as you need to select the second block, ...
I thought I was doing that already.   :? Was I?


and then pass the 'vla object' to the function above.... 
isn't that going in the wrong direction?  :?


I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting the ID of Attribute ??????
« Reply #3 on: November 27, 2006, 02:04:39 PM »
Here is how I would do it.
Code: [Select]
(defun c:Test (/ FromSel ToSel FromList ToAttList)

(if
 (and
  (setq FromSel (entsel "\n Select block to copy attribute information from: "))
  (setq ToSel (entsel "\n Select block to copy attribute information to: "))
  ; I would add checking to make sure blocks were selected, but you can do that
 )
 (progn
  (setq FromList
   (mapcar
    '(lambda (x)
     (cons
      (vla-get-TagString x)
      (vla-get-TextString x)
     )
    )
    (vlax-invoke
     (vlax-ename->vla-object (car FromSel))
     'GetAttributes
    )
   )
  )
  (setq ToAttList
   (mapcar
    '(lambda (x)
     (cons (vla-get-TagString x) x)
    )
    (vlax-invoke (vlax-ename->vla-object (car ToSel)) 'GetAttributes)
   )
  )
  (vla-put-TextString
   (cdr (assoc "NameOfTag" ToAttList))
   (cdr (assoc "RM_NO" FromList))
  )
 )
)
(princ)
)
Ofcourse you want to use 'fields' and I don't use them, so you will have to change the code a little.  And I didn't know the tag for the attribute in the 'door block' so you will have to add that.
Tim

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

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Getting the ID of Attribute ??????
« Reply #4 on: November 27, 2006, 03:19:04 PM »
Here is how I would do it.
ahh it looks like you did it for me.  I don't mean to sound ungrateful because I just got one of those "quick add room & door tags" thrust upon me and thus perfect timing; however I was hoping to kind of understand it some more for future coding

Answer me this then.
1.)  Why do we have to build a list for just one attribute?  This part is nagging me the most.  My thinking is that attribute already has a name and why cant you just go get the value by that name?
2.)  Why is the whole thing contained in a "IF" statement.  is that for checking against selection of blocks or something else?

Yes I was the poster child for kid that ask "Why" all the time  :-)

Of course you want to use 'fields' and I don't use them, so you will have to change the code a little.
I am on the fence on that one because of already thinking of how this routine is going to evolve.

And I didn't know the tag for the attribute in the 'door block' so you will have to add that.
Corrected and done.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting the ID of Attribute ??????
« Reply #5 on: November 27, 2006, 03:26:49 PM »
Answer me this then.
1.)  Why do we have to build a list for just one attribute?  This part is nagging me the most.  My thinking is that attribute already has a name and why cant you just go get the value by that name?
You don't have to build a list.  If you use the ActiveX way, a list will be created of all the attribute objects.  If you use the lisp way, 'entnext' on the block entity that is inserted, then you will have to step through each one until you find the right one.  I like this list approach as you can find more than one quickly, and lisp is great of using lists, so why not use them.


2.)  Why is the whole thing contained in a "IF" statement.  is that for checking against selection of blocks or something else?
I put the whole thing in an 'if' statment so that if only one object is selected it won't error out, or if none are selected it won't error.  Also I would add some more error checking in the 'and' area of the 'if' so that you make sure you grab a block, and that the blocks that are grabbed are the ones you want to use.  If you don't grab a block, it will error, if you don't grab a block with the correct attributes it won't work correclty either, so the 'if' is very helpful to make sure you grab the right items for your command.

Hope that helps.
Tim

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

Please think about donating if this post helped you.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Getting the ID of Attribute ??????
« Reply #6 on: November 27, 2006, 03:51:01 PM »
Answer me this then.
1.)  Why do we have to build a list for just one attribute?  This part is nagging me the most.  My thinking is that attribute already has a name and why cant you just go get the value by that name?
You don't have to build a list.  If you use the ActiveX way, a list will be created of all the attribute objects.  If you use the lisp way, 'entnext' on the block entity that is inserted, then you will have to step through each one until you find the right one.  I like this list approach as you can find more than one quickly, and lisp is great of using lists, so why not use them.
Okay that makes sense.

2.)  Why is the whole thing contained in a "IF" statement.  is that for checking against selection of blocks or something else?
I put the whole thing in an 'if' statement so that if only one object is selected it won't error out, or if none are selected it won't error.  Also I would add some more error checking in the 'and' area of the 'if' so that you make sure you grab a block, and that the blocks that are grabbed are the ones you want to use.  If you don't grab a block, it will error, if you don't grab a block with the correct attributes it won't work correctly either, so the 'if' is very helpful to make sure you grab the right items for your command.
 

So it is doing double duty.
Second thought this might bring my next version a little sooner.  Some times there might be more than one door into a space/room.  So my thought was that, I want the user to pick the doors in order that user wants and the routine adds a suffix (alpha character) to the numerical value of the room number and that suffix increases per the number of doors.  for example Room Number is 100 and there are three doors to the space.  The final result would be 100A; 100B; 100C & ETC for the total number of doors pick.  So I was think that there will be some counter and a suffix adder.  I haven't totally thought it thru so I will come back to this later

Thanks and it does help in more ways than one.   :-)
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting the ID of Attribute ??????
« Reply #7 on: November 27, 2006, 04:01:15 PM »
What you want to do shouldn't be to hard.  When you are picking the second item, the doors, do so in a while loop, while 'enter' is not hit, add what was selected, if anything, to a list.

Glad it helps.
Tim

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

Please think about donating if this post helped you.