Jump to content
JoeyG_77

If Then Statement ... ?

Recommended Posts

JoeyG_77

I have a block that is used multiple times in a dwg & it needs to show text w/ an "HD" when another certain attribute is larger than 9, but not show when its less than 9.  I've looked at diesel & a field but reading up they seem not to work well together.  All help would be much appreciated.

 

Thanks 

Joey G  

Share this post


Link to post
Share on other sites
Lee Mac
Posted (edited)

The difficulty is that Formula Field expressions can reference nested Object Property Fields (such as Attribute Values), but do not support conditional statements, and DIESEL Field expressions support conditional statements but cannot reference nested Object Property Fields... Whilst it is certainly possible (and relatively easy) to populate the attribute values using a program, I don't think this is possible to achieve using out-of-the-box functionality.

Edited by Lee Mac

Share this post


Link to post
Share on other sites
JoeyG_77

Lee ,

Thanks for the response !  What would you do in this situation ? Would it be more of a lisp that would have to be run after all the blocks are in place and then run and it would analyze all the blocks and add what was needed or not.

 

Thanks

Joey G

Share this post


Link to post
Share on other sites
Lee Mac
Posted (edited)

Personally, I would develop a program to operate on all such blocks in your drawing automatically (without any user input), and then configure the program to run either on drawing startup, or before the SAVE/PLOT commands using a basic VL Reactor.

 

Such a program might look like this:

(defun c:updateblocks ( / at1 at2 blk dst idx lst num sel src vl1 vl2 )
    (setq
        blk "myblock" ;; Block Name
        src "tag1"    ;; Source Attribute Tag
        dst "tag2"    ;; Destination Attribute Tag
        vl1 "HD"      ;; Value 1
        vl2 ""        ;; Value 2
    )
    (if (setq sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 blk))))
        (repeat (setq idx (sslength sel))
            (setq lst
                (mapcar '(lambda ( a ) (cons (strcase (vla-get-tagstring a)) a))
                    (vlax-invoke
                        (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))
                        'getattributes
                    )
                )
            )
            (if (and (setq at1 (cdr (assoc (strcase src) lst)))
                     (setq at2 (cdr (assoc (strcase dst) lst)))
                     (setq num (distof (vla-get-textstring at1) 2))
                     (vlax-write-enabled-p at2)
                )
                (vla-put-textstring at2 (if (< 9 num) vl1 vl2))
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

The above is designed for standard (i.e. non-dynamic) blocks only.

Edited by Lee Mac

Share this post


Link to post
Share on other sites
JoeyG_77

Lee thanks for always helping out.  Im having some issue with the lisp . Im attaching the lisp filled out and the block itself to see.

(defun c:updateblocks ( / at1 at2 blk dst idx lst num sel src vl1 vl2 )
    (setq
        blk "Blum Motion" 	;; Block Name
        src "Drawer_Depth_HD"   ;; Source Attribute Tag
        dst "HD1"    		;; Destination Attribute Tag
        vl1 "Heavy"    		;; Value 1
        vl2 ""     		;; Value 2
    )
    (if (setq sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 blk))))
        (repeat (setq idx (sslength sel))
            (setq lst
                (mapcar '(lambda ( a ) (cons (strcase (vla-get-tagstring a)) a))
                    (vlax-invoke
                        (vlax-ename->vla-object (ssname sel (setq idx (1- idx))))
                        'getattributes
                    )
                )
            )
            (if (and (setq at1 (cdr (assoc (strcase src) lst)))
                     (setq at2 (cdr (assoc (strcase dst) lst)))
                     (setq num (distof (vla-get-textstring at1) 2))
                     (vlax-write-enabled-p at2)
                )
                (vla-put-textstring at2 (if (> 17 num) vl1 vl2))
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

DRW.dwg

Share this post


Link to post
Share on other sites
Lee Mac

The issues are twofold:

  • As stated, the program I posted was only compatible with standard (non-dynamic) blocks.
  • "Drawer_Depth_HD" is a dynamic block parameter, not an attribute - perhaps you meant to reference the attribute "D"?

I'll see if I can find some time to update the program for dynamic blocks.

Share this post


Link to post
Share on other sites
Lee Mac

Try the following:

(defun c:updateblocks ( / at1 at2 blk dst idx lst num sel src vl1 vl2 )
    (setq
        blk "BLUM MOTION" ;; Block Name
        src "D"           ;; Source Attribute Tag
        dst "HD1"         ;; Destination Attribute Tag
        vl1 "HD"          ;; Value 1
        vl2 ""            ;; Value 2
    )
    (if (setq sel (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (strcat "`*U*," blk)))))
        (repeat (setq idx (sslength sel))
            (setq idx (1- idx)
                  obj (vlax-ename->vla-object (ssname sel idx))
            )
            (if (or (and (vlax-property-available-p obj 'effectivename)
                         (wcmatch (strcase (vla-get-effectivename obj)) blk)
                    )
                    (wcmatch (strcase (vla-get-name obj)) blk)
                )
                (progn
                    (setq lst
                        (mapcar '(lambda ( a ) (cons (strcase (vla-get-tagstring a)) a))
                            (vlax-invoke obj 'getattributes)
                        )
                    )
                    (if (and (setq at1 (cdr (assoc (strcase src) lst)))
                             (setq at2 (cdr (assoc (strcase dst) lst)))
                             (setq num (distof (vla-get-textstring at1) 2))
                             (vlax-write-enabled-p at2)
                        )
                        (vla-put-textstring at2 (if (< 9 num) vl1 vl2))
                    )
                )
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Share this post


Link to post
Share on other sites
JoeyG_77

Lee, I cant thank you enough man! Im sorry btw you did say that the first one you wrote was for non dynamic. I didnt see it until this morning =/ . The only thing is that I do need it to read the D1 & the issue is that it cant read the HD suffix that is attached to the number.  I tested it and if I remove the HD suffix the lisp runs perfect, but the HD needs to stay.  Thanks for all your help 

Joe

Share this post


Link to post
Share on other sites
Lee Mac

You're welcome Joey - rather than going backwards & forwards on the forum, I'll continue to refine this with you offline.

  • Like 1

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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