Jump to content

Recommended Posts

Posted

Hi There,

I'm trying to make various custom tools that deal with clicking on bearings, but sometimes these text entities might be enclosed by brackets, and so I need to filter those out in a lot of my routines.

So I figured, let's make a separate routine that I can load when called instead of copy pasting this a bunch.
(My initial thought was to use on_start.lsp (acad.lsp), but I think load is the correct thing to do here?)

I guess the problem is that in some instances I'd like to set a flag if brackets were removed or not, so that I can put them back on (or not).

I'm not too sure if there is such a thing as overloading in AutoLisp, but if someone could point me to what the preferred equivalent method would be that would be appreciated.

I've vaguely read about parsing lists as args, but I thought I should ask here just to confirm before I make any fundamental mistakes.

Cheers,

Posted (edited)

 

Since autolisp overwrites with the last defun,

if there may or may not be arguments,

it is recommended to receive arguments as a list as in the answer to the link,

then check the list and process it with cond or if.

 

or

I don't know the detailed routine,

but if there are multiple argument cases, like below.

(defun c:mainroutine ( / ss ssl arg )
  (defun subroutine1 ( / )
    (princ "\n case 1 selected - 1 ea")
  )
  (defun subroutine2 ( a / )
    (princ "\n case 2 selected - ")
    (princ a)
    (princ " ea")
  )

  (if (setq ss (ssget))
    (progn
      (if (> (setq ssl (sslength ss)) 1)
        (setq arg 2)
        (setq arg 1)
      )
      (cond
        ((= arg 1)
          (subroutine1)
        )
        ((= arg 2)
          (subroutine2 ssl)
        )
      )
    )
  )
  (princ)
)

 

However, if it is simply because of the bracket,

rather than dividing defun like this,

I think it would be better to create a separate routine according to the textstring using cond. in one main routine.

Edited by exceed
  • Like 1
Posted (edited)

If you make a lisp that does what you want but want to use in various routines, you are correct you can load that separate program on demand. So looking at this if the defun AH:Butts does not exists load external lisp program. Then run that defun. 

 

(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(setq bar (list "Please choose" "6" "8" "10" "12" "14" "16" "18" "20" "22" "25" "28" "32" "36" "40"))
(setq barsz (atof (ah:butts 1 "v" bar)))

 

Note the program is saved in a support path and trusted path for ACAD.

Edited by BIGAL
  • Like 1
  • 2 weeks later...
Posted

Thank you both for the guidance, it is much appreciated :)

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