Author Topic: Reverse normal Z  (Read 3812 times)

0 Members and 1 Guest are viewing this topic.

lamarn

  • Swamp Rat
  • Posts: 636
Reverse normal Z
« 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...
 
Design is something you should do with both hands. My 2d hand , my 3d hand ..

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Reverse normal Z
« Reply #1 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.)
                   )
    )
  )
)
Speaking English as a French Frog

lamarn

  • Swamp Rat
  • Posts: 636
Re: Reverse normal Z
« Reply #2 on: March 17, 2010, 06:58:37 AM »
How do you use this code as a command?
Design is something you should do with both hands. My 2d hand , my 3d hand ..

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Reverse normal Z
« Reply #3 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))

lamarn

  • Swamp Rat
  • Posts: 636
Re: Reverse normal Z
« Reply #4 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 ..
Design is something you should do with both hands. My 2d hand , my 3d hand ..

hermanm

  • Guest
Re: Reverse normal Z
« Reply #5 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?

LE3

  • Guest
Re: Reverse normal Z
« Reply #6 on: March 22, 2010, 08:51:37 PM »
¿qué no?
wow, long time did not read anything in Spanish... :)

lamarn

  • Swamp Rat
  • Posts: 636
Re: Reverse normal Z
« Reply #7 on: March 23, 2010, 11:32:47 AM »

.. just want to reverse normal (without chanching xyz values) ...
What other problem???
Design is something you should do with both hands. My 2d hand , my 3d hand ..

Daniel J. Ellis

  • Swamp Rat
  • Posts: 811
Re: Reverse normal Z
« Reply #8 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
===
dJE

KWL

  • Guest
Re: Reverse normal Z
« Reply #9 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)
)