manddarran Posted January 28, 2010 Share Posted January 28, 2010 I am trying to write a lisp routine to automatically select the center of a point in a ceiling grid. So, when you pick a point some where in the "box" of the ceiling grid for that point it will insert a block at the dead center of that grid point no matter if the grid is rotated or not. So pick a point in a box and return the dead center of the box no matter what rotation? Clear as mud? I have one that does it for a grid that is running at 0 degrees.....no optimization on the code so don't hammer me. It works for us.. :-) (defun c:MULT8 () (setq aper (getvar "aperture")) (setvar "aperture" 50) (command "setvar" "cmdecho" "0") (if (= VALUE nil) (setq VALUE " ")) ; (setq q1 (strcat "\nWhat is attribute value? <" VALUE ">..")) ; (setq OL VALUE VALUE (strcase (getstring q1))) (if (= VALUE "") (setq VALUE OL)) (SETQ PT NIL) (SETQ PT (GETPOINT)) (while (NOT (NULL PT)) (setq newpt (osnap pt "int")) (if (/= newpt nil) (progn (setq angfound (rtd (angle newpt pt))) (cond ( (and (> angfound 0) (< angfound 90) ) (setq angins 45) ) ( (and (> angfound 90) (< angfound 180) ) (setq angins 135) ) ( (and (> angfound 180) (< angfound 270) ) (setq angins 225) ) ( (and (> angfound 270) (< angfound 360) ) (setq angins 315) ) ( (= angfound 180) (setq angins 0) ) ( (= angfound 90) (setq angins 270) ) ( (= angfound 0) (setq angins 180) ) ( (= angfound 270) (setq angins 90) ) ) ) ) (if (= newpt nil) (progn (setq newpt pt) (print "newpt") (command "insert" block newpt "" "" "") ) (progn (print"past") (setq inpt (polar newpt (dtr angins) (sqrt 288))) (command "insert" block inpt "" "" "") ) ) (COMMAND "SETVAR" "HIGHLIGHT" "1") (SETQ PT NIL) (SETQ PT (GETPOINT)) ) ) Quote Link to comment Share on other sites More sharing options...
manddarran Posted January 28, 2010 Author Share Posted January 28, 2010 Here are some grid pics Quote Link to comment Share on other sites More sharing options...
JohnM Posted January 29, 2010 Share Posted January 29, 2010 Try using the -boundary command (command “-boundary” pt) (setq pt getpoint) (command “-boundary” pt) (setq ent (entget(entlast)) Now get the opposite corners and find the mid point for the insert point (entdel (entlast));_delete boundary Quote Link to comment Share on other sites More sharing options...
BIGAL Posted January 29, 2010 Share Posted January 29, 2010 Another way is to use CAL (int+int)/2.0 Or just a lisp middle of two pts Quote Link to comment Share on other sites More sharing options...
manddarran Posted January 29, 2010 Author Share Posted January 29, 2010 Thanks for the input! Boundary works ok if there is nothing else in the square. But alot of the time there might be a door or a room name in there. We could turn the room names off, but I am trying to avoid that. Quote Link to comment Share on other sites More sharing options...
TimSpangler Posted January 29, 2010 Share Posted January 29, 2010 "mtp" or "m2p" (gives you a point between 2 points) then select 2 opposing corners. Quote Link to comment Share on other sites More sharing options...
manddarran Posted January 29, 2010 Author Share Posted January 29, 2010 Yeah I could select two points, but my task is to select one point. It works just fine when the grid is 0, and 90 degrees, but when the architects or buildings are not 0 an 90 I am at a loss..... Quote Link to comment Share on other sites More sharing options...
manddarran Posted January 29, 2010 Author Share Posted January 29, 2010 OK This is what I have come up with. If you are zoomed out to far it sure is slow but works. (defun c:headins () (SETQ PT NIL) (SETQ PT (GETPOINT)) (while (NOT (NULL PT)) (Command "-boundary" pt "") (setq item (entlast)) ;convert to vl object (setq item (vlax-ename->vla-object item)) ; (setq cPl (vlax-ename->vla-object(car(entlast)))) (vla-GetBoundingBox item 'blPt 'trPt) (setq lPt(vlax-safearray->list blPt)) (setq tPt(vlax-safearray->list trPt)) (setq inspt (CAL "(lpt + tpt) / 2.0")) (entdel (entlast)) (command "insert" block inspt "" "" "") (SETQ PTOLD PT) (SETQ PT NIL) (SETQ PT (GETPOINT)) ) ) Quote Link to comment Share on other sites More sharing options...
manddarran Posted January 29, 2010 Author Share Posted January 29, 2010 This sped it up alot. I created a boundary selection set of all layers containing the text "grid". (defun c:headins () ;(ssget gridl (ssget "_X" (list "GRID"))) (setq gridl (ssget "_X" '((8 . "GRID")))) (SETQ PT NIL) (SETQ PT (GETPOINT)) (while (NOT (NULL PT)) (Command "-boundary" "a" "b" "n" (ssget "_X" '((8 . "*GRID*"))) "" "" pt "") (setq item (entlast)) ;convert to vl object (setq item (vlax-ename->vla-object item)) ; (setq cPl (vlax-ename->vla-object(car(entlast)))) (vla-GetBoundingBox item 'blPt 'trPt) (setq lPt(vlax-safearray->list blPt)) (setq tPt(vlax-safearray->list trPt)) (setq inspt (CAL "(lpt + tpt) / 2.0")) (entdel (entlast)) (command "insert" block inspt "" "" "") (SETQ PTOLD PT) (SETQ PT NIL) (SETQ PT (GETPOINT)) ) ) Quote Link to comment Share on other sites More sharing options...
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.