check if parameter exist - if not move on (ispropertyvalid)

aridzv
edited August 2023 in LISP Codes
Hi.
I need to check if a parameter exist in a block.
I use this code:
(if (setq x (getpropertyvalue ent "d1")))

if the parameter exist all is well and the lisp works,
But if it doesn't exist, the lisp throws an error instead of taking the "IF" result as false and moving on.
I have done countless searches on the issue and have not found a solution.
I rely don't know how to solve this issue and I'll be glad for any help.
thanks,
aridzv.

Comments

  • Hi,
    I got this from an old script (get the whole list of parameters and check) :

    (setq instHandle (BmLispGet "Instance" ent))
    (setq instName (BmLispGet "InstanceName" instHandle))
    (setq compHandle (BmLispGet "Component" instHandle))
    (setq paramList (BmLispGet "Parameters" compHandle))
    (foreach p paramList
    (setq parexp (BmLispGet "ParameterExpression" compHandle p))
    (setq val (BmLispGet "ParameterValue" compHandle p))
    (if (= p "Width") (setq WxH (rtos val)))
    (if (= p "Height") (setq WxH (strcat WxH "x" (rtos val))))
    (if (= p "W") (setq WxH (rtos val)))
    (if (= p "H") (setq WxH (strcat WxH "x" (rtos val))))
    (if (= p "D") (setq WxH (strcat "Ø" (rtos val))))
    )
  • Hi @Piet .
    I tried it but it didn't get the property...
    thaks,
    aridzv.
  • Lee Mac solved it:
    (defun c:test ( / ent )
        (if (setq ent (car (entsel)))
            (if (ispropertyvalid ent "d1~MCAD")
                (print (getpropertyvalue ent "d1~MCAD"))
                (princ "\nProperty not valid.")
            )
        )
        (princ)
    )