Author Topic: Need help to write menu driven lisp program for point selection  (Read 984 times)

0 Members and 1 Guest are viewing this topic.

Vikram

  • Newt
  • Posts: 50
Need help to write menu driven lisp program for point selection
« on: January 26, 2021, 03:07:14 AM »
I want to write a lisp which will act like a menu for selection of the circles on different profiles.(jobs) In attached program you will see 3 jobs with 3 circles on each job.
So the menu should be something like

"Enter points for JOB no 1"
User will select multiple points and press Enter.
"Is their anymore profiles?" <Y/N> (User will enter Y or N)
if press Y -> "Enter points for JOB no 2"
User will select multiple points and press Enter.
"Is their anymore profiles?" <Y/N> (User will enter Y or N)
if User presses N (Menu will end)

and all these points will be written in a file something like this:
Job no 1
Stopper 1 X85.548 Y96.23
Stopper 2 X75.56 Y248.36
Stopper 3 X789.56 Y45.12

Job no 3
Stopper 1 X635.748 Y106.26
Stopper 2 X12.56 Y98.36

I have written a piece of code for point selection but don't know how to do it menu driven.

Code: [Select]
(defun c:XY (/ fp p)
  (setq fp (open (strcat (getvar "dwgprefix")(vl-filename-base (getvar "dwgname")) ".pnt") "w"))
  (setq nbs 0)
  (while (setq p (getpoint(strcat "\nPick Stopper " (itoa (setq nbs (+ 1 nbs))) " position: ")))
    (write-line (strcat "Stopper " (itoa (setq nbs (+ 0 nbs))) "  X "(rtos (car p) 2) "\t" "Y "(rtos (cadr p) 2) "\t") fp)
  )
  (close fp)
  (princ)
)

DEVITG

  • Bull Frog
  • Posts: 479
Re: Need help to write menu driven lisp program for point selection
« Reply #1 on: January 26, 2021, 06:56:39 AM »
Hi Vikram, what do you mean by "MENU DRIVEN".?

As I guess you need to get the circles centers.

Please upload the same dwg where the image was taken.
 
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Vikram

  • Newt
  • Posts: 50
Re: Need help to write menu driven lisp program for point selection
« Reply #2 on: January 26, 2021, 11:57:52 AM »
By menu I mean ,when I use this lisp this steps should happen
1> It should ask please select the points for JOB 1
>User will select the different multiple points (which are actually center of circles) after selection he will press Enter.
2>Then it will ask "Are their any more Jobs?" with option <Y/N> if user presses Y i.e yes it will ask for JOB2 selection in such wau JOB3,JOB4 etc. until he presses N i.e No.

This selection for different jobs and asking yes no is what I meant like menu driven (Something like menu type)

Yes I want center of the circles. I also have different lisp program to get center coordinates and radius by selecting circles. It will be also fine if we add that menu in it.
This is the code.

Code: [Select]
(defun c:centest (/ txt opn int sel ent get)
  (and
    (setq opn (open (strcat (getvar "dwgprefix")(vl-filename-base (getvar "dwgname")) ".pnt") "w"))
    (princ
      "\nSelect circles to expor Radius & Center values to txt file : "
    )
    (setq int -1
          sel (ssget '((0 . "CIRCLE")))
    )
    (while (setq int (1+ int)
                 ent (ssname sel int)
           )
      (setq get (entget ent))
      (write-line
        (strcat "R"(rtos (cdr (assoc 40 get)) 2 2)
                "\t"
                (apply 'strcat
                       (mapcar '(lambda (q) (strcat (rtos q 2 4) " "))
                               (cdr (assoc 10 get))
                       )
                )
        )
        opn
      )
    )
    (close opn)
  )
  (princ)
)

I will attach the drawing. The small circles are actually the stoppers at the each job profile and I want to extract the center coordinates of all of them differentiated by the Job number.(The format which I showed in main question)