Jump to content

Change elevation of object based on another


Recommended Posts

Posted

Hi,

is there a lisp that I can use to change the elevation of an object based on the selection of another object?
For example, object 1 has an elevation of 0, and object 2 has an elevation of 155, I want object 1 to change elevation based on the selection of object 2.
Of course, the X and Y coordinates of object 1 must not change.

Best regards,

Mladen Lj.

Change elevation of object based on another.dwg

Posted
(defun c:MoveZ( / ss target z i en el a10)
  (princ "Select objects to be moved...")
  (setq ss (ssget))
  (setq target (entsel "select target "))
  (setq z (last (assoc 10 (entget (car target)))))
  (repeat (setq i (sslength ss))
    (setq en (ssname ss (setq i (1- i)))
	  el (entget en)
	  a10 (reverse(cons z (cdr(reverse(assoc 10 el)))))
	  el (subst a10 (assoc 10 el) el))
    (entmod el)
    )
  (setq ss nil)
  (princ)
  )

Here a quick one - I have just minutes until I go home. Does it help?

  • Like 1
Posted

Thx for help. It's work.

 

In the meantime i got this one (also work):

 

(defun c:Zmatch ( / s d)
  
  (and (setq s (car (entsel "\nSource: ")))
       (setq s (last (assoc 10 (entget s))))
       (setq d (car (entsel (strcat "\nObject to apply z=" (rtos s) " to: "))))
       (setq d (entget d))
       (entmod (subst (reverse (cons s (cdr (reverse (assoc 10 d))))) (assoc 10 d) d))
       )
  (princ)
  )

 

br

Posted

Maybe this post can help you 

Quote

 

you only need to select a point on the object.

Posted

I use the .xyz shortcuts

 

(defun c:MX   () (ssget ":LI") (SAA_CMDACTIVE nil) (command "MOVE" "P" "" pause ".yz" "non" "@") (princ))
(defun c:MY   () (ssget ":LI") (SAA_CMDACTIVE nil) (command "MOVE" "P" "" pause ".xz" "non" "@") (princ))
(defun c:MZ   () (ssget ":LI") (SAA_CMDACTIVE nil) (command "MOVE" "P" "" pause ".xy" "non" "@") (princ))

;;;==========================================================
;;; Continue pausing until exited command mode
;;; nil = pause
;;; otherwise pass string to use
;;; credit unknown
;;; usage example: (command "line" (SAA_CMDACTIVE nil))
;;;==========================================================
(defun SAA_CMDACTIVE ( passcmd / )
  (if (null passcmd) (setq passcmd pause))
  (while (not (= 0 (getvar "cmdactive")))
    (if (= 'LIST (type passcmd))
      (foreach x passcmd
        (command x)
      ) ;_foreach
      (command passcmd)
    ) ;_if
  ) ;end while
)

 

  • Like 1
Posted

As your dealing with objects with possible Z values, the entmod would be more reliable method. Else check is object to move at z=0.

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