Copy objects using previous basepoint

Copy objects using previous basepoint

Anonymous
Not applicable
1,078 Views
5 Replies
Message 1 of 6

Copy objects using previous basepoint

Anonymous
Not applicable

Hey guys,

 

I currently have a small LISP program that i wrote that will copy an object to multiple positions and the basepoint would change according to the new position.

 

Now the problem i have with my LISP program is that when i call up the COPY command, i cannot temporarily disable my snaps after i have selected the new position. When i place an object down and want to copy the object 3000mm to the right (can be any length or direction), it will snap to any other object in the vacinity of the new position.

 

I have had a look at using the standard COPY command, the only problem with that is if i want it to update my basepoint, i have to pick a basepoint, and then shift-right-click and select "From", then select the basepoint again before i can carry on, and i will have to do this every time i use the COPY command.

 

Below is the Lisp program, if anybody could help, it would be highly appreciated.

 

(defun C:BASECOPY( / selset pt xsel)


(defun *error* (msg)
(princ "Error: ")
(princ msg)
(setvar "OSMODE" cosmode)
(command "COLOR" ccolor)
(setvar "CLAYER" curlayer)
(command "LINETYPE" cline)
(setvar "cmdecho" 1)
(princ)
)

(setq cosmode (getvar "OSMODE")
ccolor (getvar "COLOR")
curlayer (getvar "CLAYER")
cline (getvar "LINETYPE"))


(setq selset (ssget))
(setq pt (getpoint "\nSpecify Base Point:"))
(while
(setq xsel (entlast))
(command "COPY" selset "" pt Pause "'_OSMODE" 0)
(setq pt (car (cdr (grread 1 4 1 ))))
(setq pt (getvar "lastpoint"))
(setq selset (ssadd))
(while (/= xsel nil)
(if (/= xsel nil)(setq xsel (entnext xsel)))
(if (/= xsel nil)(ssadd xsel selset))
)
(setvar "OSMODE" cosmode)
)
(princ)
)

0 Likes
1,079 Views
5 Replies
Replies (5)
Message 2 of 6

rkmcswain
Mentor
Mentor
CGeylen wrote:

Now the problem i have with my LISP program is that when i call up the COPY command, i cannot temporarily disable my snaps after i have selected the new position. When i place an object down and want to copy the object 3000mm to the right (can be any length or direction), it will snap to any other object in the vacinity of the new position.

You can call the "non" object snap mode to disable object snap.

Example: (command "._arc" "_non" pt1 "_non" pt2)

R.K. McSwain     | CADpanacea | on twitter
0 Likes
Message 3 of 6

marko_ribar
Advisor
Advisor

Not sure ab OSNAPs, but few years ago I wrote something similar to your routine... You can try it, it has many options and I use it very often...

Maybe it can help you, although not sure ab snapping, but I had no such issues when inputing multiple copy actions for the same distance and same direction...

 

Routine can be found here :

https://www.theswamp.org/index.php?topic=40547.msg481693#msg481693

 

HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... a small LISP program that i wrote that will copy an object to multiple positions and the basepoint would change according to the new position.

 

.... When i place an object down and want to copy the object 3000mm to the right (can be any length or direction), it will snap to any other object in the vacinity of the new position.

....

 

