Author Topic: Copy with initget  (Read 1940 times)

0 Members and 1 Guest are viewing this topic.

mohan

  • Newt
  • Posts: 98
Copy with initget
« on: October 11, 2023, 05:12:31 AM »
Dear Colleagues;

Please help to fix the route
Code - Auto/Visual Lisp: [Select]
  1. (defun c:471st ( / ans cpy cpy1)
  2. (princ "\nInitializing...")
  3.    (initget 1 "Select Select-All")
  4.    (setq ans (getkword "\nChoose your option as [Select/Select-All]: "))
  5. (cond ((= ans "Select-all") (setq cpy (ssget "_x" '((410 . "Model"))))
  6.                                (command "_.copybase" "_non" '(0 0) cpy "")
  7.        )
  8.      
  9.       ((= ans "Select") (setq cpy1 (ssget))
  10.                                    (command "_.copybase" "_non" '(0 0) cpy1 "")
  11.        
  12.        ))
  13. (princ (strcat "\nmohan total of " (itoa (sslength cpy)) " Object(s) were copied with 0,0 base ... " )) (princ))
« Last Edit: October 11, 2023, 05:16:22 AM by mohan »
"Save Energy"

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: Copy with initget
« Reply #1 on: October 11, 2023, 05:39:54 AM »
"Select-all" should be "Select-All" for a start.

mhupp

  • Bull Frog
  • Posts: 250
Re: Copy with initget
« Reply #2 on: October 11, 2023, 10:19:25 AM »
I would just remove the initget entirely. So it ask for a selection and makes a copy. If nothing is selected it will then use the select all option on the current tab. could use some error handling if nothing is selected from the select all option.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:471st (/ cpy)
  2.   (prompt "\nMake your Selection: ")
  3.   (if (setq cpy (ssget))
  4.     (command "_.copybase" "_non" '(0 0) cpy "")
  5.     (progn
  6.       (if (setq cpy (ssget "_X" (list (cons 410 (getvar 'CTAB))))) ;works on current tab instead of just model.
  7.         (command "_.copybase" "_non" '(0 0) cpy "")
  8.         (prompt "\nNothing Found")
  9.       )
  10.     )
  11.   )
  12.   (if cpy
  13.     (prompt (strcat "\n" (itoa (sslength cpy)) " Object(s) were copied with 0,0 base ... " ))
  14.   )
  15.   (princ)
  16. )


EDIT (Jon): Fixed Code tags.
« Last Edit: October 12, 2023, 08:48:16 AM by JohnK »

JohnK

  • Administrator
  • Seagull
  • Posts: 10663
Re: Copy with initget
« Reply #3 on: October 11, 2023, 11:11:10 AM »
I would approach the task more like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:471st ( / ss)
  2.   (princ "\nInitializing...")
  3.   (initget 0 "Select Select-All")
  4.   (setq ss
  5.         (cond
  6.           ((getkword "\nOption: [Select/Select-All] <Select-All>: ")
  7.            (ssget))
  8.           ((ssget "_x" '((410 . "Model"))))
  9.           )
  10.         )
  11.   (command "_.copybase" "_non" '(0 0) ss "")
  12.   (princ (strcat "\nmohan total of " (itoa (sslength ss)) " Object(s) were copied with 0,0 base ... " ))
  13.   (princ)
  14.   )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

mohan

  • Newt
  • Posts: 98
Re: Copy with initget
« Reply #4 on: October 11, 2023, 11:24:01 AM »
I would approach the task more like this:
Wonderful -  :smitten:
"Save Energy"

mohan

  • Newt
  • Posts: 98
Re: Copy with initget
« Reply #5 on: October 11, 2023, 11:28:54 AM »
I would just remove the initget entirely. So it ask for a selection and makes a copy. If nothing is selected it will then use the select all option on the current tab. could use some error handling if nothing is selected from the select all option.

It works for selecting object, but gives error for without selecting anything & press enter
"Save Energy"

mhupp

  • Bull Frog
  • Posts: 250
Re: Copy with initget
« Reply #6 on: October 12, 2023, 12:02:09 AM »
Tested the code inside BricsCAD Should work now.

mohan

  • Newt
  • Posts: 98
Re: Copy with initget
« Reply #7 on: October 12, 2023, 08:53:13 AM »
Tested the code inside BricsCAD Should work now.
Now it works fine.   :smitten:
"Save Energy"