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

0 Members and 1 Guest are viewing this topic.

nivuahc

  • Guest
Ceiling Grid - Revisited - assistance, please
« on: March 02, 2005, 03:42:43 PM »
I'm working out the new, sleeker, better code for the ceiling grid routine that I want to implement. The whole change was sparked by the idea, which never even occurred to me originally, of changing my snapbase. That was a superb idea. I'm glad I posted that ugly code, simply for that.

Take a look at this image and try to understand what I'm doing here, if you would. My intent is to have the drafter draw the frame around the room using a polyline, collecting a list of the points along the way and calculating the center of the room.



The list of points displayed, if you want to try the math out on your own, are as follows:

(107.508 381.76 0.0)
(107.508 278.607 0.0)
(177.133 278.607 0.0)
(177.133 169.462 0.0)
(330.07 169.481 0.0)
(330.07 169.481 0.0)

With my new snapbase figured as

(218.789 275.611 0.0)


How do I go about figuring that out? To figure out the new value of X for my new snapbase I use

Code: [Select]
((highest_X_value - lowest_X_value) / 2 + lowest_X_value) = new_X_value

so, in my example, I get this:

Code: [Select]
((330.07 - 107.508) / 2 + 107.508) = 218.789

Same formula, essentially, for figuring the new value of Y as in

Code: [Select]
((highest_Y_value - lowest_Y_value) / 2 + lowest_Y_value) = new_Y_value

so, in my example, I get this:

Code: [Select]
((381.76 - 169.462) / 2 + 169.462) = 275.611

That works out wonderfully. Perfect, in fact. Is there a better, quicker, sleeker way to do it? That's what I'm asking you. But take a look at this, because this is where I'm really stumped:





At an angle:

(475.141 324.779 0.0)
(548.081 251.839 0.0)
(597.314 301.071 0.0)
(674.491 223.894 0.0)
(782.621 332.05 0.0)
(632.516 482.154 0.0)

My snapbase, which I have figured out manually, should come out to be:

(628.895 328.419 0.0)

My formula above doesn't work, I am suffering from severe tunnel vision regarding what I need to do, so I really could use a fresh set of eyes and another brain to look at this and guide me in the right direction. My brain is stuck in a do-while loop.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #1 on: March 02, 2005, 04:18:25 PM »
You must get the user to make the first two picks along the wall you want as the horizontal reference.
When you get all points you can set a new UCS, trans the points, get the snapbase & trans back before
you use it. Another way would be to mathematically rotate the point about the first pick based on the
angle of p1 p2. I don't know how to do that but it can be done.
Another way would be to draw a pline using the points, rotate it as mentioned above. Get the snapbase
and place a point. Then rotate that point back. Then it would be the base point you need.

The last two make my head hurt so I choose number one. :)
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 #2 on: March 02, 2005, 04:34:21 PM »
Thanks CAB.

I considered having them select the points, using the 'rubber-band' method, getting the angle from point_1 to point_2, drawing the polyline, rotating it based on that angle (point_1 to point_2), getting a list of the points along that newly rotated polyline, calculating the center, changing the snapbase, doing the hatch, putting the snapbase back, then rotating the whole mess back in place... but that seems like an awful lot of un-necessary stuff. I know there is a better way and I know I just can't see it right now.

The only problem I see is, whenever you start off thinking "You must get the user to..." you can usually rest assured that the user will do anything but what you want/need them to do.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #3 on: March 02, 2005, 04:43:15 PM »
Your method will work fine. It gets the job done. It's not that hard.
As for the room orientation, there is no way to tell what wall to use as
a base line with out help from the user, period. Given an irregular
shaped room it is the user that decides which way the grid should orient.
So the user must convey that to the routine.

You may want the user to pick the orientation separately from the outline
to be sure you are communicating.
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 #4 on: March 02, 2005, 04:56:49 PM »
Actually, think it through... if a user picks the first point, then the next, despite which point the choose at whatever angle they choose, I have an angle that I can use to do my rotating. It doesn't really matter which two points they pick, just so long as they are on the same wall. Right?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #5 on: March 02, 2005, 05:21:24 PM »
Take a look at this living room. There are several starting points that will get you into trouble.
Given some time I can come up with a better example, if you need it. :)
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 #6 on: March 02, 2005, 05:26:09 PM »
point duly noted! :lol:

whdjr

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #7 on: March 02, 2005, 05:26:29 PM »
WOW CAB!

