MastroLube Posted September 17, 2019 Posted September 17, 2019 Hi there! I've a problem managing custom keys. I'm not able to check if they exist. If I query a custom key that doens't exist i got an error and it exit the lisp. What's the right command to accomplish that? (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) summaryInfo (vla-Get-SummaryInfo Doc) (IF (/ nil (vla-GetCustomByKey summaryInfo "n_project" 'Value)) ... ... ) Currently I'm just looking for the number of elements and if they are less then 3 i create them all.. It's time to fix that (IF (< (vla-NumCustomInfo summaryInfo) 3) (crea_customkeys summaryInfo) ) Thanks for the help! Dennis Quote
Tharwat Posted September 17, 2019 Posted September 17, 2019 Hi, The forward slash ( / ) is a dividing symbol and despite of that, you don't need to check if a variable is not equal to nil to know that it has a value so just remove the (/= .... nil) Quote
MastroLube Posted September 17, 2019 Author Posted September 17, 2019 (edited) Thanks for the advice! It was a misspelling of "/=" anyway i get NIL and not his value Command: (vla-GetCustomByKey summaryInfo "n_project" 'Value) nil It should return "IT.19.9655". Am I missing something? Thanks! Edited September 17, 2019 by MastroLube Quote
Tharwat Posted September 17, 2019 Posted September 17, 2019 Yeah me also get nil value although that it has a value as per your posted example. ! That's really odd. Quote
tombu Posted September 17, 2019 Posted September 17, 2019 1 hour ago, MastroLube said: Hi there! I've a problem managing custom keys. I'm not able to check if they exist. If I query a custom key that doens't exist i got an error and it exit the lisp. What's the right command to accomplish that? Thanks for the help! Dennis (SetCustomDwgProp "Pages" "1") Will add only if necessary then set the Custom Property "n_project" to "IT.19.9655" using the following code. (defun getCustomDwgProp (key / app doc dwgprops try val) (vl-load-com) (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc) ) (cond ((vl-catch-all-error-p (setq try (vl-catch-all-apply 'vla-GetCustomByKey (list DwgProps key 'val) ) ) ) (setq val nil) ) ) val ) (defun SetCustomDwgProp (key value / App Doc DwgProps) (vl-load-com) (setq App (vlax-Get-Acad-Object) Doc (vla-Get-ActiveDocument App) DwgProps (vla-Get-SummaryInfo Doc) ) (if (getCustomDwgProp key) (vla-SetCustomByKey DwgProps key value) (vla-AddCustomInfo DwgProps key value) ) ) 3 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.