broncos15 Posted January 12, 2016 Posted January 12, 2016 I had a quick question on editing a LISP routine to allow an argument. As it is currently written, it allows the user to select an xref, and then it opens it as read only. I want to rewrite it so that I can add it to my CUI so when an xref is selected and then I right click I can choose to open it as read only. What function should I use instead of entsel so that the argument accepts the currently selected xref? I have it currently as: (setq sel (entsel "\nSelect an Xref: ")) Quote
broncos15 Posted January 12, 2016 Author Posted January 12, 2016 Have a read of THIS Thanks Tharwat! If I understand correctly, I need to add the argument in like this... (defun c:xopenreadonly (x / other variables) ...rest of code ) . How do I make it so that entsel accepts the argument? Quote
Tharwat Posted January 12, 2016 Posted January 12, 2016 Remove the prefix c: then call it like this: (if (setq sel (entsel "\nSelect an Xref: ")) (xopenreadonly sel) ) The c: stands for command and the chars that come after the colon would represent the command name so in your case you need a sub-function and not stand-alone program. Quote
broncos15 Posted January 12, 2016 Author Posted January 12, 2016 Remove the prefix c: then call it like this: (if (setq sel (entsel "\nSelect an Xref: ")) (xopenreadonly sel) ) [code] The c: stands for command and the chars that come after the colon would represent the command name so in your case you need a sub-function and not stand-alone program.[/quote] So I have tried what you were saying, but I am still having to select an xref. My code is as follows: (defun c:xopenreadonly2 (/ blk path) (if (setq sel (entsel "\nSelect an Xref: ")) (xopen sel) ) ) (defun xopen (sel / blk path) (setq blk (vlax-ename->vla-object (car sel))) (vlax-property-available-p blk 'Path) (setq path (vla-get-path blk)) (setq path (findfile path)) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) (strcat "\"" path "\"") :vlax-true ) ) (princ) ) Quote
Tharwat Posted January 12, 2016 Posted January 12, 2016 I guess you need something like this: Try this [uNTESTED] and let me know. (defun c:xopenreadonly2 (/ sel) (if (setq sel (ssget "_I" '((0 . "INSERT")))) (xopen (ssname sel 0)) (if (and (setq sel (car (entsel "\nSelect an Xref: "))) (eq (cdr (assoc 0 (entget sel))) "INSERT") ) (xopen sel) ) ) (defun xopen (sel / blk path) (if (and (setq blk (vlax-ename->vla-object sel)) (vlax-property-available-p blk 'Path) (setq path (vla-get-path blk)) (setq path (findfile path)) ) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) (strcat "\"" path "\"") :vlax-true ) ) ) ) (princ) ) Quote
broncos15 Posted January 12, 2016 Author Posted January 12, 2016 That worked perfectly, I just had to make a small tweak. Thank you so much for the help! (defun c:xopenreadonly2 (/ sel) (if (setq sel (ssget "_I" '((0 . "INSERT")))) (xopen (ssname sel 0)) (if (and (setq sel (car (entsel "\nSelect an Xref: "))) (eq (cdr (assoc 0 (entget sel))) "INSERT") ) (xopen sel) ) ) (princ) ) (defun xopen (sel / blk path) (if (and (setq blk (vlax-ename->vla-object sel)) (vlax-property-available-p blk 'Path) (setq path (vla-get-path blk)) (setq path (findfile path)) ) (vla-activate (vla-open (vla-get-documents (vlax-get-acad-object)) (strcat "\"" path "\"") :vlax-true ) ) ) ) Quote
Tharwat Posted January 12, 2016 Posted January 12, 2016 That worked perfectly, I just had to make a small tweak. Thank you so much for the help! Excellent. You're welcome. 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.