Author Topic: Subtrat or add Z to all items  (Read 455 times)

0 Members and 1 Guest are viewing this topic.

renkor

  • Newt
  • Posts: 27
Subtrat or add Z to all items
« on: June 11, 2019, 02:21:21 PM »
Hello all,

I need help you. I has a drawing with different elements (lines, plines, block, arcs....) with different Z value each one. And I would like to be able to subtract or add Z to all items (not move to Z=0)

Example:

Line 1-->original Z=5.
Line 1--> Desired Z=6+2 (2 or whatever I need)= 8. Or 6-2=4

ronjonp

  • Needs a day job
  • Posts: 7009
Re: Subtrat or add Z to all items
« Reply #1 on: June 11, 2019, 04:26:18 PM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ b i s)
  2.   ;; RJP 2019-06-11
  3.   (cond
  4.     ((and (setq i (getreal "\nEnter number [+ or -]: "))
  5.           (setq s (ssget ":L" '((0 . "arc,circle,insert,line,lwpolyline,*text"))))
  6.      )
  7.      (foreach a (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
  8.        (foreach x '(insertionpoint center elevation startpoint endpoint)
  9.          (cond ((= 'list (type (vl-catch-all-apply 'vlax-get (list a x))))
  10.                 (setq b (vlax-get a x))
  11.                 (vl-catch-all-apply 'vlax-put (list a x (list (car b) (cadr b) (+ (caddr b) i))))
  12.                )
  13.          )
  14.        )
  15.      )
  16.     )
  17.   )
  18.   (princ)
  19. )
« Last Edit: June 11, 2019, 04:30:10 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12241
  • London, England
Re: Subtrat or add Z to all items
« Reply #2 on: June 11, 2019, 04:53:47 PM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:chz ( / s z )
  2.     (if (and (setq z (getreal "\nSpecify elevation change: "))
  3.              (setq s (ssget "_:L"))
  4.         )
  5.         (vl-cmdf "_.move" s "" "_non" '(0 0 0) "_non" (list 0 0 z))
  6.     )
  7.     (princ)
  8. )

ronjonp

  • Needs a day job
  • Posts: 7009
Re: Subtrat or add Z to all items
« Reply #3 on: June 12, 2019, 09:20:39 AM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:chz ( / s z )
  2.     (if (and (setq z (getreal "\nSpecify elevation change: "))
  3.              (setq s (ssget "_:L"))
  4.         )
  5.         (vl-cmdf "_.move" s "" "_non" '(0 0 0) "_non" (list 0 0 z))
  6.     )
  7.     (princ)
  8. )
Nice :)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12241
  • London, England
Re: Subtrat or add Z to all items
« Reply #4 on: June 12, 2019, 12:28:15 PM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:chz ( / s z )
  2.     (if (and (setq z (getreal "\nSpecify elevation change: "))
  3.              (setq s (ssget "_:L"))
  4.         )
  5.         (vl-cmdf "_.move" s "" "_non" '(0 0 0) "_non" (list 0 0 z))
  6.     )
  7.     (princ)
  8. )
Nice :)

Thanks  :-)

renkor

  • Newt
  • Posts: 27
Re: Subtrat or add Z to all items
« Reply #5 on: June 15, 2019, 01:44:48 PM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ b i s)
  2.   ;; RJP 2019-06-11
  3.   (cond
  4.     ((and (setq i (getreal "\nEnter number [+ or -]: "))
  5.           (setq s (ssget ":L" '((0 . "arc,circle,insert,line,lwpolyline,*text"))))
  6.      )
  7.      (foreach a (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
  8.        (foreach x '(insertionpoint center elevation startpoint endpoint)
  9.          (cond ((= 'list (type (vl-catch-all-apply 'vlax-get (list a x))))
  10.                 (setq b (vlax-get a x))
  11.                 (vl-catch-all-apply 'vlax-put (list a x (list (car b) (cadr b) (+ (caddr b) i))))
  12.                )
  13.          )
  14.        )
  15.      )
  16.     )
  17.   )
  18.   (princ)
  19. )

Thanks for your time!

renkor

  • Newt
  • Posts: 27
Re: Subtrat or add Z to all items
« Reply #6 on: June 15, 2019, 01:45:20 PM »
Try this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:chz ( / s z )
  2.     (if (and (setq z (getreal "\nSpecify elevation change: "))
  3.              (setq s (ssget "_:L"))
  4.         )
  5.         (vl-cmdf "_.move" s "" "_non" '(0 0 0) "_non" (list 0 0 z))
  6.     )
  7.     (princ)
  8. )
Nice :)

