Author Topic: Ceiling Grid - Revisited - assistance, please  (Read 10089 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #15 on: March 03, 2005, 09:50:18 AM »
You know after thinking about it, the center does not change by rotating the room
when you use the Max/Min X & Y method, or the bounding box. The Max/Min x & y values
change but the center remains the same. The Only thing left to do is determine the
orientation of the grid.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #16 on: March 03, 2005, 09:54:47 AM »
I started the code but have to work today. :(
Here is the untested code.
Code: [Select]
(defun c:Grid(/ pt1 elast en elist x y )
  (prompt "\nPick points, Enter when done.")
  (if (setq pt1 (getpoint))
    (progn
      (setq elast (entlast))
      (command "PLINE" pt1 (setq pt2 (getpoint pt1)))
      (while (setq pt2 (getpoint pt2 "\nNext point: ")) (command pt2))
      (command "")
      (if (not(eq elast (setq en(entlast))))
        (progn
          (setq elist (entget en))
          (setq ptlist (mapcar 'cdr(vl-remove-if-not
                      '(lambda (x) (= (car x) 10)) elist)))
          ;; get mid point x,y   x = min-x + ((max-x - min-x)/2)
          (setq snpt(list (+ x (/ (- (apply 'max (mapcar 'car  ptlist))
                            (setq x (apply 'min (mapcar 'car ptlist))))2))
                          (+ y (/ (- (apply 'max (mapcar 'cadr  ptlist))
                           (setq y (apply 'min (mapcar 'cadr ptlist))))2)))
          )
          ;; ++++++++++++++++++++
          ;; +  Get Grid angle  +
          ;; +  Hatch Grid      +
          ;; ++++++++++++++++++++
        ); progn
      ); enfif
    ); progn
  ); enfif
 
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

nivuahc

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #17 on: March 03, 2005, 10:58:41 AM »
I initially thought the same thing CAB. Take a look at this, though. Red is the actual point.



The more complex the area, the less I can assume anything.

Drawing the pline, getting the angle, rotating the pline, hatching the area, rotating all of it back in place... that's looking better and better.

And I've got 3 engineers in my office scratching their heads right now trying to figure out the math needed to calculate this... so I don't feel so bad now. :)

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Ceiling Grid - Revisited - assistance, please
« Reply #18 on: March 03, 2005, 12:10:31 PM »
I tried it three differant ways.

Center Points
(can't figure out how to show img's)

1 (White Point) I used a lisp to find the centroid of a boundary with the room at a right angle.

2 (Yellow point) with the room oriented in the same manner as 1 I found the outer most boundaries and struck a line from corner to corner and got its mid piint (slightly differant than point 1)

3. (Blue point) room turned at 45) I found its outer most boundaries and struck lines from corner to corner and got it mid point.

while looking at 3 i thought to myself "Why would you do it like that, the tiles would still run with the walls right? So there for it takes you back to 2"  Right Wrong?[/img]
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

nivuahc

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #19 on: March 03, 2005, 12:23:55 PM »
This is a quick-n-dirty based on the code CAB posted, provided that the room is NOT rotated.

Code: [Select]
(defun c:cgrid ( / )
  (vl-Load-Com)
  (prompt "\nPick points, starting with lower left-most corner of the room. Enter when done.")
  (if (setq pt1 (getpoint))
    (progn
      (setq elast (entlast))
      (command "PLINE" pt1 (setq pt2 (getpoint pt1)))
      (while (setq pt2 (getpoint pt2 "\nNext point: ")) (command pt2))
      (command "")
      )
    )
  (setq en (entlast)
elist (entget en)
ptlist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) elist)))

  (setq max_x (apply 'max (mapcar 'car  ptlist))
min_x (apply 'min (mapcar 'car ptlist))
max_y (apply 'max (mapcar 'cadr  ptlist))
min_y (apply 'min (mapcar 'cadr ptlist)))

  (setq snpbase (list ( + (/ (- max_x min_x) 2) min_x)( + (/ (- max_y min_y) 2) min_y)))
  (command "snapbase" snpbase)
  (command "_hatch" "u" "0" "24" "y" en "")
  (command "snapbase" "0,0")
  )


I'll work on doing the same thing, should the room be rotated, by using the method I described above. I'll have the user draw the polyline, if it's at an angle, rotate it to 0, find the center, place the hatch, rotate it all back.

nivuahc

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #20 on: March 03, 2005, 12:32:58 PM »
The one caveat to this code?

If the coordinates are negative values (i.e. (-755.456, -543.587)) the math gets completely screwed up.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #21 on: March 03, 2005, 12:49:43 PM »
OK, Here is another approach. I mentioned in another thread on the subject.
This is a test code and no error checking [your job] :)
Pick a pline to hatch, select angle reference or Enter for zero.
Note Zero causes 45 deg to be added to hatch angle to make this one work.
You may then move the snapbase of the hatch to suite your eye.
Press Enter when done.


