- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm learning Visual Lisp trying to create lines using vlax-curve-getclosestpointto,
complete code:
(defun j_iferror (x y / j_caa j_cae_p)
(setq j_caa (vl-catch-all-apply
(list x)
)
j_cae_p (cond
((vl-catch-all-error-p j_caa)
y
)
((not (vl-catch-all-error-p j_caa))
x
)
(T
(vl-exit-with-error
(strcat "\nError: " (vl-catch-all-error-message j_caa))
)
)
)
)
)
(defun c:JTMgetclosestpointto2 (/ j_acadobj j_actdoc j_ssget j_ssadd j_ctrl item
item_dump j_delete pt1 3dpt1
)
(vl-load-com)
(setq j_acadobj (vlax-get-acad-object)
j_actdoc (vla-get-activedocument j_acadobj)
j_ssget (vla-get-selectionsets j_actdoc)
j_delete_p (JTMextract-j-delete-p j_ssget)
j_ctrl 0
)
(eval (j_iferror '(vla-add j_ssget "j_ss02") '(vla-delete (vla-item j_ssget "j_ss02"))))
(setq j_ssadd (vla-add j_ssget "j_ss02"))
(vla-selectonscreen j_ssadd)
(while (setq pt1 (getpoint "\n pick point:"))
(setq item (vla-item j_ssadd j_ctrl)
3dpt1 (vlax-3d-point pt1)
item_dump (vlax-curve-getclosestpointto item pt1)
j_addline (vla-addline j_mspace
(vlax-3d-point item_dump)
(vlax-3d-point pt1)
) ;j_ctrl (1+ j_ctrl)
)
)
(setq j_delete (vl-catch-all-apply '(vla-delete (vla-item j_ssget "j_ss02"))))
)
... but when I try manage the error with an external defun is impossible, the problem is in:
(eval (j_iferror '(vla-add j_ssget "j_ss02") '(vla-delete (vla-item j_ssget "j_ss02"))))
... this should work like excel iferror function, I mean, if the first expression fails, should return the 2nd expression being evaluated, if there are no errors, the 1st expression should be evaluated.
... until I understand, the problem is the variable's scope.
Then, how to solve? (or how to create an excel iferror equivalent in visual lisp?)
Solved! Go to Solution.