Move vla-object to zero elevation

Move vla-object to zero elevation

etilley327KA
Advocate Advocate
1,461 Views
22 Replies
Message 1 of 23

Move vla-object to zero elevation

etilley327KA
Advocate
Advocate

How do I move my vla-object to zero elevation?

 

(if
  (and(setq Dline (nentsel "\nSelect Destination property line: ")))
  (progn
    (setq xrefcopy (cadr Dline))
    (command "_.ncopy" xrefcopy "" "" "")
    (setq xrefcopy (entlast))
    (setq xrefcopy (vlax-ename->vla-object xrefcopy))
    (vla-move xrefcopy) ?????
       (setq
          1stS (vlax-curve-getStartPoint Sline)
          2ndS (vlax-curve-getEndPoint Sline))
       (setq
          1stD (vlax-curve-getStartPoint xrefcopy)
          2ndD (vlax-curve-getEndPoint xrefcopy))
       (vla-delete xrefcopy)
   (command "_.align" A "" 1stS 1stD 2ndS 2ndD "" ""))
)
0 Likes
1,462 Views
22 Replies
Replies (22)
Message 2 of 23

paullimapa
Mentor
Mentor

how's about good old fashion CHANGE command?

(setq xrefcopy (entlast))
(command"_.CHANGE" xrefcopy "" _P" "_E" "0.0" "")

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 23

etilley327KA
Advocate
Advocate

Well, I guess my second question would be is it possible for the ncopy to ever come in with a varying start and endpoint elevation? I know that the move will always ensure that the elevation is zero.

0 Likes
Message 4 of 23

paullimapa
Mentor
Mentor

if the object like a LINE or 3dPoly was originally drawn with different elevations at start & end points then the ncopy will also have the same.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 23

etilley327KA
Advocate
Advocate

Thanks, then I believe change will not work with varying elevations.

0 Likes
Message 6 of 23

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

.... my second question would be is it possible for the ncopy to ever come in with a varying start and endpoint elevation? .....


Yes, if it's that way in the source Block or Xref.

Kent Cooper, AIA
0 Likes
Message 7 of 23

Kent1Cooper
Consultant
Consultant
One way to not bother with Moving anything is to just replace the Z coordinates with 0 -- this is just one way to do that:
       (setq
          1stD (reverse (cons 0.0 (cdr (reverse (vlax-curve-getStartPoint xrefcopy))))
          2ndD (reverse (cons 0.0 (cdr (reverse (vlax-curve-getStartPoint xrefcopy)))))
Kent Cooper, AIA
0 Likes
Message 8 of 23

etilley327KA
Advocate
Advocate

I like it, thank you sir.

0 Likes
Message 9 of 23

etilley327KA
Advocate
Advocate

A bit stumped. The aligned objects are still coming in with an elevation. Why isnt it aligning to zero? The xref destination line has varying elevations.

 

 (setq A (ssget ))
          (command "_.copybase" "0,0" A "")
          (command "_.pasteclip" "0,0")
       (setq Sline (entsel "\nSelect Source property line: "))
       (setq Sline (car Sline))
(if
  (and(setq Dline (nentsel "\nSelect Destination property line: ")))
  (progn
    (setq xrefcopy (cadr Dline))
    (command "_.ncopy" xrefcopy "" "" "")
    (setq xrefcopy (entlast))
    (setq xrefcopy (vlax-ename->vla-object xrefcopy))
       (setq
          1stS (vlax-curve-getStartPoint Sline)
          2ndS (vlax-curve-getEndPoint Sline))
       (setq
          1stD (reverse (cons 0.0 (cdr (reverse (vlax-curve-getStartPoint xrefcopy)))))
          2ndD (reverse (cons 0.0 (cdr (reverse (vlax-curve-getEndPoint xrefcopy))))))
       (vla-delete xrefcopy)
   (command "_.align" A "" 1stS 1stD 2ndS 2ndD "" "")
  )
)
0 Likes
Message 10 of 23

Kent1Cooper
Consultant
Consultant

Do you have any running Osnap mode(s) on?

Kent Cooper, AIA
0 Likes
Message 11 of 23

etilley327KA
Advocate
Advocate
Yes
0 Likes
Message 12 of 23

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:
Yes

.... and ....  Does it work right if you turn them off?

Kent Cooper, AIA
0 Likes
Message 13 of 23

etilley327KA
Advocate
Advocate
No sir.
0 Likes
Message 14 of 23

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

.... The xref destination line has varying elevations.

....

       (setq Sline (entsel "\nSelect Source property line: "))
       (setq Sline (car Sline))
....
       (setq
          1stS (vlax-curve-getStartPoint Sline)
          2ndS (vlax-curve-getEndPoint Sline))
....
   (command "_.align" A "" 1stS 1stD 2ndS 2ndD "" "")
....

And does the property line in the Sline variable ever have varying elevation?  Does that need the same Z-zeroing applied as to the one in the xrefcopy variable?

Kent Cooper, AIA
0 Likes
Message 15 of 23

etilley327KA
Advocate
Advocate

No sir

 

0 Likes
Message 16 of 23

etilley327KA
Advocate
Advocate

I guess I could move all of selection A to zero z after the alignment. Could varying elevations change the placement of the alignment in any way?

0 Likes
Message 17 of 23

Kent1Cooper
Consultant
Consultant

Read about the differences between the ALIGN and 3DALIGN commands -- that may shed some light [I don't work in 3D often enough to have detailed knowledge].

Kent Cooper, AIA
0 Likes
Message 18 of 23

etilley327KA
Advocate
Advocate

Is there a way to move the entire vla-object to zero z and would that differ from changing the start and end point to zero?

0 Likes
Message 19 of 23

john.uhden
Mentor
Mentor

@etilley327KA ,

 

One thing for certain...

 (setq xrefcopy (cadr Dline))

won't work if xrefcopy is supposed to be an ename.

It needs to be car not cadr.

It won't cancel out with that line, but xrefcopy will be the point of selection, not an ename.

John F. Uhden

0 Likes
Message 20 of 23

paullimapa
Mentor
Mentor

See if you can understand the logic behind this modified version of the FLAT.lsp routine and apply it in your code.

Basically the idea is that an object like LINE or 3dPOLY with different elevation points can be flattened to 0 by first moving to z of 1e99 and then back down again to -1e99. Finally I just added an option to then move the flattened object now to a desired elevation: 

; Flat command is an alternative to Express Tools Flatten 
; modified from: 
; https://www.cadtutor.net/forum/topic/2007-flatten-alternatives/
; Lisp to flatten All to 0:
; (command"_.move""_all""""0,0,0""0,0,1e99""_.move""_p""""0,0,0""0,0,-1e99")
; Menu Macro to flatten All to 0:
; C^C_move;_all;;0,0,0;0,0,1e99;_move;_p;;0,0,0;0,0,-1e99;
; Flat offers option to enter elevation value to flatten selected objects
(defun c:flat (/ cmdecho elev menuecho selected total-nabor)
 (if(not(car (atoms-family 1 '("vl-load-com"))))(vl-load-com))
; setup environment
 (setq cmdecho (getvar"cmdecho"))
 (setq menuecho (getvar"menuecho"))  
 (setvar"menuecho"0)
 (setvar"cmdecho"0)
 (if(not *elev*)(setq *elev* 0.0))     ; set default global elevation to 0
 (setq elev (getreal(strcat"\nEnter Elevation To Flatten Objects To: <" (rtos *elev* 2 (getvar"luprec"))">: ")))
 (if(not elev)(setq elev *elev*)(setq *elev* elev))
 (princ(strcat"\nSelect Objects To Move To Elevation [" (rtos *elev* 2 (getvar"luprec")) "]:"))(princ)
 (if 
; (setq total-nabor (ssget "x" '((410 . "model")))) 
  (setq total-nabor (ssget"_:L")) ; only select objects on unlocked layers
  (progn 
   (setq selected (sslength total-nabor)) ; get total number of selected objects
   (setq total-nabor (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex total-nabor))))
   ; first flatten selected objects to 1e99 -1e99 which = 0 elevation and then to given elev 
   (foreach i (list 1e99 -1e99 *elev*) ; 
    (mapcar(function(lambda (x) (vla-move x (vlax-3d-point (list 0 0 0)) (vlax-3d-point (list 0 0 i))))) total-nabor) 
   ) ; foreach
   (princ(strcat"\nSuccessfully Flattened [" (itoa selected) "] Selected Objects to Elevation: [" (rtos *elev* 2 (getvar"luprec")) "]."))
  ) ; progn
  (princ"\nNo Objects Selected.")
 ) ; if objects selected
; return environment
 (setvar"menuecho"menuecho)
 (setvar"cmdecho"cmdecho) 
 (princ) 
) ; defun

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes