TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: lamarn on October 21, 2009, 03:11:02 PM

Title: Reverse normal Z
Post by: lamarn on October 21, 2009, 03:11:02 PM
Is there a way, code, to turn "normal Z" from -1 to 1?
We are not able to join arc's and lines into pline because of the difference...
 
Title: Re: Reverse normal Z
Post by: gile on October 21, 2009, 04:19:09 PM
Hi,

Something like this ?

Code: [Select]
(defun InvNormal (obj)
  (or (= (type obj) 'VLA-OBJECT)
      (setq obj (vlax-ename->vla-object obj))
  )
  (vla-transformBy
    obj
    (vlax-tmatrix '((1. 0. 0. 0.)
                    (0. 1. 0. 0.)
                    (0. 0. -1. 0.)
                    (0. 0. 0. 1.)
                   )
    )
  )
)
Title: Re: Reverse normal Z
Post by: lamarn on March 17, 2010, 06:58:37 AM
How do you use this code as a command?
Title: Re: Reverse normal Z
Post by: Lee Mac on March 17, 2010, 08:45:47 AM
Nice code Gile as always  :-)

An example for you Lammerts:

Code: [Select]
(defun c:RevNorm (/ InvNormal doc ss)
  (vl-load-com)

  (defun InvNormal (obj) ;;Gile
    (or (= (type obj) 'VLA-OBJECT)
        (setq obj (vlax-ename->vla-object obj))
    )
    (vla-transformBy obj
      (vlax-tmatrix '((1. 0.  0. 0.)
                      (0. 1.  0. 0.)
                      (0. 0. -1. 0.)
                      (0. 0.  0. 1.)
                     )
      )
    )
  )

  (if (ssget "_:L")
    (progn
      (vla-StartUndoMark (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))     
      (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
        (InvNormal obj))
      (vla-delete ss)

      (vla-EndUndoMark doc)))

  (princ))
Title: Re: Reverse normal Z
Post by: lamarn on March 22, 2010, 04:33:43 PM
This code mirrors the z-value also!
usable in 2d, for 3d you have to watch out and restore z value ..
Title: Re: Reverse normal Z
Post by: hermanm on March 22, 2010, 08:23:46 PM
Nice code Gile as always  :-)

An example for you Lammerts:

Code: [Select]
(defun c:RevNorm (/ InvNormal doc ss)
  (vl-load-com)

  (defun InvNormal (obj) ;;Gile
    (or (= (type obj) 'VLA-OBJECT)
        (setq obj (vlax-ename->vla-object obj))
    )
    (vla-transformBy obj
      (vlax-tmatrix '((1. 0.  0. 0.)
                      (0. 1.  0. 0.)
                      (0. 0. -1. 0.)
                      (0. 0.  0. 1.)
                     )
      )
    )
  )

  (if (ssget "_:L")
    (progn
      (vla-StartUndoMark (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))     
      (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
        (InvNormal obj))
      (vla-delete ss)

      (vla-EndUndoMark doc)))

  (princ))

Um, yeah, but if the segments are not joining it means the normal vectors are incompatible on at least two segments.

So, reversing all the normals will not solve the problem, ¿qué no?
Title: Re: Reverse normal Z
Post by: LE3 on March 22, 2010, 08:51:37 PM
¿qué no?
wow, long time did not read anything in Spanish... :)
Title: Re: Reverse normal Z
Post by: lamarn on March 23, 2010, 11:32:47 AM

.. just want to reverse normal (without chanching xyz values) ...
What other problem???
Title: Re: Reverse normal Z
Post by: Daniel J. Ellis on March 23, 2010, 02:42:51 PM
Do you just want to use the UCS command to rotate your UCS 180 degrees around the x axis?

That still won't allow you to turn lines etc. into polylines.

To do that you'd need to either adjust your UCS to match the object in question, or adjust the objects to all have the same z value

What exactly are you trying to do?

dJE
Title: Re: Reverse normal Z
Post by: KWL on April 02, 2010, 02:57:25 PM
Is there a way, code, to turn "normal Z" from -1 to 1?
We are not able to join arc's and lines into pline because of the difference...

This will reverse arc normals:

Code: [Select]
;fliparcs by KWL
(defun c:fliparcs (/ ss hpi en el)
  (princ "\nSelect arcs to flip")
  (setq
    ss (ssget (list (cons 0 "ARC")))
    hpi (* 0.5 pi)
  )
  (cond
    (
      (not (null ss))
      (repeat (sslength ss)
        (ssdel (setq en (ssname ss 0)) ss)
        (setq el (entget en))
        (entmod
          (mapcar
            (function
              (lambda (x / g)
                (setq g (car x))
                (cond
                  ((= g 10) (cons 10 (mapcar '* (list -1.0 1.0 -1.0) (cdr x))))
                  ((= g 210) (cons 210 (mapcar '- (cdr x))))
                  ((= g 50) (cons 50 (+ hpi (- hpi (cdr (assoc 51 el))))))
                  ((= g 51) (cons 51 (+ hpi (- hpi (cdr (assoc 50 el))))))
                  (t x)
                )
              )
            )
            el
          )
        )
      )
      (princ "\nDone")
    )
    (t (princ "\nNothing selected"))
  )
  (princ)
)