Code: [Select]
;;  Modify Hatch Base Point
(defun hbp (elst / obp nbp)
  (setq obp '(0 0))
  (while (setq nbp (getpoint obp "\nSelect new basepoint or Enter to Quit: "))
    (setq elst (subst (cons 43 (car nbp))
                     (assoc 43 elst) ; new x basepoint
                     elst
              )
    )
    (setq elst (subst (cons 44 (cadr nbp))
                     (assoc 44 elst) ; new y basepoint
                     elst
              )
    )
    (entmod elst)
    (setq obp nbp)
  ) ;end while
) ; end defun

(defun c:hgrid (/ pt1 elast en elist x y osm)
  (setq osm (getvar "OSMODE"))
  (setvar "OSMODE" 512)

  (cond
    ((and (setq pline (entsel "\nSelect pline to hatch."))
          (setq ang (cond ((getangle "\nPick 2 points for hatch alignment. Enter=0")) (0)))
          (setq ang (+ (* 180.0 (/ ang pi)) 45))
     ) ; and
     (command ".-bhatch" "S" pline "" "P" "ANSI37" "192" ang "")
     (setvar "OSMODE" 0)
     (hbp (entget(entlast)))
    )
  )
  (setvar "OSMODE" osm)
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #22 on: March 03, 2005, 12:56:34 PM »
I edited the code above, adding some OsMode statements.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Ceiling Grid - Revisited - assistance, please
« Reply #23 on: March 03, 2005, 12:58:02 PM »
While we are on the subject of ceiling grids I have a question for everyone/ anyone.  do you prefer you grid be hatched, seperate objects, or a group?

The prog that I made hatches then explodes then groups.  This gives me the ability to move as I need.

Thoughts, comments?
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

nivuahc

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #24 on: March 03, 2005, 12:58:42 PM »
CAB, you amaze me dude. Did you try out the stuff I threw together above?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #25 on: March 03, 2005, 01:05:37 PM »
Quote from: nivuahc
The one caveat to this code?

If the coordinates are negative values (i.e. (-755.456, -543.587)) the math gets completely screwed up.

You may have to use abs like this (abs (- max_x min_x))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #26 on: March 03, 2005, 01:09:33 PM »
Quote from: nivuahc
CAB, you amaze me dude. Did you try out the stuff I threw together above?


Hey, just tried it & with the abs, workes fine.
You just have to establish the base angle. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #27 on: March 03, 2005, 07:51:19 PM »
How about a combination of the two routines?
Code: [Select]
(defun c:cgrid (/ pt1 elast elist ptlist max_x min_x max_y min_y en snpbase osm ang hbp)
  ;;  Modify Hatch Base Point
  (defun hbp (elst obp / nbp)
    (while (setq nbp (getpoint obp "\nSelect new basepoint or Enter to Quit: "))
      (setq elst (subst (cons 43 (car nbp))
                        (assoc 43 elst) ; new x basepoint
                        elst
                 )
      )
      (setq elst (subst (cons 44 (cadr nbp))
                        (assoc 44 elst) ; new y basepoint
                        elst
                 )
      )
      (entmod elst)
      (setq obp nbp)
    ) ;end while
  ) ; end defun

  (command "undo" "begin")

  (prompt "\nPick points to define the room. Enter when done.")
  (if (setq pt1 (getpoint))
    (progn
      (setq elast (entlast))
      (command "PLINE" pt1)
      (while (> (getvar "CMDACTIVE") 0)
        (command pause)
      )
    )
  )
  (setq osm (getvar "OSMODE"))
  (setvar "OSMODE" 512)

  (if (not (eq elast (setq en (entlast))))
    (progn
      (setq elist  (entget en)
            ptlist (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) elist))
      )

      (setq max_x (apply 'max (mapcar 'car ptlist))
            min_x (apply 'min (mapcar 'car ptlist))
            max_y (apply 'max (mapcar 'cadr ptlist))
            min_y (apply 'min (mapcar 'cadr ptlist))
      )

      (setq snpbase (list (+ (/ (abs (- max_x min_x)) 2) min_x)
                          (+ (/ (abs (- max_y min_y)) 2) min_y)
                    )
      )
      (command "snapbase" snpbase)
      (setq ang (cond ((getangle "\nPick 2 points for hatch alignment. Enter=0"))
                      (0)
                )
      )
      (setq ang (* 180.0 (/ ang pi)))
      (command "_hatch" "u" ang "24" "y" en "")
      (command "snapbase" "0,0")
      (setvar "OSMODE" 0)
      (hbp (entget (entlast)) snpbase)
    )
  )
  (setvar "OSMODE" osm)
  (command "undo" "end")
  (princ)
)
(prompt "\nLighting Grid Loaded, Enter cgrid to run.")
(princ)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

nivuahc

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #28 on: March 03, 2005, 07:58:02 PM »
Dangit! I wish I had a pirated copy of AutoCAD running on my machine at home so I could test that! :D

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #29 on: March 03, 2005, 09:10:23 PM »
It'll be here tomorrow, unless it's written in disappearing ink. :)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.