Thanks  :-)

Now, I have two options hehe, thanks!

notredave

  • Newt
  • Posts: 94
Re: Subtrat or add Z to all items
« Reply #7 on: June 19, 2019, 09:15:42 AM »
Good morning all,

Lee Mac or anybody else listening. I come across drawings that I can't fillet lines because they are non coplanar due to Z values not being at 0. Can this lisp be tweaked to change Start Z and End Z to 0? I sure would appreciate the help.

Thank you,
David

ronjonp

  • Needs a day job
  • Posts: 7009
Re: Subtrat or add Z to all items
« Reply #8 on: June 19, 2019, 09:38:02 AM »
Good morning all,

Lee Mac or anybody else listening. I come across drawings that I can't fillet lines because they are non coplanar due to Z values not being at 0. Can this lisp be tweaked to change Start Z and End Z to 0? I sure would appreciate the help.

Thank you,
David

In my code above, change this line:
Code - Auto/Visual Lisp: [Select]
  1. (vl-catch-all-apply 'vlax-put (list a x (list (car b) (cadr b) (+ (caddr b) i))))
To this:
Code - Auto/Visual Lisp: [Select]
  1. (vl-catch-all-apply 'vlax-put (list a x (list (car b) (cadr b) 0.)))

Or you could use something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo nil (sssetfirst nil (ssget "_x" '((0 . "line")))) (princ))

And change the values in the properties palette.

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

notredave

  • Newt
  • Posts: 94
Re: Subtrat or add Z to all items
« Reply #9 on: June 19, 2019, 10:22:09 AM »
ronjonp,

Thank you for replying. I tried your suggestion and I'm confused how it worked. I drew 2 different lines with different start and end Z numbers. I ran your lisp and was confused with the response "Enter number [+ or -]. I used the - option and entered 1. It fixed line to 0 on start and end. So, it worked! I'm just curious about what to really enter at the + and - option. I just want all lines I select to go to 0. I hope I didn't confuse you and thanks again for responding. I appreciate it.

Thank you,
David

ronjonp

  • Needs a day job
  • Posts: 7009
Re: Subtrat or add Z to all items
« Reply #10 on: June 19, 2019, 10:33:52 AM »
Oops .. forgot to take out the option. Just change this:

Code - Auto/Visual Lisp: [Select]
  1. (and (setq i (getreal "\nEnter number [+ or -]: "))
  2.      (setq s (ssget ":L" '((0 . "arc,circle,insert,line,lwpolyline,*text"))))
  3. )
To this:
Code - Auto/Visual Lisp: [Select]
  1. (setq s (ssget ":L" '((0 . "arc,circle,insert,line,lwpolyline,*text"))))

If you look at the filter above be aware that the code is working on items other than lines, remove all the other object types ( arc,circle etc... ).

Or just use this simplified code to strip elevations from lines:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ s)
  2.   (if (setq s (ssget ":L" '((0 . "line"))))
  3.     (foreach a (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
  4.       (entmod (append (entget a)
  5.                       (list (mapcar '+ '(0 0 0) (assoc 10 (entget a)))
  6.                             (mapcar '+ '(0 0 0) (assoc 11 (entget a)))
  7.                       )
  8.               )
  9.       )
  10.     )
  11.   )
  12.   (princ)
  13. )
« Last Edit: June 19, 2019, 10:45:50 AM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

notredave

  • Newt
  • Posts: 94
Re: Subtrat or add Z to all items
« Reply #11 on: June 19, 2019, 10:49:52 AM »
ronjonp,

You are the man!!! It works perfectly now. Thank you for all your hard work, I appreciate it. Have a great rest of the day!

Thank you sir,
David

ronjonp

  • Needs a day job
  • Posts: 7009
Re: Subtrat or add Z to all items
« Reply #12 on: June 19, 2019, 12:12:17 PM »
ronjonp,

You are the man!!! It works perfectly now. Thank you for all your hard work, I appreciate it. Have a great rest of the day!

Thank you sir,
David
Glad to help :)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC