Author Topic: Nested Dynamic Block  (Read 3858 times)

0 Members and 1 Guest are viewing this topic.

artisteroi

  • Guest
Nested Dynamic Block
« on: August 30, 2007, 08:29:46 PM »
Is it possible to change the dynamic props of a nested dynamic block?  I have been working on a routine in vba as my co-worker works in .net both attempting the same goal. Select a nested dynamic block, iterate through the dynamic properties and update them with new values. I would not believe there were so many brick walls. We have managed to pull the info for the nested block from the table record but it only gives data that we are not able to relay back to block reference in order to modify the dynamic properties. Miff.
So anyhow if someone would be kind enough to assist me with your brilliance I would be forever en-debted. Here is a simple block with dynamic visibilties. In one of those visibilities there is another simple dynamic block with dynamic visiblities. The goal is a form that reads the the dynamic props from both of the blocks, populates a dropdown list with the options, then you can choose the other available option and click apply and it will change.
Wow that's a lot to ask isn't it? I would be happy with code that reads the props from the block ref instead of the block table. I think if we could get that we could get it.
But if you do want to try for the form I got a great chunck of lisp animation I will post as way of payment. It builds a 3D animation of assemblys by thawing layers in sequence set by the user while it does a fly around of the object. Great for architectural uses as you can show a building being built from the ground up.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Nested Dynamic Block
« Reply #1 on: August 31, 2007, 12:00:32 PM »
I was able to alter the square to a circle using lisp, but it affects all occurances of the inserted block.....which I think is what you are trying to avoid.

artisteroi

  • Guest
Re: Nested Dynamic Block
« Reply #2 on: August 31, 2007, 12:08:45 PM »
I was able to alter the square to a circle using lisp, but it affects all occurances of the inserted block.....which I think is what you are trying to avoid.

true but if you were able to alter it from the outside It would be a simple matter to filter out things that are out side a selection window or coordinate set

artisteroi

  • Guest
Re: Nested Dynamic Block
« Reply #3 on: September 06, 2007, 10:32:45 AM »
Jeff,
Hey can I see that code you made for lisp to change the dyna-block props? I think I got an idea of a how to modify the code so it will only select certain blocks.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Nested Dynamic Block
« Reply #4 on: September 26, 2007, 12:09:49 PM »
Here is some code I did.
Code: [Select]
(defun c:ShowDyProps (/ Sel NestList Obj ObjPropList tempStr)

(if
(and
(setq Sel (nentsel "\n Select item in nested block: "))
(> (length Sel) 2)
(> (length (setq NestList (last Sel))) 1)
)
(foreach ent NestList
(setq Obj (vlax-ename->vla-object ent))
(setq ObjPropList
(cons
(cons Obj (vlax-invoke Obj 'GetDynamicBlockProperties))
ObjPropList
)
)
)
)
(foreach lst ObjPropList
(prompt (strcat "\n\n Block effective name: " (vla-get-EffectiveName (car lst))))
(foreach dyprop (cdr lst)
(prompt
(strcat
"\n   Property name [ Current value ]: "
(vla-get-PropertyName dyprop)
" [ "
(vlax-get dyprop 'Value)
" ]"
)
)
(setq tempStr nil)
(foreach value (vlax-get dyprop 'AllowedValues)
(setq tempStr
(if tempStr
(strcat tempStr " , " value)
value
)
)
)
(prompt (strcat "\n      Allowed values: " tempStr))
)
)
(princ)
)
Print on the command line.
Quote
Command: ShowDyProps
 Select item in nested block:

 Block effective name: test2
   Property name [ Current value ]: Visibility [ Fancy ]
      Allowed values: Plain , Fancy

 Block effective name: test1
   Property name [ Current value ]: Visibility [ Circle ]
      Allowed values: Square , Circle

I then copied the block three times.  When I changed the 'visibility' property of the block 'test1' it would change them all, which makes sense since they are all read from one blocks definition.  Here is how I change the property (have to make the variable 'ObjPropList' global)
Quote
(vlax-put (cadadr ObjPropList) 'Value "Square")

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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Nested Dynamic Block
« Reply #5 on: September 26, 2007, 12:38:40 PM »
Here is a dialog format (was bored)
Code: [Select]
(defun c:ShowDyProps (/ Sel NestList Obj ObjPropList tempStr DiaRtn tempList)

(defun SingleSelect (Listof Message Toggle / DiaLoad tmpStr tmpTog tmpList)

(setq DiaLoad (load_dialog "MyDialogs.dcl"))
(if (new_dialog "SingleSelect" DiaLOad)
 (progn
  (start_list "listbox" 3)
  (mapcar 'add_list Listof)
  (end_list)
  (if Message
   (set_tile "text1" Message)
  )
  (if (not Toggle)
   (mode_tile "toggle1" 1)
  )
  (action_tile "listbox"
   "(if (= $reason 4)
    (progn
     (setq tmpStr (get_tile \"listbox\"))
     (if Toggle
      (setq tmpTog (get_tile \"toggle1\"))
     )
     (done_dialog 1)
    )
   )"
  )     
  (action_tile "accept"
   "(progn
    (setq tmpStr (get_tile \"listbox\"))
    (if Toggle
     (setq tmpTog (get_tile \"toggle1\"))
    )
    (done_dialog 1)
   )"
  )
  (action_tile "cancel" "(done_dialog 0)")
  (if (= (start_dialog) 1)
   (progn
    (setq tmpList (read (strcat "(" tmpStr ")")))
    (if (= tmpTog "1")
     (cons T tmpList)
     tmpList
    )
   )
  )
 )
)
)
;--------------------------------------------------------------------------
(if
(and
(setq Sel (nentsel "\n Select item in nested block: "))
(> (length Sel) 2)
(> (length (setq NestList (last Sel))) 1)
)
(foreach ent NestList
(setq Obj (vlax-ename->vla-object ent))
(setq ObjPropList
(cons
(cons Obj (vlax-invoke Obj 'GetDynamicBlockProperties))
ObjPropList
)
)
)
)
;|
(foreach lst ObjPropList
(prompt (strcat "\n\n Block effective name: " (vla-get-EffectiveName (car lst))))
(foreach dyprop (cdr lst)
(prompt
(strcat
"\n   Property name [ Current value ]: "
(vla-get-PropertyName dyprop)
" [ "
(vlax-get dyprop 'Value)
" ]"
)
)
(setq tempStr nil)
(foreach value (vlax-get dyprop 'AllowedValues)
(setq tempStr
(if tempStr
(strcat tempStr " , " value)
value
)
)
)
(prompt (strcat "\n      Allowed values: " tempStr))
)
)
|;
(if
(and
ObjPropList
(setq DiaRtn
(SingleSelect
(mapcar
'vla-get-EffectiveName
(mapcar 'car ObjPropList)
)
"Select block name to change property."
nil
)
)
(setq DiaRtn
(SingleSelect
(mapcar
'(lambda (x)
(vlax-get x 'PropertyName)
)
(setq tempList
(cdr (nth (car DiaRtn) ObjPropList))
)
)
"Select property to change."
nil
)
)
(setq DiaRtn
(SingleSelect
(setq tempList (vlax-get (setq Obj (nth (car DiaRtn) tempList)) 'AllowedValues))
(strcat "Select new value. Current value: " (vlax-get Obj 'Value))
nil
)
)
)
(vlax-put Obj 'Value (nth (car DiaRtn) tempList))
)
(vla-Regen (vla-get-ActiveDocument (vlax-get-Acad-Object)) acActiveViewport)
(princ)
)
Tim

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

Please think about donating if this post helped you.