you got a bunch of stuff runnin on your machine.  You must have a super computer over there. 8)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #8 on: March 02, 2005, 05:53:24 PM »
You would laugh if you saw it. The side panel of the tower is open & I have a small electric fan
blowing on the mother board. The early AUSUS with AMDs have an inferior fan.
At 1.4ghz it is slow compared to today's toys. :D
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.

hudster

  • Gator
  • Posts: 2848
Ceiling Grid - Revisited - assistance, please
« Reply #9 on: March 03, 2005, 03:55:51 AM »
CAB, I see you are using IE, try the fox, it's way better.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

SMadsen

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #10 on: March 03, 2005, 07:23:46 AM »
Nothing happens when I click the buttons on your screen, CAB. Why?!?

 :lol:

By the way, what's a lanai? Is that an outdoor thing?

daron

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #11 on: March 03, 2005, 07:32:31 AM »
Lanai, is another one of those words for porch or patio, mostly enclosed. Yes, it's an outdoor thing.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #12 on: March 03, 2005, 07:38:36 AM »
Quote from: SMadsen
Nothing happens when I click the buttons on your screen, CAB. Why?!?

 :lol:

By the way, what's a lanai? Is that an outdoor thing?


I put my screen lock on. :)

When a house living area gets over 4000 sq feet living area you're not allow to use
mundane labels like porch and hall. You must use Lanai [French] and gallery.
Makes the rich folk happy. 8)
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.

sinc

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #13 on: March 03, 2005, 08:09:15 AM »
I'm not entirely sure what you're trying to accomplish here and why, but it seems like you might be able to use regions to find the centroid, instead of using a closed polyline.  You might want to check the documentation on Region objects and see if they'll help you.  You can create a region with lines and arcs, then simply ask it for its centroid.

nivuahc

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #14 on: March 03, 2005, 09:26:25 AM »
Quote from: sinc
I'm not entirely sure what you're trying to accomplish here and why, but it seems like you might be able to use regions to find the centroid, instead of using a closed polyline.  You might want to check the documentation on Region objects and see if they'll help you.  You can create a region with lines and arcs, then simply ask it for its centroid.


Nice idea, but it's a no-go.

Tried several methods for obtaining the centroid of the newly created region (in the first image) and each method came up with a different result. None of them came up with the actual center of the room, though.

But I appreciate you thinking outside of the box. That's the kind of responses I was looking for. I fear that I have poisoned the mind of anyone who reads this thread by telling how I intended to go about accomplishing this.

The normal, manual, method that we use to determine the center of a room is simply to draw a diagonal line from the apparent intersections of the outermost corners of a room and select the midpoint of that line. I'll try to illustrate:



You see, in the example above, with a room that is not at an angle that this is fairly simple. The midpoint of my diagonal line is the location of my new snapbase. Setting my snapbase to this point, then creating a user defined hatch with a spacing of 24 inches places my ceiling grid centered in the room, just like the contractor would install it, and spaced evenly so that the lighting that I will place will have the most even distribution possible.

When the room is at an angle, however, we use a different method as shown here:



While, in this example, the diagonal line method would also work, that quickly becomes a problem when the room area gets a little more complex, like the image that CAB posted. In this situation, we would draw two lines. One of them from the midpoint of an outermost wall perpindicular to the outermost wall in the opposite direction (it doesn't matter at this point if the wall you choose is the larger or the smaller). Again, another line, perpindicular to the first. Both lines are moved to their respective midpoints and you get what is shown above, with the location of the new snapbase being the intersection of those two lines.

All of this is to achieve what we have in the following image:



The tile (grid) is equal on each opposite side of the room. The length of the tile along the wall with our bathroom and the opposing door is the same length as our tile on the opposite wall. The length of the tile on the wall with the two outgoing doors is the same length as the tile on the opposing wall of the overall room. All of our tiles are 'centered', all of our lights are placed in these tiles, and our light distribution is as even as it can be throughout the room.

Whatever method I use to determine the center of a room at an angle should also be capable of finding the center of a room that is not at an angle. The manual method that I spoke of does just that. I know there has to be a simpler, less complicated way to get to this point.

Forget any method I have mentioned thus far and consider it your task to find the center of the room using lisp. How would you go about doing that? And, for the record, we're working in 2D.

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.

nivuahc

  • Guest
Ceiling Grid - Revisited - assistance, please
« Reply #30 on: March 04, 2005, 02:16:11 PM »
That is purty danged sweet CAB!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Ceiling Grid - Revisited - assistance, please
« Reply #31 on: March 04, 2005, 02:26:15 PM »
That'll get you by until you think of a better way.
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 #32 on: March 04, 2005, 02:31:11 PM »
most definately