Jump to content

Editing LISP to accept an argument


broncos15

Recommended Posts

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: "))

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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
       )
     )
   )
 )

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...