Author Topic: Constant Attribute pain  (Read 3672 times)

0 Members and 1 Guest are viewing this topic.

hendie

  • Guest
Constant Attribute pain
« on: December 16, 2005, 04:00:43 AM »
I'm looping through a selection set of blocks and creating a list from a number of Constant (& Invisible) attributes.

The problem I'm having is that I cannot filter by block name (a gazillion different blocks), the number of attributes differs with each block and some of the blocks don't have Constant atttributes at all.

I'm using
Code: [Select]
(vlax-safearray->list
      (vlax-variant-value
(vla-getconstantattributes (vlax-ename->vla-object MyBlkent))
      )
    )

to get the constant attributes, but it throws a wobbly with vlax-safearray->list when it comes across a block without any constant attributes. I keep getting ; error: ActiveX Server returned an error: Invalid index

I've tried all sorts of  combinations of vl-catch-all-whatever and I just can't seem to get round this one.

Basically I want the routine to skip over any blocks that do not contain Constant attributes... anyone have any pointers ?

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Constant Attribute pain
« Reply #1 on: December 16, 2005, 05:28:52 AM »
Hi

Use the Invoke method (variable AttLst is a list in this case):
Code: [Select]
(repeat (sslength SelSet)
 (setq CurObj (vlax-ename->vla-object (ssname SelSet SetCnt))
       SetCnt (1+ SetCnt)
 )
 (if (setq AttLst (vlax-invoke CurObj 'GetConstantAttributes))
  (DoYourStuff)
 )
)
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Constant Attribute pain
« Reply #2 on: December 16, 2005, 05:36:45 AM »
Or optionally ....

See if this helps

Just drop it into the VLIDE, select the lot  and load the selection ... or just run it one procedure at a time.

Code: [Select]
(setq *TempEnt* (vlax-ename->vla-object (car (entsel))))


(setq Att (vlax-variant-value (vla-getattributes *TempEnt*))
      Conatt (vlax-variant-value (vla-getconstantattributes *TempEnt*))
)

(setq AttributeReference (safearray-value Att))

(setq ConAttributeReference (safearray-value ConAtt))


so the trick this way is use safearray-value on the variable to test ..

but vlax-invoke as Jürg shows solves a lot of issues, not just with attributes.
« Last Edit: December 16, 2005, 05:40:55 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

hendie

  • Guest
Re: Constant Attribute pain
« Reply #3 on: December 16, 2005, 05:54:10 AM »
thanks guys, excellent information.
That solved the problem ~ I ended up using Jürg's option but I'lll hold on to the rest as well,

thanks Kerry, and thanks Jürg

Fatty

  • Guest
Re: Constant Attribute pain
« Reply #4 on: December 16, 2005, 07:39:56 AM »
Hi hendie

Here are my two pence

Change by suit

Thank you

Fatty :-)

 
Code: [Select]
;; Get all attributes include constant attributes
  (vl-load-com)
  (defun get-all-atts (/ atts att_list const_atts const_list ent obj)
    (and (setq ent (car (entsel "\nSelect block to make attributes list: ")))
(setq obj (vlax-ename->vla-object ent))
(if (and (vlax-property-available-p obj 'Hasattributes)
  (eq :vlax-true (vla-get-hasattributes obj))
     )
   (progn
     (setq atts (vlax-invoke obj 'Getattributes))
     (foreach att atts
       (setq att_list
      (cons (cons (vla-get-tagstring att)
  (vla-get-textstring att)
    )
    att_list
      )
       )
     )
   )
)
    )
    (cond ((vlax-method-applicable-p obj 'Getconstantattributes)
   (setq const_atts (vlax-invoke obj 'Getconstantattributes))
   (foreach att const_atts
     (setq const_list
    (cons (cons (strcat "*CONSTANT*: " (vla-get-tagstring att))
(vla-get-textstring att)
  )
  const_list
    )
     )
   )
   (setq att_list (append const_list att_list))
  )
  (T att_list)
    )
  )
;CaLL:(setq blk_info (get-all-atts))

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Constant Attribute pain
« Reply #5 on: December 16, 2005, 08:16:54 AM »
BTW, that's my standard attribute read function:
Code: [Select]
;
; == Function MeGetAtts
; Reads all attribute values from an inserted block.
; Arguments [Type]:
;   Obj = Insert object [VLA-OBJECT]
;   Mde = Attribute mode [INT]
;         1 = Attributes only
;         2 = Constant attributes only
;         3 = Both
; Return [Type]:
;   > Dotted pair list '(("Tag1" . "Val1")...) [LIST]
; Notes:
;   - None
;
(defun MeGetAtts (Obj Mde)
 (mapcar
 '(lambda (Att) (cons (vla-get-TagString Att) (vla-get-TextString Att)))
  (append
   (if (= (logand Mde 1) 1) (vlax-invoke Obj 'GetAttributes))
   (if (= (logand Mde 2) 2) (vlax-invoke Obj 'GetConstantAttributes))
  )
 )
)
« Last Edit: December 17, 2005, 06:53:39 AM by Jürg Menzi »
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Fatty

  • Guest
Re: Constant Attribute pain
« Reply #6 on: December 16, 2005, 10:21:38 AM »
BTW, that's my standard attribute read function:


Hi Juergen

Nice routine

You killed me

Thanks again

Fatty

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Re: Constant Attribute pain
« Reply #7 on: December 16, 2005, 10:46:04 AM »
Hi Fatty, nice to see you here at TheSwamp... :-)

You killed me
I hope not... :-D
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

Fatty

  • Guest
Re: Constant Attribute pain
« Reply #8 on: December 16, 2005, 11:15:41 AM »
Quote
I hope not... :-D

Thanks Juergen

Have a nice weekend

Fatty :-)