Author Topic: Dynamic Blocks and Visual LISP  (Read 12546 times)

0 Members and 1 Guest are viewing this topic.

nivuahc

  • Guest
Dynamic Blocks and Visual LISP
« on: May 14, 2005, 05:19:32 PM »
Okay, so I'm tinkering around with 2006 and Dynamic Blocks...

Let's say I have a dynamic block of a receptacle. Inside the dynamic block, I have a GFI type, an above counter duplex type, a plain duplex receptacle and an Isolated Ground type.

I want to know, using Visual LISP, how I can change the variant of a dynamic block from, say Duplex to GFI.

I used Michaels really great new routine and found out that one of the methods available to me with a Dynamic Block is GetDynamicBlockProperties.

So I tried this:

Code: [Select]
(vla-GetDynamicBlockProperties  (vlax-ename->vla-object (car (entsel))))

And it returned this:

Code: [Select]
Select object: #<variant 8201 ...>

That tells me.... well, nothing that I can see...

So far, I haven't found anything that will let me change the state of a Dynamic Block. I'm hoping someone has already investigated this and has an idea...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Dynamic Blocks and Visual LISP
« Reply #1 on: May 14, 2005, 05:30:24 PM »
I dont have 2006 yet, but I had this bookmarked for futures ...
Code: [Select]
;; From: "Tony Tanzillo"
;; Newsgroups: autodesk.autocad.customization
;; Sent: Friday, May 13, 2005 6:37 AM
;; Subject: Re: DynamicBlock method

;; Get a single dynamic block property object by name