(defun C:BASECOPY( / selset pt xsel)


(defun *error* (msg) ; this should be listed among localized variables to revert to AutoCAD's when done
(princ "Error: ")
(princ msg)
(setvar "OSMODE" cosmode)
(command "COLOR" ccolor) ; newer versions don't like (command) functions in *error*
(setvar "CLAYER" curlayer)
(command "LINETYPE" cline) ; newer versions don't like (command) functions in *error*
(setvar "cmdecho" 1) ; [cmdecho was never turned off]
(princ)
)

(setq cosmode (getvar "OSMODE")
ccolor (getvar "COLOR") ; incorrect System Variable name
curlayer (getvar "CLAYER")
cline (getvar "LINETYPE")) ; incorrect System Variable name


(setq selset (ssget))
(setq pt (getpoint "\nSpecify Base Point:"))
(while
(setq xsel (entlast))
(command "COPY" selset "" pt Pause "'_OSMODE" 0)
(setq pt (car (cdr (grread 1 4 1 ))))
(setq pt (getvar "lastpoint"))
(setq selset (ssadd))
(while (/= xsel nil) ; [not used in mine, but this kind of thing can be just  (while xsel

  ; since the mere existence of the variable is the same as its not being nil]
(if (/= xsel nil)(setq xsel (entnext xsel))) ; and likewise, just  (if xsel  ]
(if (/= xsel nil)(ssadd xsel selset))
)
(setvar "OSMODE" cosmode)
)
(princ) ; no point -- it never gets to this, since it has to be ended with Esc
)


I would go about this in a different way.  If you Copy things in place and then Move the copy, you can keep going along using the Previous selection repeatedly, without the need to re-construct the selection set every time.

 

[You also have some errors I commented about above.]

 

Try this, which goes about it in the Copy-in-place-then-Move way, and does not Osnap to nearby locations when given direction-and-distance input as you describe:

 

(defun C:BASECOPY(/ *error* cosmode ccolor curlayer cline n ss)

  (defun *error* (msg)
    (if (not (wcmatch msg "Function cancelled,quit / exit abort,console break"))
      (prompt (strcat "Error: " msg))
    ); if
    (setvar 'osmode cosmode)
    (setvar 'cecolor ccolor)
    (setvar 'clayer curlayer)
    (setvar 'celtype cline)
    (repeat (setq n (sslength (setq ss (ssget "_P"))))
      (entdel (ssname ss (setq n (1- n))))
; [remove latest copy that's being Moved when routine is cancelled] ); repeat (princ) ) (setq cosmode (getvar 'osmode) ccolor (getvar 'cecolor) curlayer (getvar 'clayer) cline (getvar 'celtype) ) (command "_.select" pause ; allows any amount of selection; don't need selection-set variable here "_.copy" "_previous" "" pause "_none" "@"
; copy in-place [pause gets initial base pt without need for variable] "_.move" "_previous" "" "_none" "@" pause ); command (while T ; as long as you want to keep going (command "_.copy" "_previous" "" "_none" "@" "_none" "@" ; copy in-place "_.move" "_previous" "" "_none" "@" pause ); command ); while ); defun
Kent Cooper, AIA
0 Likes
Message 5 of 6

scot-65
Advisor
Advisor
I would eliminate the pause and incorporate the second point
inside the while test.

>> (command "COPY" selset "" pt Pause "'_OSMODE" 0)

Within your while, at the end, set pt2 to pt1 and call the next pt2 in the while test:

(if (and (setq selset (ssget)) (setq pt1 (getpoint "\nFirst point: ")))
(while (setq pt2 (getpoint pt1 "Next point: "))
(setq xsel (entlast))
...
(setvar 'OSMODE (+ (getvar 'OSMODE) 16384))
(command "COPY"...
(setvar 'OSMODE (- (getvar 'OSMODE) 16384))
...
(setq pt2 pt1)
);while
(princ :\nNo object(s) selected or point specified. ")
);if

- One can error out if (ssget) has no members. You need to test
for that before proceeding to the next user input.
- Notice that there is also a test for pt1's validity before proceeding
to the while.
- Notice 16384 is added to OSMODE. This will toggle the status icon
in the status line. So if there really is an error, the user can simply turn
OSMODE back on by selecting the icon.
- And finally, [Esc] does not need to be used to terminate the while.
Just a simple right-click or [Enter] or [spacebar], like most all the
AutoCAD commands.

- ALWAYS TEST USER INPUT BEFORE PROCEEDING!
If done correctly, one does not need any *error* handling, ever.
The structure I show above does not need an error handler since
there are no variables that are set during the user input gathering
section of the code.

Color, Layer and Linetype does not need to be retained when using
the copy command.

(untested)
???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 6 of 6

Anonymous
Not applicable

Thanks guys for all the help.

I did try all the lisp programs but i think the problem rests in the copy command in Autocad itself and not within the Lisp Programming.

When i do copy an object, Autocad does not temporarily disable the snaps when you input a distance. causing it to snap to diferent objects when it lays the copy down.

 

I will continue to investigate and post if i find a solution.

 

Much appreciated.

 

0 Likes