Author Topic: Dynamic block's parameters (Vanilla way)  (Read 2607 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Dynamic block's parameters (Vanilla way)
« on: November 09, 2016, 05:52:34 PM »
The curiousity is killing me.
Is there a way to get the parameter objects of a dynamic block reference as enames?
 Similar to:
Code: [Select]
(vlax-invoke o 'GetDynamicBlockProperties)I was digging into some dynamic block reference with the inspect tool but I'm getting lost.
As for the attributes its known that the key is with entnext.

 Here are some obvious thoughts:
Code: [Select]
(setq e (car (entsel "\nSelect attributed, dynamic block: ")))
(setq next (entnext e))
(while (and next (/= "SEQEND" (cdr (assoc 0 (entget next)))))
(setq AttribEnamesLst (cons next AttribEnamesLst))
(setq next (entnext next))
); while

_$ (mapcar '(lambda (x) (cdr (assoc 0 (entget x)))) AttribEnamesLst)
("ATTRIB" "ATTRIB" "ATTRIB")
_$ (setq o (vlax-ename->vla-object e))
#<VLA-OBJECT IAcadBlockReference 000000198c24f0a8>
_$ (setq AttribObjsLst (vlax-invoke o 'GetAttributes))
(#<VLA-OBJECT IAcadAttributeReference 000000198e88f328> #<VLA-OBJECT IAcadAttributeReference 000000198e88e248> #<VLA-OBJECT IAcadAttributeReference 000000198e88ea28>)
_$ (mapcar '(lambda (x) (vla-get-ObjectName x)) AttribObjsLst)
("AcDbAttribute" "AcDbAttribute" "AcDbAttribute")
_$ (setq ParamsObjsLst (vlax-invoke o 'GetDynamicBlockProperties))
(#<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ec0fa68> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ec0fd68> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ec0fda8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ec0f868> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ec0f8a8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ec0f6e8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ec0f3a8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ec0f5a8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ec0f728> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebef3e8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf0168> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf0e28> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf0428> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf0328> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf03a8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf07a8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf0968> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf01a8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf01e8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf03e8> #<VLA-OBJECT IAcadDynamicBlockReferenceProperty 000000198ebf0468>)
_$ (mapcar 'vlax-vla-object->ename ParamsObjsLst)
(nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil)
_$

Looks like the dynamic parameter objects cannot be converted into enames, however they can be found inside block's definition...
 but with the Visual approach it looks that they are extracted directly from the block reference + you have access to the actual parameter values that are set on that same block reference.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic block's parameters (Vanilla way)
« Reply #1 on: November 09, 2016, 06:07:12 PM »
Hint: here's your entry point:
Code - Auto/Visual Lisp: [Select]
  1. (dictsearch (cdr (assoc 360 (entget (cdr (assoc 330 (entget (tblobjname "block" "YourDynamicBlock"))))))) "acad_enhancedblock")

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Dynamic block's parameters (Vanilla way)
« Reply #2 on: November 10, 2016, 04:54:29 AM »
Thanks Lee,
But I am unsure that once I get inside the block's definition, I'll be able to get/set any parameter value for that block reference.
This was my attempt (bit longer than your suggestion - but practically the same):
Code: [Select]
(defun C:test ( / e BlkDef BlkRecord BlkRecXdict BlkEvalGraph EnamesOf-Actions_Parameters_Grips_Components rtn )
(while (not (and (setq e (car (entsel "\nSelect dynamic block: "))) (= "INSERT" (cdr (assoc 0 (entget e)))))) e )
(setq BlkDef (entget (tblobjname "BLOCK" (vla-get-EffectiveName (vlax-ename->vla-object e))) '("*") ))
(setq BlkRecord (digByItem 330 BlkDef))
(setq BlkRecXdict (digByName '(102 . "{ACAD_XDICTIONARY") BlkRecord))

(if (member '(3 . "ACAD_ENHANCEDBLOCK") BlkRecXdict)
(progn
(setq BlkEvalGraph (digByName '(3 . "ACAD_ENHANCEDBLOCK") BlkRecXdict))
(setq EnamesOf-Actions_Parameters_Grips_Components (mapcar 'cdr (vl-remove-if-not '(lambda (pair) (= 360 (car pair))) BlkEvalGraph)))
(setq rtn (mapcar '(lambda (x) (cdr (assoc 0 (entget x)))) EnamesOf-Actions_Parameters_Grips_Components)) ; check
); progn
); if
(if rtn (foreach x rtn (print x)))
(princ)
);| defun C:test |; (vl-load-com)


; Example: (digByItem 330 BlkDefElist)
(defun digByItem ( key elist / rtn )
(and
(listp elist) (mapcar 'car elist) (mapcar 'cdr elist) (assoc key elist) (= 'ENAME (type (cdr (assoc key elist))))
(setq rtn (entget (cdr (assoc key elist))))
)
rtn
); defun digByItem


; Example: (digByName '(102 . "{ACAD_XDICTIONARY") BlkRecordElist)
(defun digByName ( keyDpair elist / rtn )
(and
(listp keyDpair) (car keyDpair) (cdr keyDpair)
(listp elist) (mapcar 'car elist) (mapcar 'cdr elist)
(member keyDpair elist) (= 'ENAME (type (cdr (nth (1+ (vl-position keyDpair elist)) elist))))
(setq rtn (entget (cdr (nth (1+ (vl-position keyDpair elist)) elist))))
)
rtn
); defun digByName
In command prompt to confirm the results:
Code: [Select]
Select dynamic block:
"BLOCKLINEARPARAMETER"
"BLOCKLINEARGRIP"
"BLOCKGRIPLOCATIONCOMPONENT"
"BLOCKGRIPLOCATIONCOMPONENT"
"BLOCKLINEARPARAMETER"
"BLOCKLINEARGRIP"
"BLOCKGRIPLOCATIONCOMPONENT"
"BLOCKGRIPLOCATIONCOMPONENT"
"BLOCKLINEARPARAMETER"
"BLOCKLINEARGRIP"
"BLOCKGRIPLOCATIONCOMPONENT"
"BLOCKGRIPLOCATIONCOMPONENT"
"BLOCKLINEARPARAMETER"
"BLOCKLINEARGRIP"
"BLOCKGRIPLOCATIONCOMPONENT"
"BLOCKGRIPLOCATIONCOMPONENT"
"BLOCKSTRETCHACTION"
"BLOCKSTRETCHACTION"
"BLOCKSTRETCHACTION"
"BLOCKSTRETCHACTION"

I thought that the alternative VLA approach for this, would be like iterating thru the objects inside the block definition, but I was wrong:
Code: [Select]
_$ (while (not (and (setq e (car (entsel "\nSelect dynamic block: "))) (= "INSERT" (cdr (assoc 0 (entget e)))))) e )
nil
_$ (setq BlkRefObj (vlax-ename->vla-object e))
#<VLA-OBJECT IAcadBlockReference 000000890279eb48>
_$ (setq BlkDefObj (vla-item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-EffectiveName BlkRefObj)))
#<VLA-OBJECT IAcadBlock 000000890218ea78>
_$ (vlax-for o BlkDefObj (setq Lst (cons o Lst)))
(#<VLA-OBJECT IAcadAttribute 000000917c9001c8> #<VLA-OBJECT IAcadAttribute 000000917c9010a8> #<VLA-OBJECT IAcadAttribute 000000917c8ff748> #<VLA-OBJECT IAcadBlockReference 000000890279ee88> #<VLA-OBJECT IAcadBlockReference 000000890279ec18> #<VLA-OBJECT IAcadBlockReference 000000890279e188> #<VLA-OBJECT IAcadBlockReference 000000890279e0b8> #<VLA-OBJECT IAcadLine 00000089027a57d8> #<VLA-OBJECT IAcadLine 00000089027a3918> #<VLA-OBJECT IAcadLWPolyline 000000917c80f238> #<VLA-OBJECT IAcadAttribute 000000917c9001c8> #<VLA-OBJECT IAcadAttribute 000000917c9010a8> #<VLA-OBJECT IAcadAttribute 000000917c8ff748> #<VLA-OBJECT IAcadBlockReference 000000890279ee88> #<VLA-OBJECT IAcadBlockReference 000000890279ec18> #<VLA-OBJECT IAcadBlockReference 000000890279e188> #<VLA-OBJECT IAcadBlockReference 000000890279e0b8> #<VLA-OBJECT IAcadLine 00000089027a57d8> #<VLA-OBJECT IAcadLine 00000089027a3918> #<VLA-OBJECT IAcadLWPolyline 000000917c80f238>)
_$
Since there are no parameter objects collected in the list.

It seems that with vanilla lisp, we successfuly can extract the type of parameter type (assoc 0) and its "Tag Name" (assoc 305) and aswell the allowed values.

Do you have any ideas is it possible to set/get a dyn prop value with vanilla?
I always thought that if theres a way with VLA there must be a way with Vanilla.
« Last Edit: November 10, 2016, 05:01:19 AM by Grrr1337 »
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg