Jump to content

Recommended Posts

Posted (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 by SLW210
Added Code Tags!!
Posted

Please use Code Tags (not Quote Tags) for your code. (<> in the editor toolbar)

Posted

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

 

  • Like 1
Posted (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 by mhupp
Posted

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.

Posted

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.

image.png.ce724279a255daa178b62a7c47eb782b.png

Posted

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?

  • Like 1
  • Agree 1

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