Jump to content

Recommended Posts

Posted

Hello...I often move objects along the axes.

The peculiarity of these movements is that they always have the same step (distance) to be repeated several times.

I was looking for a lisp that starting from selected objects and given a direction, moved the objects of one "step" (fixed distance) for each "click" in the indicated direction.

In your forum I found this discussion, but I don't know how to correct it to choose the direction and to carry out the repetition of the command.

Someone can help me?

Thank you in advance

 

Posted (edited)

Something like this?

(defun c:up50 (/ s)
  (if (setq s (ssget ":L"))
    (while (getpoint "\nPick a point to nudge: ")
      (command "_.move" s "" '(0. 0. 0.) '(0. 50. 0.))
    )
  )
  (princ)
)

 

Edited by ronjonp
Posted (edited)

Actually .. maybe this:

(defun c:foo (/ d i g s)
  ;; RJP » 2018-12-13
  (cond	((and (setq d (getdist "\nEnter nudge distance: ")) (setq s (ssget ":L")))
	 (setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))))
	 (while	(and (setq g (grread 2 1)) (not (member (cadr g) '(13 32))))
	   (princ "\r4A-LEFT 6D-RIGHT 2S-DOWN 8W-UP [ENTER/SPACEBAR to Exit]")
	   (cond ((= 2 (car g))
		  (setq g (strcase (chr (cadr g))))
		  (if (setq i (cond ((wcmatch g "2,S") (list 0. (- d) 0.))
				    ((wcmatch g "4,A") (list (- d) 0. 0.))
				    ((wcmatch g "6,D") (list d 0. 0.))
				    ((wcmatch g "8,W") (list 0. d 0.))
			      )
		      )
		    (foreach x s (vlax-invoke x 'move '(0. 0. 0.) i))
		  )
		 )
	   )
	 )
	)
  )
  (princ)
)

 

Edited by ronjonp
OCD made me remove command calls :P
Posted

oh great! Thank you very much! it is exactly what I need! I will call this command movenudge!

with the aim of being able to read the difference but also because it is a special case that I need, can you write the code without entering the push distance? it is a costant = 0.9 so in that case I would save the passage to enter the distance...so in that case I would save the passage to enter the distance

Thank you again

Posted
16 minutes ago, itacad said:

oh great! Thank you very much! it is exactly what I need! I will call this command movenudge!

with the aim of being able to read the difference but also because it is a special case that I need, can you write the code without entering the push distance? it is a costant = 0.9 so in that case I would save the passage to enter the distance...so in that case I would save the passage to enter the distance

Thank you again

To make the distance preset change this:

(setq d (getdist "\nEnter nudge distance: "))

To this:

(setq d 0.9)

 

Posted
10 minutes ago, itacad said:

ok! thank you! I learned something!

Glad to help! :)

  • 1 year later...
Posted (edited)

Thanks! This is the LISP I want to use.But after select object,  it display

;error: no function definition: nil

Why?

  

On 12/13/2018 at 10:55 PM, ronjonp said:

Actually .. maybe this:


(defun c:foo (/ d i g s)
  ;; RJP » 2018-12-13
  (cond	((and (setq d (getdist "\nEnter nudge distance: ")) (setq s (ssget ":L")))
	 (setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))))
	 (while	(and (setq g (grread 2 1)) (not (member (cadr g) '(13 32))))
	   (princ "\r4A-LEFT 6D-RIGHT 2S-DOWN 8W-UP [ENTER/SPACEBAR to Exit]")
	   (cond ((= 2 (car g))
		  (setq g (strcase (chr (cadr g))))
		  (if (setq i (cond ((wcmatch g "2,S") (list 0. (- d) 0.))
				    ((wcmatch g "4,A") (list (- d) 0. 0.))
				    ((wcmatch g "6,D") (list d 0. 0.))
				    ((wcmatch g "8,W") (list 0. d 0.))
			      )
		      )
		    (foreach x s (vlax-invoke x 'move '(0. 0. 0.) i))
		  )
		 )
	   )
	 )
	)
  )
  (princ)
)

 

 

Edited by yxl030
Posted

Try changing the start of the lisp to :

