MSasu Posted March 18, 2010 Posted March 18, 2010 I’m trying to locate the closest point to selection point on a line contained in a block (the only one item in that block); that it, I’m looking for a point that lays on that entity. By using code below seems that the line is recognized as misplaced?!? (setq UserSelection (nentsel "\nSelect line (in block): ") LineFromBlock (car UserSelection) SelectionPoint (cadr UserSelection)) (setq ClosestPoint (vlax-curve-getClosestPointTo (vlax-ename->vla-object LineFromBlock) SelectionPoint T)) (command "CIRCLE" ClosestPoint 1.0) ;DEBUG ONLY Can someone help solve my issue? Thank you! Regards, Quote
lpseifert Posted March 18, 2010 Posted March 18, 2010 Try this (setq UserSelection (nentsel "\nSelect line (in block): ") LineFromBlock (car UserSelection) SelectionPoint (OSNAP(cadr UserSelection) "NEA")) (command "CIRCLE" SelectionPoint 1.0) ;DEBUG ONLY Quote
MSasu Posted March 18, 2010 Author Posted March 18, 2010 Yes, the point lays on line now. Thank you very much! Have done a lot of tests with my code trying to understand the result and its strange how the debug points tend to align to a fictive line. Quote
lpseifert Posted March 18, 2010 Posted March 18, 2010 Can't answer for sure but it may have something to do with the difference with the UCS and ECS (Entity Coordinate System, which blocks use for definition of the entities within) But I could be wrong... Quote
MSasu Posted March 18, 2010 Author Posted March 18, 2010 Already tried to convert the point to/from Entity Coordinates System (used entity name as argument for TRANS function) but no luck… Quote
lpseifert Posted March 18, 2010 Posted March 18, 2010 I don't think TRANS will work directly for the conversion; a transformation matrix is needed. I'm sure someone else on this forum could explain/demonstrate the method better than I, I've just read about it. Quote
Lee Mac Posted March 18, 2010 Posted March 18, 2010 Msasu, For a nested object, you will need to use the transformation matrix returned by nentsel to get the correct points. Will post an example in a bit. Quote
lpseifert Posted March 18, 2010 Posted March 18, 2010 I figured post #6 would get you involved... Quote
Lee Mac Posted March 18, 2010 Posted March 18, 2010 Hehe Something like this Msasu: (defun GetClosestNested (/ ent cPt Matr pt) (vl-load-com) (if (and (setq ent (nentselp "\nSelect Line in Block: ")) (setq cPt (getpoint "\nSelect Point to Test: "))) (progn (setq Matr (caddr ent) ent (entmakex (append (entget (car ent)) '((60 . 1))))) (if Matr (vla-transformby (vlax-ename->vla-object ent) (vlax-tmatrix Matr))) (setq pt (vlax-curve-getClosestPointto ent cPt)) (entdel ent))) pt) (defun c:test (/ p) (if (setq p (GetClosestNested)) (entmakex (list (cons 0 "POINT") (cons 10 p)))) (princ)) Quote
alanjt Posted March 18, 2010 Posted March 18, 2010 Here's an example I did for a nested offset. http://www.cadtutor.net/forum/showthread.php?p=290166#post290166 Quote
alanjt Posted March 18, 2010 Posted March 18, 2010 For the rest of the world, here's Gile's example: http://www.theswamp.org/index.php?topic=32590.msg380852#msg380852 Quote
MSasu Posted March 19, 2010 Author Posted March 19, 2010 @lpseifert, @Lee Mac and @alanjt - Thank you very much for your solutions and examples! Quote
alanjt Posted March 19, 2010 Posted March 19, 2010 @lpseifert, @Lee Mac and @alanjt - Thank you very much for your solutions and examples! Hope it helped. Quote
Lee Mac Posted March 19, 2010 Posted March 19, 2010 You're welcome Msasu, happy to help. Its a shame a copy must be created, as this can be a problem if used within a loop but, if made invisible (as in my example), you needn't delete it til after the loop, meaning the routine is less CPU intensive. Quote
wizman Posted March 20, 2010 Posted March 20, 2010 I went the long way, works with non-uniformly scaled blocks, rotated blocks, non-world ucs: ;;------------------------------------------------------------------------------------------- ;; SAMPLE ROUTINE TO TRANSFORM POINT FROM/TO BLOCK COORDINATE/UCS ;; (setq UserSelection (nentsel "\nSelect line (in block): ") LineFromBlock (car UserSelection) SelectionPoint (cadr UserSelection) blockinspoint (cdr (assoc 10 (entget (car (last UserSelection))))) blockscale_x (cdr (assoc 41 (entget (car (last UserSelection))))) blockscale_y (cdr (assoc 42 (entget (car (last UserSelection))))) blockscale_z (cdr (assoc 43 (entget (car (last UserSelection))))) blockrotation (cdr (assoc 50 (entget (car (last UserSelection))))) ) ;; ;; ;; (setq ClosestPoint (vlax-curve-getClosestPointTo LineFromBlock ;; ;; ;; TRANSFORM SELECTIONPOINT COORDINATE FROM ;; USER COORDINATE SYSTEM TO ;; BLOCK COORDINATE SYSTEM ;; ;; UCS->WORLD => MOVE => ROTATE => SCALE ;; ;; (mapcar '/ (polar '(0 0 0) (- (angle '(0 0 0) (mapcar '- (trans SelectionPoint 1 0) (polar '(0 0 0) (angle '(0 0 0) blockinspoint) (distance '(0 0 0) blockinspoint) ) ) ) blockrotation ) (distance '(0 0 0) (mapcar '- (trans SelectionPoint 1 0) (polar '(0 0 0) (angle '(0 0 0) blockinspoint) (distance '(0 0 0) blockinspoint) ) ) ) ) (list blockscale_x blockscale_y blockscale_z) ) ) ) ;; ;; ;; (setq ClosestPoint ;; ;; ;; TRANSFORM CLOSESTPOINT FROM ;; BLOCK COORDINATE SYSTEM ;; TO USER COORDINATE SYTEM ;; ;; SCALE => ROTATE => MOVE => WORLD->UCS ;; ;; (trans (mapcar '+ (polar '(0 0 0) (+ (angle '(0 0 0) (mapcar '* ClosestPoint (list blockscale_x blockscale_y blockscale_z) ) ) blockrotation ) (distance '(0 0 0) (mapcar '* ClosestPoint (list blockscale_x blockscale_y blockscale_z) ) ) ) (polar '(0 0 0) (angle '(0 0 0) blockinspoint) (distance '(0 0 0) blockinspoint) ) ) 0 1 ) ) ;; ;; (command "CIRCLE" ClosestPoint 1.0) ;; ;;WIZ_20MAR10-------------------------------------------------------------------------------- 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.