Jump to content

If Then Statement ... ?


JoeyG_77

Recommended Posts

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  

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 year later...
On 09/01/2020 at 06:36, Lee Mac said:

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)

 

This is great..! I had a similar requirement, in which I need to add a suffix in the source attribute, with this I added an additional attribute nearby, and made it as the destination. I had to modify the block, but it does the job..! But it would be much easier if the values get filled as suffix in the source attribute(have no idea how to).  :) Thanks..!

Link to comment
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
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...