Author Topic: Dynamic Block Angle Property  (Read 6476 times)

0 Members and 1 Guest are viewing this topic.

surveyor_randy

  • Guest
Dynamic Block Angle Property
« on: April 21, 2008, 04:12:13 PM »
Could someone tell me how I can access the Custom property "Angle" in a dynamic block.  Not the block rotation, but the angle of a rotation action.  I am trying to design some lisp that will allow my dynamic north arrow to sync with the twist angle of a selected viewport.   Any information you provide would be greatly appreciated.  Thanks!

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Dynamic Block Angle Property
« Reply #1 on: April 21, 2008, 04:29:52 PM »
You need to use the GetDynamicBlockProperties method of the DB, then cycle through the returned object(s), checking the PropertyName value,  until you get the property you want to read/set.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Dynamic Block Angle Property
« Reply #2 on: April 21, 2008, 05:28:05 PM »
Maybe some of this code can help you:

http://www.theswamp.org/index.php?topic=21164.msg256839#msg256839

Here is a routine I put together to insert north arrows at the same rotation as the twist angle of the pspace viewport.

http://www.theswamp.org/index.php?topic=19285.msg234429#msg234429

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

surveyor_randy

  • Guest
Re: Dynamic Block Angle Property
« Reply #3 on: April 21, 2008, 08:19:36 PM »
You need to use the GetDynamicBlockProperties method of the DB, then cycle through the returned object(s), checking the PropertyName value,  until you get the property you want to read/set.


Hi Jeff!

Thanks for the reply, I looked through the help file and the functions and didn't see any 'GetDynamicBlockProperties' functions.  Then I went to Autodesks website and searched and found that it is 'vla-getdynamicblockproperties' and it seems that you have to use it in combination with safearray and variant... hmmm...  strangely like VBA!  :-)

Where can I find more documentation on the 'vla' based commands, since I didn't see it in the 'V' section of the functions help file.  I really appreciate your time and input!  I am fairly strong in VBA and am picking up lisp fairly quickly thanks to everyone at The Swamp.  Thanks again everyone!

surveyor_randy

  • Guest
Re: Dynamic Block Angle Property
« Reply #4 on: April 21, 2008, 08:25:34 PM »
Maybe some of this code can help you:

http://www.theswamp.org/index.php?topic=21164.msg256839#msg256839

Here is a routine I put together to insert north arrows at the same rotation as the twist angle of the pspace viewport.

http://www.theswamp.org/index.php?topic=19285.msg234429#msg234429

Wow!  Very nice code!  I am still learning lisp and your sample code will be a great study for me!  I can't believe how powerful Lisp really is.  I've spent all this time in VB and had no idea.  Great code and thanks for sharing it with us!  :-)

