Author Topic: Dynamic Block Properties  (Read 7649 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Dynamic Block Properties
« on: January 06, 2010, 07:26:00 PM »
This is new ground for me, so bear with me a bit...  :wink:

A recent thread involved modifying dynamic block properties, and so I thought I'd finally give it a shot at learning how to do it.

I've done a search on here, but, although I have found methods, and threads relating to it, I still have an outstanding query.



Say I am trying to enter a Dynamic Block Property after insertion, knowing its Property Name.

I am currently using methods along these lines:

Code: [Select]
(foreach Prop (vlax-invoke obj 'GetDynamicBlockProperties)

  (if (eq <PropName> (vla-get-PropertyName Prop))
    (vla-put-value Prop
      (vlax-make-variant <New Value>
        (vlax-variant-type
          (vla-get-value Prop))))))

And have also tried:

Code: [Select]
(foreach Prop (vlax-invoke obj 'GetDynamicBlockProperties)

  (if (eq <PropName> (vla-get-PropertyName Prop))
    (vlax-put-property Prop 'Value <New Value>)))

But, when entering some values, (namely zero), I get: ** Automation Error: Invalid Input **

Could this be due to the Dynamic Block that I am using? Or the method I am using to enter the value?



Once again, I stress - I have never used Dynamic Blocks before, and don't even know how to make them, and so I can only test on blocks that I find in threads...  :cry:

Any advice is appreciated.

Lee


T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dynamic Block Properties
« Reply #1 on: January 06, 2010, 07:33:12 PM »
This worked just fine for me

Code: [Select]
(foreach i (vlax-invoke ob2 'getdynamicblockproperties)
    (if (= "Visibility" (vla-get-PropertyName i))
        (vla-put-Value i "Elevation")
    )
)

Maybe you should test to make sure it is an allowed value to enter.
Quote
; IAcadDynamicBlockReferenceProperty: AutoCAD Dynamic Block Property Interface
; Property values:
;   AllowedValues (RO) = ("Detail" "Elevation" "Section" "Section-Single" "Section-Double")
;   Description (RO) = ""
;   PropertyName (RO) = "Visibility"
;   ReadOnly (RO) = 0
;   Show (RO) = -1
;   UnitsType (RO) = 0
;   Value = "Detail"
Tim

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

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Dynamic Block Properties
« Reply #2 on: January 06, 2010, 07:55:35 PM »
Ahh... I didn't realise there were values you were "allowed" to enter!

Thanks Tim, that solves it!

At least I learnt a lot with my digging  8-)

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Dynamic Block Properties
« Reply #3 on: January 07, 2010, 03:01:52 AM »
Hi Lee,

Maybe you can get some inspiration from this one.
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Dynamic Block Properties
« Reply #4 on: January 07, 2010, 05:41:29 AM »
Hi Lee,

Maybe you can get some inspiration from this one.

Many thanks Gile, I'll check it out  :-)

Oak3s

  • Guest
Re: Dynamic Block Properties
« Reply #5 on: October 21, 2010, 08:35:00 PM »
How do I find this information for my DB?
Quote
; IAcadDynamicBlockReferenceProperty: AutoCAD Dynamic Block Property Interface
; Property values:
;   AllowedValues (RO) = ("Detail" "Elevation" "Section" "Section-Single" "Section-Double")
;   Description (RO) = ""
;   PropertyName (RO) = "Visibility"
;   ReadOnly (RO) = 0
;   Show (RO) = -1
;   UnitsType (RO) = 0
;   Value = "Detail"
Also, I am not doing to well trying to follow that code? Could someone help me out. Below is the code T.Willey posted. I attempted to change what I thought was necessary but its a no go :)
Code: [Select]
(defun c:dyn (/)
(vl-load-com)
(foreach i ;variable that each element in the list will be assigned to
(vlax-invoke-method ob2 'getdynamicblockproperties) ;list to be stepped through and evaluated
(if (= "Width" (vla-get-PropertyName i)) ;expression to be evaulated for each element in list
    (vla-put-Value i "6")
)
)
)

Oak3s

  • Guest
Re: Dynamic Block Properties
« Reply #6 on: October 21, 2010, 08:45:08 PM »
I spend time trying to figure something out myself and then post...5 minutes later I find something. :)

Okay, so first I need to assign the VLA-object...right?

Code: [Select]
(setq ob2 (vlax-ename->vla-object(car(entsel))))
I dont know if that is the proper way to do it but its what I found.
So after that I can get the property list T.Willey showed by:
Code: [Select]
(vlax-dump-object ob2 T)Again, I dont know if that is the proper way but it is what I found. :)
I am going to continue digging. Not solved for me yet.

Oak3s

  • Guest
Re: Dynamic Block Properties
« Reply #7 on: October 21, 2010, 09:21:24 PM »
:( I lied. the vlax-dump wasnt giving me the dynamic properties like the example posted above.

m4rdy

  • Newt
  • Posts: 62
Re: Dynamic Block Properties
« Reply #8 on: October 22, 2010, 03:29:35 AM »
Q & R

Code: [Select]
(mapcar (function (lambda (x) (vlax-dump-object x T)))
(vlax-safearray->list
  (vlax-variant-value
    (vla-getdynamicblockproperties
      (vlax-ename->vla-object (car (entsel)))
    )
  )
)
);_===>> he..he..he
« Last Edit: October 22, 2010, 08:08:20 AM by m4rdy »
Autocad 2007, Windows XP

Gliderider

  • Guest
Re: Dynamic Block Properties
« Reply #9 on: October 22, 2010, 07:18:41 AM »
misplaced parenthesis ^^^^^^^
Code: [Select]
(mapcar
  (function (lambda (x) (vlax-dump-object x T)))
  (vlax-safearray->list
    (vlax-variant-value
      (vla-getdynamicblockproperties
      (vlax-ename->vla-object (car (entsel))))
    )
  )
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dynamic Block Properties
« Reply #10 on: October 22, 2010, 08:09:07 AM »
misplaced parenthesis ^^^^^^^
< .. snip .. >

looks like I'm not the only one who posts code untested  :wink:
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.

m4rdy

  • Newt
  • Posts: 62
Re: Dynamic Block Properties
« Reply #11 on: October 22, 2010, 08:10:01 AM »
Oops ... Edited above.

mardi
Autocad 2007, Windows XP

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dynamic Block Properties
« Reply #12 on: October 22, 2010, 06:58:32 PM »
:( I lied. the vlax-dump wasnt giving me the dynamic properties like the example posted above.

My dump was a dump of each dynamic property of the block, so you would code it up like

Code: [Select]
(foreach i (vlax-invoke (vlax-ename->vla-object (car (entsel))) 'GetDynamicBlockProperties)
(vlax-dump-object i T)
)(princ)

Then select a dy block.
Tim

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

Please think about donating if this post helped you.

Oak3s

  • Guest
Re: Dynamic Block Properties
« Reply #13 on: October 22, 2010, 07:12:24 PM »
That works well. How can it be modified to use entlast rather than entsel?
As I understand it entlast isnt reterning the pickpoint. I dont understand why that is effecting vlax-ename->vla-object...doesnt that just need the name?
Ah, this is making my head hurt. (that might make it into the 'out of context' thread)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dynamic Block Properties
« Reply #14 on: October 22, 2010, 07:17:07 PM »
' vlax-ename->vla-object ' just needs an ename, so if you want to use ' entlast ', replace ' (car (entsel)) ' with ' (entlast) '.
Tim

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

Please think about donating if this post helped you.

Oak3s

  • Guest
Re: Dynamic Block Properties
« Reply #15 on: October 22, 2010, 07:25:14 PM »
I could have sworn I did that...thats why I asked the question.  :roll:
Thank you.

Code: [Select]
(foreach i (vlax-invoke (vlax-ename->vla-object (entlast)) 'GetDynamicBlockProperties)
(vlax-dump-object i T)
)(princ)

Okay, so here is an attempt to us entlast to change the "Width" in the block to 6
Code: [Select]
(defun c:dyn (/ ob2)
(vl-load-com)
(foreach i (vlax-invoke (vlax-ename->vla-object (entlast)) 'GetDynamicBlockProperties)
(if (= "Width" (vla-get-PropertyName i))
        (vla-put-Value i 6)
)
)
)

I am not sure that the nil for AllowedValues is causing a problem?
Code: [Select]
; IAcadDynamicBlockReferenceProperty: AutoCAD Dynamic Block Property Interface
; Property values:
;   AllowedValues (RO) = nil
;   Description (RO) = ""
;   PropertyName (RO) = "Width"
;   ReadOnly (RO) = 0
;   Show (RO) = -1
;   UnitsType (RO) = 2
;   Value = 4.0

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Dynamic Block Properties
« Reply #16 on: October 22, 2010, 07:33:58 PM »
You may just need to update it once you change the property, or regen the drawing.  I think a nil is always returned.

I tested your code on one of my dynamic blocks, and it changed the property, and it showed it right away.  And my property looked like yours.  The only thing I can guess is maybe that is the wrong property.  Try changing one of the others, or looking at the block in the block editor, and make sure that is the right one.  Besides that, I'm not sure what else to try, as I don't use dy blocks.
Tim

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

Please think about donating if this post helped you.

Oak3s

  • Guest
Re: Dynamic Block Properties
« Reply #17 on: October 22, 2010, 07:43:47 PM »
That gave me hope...so I added a . after the 6 and it worked...hmmmm...why would it work for you without it.

Code: [Select]
(defun c:dyn (/ ob2)
(vl-load-com)
(foreach i (vlax-invoke (vlax-ename->vla-object (entlast)) 'GetDynamicBlockProperties)
(if (= "Width" (vla-get-PropertyName i))
        (vla-put-Value i 6.)
)
)
)

I just tested this back and forth and that . is doing something. Any ideas?

Oak3s

  • Guest
Re: Dynamic Block Properties
« Reply #18 on: October 22, 2010, 07:48:55 PM »
For what its worth.
Code: [Select]
(defun c:dyn (/ ob2 val)
(vl-load-com)
(setq val (getreal "Width: "))
(foreach i (vlax-invoke (vlax-ename->vla-object (entlast)) 'GetDynamicBlockProperties)
(if (= "Width" (vla-get-PropertyName i))
        (vla-put-Value i val)
)
)
)
This seems to accomplish what I was trying to do. Now to get the thing to rotate...that is after I insert it.