Jump to content

Lisp command to move selected objects to defined OR global elevation.


Recommended Posts

Posted
(defun C:TESTJKLISP ()
  (ssget)
   (command "move" "p" "" '(0 0 0) '(0 0 1e99) "move" "p" "" '(0 0 0) '(0 0 1e99))
)

 

Hello all, I'm fairly new to writing LISP so please excuse my ignorance. The above AutoLISP command allows a selection of dimensions, blocks, etc. to be automatically moved the Z 0 axis. I need help modifying this code to replace the Z 0 data by either prompting for input of desired elevation OR retrieve the global elevation that has been previously changed. I believe that it would be similar to this: 

(setq ZE (command (getvar "ELEVATION"))

but I have been unsuccessful in its implementation. Any advice would be most appreciated, Thanks!

Posted
55 minutes ago, Guspar said:
(setq ZE (command (getvar "ELEVATION"))

You can retrieve it by 

(setq ZE  (getvar "ELEVATION"))

 

  • Thanks 1
Posted
35 minutes ago, devitg said:

You can retrieve it by 

(setq ZE  (getvar "ELEVATION"))

 

Thank you @devitg ! I'm eager to learn and have been practicing tutorials, feels like I am just piece milling it together currently but have a real-world application where I need to utilize this. Are aware of the functions I need to know in order to replace the Z 0 with ZE in the string? 

Best regards!

Posted
1 hour ago, Guspar said:

I need to know in order to replace the Z 0 with ZE in the string

@Guspar.  see it 

 

(defun C:move-to-elevation ()
  (setq ss (ssget))

  (setq elevation (getreal "the elevation"))
  
  (setq osmode (getvar 'osmode))
  (setvar 'osmode 0)
   (command "move" ss "" '(0 0 0)  (list 0 0 elevation)) ; just set the dstination point  
(setvar 'osmode osmode)
 (princ) 
)

 

  • Like 2
Posted

I use entmod to change things.

  1.  you don't have to mess with osnaps
  2. it should be faster then using command
;;----------------------------------------------------------------------;;
;; Change Elevation of selected items
(defun C:ELV (/ SS)
  (or (setq *elv (vlax-ldata-get "Set" "Elevation")) (setq *elv 5.0)) ;Change 5.0 to your default
  (if (setq elv (getreal (strcat "\nSpecify Elevation <" (rtos *elv) ">: ")))
    (vlax-ldata-put "Set" "Elevation"  elv) ;saves new elevation to drawing file to be called next time the command is
    (vlax-ldata-put "Set" "Elevation" (setq elv *elv))  ;stores old elevation ...
  )       
  (While (setq SS (ssget))
    (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (entmod
        (mapcar
          '(lambda (a)
             (if (member (car a) '(10 11 12 13 14 15 16 17 18))
               (list (car a) (cadr a) elv)
               a
             )
           )
          (entget e)
        )
      )
    )
  )
  (princ)
)

 

 

  • Like 1
  • 2 months later...
Posted

Good morning everyone, and many thanks for everyone who posted on this thread. Even though it has been few months since I posted I thought I would updated the thread on the final Lisp that was utilized. For a short summary the final code that accomplished my task is shared below. There was an additional issue discovered with dimension lines that were not associated and once moved left a floating point or node just out in model space. For example, the issue came from the start and finish points of the linear dimensions being at true elevation but the actual dimension text and arrows would always draw on the 0" elevation on the Z axis. This Lisp would allow selection of a wide variety of objects, flatten anything that was left floating, then return it to the desired elevation. The code is short and functional. I'm open to further suggestions or questions if any. Thanks again!

(defun C:Z0 ()
 (ssget)
 (setq elevation (getreal "Enter Desired Elevation: "))
  (command "move" "p" "" '(0 0 0) '(0 0 1e99) "move" "p" "" '(0 0 0) '(0 0 -1e99))
  (command "move" "p" "" '(0 0 0) (list 0 0 elevation)) 
 (princ) 
)

 

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