Lt Dan's legs Posted November 5, 2010 Posted November 5, 2010 Why does this seem a bit sluggish? (defun c:mod (/ ent id ss i) (if (setq ss (ssget '((0 . "insert")))) (repeat (setq id (sslength ss)) (if (eq (vlax-get-property (setq ent (vlax-ename->vla-object (ssname ss (setq id (1- id))))) "effectivename") "panel") (repeat (setq i (length (setq ent (vlax-invoke ent "getdynamicblockproperties")))) (if (eq (vla-get-propertyname (nth (setq i (1- i)) ent)) "Panel Length") (vla-put-value (nth i ent) "2") ) ) ) ) (prompt "No objects selected!") ) (princ) ) Quote
alanjt Posted November 5, 2010 Posted November 5, 2010 Step through the Dynamic block properties with foreach. Quote
Lee Mac Posted November 5, 2010 Posted November 5, 2010 (edited) Took it as a challenge, this is about as optimised as I could get it: (defun c:mod ( / doc ss ) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (if (ssget '((0 . "INSERT") (2 . "panel,`*U*"))) (progn (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc)) (if (eq "panel" (vla-get-EffectiveName obj)) (vl-some (function (lambda ( p ) (if (eq "Panel Length" (vla-get-PropertyName p)) (progn (vla-put-Value p "2") T) ) ) ) (vlax-invoke obj 'GetDynamicBlockProperties) ) ) ) (vla-delete ss) ) ) (princ) ) Untested of course. Edited November 5, 2010 by Lee Mac Quote
alanjt Posted November 5, 2010 Posted November 5, 2010 Does vla-put-Value return the put value or nil? Wouldn't vl-some need a non-nil value to stop iterating through the list? Quote
Lee Mac Posted November 5, 2010 Posted November 5, 2010 Good point - hadn't considered that - no error, just less efficient than it could be Updated. Quote
alanjt Posted November 5, 2010 Posted November 5, 2010 Good point - hadn't considered that - no error, just less efficient than it could be Updated. Just defeated the purpose of vl-some and made it like using mapcar+lambda. Quote
Lee Mac Posted November 5, 2010 Posted November 5, 2010 Just defeated the purpose of vl-some and made it like using mapcar+lambda. Exactly - not the intention of course Quote
alanjt Posted November 5, 2010 Posted November 5, 2010 Exactly - not the intention of course I know. Just helping you optimize. Quote
Lt Dan's legs Posted November 5, 2010 Author Posted November 5, 2010 Guess it's just my computer because it seems sluggish with alan's foreach suggestion and Lee's routine. Thanks guys! Quote
Lt Dan's legs Posted November 5, 2010 Author Posted November 5, 2010 between 10 and 20. Just doing this to learn more about VL. Quote
Lt Dan's legs Posted December 8, 2010 Author Posted December 8, 2010 (edited) I cannot figure out why this isn't working on this door (defun c:mod ( / doc ss ) ;;Lee Mac (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (if (ssget '((0 . "INSERT") (2 . "34door,`*U*"))) (progn (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc)) (if (eq "34DOOR" (vla-get-EffectiveName obj)) (vl-some (function (lambda ( p ) (if (eq "Door Hinge" (vla-get-PropertyName p)) (progn (vla-put-Value p "LEFT") T) ) ) ) (vlax-invoke obj 'GetDynamicBlockProperties) ) ) ) (vla-delete ss) ) ) (princ) ) Edited December 8, 2010 by Lt Dan's legs Quote
Lee Mac Posted December 8, 2010 Posted December 8, 2010 (defun c:mod ( / doc ss ) ;;Lee Mac (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) (if (ssget '((0 . "INSERT") (2 . "34door,`*U*"))) (progn (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc)) (if (eq "34DOOR" (strcase (vla-get-EffectiveName obj))) (LM:SetDynamicPropValue obj "Door Hinge" 0) ) ) (vla-delete ss) ) ) (princ) ) ;;------------=={ Set Dynamic Property Value }==--------------;; ;; ;; ;; Modifies the value of a Dynamic Block Property ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; block - VLA Dynamic Block Reference Object ;; ;; prop - Dynamic Block Property Name ;; ;; value - New value for Property ;; ;;------------------------------------------------------------;; ;; Returns: Value property was set to, else nil ;; ;;------------------------------------------------------------;; (defun LM:SetDynamicPropValue ( block prop value ) ;; © Lee Mac 2010 (vl-some (function (lambda ( _prop ) (if (eq prop (vla-get-propertyname _prop)) (progn (vla-put-value _prop (vlax-make-variant value (vlax-variant-type (vla-get-value _prop)) ) ) value ) ) ) ) (vlax-invoke block 'GetDynamicBlockProperties) ) ) http://lee-mac.com/dynamicblockfunctions.html Quote
alanjt Posted December 8, 2010 Posted December 8, 2010 Couldn't you just change (progn (vla-put-Value p "LEFT") T) to (progn (vla-put-Value p 0) T) ? I've been able to successfully set dynamic values like this without having to convert them to variants. Quote
Lt Dan's legs Posted December 8, 2010 Author Posted December 8, 2010 @ Alan That didn't work... Drawing1.dwg Quote
Lee Mac Posted December 8, 2010 Posted December 8, 2010 Give: (progn (vlax-put p 'Value 0) T) a try. *just curious* Quote
Lt Dan's legs Posted December 8, 2010 Author Posted December 8, 2010 ** Error: AutoCAD.Application: Invalid input ** Quote
Lee Mac Posted December 8, 2010 Posted December 8, 2010 ** Error: AutoCAD.Application: Invalid input ** Yeah - thought it might do that Quote
Lt Dan's legs Posted December 8, 2010 Author Posted December 8, 2010 Does this problem only come up when flipping dynamic objects? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.