Jump to content

better way to write this?


Recommended Posts

Posted

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)
)

  • Replies 21
  • Created
  • Last Reply

Top Posters In This Topic

  • Lt Dan's legs

    9

  • Lee Mac

    7

  • alanjt

    6

Top Posters In This Topic

Posted

Step through the Dynamic block properties with foreach.

Posted (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 by Lee Mac
Posted

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?

Posted

Good point - hadn't considered that - no error, just less efficient than it could be :)

 

Updated. 8)

Posted
Good point - hadn't considered that - no error, just less efficient than it could be :)

 

Updated. 8)

Just defeated the purpose of vl-some and made it like using mapcar+lambda.

Posted
Just defeated the purpose of vl-some and made it like using mapcar+lambda.

 

Exactly - not the intention of course :)

Posted
Exactly - not the intention of course :)
I know. Just helping you optimize.
Posted

Guess it's just my computer because it seems sluggish with alan's foreach suggestion and Lee's routine.

 

Thanks guys!

Posted

between 10 and 20. Just doing this to learn more about VL.

  • 1 month later...
Posted (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 by Lt Dan's legs
Posted

(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

Posted

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.

Posted

** Error: AutoCAD.Application: Invalid input **

Posted
** Error: AutoCAD.Application: Invalid input **

 

Yeah - thought it might do that :)

Posted

Does this problem only come up when flipping dynamic objects?

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...