TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: surveyor_randy 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!
-
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.
-
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
-
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!
-
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!
-
Glad I could help :) Feel free to use the code as long as you wish.
-
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?
-
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 ...>
(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:
;;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)))
-
Actually, these will work:
;;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
-
Q & D, no error checking:
;;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
-
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!
-
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.