Jump to content

Get a point at the center of a ceiling grid.


manddarran

Recommended Posts

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))
)
)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.....

Link to comment
Share on other sites

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))
)
)

Link to comment
Share on other sites

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))
)
)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...