PS - I hope you don't mind if I borrow this code temporarily for work!

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Dynamic Block Angle Property
« Reply #5 on: April 21, 2008, 10:27:34 PM »
Glad I could help :) Feel free to use the code as long as you wish.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Dynamic Block Angle Property
« Reply #6 on: April 21, 2008, 10:42:41 PM »
Randy,
the (vla-*) stuff is just ActiveX in lispy clothes. There is NO lisp specific help for this, you use the VBA/ActiveX developers guide and work out (either thru trial & error *ACK* or by searching and studying other's code). Since you do have a strong VBA background, it should be quite easy for you to pickup. I went from lisp to trying to use the ActiveX stuff and was really lost. I went and learned VBA and it all fell into place.

Some things for you to play with. With MANY of the methods & properties, using a different format can help reduce those safe-arrays & variants. I will almost always try to return a list or usable value first, then resort to the conversion process if it doesn't work. For example, if you use this to get the DBProperties:

(vla-getDynamicBlockProperties blk)

it returns a safearray (I think, I'm not on a pc with Autocad to verify what I'm posting....but it should be pretty close), as will this:

(vlax-invoke-method blk 'getDynamicBlockProperties)

However, this will (should that is, again I cannot test right now) return a basic list that you can loop through without any conversions:

(vlax-invoke blk 'getDynamicBlockProperties)

Just knowing that can save a lot of time in the future. The same thing applies with (vlax-get) & (vlax-put) for properties.

Make sense?

hermanm

  • Guest
Re: Dynamic Block Angle Property
« Reply #7 on: April 22, 2008, 12:17:28 AM »
Using ACAD 2006:

Command: (vlax-invoke obj  'getDynamicBlockProperties)
(#<VLA-OBJECT IAcadDynamicBlockReferenceProperty 0dae86f4> #<VLA-OBJECT
IAcadDynamicBlockReferenceProperty 0daeec44> #<VLA-OBJECT
IAcadDynamicBlockReferenceProperty 0daeb034> #<VLA-OBJECT
IAcadDynamicBlockReferenceProperty 0daeb014> #<VLA-OBJECT
IAcadDynamicBlockReferenceProperty 0daf2714> #<VLA-OBJECT
IAcadDynamicBlockReferenceProperty 0daf4974> #<VLA-OBJECT
IAcadDynamicBlockReferenceProperty 0daf25b4>)

Command: (vlax-invoke-method obj  'getDynamicBlockProperties)
#<variant 8201 ...>

Code: [Select]

(defun getdynprops (obj / v)
  (mapcar '(lambda (x)
              (if (setq v (vlax-variant-value (vla-get-value x)))
              (cons (vla-get-propertyname x) v)))
   (vlax-invoke obj 'getdynamicblockproperties))
);defun

(defun getdynpropvalue (obj name / v)
  (cdr (assoc name
      (mapcar '(lambda (x)
                (if (setq v (vlax-variant-value (vla-get-value x)))
                (cons (vla-get-propertyname x) v)))
      (vlax-invoke obj 'getdynamicblockproperties)))) 
);defun


Command: (getdynprops obj)
(("Bolt Length" . 1.25) ("Origin" . #<safearray...>) ("Grip" . 0.5) ("Origin" .
#<safearray...>) ("Nut Space" . 0.75) ("Origin" . #<safearray...>)
("Visibility" . "Side View"))

Command: (getdynpropvalue obj "Grip")
0.5

I don't know the significance of the "Origin" properties.
In one block I tested, they seemed to all be null, but that is obviously not the case here..

I haven't got the (putdynpropvalue obj <property>) function just yet, but here are the two "by index" functions:

Code: [Select]

;;function to retrieve a dynamic block property
(defun get-block-property (obj index property value / n)
  (setq n (vlax-safearray-get-element (vlax-variant-value
            (vla-getdynamicblockproperties obj)) index))
  (vlax-get-property n property value)
);get-block-property

;;function to change dynamic block property
(defun put-block-property (obj index property value / n)
  (setq n (vlax-safearray-get-element (vlax-variant-value
            (vla-getdynamicblockproperties obj)) index))
  (vlax-put-property n property value)
);put-block-property


Jeff, thanks for the tip on using (vlax-invoke)

I had naively used the "long way" i.e.,

(vlax-safearray->list
       (vlax-variant-value
        (vla-getdynamicblockproperties obj)))
















hermanm

  • Guest
Re: Dynamic Block Angle Property
« Reply #8 on: April 22, 2008, 01:20:44 AM »
Actually, these will work:

Code: [Select]

;;shorter version  - thanks to Jeff Mishler

(defun getdynprops (obj / v)
  (mapcar '(lambda (x)
            (if (setq v (vlax-get x 'Value))
            (cons (vla-get-propertyname x) v)))
   (vlax-invoke obj 'getdynamicblockproperties))
);defun


(defun getdynpropvalue (obj name / v)
  (cdr (assoc name
      (mapcar '(lambda (x)
                (if (setq v (vlax-get x 'Value))
                (cons (vla-get-propertyname x) v)))
      (vlax-invoke obj 'getdynamicblockproperties))))
);defun



hermanm

  • Guest
Re: Dynamic Block Angle Property
« Reply #9 on: April 22, 2008, 01:54:35 AM »
Q & D, no error checking:

Code: [Select]

;;put dynamic property by property name
(defun putdynpropvalue (obj name value / props names)
  (setq props (vlax-invoke obj 'getdynamicblockproperties)
        names (member name (mapcar 'vla-get-propertyname props)))
  (vlax-put (nth (- (length props)(length names)) props) 'Value value)
);defun



surveyor_randy

  • Guest
Re: Dynamic Block Angle Property
« Reply #10 on: April 22, 2008, 02:22:03 PM »
Randy,
the (vla-*) stuff is just ActiveX in lispy clothes.

Make sense?

Yes, it is beginning to!   I'm not sure that I like working with all of the parentheses and the ide leaves a lot to be desired, but I am having fun learning never the less!  Thanks for your informative post Jeff!

surveyor_randy

  • Guest
Re: Dynamic Block Angle Property
« Reply #11 on: April 22, 2008, 02:37:03 PM »
Thanks a bunch for the sample code Hermanm, it is greatly appreciated!

The code still looks a little greek to me but I am going through it line by line and trying to understand exactly what it is doing.  I can see that lisp is going to take some getting used to.
« Last Edit: April 22, 2008, 02:54:23 PM by surveyor_randy »