My Photo

May 2009

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

BLOGMap


« Skype- Voice-over-IP- 129,329,764 FREE Downloads | Main | Tech Call -PDF vs DWF »

July 25, 2005

Dynamic Lisp Code

After about a couple months of messing with Lisp codes that users have been sending me. I'm pretty happy with this one. Taking this code, and placing it in my Lisp toolbox allows me to call it from many other Lisp codes. Tremendously opening the door to more uses of Dynamic Blocks. Before we would use a lot of (ENTMAKE's to create custom blocks. The code is relatively simply to manipulate Dynamic blocks by simply getting a selection set. Then modifying the bottom portion of the Dynamic block code for the parameter and what you want it to be set to.

Here is the code. Don't get scared if you're new to LISP because only the bottom line is what needs to be modified.
(defun myModifyBk ( lstProp / ss index cnt oBkRef oProps i j oSBReferenceProperty)
(vl-load-com)
(SETQ ss (SSGET "L"))
(setq index 0
       cnt (sslength ss)
)

(while (< index cnt)
  (setq e (ssname ss index))
  (setq oBkRef (vlax-ename->vla-object e))
   
  (setq oProps (vlax-variant-value (vla-GetDynamicBlockProperties oBkRef)))

  (setq i (vlax-safearray-get-l-bound oProps 1))
  (while (<= i (vlax-safearray-get-u-bound oProps 1))
   (setq oSBReferenceProperty (vlax-safearray-get-element oProps i))
   (print (strcat (vla-get-PropertyName oSBReferenceProperty) "="))
   (princ (vlax-variant-value (vla-get-value oSBReferenceProperty)))
   (setq i (1+ i))
  )

  (setq j 0)
  (while (< j (length lstProp))
   (setq sProp (strcase (nth j lstProp)))
   (setPropValue oProps sProp (nth (+ 1 j) lstProp))
   (setq j (+ 2 j))
  ) ;while < j (length lstProp)
 
  (setq index (1+ index))
) ;while < index cnt

(princ)
)

(defun setPropValue (oProps sProp Val / i oSBReferenceProperty sPName iFound)
(setq i (vlax-safearray-get-l-bound oProps 1))
(setq iFound 0)
(while (and (<= i (vlax-safearray-get-u-bound oProps 1)) (= iFound 0))
  (setq oSBReferenceProperty (vlax-safearray-get-element oProps i))
  (setq sPName (vla-get-PropertyName oSBReferenceProperty))
  (if (= (strcase sPName) sProp)
   (progn
    (print (strcat "Old value of " sPName "="))
    (princ (vlax-variant-value (vla-get-value oSBReferenceProperty)))
    (vla-put-value oSBReferenceProperty
     (vlax-make-variant Val
      (vlax-variant-type (vla-get-value oSBReferenceProperty))
     )
    )
    (print "New value=")
    (princ (vlax-variant-value (vla-get-value oSBReferenceProperty)))
    (setq iFound 1)
   )
  )

  (setq i (1+ i))
)
(princ)
)

;;;;DTR converts degrees to radians.
(defun dtr (a)
(* pi (/ a 180.0))
)

;;RTD converts radians to degrees.
(defun rtd (a)
(/ (* a 180.0) pi)
)
;;The section below is the portion to modify to manipulate your dynamic block afte ryou establish a selection set.
(myModifyBk (list "DynamicBlockParmatername" DynamicBlockValue))

Hope this helps everyone with getting their Dynamic blocks into some custom LISP codes.
Click here to download the LISP file:Download Dblockcode.lsp

Comments

I would like to thank very much for the lisp "Dblockcode.lsp". Really, I have been looking for codes to work with dynamic blocks. At last, thanks for you, because you have given me what I was in need. I work in a large company in the Middle East known as Dar Al-Handasah and I have been working as a Lisp programmer since AutoCAD release five. Thanks again and keep on!
Victor Jammal

Glad to help!! This also has really helped the office I work at transition to 2006 and Dynamic blocks. There still needs some work, but im sure a lot of the minor problems will be fixed in a future release.

Thanks for the comments...

Mark

Holy Cow man, this is exactly the type of thing I've been looking for since we switched to 2006.

Thanks,
Lance

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.