(defun c:foo (/ d i g s)
  (vl-load-com)
  ;; RJP >> 2018-12-13
  • Like 1
Posted

dlanorh, thanks! It's working.

9 minutes ago, dlanorh said:

Try changing the start of the lisp to :


(defun c:foo (/ d i g s)
  (vl-load-com)
  ;; RJP >> 2018-12-13

 

Posted
2 hours ago, yxl030 said:

dlanorh, thanks! It's working.

 

Great, Glad I could help.👍

  • Like 1
Posted

A very old like 30 years ago made some defuns CHX CHY CHZ did what they imply. Makes it easy to remember what to do.

Posted
2 hours ago, BIGAL said:

A very old like 30 years ago made some defuns CHX CHY CHZ did what they imply. Makes it easy to remember what to do.

Please provide a link to these invaluable 'defuns'. Not sure what 'Makes it easy to remember what to do' means?

I'm sorry If I'm coming off brash but this post confuses the hell out of me.  😬

  • Funny 2
Posted

Type chx as name implies "change in X direction" it would ask for a distance then pick objects, -ve is ok its old code 1990 needs to be redone made a bit smarter that is  why I did not post its loaded on startup.  It does not do multiple selections rather pick pick.

 

(defun C:CHX ( / oldsnap k x newx)
  (SETVAR "CMDECHO" 0)
  (setq oldsnap (getvar "osmode"))
  (setvar 'osmode 512)
  (princ "\nMoves  object in X direction")
  (setq x (getstring "\n What is amount of change: "))
  (setq newx (strcat x ",0"))
  (while 
    (setq newobj (entsel "\nPoint to object: Enter to exit "))
    (command "move" newobj "" "0,0" newx)
  )
  (setvar 'osmode oldsnap)
  (princ)
)

 

  • Thanks 1
Posted

The Lisp now runs like this: select --> [4A/6D/2S/8W]to move ---> [4A/6D/2S/8W]to move ---> ... ---> [ENTER/SPACEBAR to] exit.

How to change to like this : Select ---> move ---> select another ---> move another ---> ..... ---> [ENTER/SPACEBAR to]  exit.

 

On 12/13/2018 at 10:55 PM, ronjonp said:

Actually .. maybe this:


(defun c:foo (/ d i g s)
  ;; RJP » 2018-12-13
  (cond	((and (setq d (getdist "\nEnter nudge distance: ")) (setq s (ssget ":L")))
	 (setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))))
	 (while	(and (setq g (grread 2 1)) (not (member (cadr g) '(13 32))))
	   (princ "\r4A-LEFT 6D-RIGHT 2S-DOWN 8W-UP [ENTER/SPACEBAR to Exit]")
	   (cond ((= 2 (car g))
		  (setq g (strcase (chr (cadr g))))
		  (if (setq i (cond ((wcmatch g "2,S") (list 0. (- d) 0.))
				    ((wcmatch g "4,A") (list (- d) 0. 0.))
				    ((wcmatch g "6,D") (list d 0. 0.))
				    ((wcmatch g "8,W") (list 0. d 0.))
			      )
		      )
		    (foreach x s (vlax-invoke x 'move '(0. 0. 0.) i))
		  )
		 )
	   )
	 )
	)
  )
  (princ)
)

 

 

Posted

Did you look at my CHX you can have CHY CHZ also it accepts positive and -ve numbers so CHX -20 will go left 20 will go right and its pick pick method

Posted

That would require running the lisp multiple times,and entering different values。

Ronjonp‘s Lisp ,entering the same number  can move an object in four directions。More suitable for my use,But it's too difficult for me。

6 hours ago, BIGAL said:

Did you look at my CHX you can have CHY CHZ also it accepts positive and -ve numbers so CHX -20 will go left 20 will go right and its pick pick method

 

Posted

Try this:

(defun c:foo (/ d i g s)
  ;; RJP » 2020-12-01
  (if (setq d (getdist "\nEnter nudge distance: "))
    (while (setq s (ssget ":L"))
      (setq s (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))))
      (while (and (setq g (grread 2 1)) (not (member (cadr g) '(13 32))))
	(princ "\r4A-LEFT 6D-RIGHT 2S-DOWN 8W-UP [ENTER/SPACEBAR to Exit]")
	(cond ((= 2 (car g))
	       (setq g (strcase (chr (cadr g))))
	       (if (setq i (cond ((wcmatch g "2,S") (list 0. (- d) 0.))
				 ((wcmatch g "4,A") (list (- d) 0. 0.))
				 ((wcmatch g "6,D") (list d 0. 0.))
				 ((wcmatch g "8,W") (list 0. d 0.))
			   )
		   )
		 (foreach x s (vlax-invoke x 'move '(0. 0. 0.) i))
	       )
	      )
	)
      )
    )
  )
  (princ)
)

 

Posted

ronjonp,Thank you for your reply so quickly. 

That's pretty much it.

Can you make the program like this: [press the 4a/5s/6d/8w] after the object is moved, allowed to select a new object immediately ?

Now that this one   is waiting for the arrow key again, it's easy to make an error by moving the object again.

Posted

By the way, I often divide a picture drawn together into 3 or 4 pictures.

Your program is very helpful to me.

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