rlx Posted April 17, 2018 Posted April 17, 2018 a place to start could be here : http://www.lee-mac.com/cursorrotate.html Quote
eimimitu Posted April 17, 2018 Author Posted April 17, 2018 Thanks for all the tips I appreciate it... I found this which seems to touch on it a bit: http://https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/points-from-a-region/td-p/2651482 something about translating the encrypted acis data... does anyone have experience with this? Quote
hanhphuc Posted April 19, 2018 Posted April 19, 2018 (edited) That's what it's looking like... That said how do i determine rotation of each axis based on the normal vector? haven't been able to figure it out by experimenting... Hi, Do you mean command: ALIGN ? But if the region gets normalized '(0.0 0.0 1.0), looks weird like this because of flatten p/s: bugs ac2007-2012 Edited April 19, 2018 by hanhphuc [IMG] Quote
marko_ribar Posted April 19, 2018 Posted April 19, 2018 Here, try this... I only partially read topic, but if you want to align REGION to WCS plane you can do it with following code (still normal vector not exactly (0.0 0.0 1.0), but REGION is assumed that lie in WCS as there is Centroid and other previously missing properties...) : (defun c:normalizeregion ( / unit v^v LM:InverseMatrix reg n x y z p elev m ) (vl-load-com) (defun unit ( v / d ) (if (not (equal (setq d (distance '(0.0 0.0 0.0) v)) 0.0 1e-) (mapcar '(lambda ( x ) (/ x d)) v) ) ) (defun v^v ( u v ) (list (- (* (cadr u) (caddr v)) (* (caddr u) (cadr v))) (- (* (caddr u) (car v)) (* (car u) (caddr v))) (- (* (car u) (cadr v)) (* (cadr u) (car v))) ) ) ;;--------------------=={ Inverse Matrix }==------------------;; ;; ;; ;; Implements the Gauss-Jordan Elimination algorithm to ;; ;; inverse a non-singular nxn matrix. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: m - nxn Matrix ;; ;;------------------------------------------------------------;; ;; Returns: Matrix inverse, or nil if matrix is singular ;; ;;------------------------------------------------------------;; (defun LM:InverseMatrix ( m / _identity _eliminate p r x ) (defun _identity ( n / i j l m ) (setq i 1) (repeat n (setq j 0) (repeat n (setq l (cons (if (= i (setq j (1+ j))) 1. 0.) l)) ) (setq m (cons l m) l nil i (1+ i)) m ) ) (defun _eliminate ( m p ) (mapcar (function (lambda ( x / d ) (setq d (car x)) (mapcar (function (lambda ( a b ) (- a (* d b)))) (cdr x) p) ) ) m ) ) (setq m (mapcar 'append m (_identity (length m)))) (while m (setq p (apply 'max (mapcar 'abs (mapcar 'car m)))) (while (not (equal p (abs (caar m)) 1e-14)) (setq m (append (cdr m) (list (car m)))) ) (if (equal 0.0 (caar m) 1e-14) (setq m nil) (setq p (/ 1. (caar m)) p (mapcar (function (lambda ( x ) (* p x))) (cdar m)) m (_eliminate (cdr m) p) r (cons p (_eliminate r p)) ) ) ) (reverse r) ) (while (or (not (setq reg (car (entsel "\nPick REGION to normalize it with WCS z vector '(0.0 0.0 1.0)...")))) (if reg (/= (cdr (assoc 0 (entget reg))) "REGION"))) (prompt "\nMissed or picked wrong entity type...") ) (setq n (vlax-safearray->list (vlax-variant-value (vla-get-normal (vlax-ename->vla-object reg))))) (setq x (if (equal n '(0.0 0.0 1.0) 1e-6) '(1.0 0.0 0.0))) (setq y (if (equal n '(0.0 0.0 1.0) 1e-6) '(0.0 1.0 0.0))) (if (and (null x) (equal n '(0.0 0.0 -1.0) 1e-6)) (setq x '(-1.0 0.0 0.0)) ) (if (and (null y) (equal n '(0.0 0.0 -1.0) 1e-6)) (setq y '(0.0 1.0 0.0)) ) (if (null x) (setq x (unit (v^v '(0.0 0.0 1.0) n))) ) (if (null y) (setq y (unit (v^v n x))) ) (setq z n) (vl-cmdf "_.EXPLODE" reg) (while (< 0 (getvar 'cmdactive)) (vl-cmdf "")) (setq p (vlax-curve-getstartpoint (entlast))) (vl-cmdf "_.UNDO" "1") (setq elev (caddr (trans p 0 n))) (setq m (list (list (car x) (car y) (car z) 0.0) (list (cadr x) (cadr y) (cadr z) 0.0) (list (caddr x) (caddr y) (caddr z) 0.0) (list 0.0 0.0 0.0 1.0))) (vla-transformby (vlax-ename->vla-object reg) (vlax-tmatrix (LM:InverseMatrix m))) (vla-move (vlax-ename->vla-object reg) (vlax-3d-point (list 0.0 0.0 elev)) (vlax-3d-point '(0.0 0.0 0.0))) (princ) ) HTH., M.R. Quote
eimimitu Posted April 20, 2018 Author Posted April 20, 2018 that works Marko... thank you much... now off to figure out how it does it! Thanks to all the contributors... Quote
Recommended Posts
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.