(defun GetDynBlockRefProperty (DynBlockRef Name)
   (vl-some
     '(lambda (property)
         (if (eq (vlax-get-property property 'PropertyName) Name)
            property
         )
      )
      (vlax-safearray->list
         (vlax-variant-value
            (vla-getDynamicBlockProperties DynBlockRef)
         )
      )
   )
)

;; Set the vlaue of a single dynamic block property object by name

(defun SetDynBlockRefPropertyValue (DynBlockRef Name NewValue / Property)
   (if (setq property (GetDynBlockRefProperty DynBlockref Name))
      (progn
         (vlax-put-property property 'Value NewValue)
         (vlax-release-object Property)
      )
   )
)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

nivuahc

  • Guest
Dynamic Blocks and Visual LISP
« Reply #2 on: May 14, 2005, 06:21:51 PM »
Thanks Kerry. Hopefully, one day when I grow up, some of that will make some sense to me. :P

Seriously... does Mr. Tanzillo ever comment his code? I have no idea what's goin' on there. Take the arguments DynBlockRef and Name in the first routine...

I'm guessing that DynBlockRef is looking for a vl object, which should be a dynamic block... 'course I could be wrong. And Name, I assume, is looking for the name of the Property you're looking for? Is there a list, somewhere, of available properties that aren't visible when I run

Code: [Select]
(vlax-dump-object  (vlax-ename->vla-object (car (entsel))) T)

That returns this list (I just ran it on a dynamic block I created, just like the one I Described, so I could test this out):

Code: [Select]
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00c2db8c>
;   Document (RO) = #<VLA-OBJECT IAcadDocument 0cfddd34>
;   EffectiveName (RO) = "receptacle"
;   Handle (RO) = "9B"
;   HasAttributes (RO) = 0
;   HasExtensionDictionary (RO) = -1
;   Hyperlinks (RO) = #<VLA-OBJECT IAcadHyperlinks 0d00efc4>
;   InsertionPoint = (21.9314 17.2553 0.0)
;   InsUnits (RO) = "Inches"
;   InsUnitsFactor (RO) = 1.0
;   IsDynamicBlock (RO) = -1
;   Layer = "0"
;   Linetype = "ByLayer"
;   LinetypeScale = 1.0
;   Lineweight = -1
;   Name = "*U5"
;   Normal = (0.0 0.0 1.0)
;   ObjectID (RO) = 2130161432
;   ObjectName (RO) = "AcDbBlockReference"
;   OwnerID (RO) = 2130160888
;   PlotStyleName = "ByLayer"
;   Rotation = 0.0
;   TrueColor = #<VLA-OBJECT IAcadAcCmColor 0d00fde0>
;   Visible = -1
;   XEffectiveScaleFactor = 1.0
;   XScaleFactor = 1.0
;   YEffectiveScaleFactor = 1.0
;   YScaleFactor = 1.0
;   ZEffectiveScaleFactor = 1.0
;   ZScaleFactor = 1.0
; Methods supported:
;   ArrayPolar (3)
;   ArrayRectangular (6)
;   ConvertToAnonymousBlock ()
;   ConvertToStaticBlock (1)
;   Copy ()
;   Delete ()
;   Explode ()
;   GetAttributes ()
;   GetBoundingBox (2)
;   GetConstantAttributes ()
;   GetDynamicBlockProperties ()
;   GetExtensionDictionary ()
;   GetXData (3)
;   Highlight (1)
;   IntersectWith (2)
;   Mirror (2)
;   Mirror3D (3)
;   Move (2)
;   ResetBlock ()
;   Rotate (2)
;   Rotate3D (3)
;   ScaleEntity (2)
;   SetXData (2)
;   TransformBy (1)
;   Update ()
T


So if I want to get the value of one of those properties, why wouldn't I just use vlax-get-property?

The only thing I see in the list above, that might have something to do with what I'm trying to accomplish, is the GetDynamicBlockProperties method. But, like I mentioned, when I do this:
Code: [Select]
(vla-GetDynamicBlockProperties  (vlax-ename->vla-object (car (entsel))))

I get this:

Code: [Select]
#<variant 8201 ...>

I tried changing the block from a GFI (which I had it set to when I ran the dump and vla-GetDynamicBlockProperties) to an above counter duplex and I ran them again. The results are identical.


What am I not seeing?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Dynamic Blocks and Visual LISP
« Reply #3 on: May 14, 2005, 06:29:29 PM »
I'm at a bit of a loss 'cause I dont have 2006, and not sure how the properties are put together. What's in the VBA / ActiveX help ??
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Dynamic Blocks and Visual LISP
« Reply #4 on: May 14, 2005, 06:30:33 PM »
Do you know how to evaluate the variant value ??
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

nivuahc

  • Guest
Dynamic Blocks and Visual LISP
« Reply #5 on: May 14, 2005, 06:32:33 PM »
Quote from: AutoCAD Help file

DynamicBlockReferenceProperty object

An object containing the properties of a dynamic block.

VBA class name:
 AcadDynamicBlockReferenceProperty
 
Create using:
 N/A
 
Access via:
 BlockRef.GetDynamicBlockProperties
 

You cannot create this object; BlockRef.GetDynamicBlockProperties returns a collection of DynamicBlockReferenceProperty objects if the block reference is a dynamic block containing custom properties.

Once you have obtained a dynamic block reference property object, use the following properties to query or edit its values:

Methods
None

Properties
AllowedValues
Description
PropertyName
ReadOnly
Show
UnitsType
Value

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Dynamic Blocks and Visual LISP
« Reply #6 on: May 14, 2005, 06:34:38 PM »
What does this give you ??
Code: [Select]

(setq bxxx (vla-GetDynamicBlockProperties  (vlax-ename->vla-object (car (entsel)))))

(vlax-safearray->list   (vlax-variant-value bxxx))
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

nivuahc

  • Guest
Dynamic Blocks and Visual LISP
« Reply #7 on: May 14, 2005, 06:37:01 PM »
Quote from: AutoCAD help file
Dynamic blocks enhance simple blocks by increasing their intelligence potential and adaptability. The internal geometry of a dynamic block instance can be adjusted independently of both its base definition and other instances. This flexibility is the central concept of dynamic blocks. Inserting an instance of a dynamic block into the current drawing creates a BlockReference object. From the block reference, you can get the DynamicBlockReferenceProperty object.

To identify a block's type, use the IsLayout, IsXRef, and IsDynamicBlock properties. If these properties are FALSE, then the block is a simple block. If the IsXRef property is TRUE, then the block is an external reference. If the IsLayout property is TRUE, then the block contains all the geometry associated with a layout. If the IsDynamicBlock property is TRUE, then the block is a dynamic block.

nivuahc

  • Guest
Dynamic Blocks and Visual LISP
« Reply #8 on: May 14, 2005, 06:39:15 PM »
Quote from: Kerry Brown
What does this give you ??
Code: [Select]

(setq bxxx (vla-GetDynamicBlockProperties  (vlax-ename->vla-object (car (entsel)))))

(vlax-safearray->list   (vlax-variant-value bxxx))


Code: [Select]
(#<VLA-OBJECT IAcadDynamicBlockReferenceProperty 0d025f74>)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Dynamic Blocks and Visual LISP
« Reply #9 on: May 14, 2005, 06:44:08 PM »
How about :

(setq objsadbl (vlax-safearray->list   (vlax-variant-value bxxx)))

(list-val objsadbl)

or

(list-val bxxx)


Code: [Select]

;;; lisp-value : Author : Vladimir Nesterovsky 2002
(defun lisp-value (val)
  (cond ((= (type val) 'variant) (lisp-value (variant-value val)))
        ((= (type val) 'safearray)
         (mapcar 'lisp-value (safearray-value val))
        )
        (t val)
  )
)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Dynamic Blocks and Visual LISP
« Reply #10 on: May 14, 2005, 06:45:34 PM »
I think I would need to see AC2006 and the help files to go any further with my guesses :)
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

nivuahc

  • Guest
Dynamic Blocks and Visual LISP
« Reply #11 on: May 14, 2005, 06:51:38 PM »
Quote from: Kerry Brown
How about :

(setq objsadbl (vlax-safearray->list   (vlax-variant-value bxxx)))

(list-val objsadbl)

or

(list-val bxxx)


Code: [Select]

;;; lisp-value : Author : Vladimir Nesterovsky 2002
(defun lisp-value (val)
  (cond ((= (type val) 'variant) (lisp-value (variant-value val)))
        ((= (type val) 'safearray)
         (mapcar 'lisp-value (safearray-value val))
        )
        (t val)
  )
)


When I run (list-val objsadbl) I get

Code: [Select]
; error: no function definition: LIST-VAL

When I run (lisp-value objsadbl) I get
Code: [Select]
(#<VLA-OBJECT IAcadDynamicBlockReferenceProperty 0d025f74>)

Thanks for helping me out here Kerry. This is fun.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Dynamic Blocks and Visual LISP
« Reply #12 on: May 14, 2005, 06:55:00 PM »
DUH !!! stupe typo ..
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Dynamic Blocks and Visual LISP
« Reply #13 on: May 14, 2005, 07:01:06 PM »
This is from Herman Mayfarth
Code: [Select]

(defun getdynprops (obj / v)
  (vl-remove-if 'null
    (mapcar '(lambda (x)
              (if (setq v (vlax-variant-value (vla-get-value x)))
              (cons (vla-get-propertyname x) v)))
    (vlax-safearray->list
      (vlax-variant-value
        (vla-getdynamicblockproperties obj)))))
)


What happens when you feed it with the block object .. ?
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

nivuahc

  • Guest
Dynamic Blocks and Visual LISP
« Reply #14 on: May 14, 2005, 07:28:15 PM »
Oh that's sweeeeet...

Code: [Select]
Command: (getdynprops (vlax-ename->vla-object (car (entsel))))

Select object: (("Visibility" . "Isolated Ground Duplex"))