Shukoor Posted April 13 Posted April 13 (edited) I want to create an AutoLISP file that can paste objects to multiple reference points within a CAD file. I have a sample generated by GPT that works, but the problem is that I have to hardcode the reference point inside the LISP code every time. I need to modify it so that I can define the base point manually within CAD instead. See the reference and suggest the solution (defun c:PASTEPOINT ( / choice basept) ;; Define your reference points for each floor ;; Replace the coordinates with your actual base points (setq basement '(0 0 0)) (setq ground '(1000 0 0)) (setq first '(2000 0 0)) ;; Ask user which floor to paste into (setq choice (strcase (getstring "\nPaste to which floor? [Basement/Ground/First]: ") ) ) ;; Select base point based on user choice (cond ((= choice "BASEMENT") (setq basept basement)) ((= choice "GROUND") (setq basept ground)) ((= choice "FIRST") (setq basept first)) (T (progn (prompt "\nInvalid option. Use Basement, Ground, or First.") (exit) ) ) ) ;; Execute paste command at selected base point (command "_.PASTECLIP" basept) (princ) ) Edited April 13 by SLW210 Added Code Tags!! Quote
SLW210 Posted April 13 Posted April 13 Please use Code Tags (not Quote Tags) for your code. (<> in the editor toolbar) Quote
Tsuky Posted April 13 Posted April 13 And simply with this, can be done? (defun c:PASTEPOINT ( / basept) ;; Define your reference points for each floor ;; Replace the coordinates with your actual base points (setq basept "Basement") (initget 9 "Basement Ground First") (while (not (listp basept)) (setq basept (getpoint (strcat "\nPaste to which floor? [Basement/Ground/First]<" basept ">: "))) (initget 9 "Basement Ground First") ) ;; Execute paste command at selected base point (command "_.PASTECLIP" "_none" basept) (prin1) ) 1 Quote
mhupp Posted April 13 Posted April 13 (edited) I'd be interested in what you prompted to get that code. GPT score 5/10 - missed localized variables - hard code points instead of getpoint - choice doesn't use getkword or use ucase (will only accept all caps input?) Edited April 13 by mhupp Quote
Steven P Posted April 13 Posted April 13 Look at using (getpoint), its uses is well documented if you search for it, and while you are looking try to add in mhupps suggestions too - great way to learn is to try - and if you cannot get it to work post what you have tried, it is usual to be very close needing a small change to make it all work. Localise the variables if you want to define the points each time the LISP runs otherwise, define them once the first time you use the LISP in each session. Quote
BIGAL Posted April 13 Posted April 13 The points can be in a text file, a CSV file or an Excel file, all of which can be read via lisp. A DCL can be used to input XYZ so you can see what your inputting and avoid incorrect values. Something like this but done horizontal. Quote
SLW210 Posted April 14 Posted April 14 What are the "objects" you are pasting? What are the reference "points", are they actual points in the drawing or just coordinates to be entered manually? Do you have an example drawing? 1 1 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.