Author Topic: Help but please no code.  (Read 18486 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« on: March 02, 2004, 11:17:25 AM »
I'm trying to write a lisp routing to set out lighting within a room.

What I want to do is click on 4 corners of a room to allow AutoCAD to calculate the room area, then after I input the number of fittings required in the x and y directions, lisp calculates the spacing required and insert a block at the required spacings

Now as I'm a newbie at this and don't have a clue where to start, I'm hoping someone will take me under their wing and help me out.

What i don't want is someone to write the lisp for me, that way I'll never learn.

So where do i start?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Help but please no code.
« Reply #1 on: March 02, 2004, 11:56:12 AM »
Well, I would usually tell someone to start by putting together Pseudo code... You have started that already, whether you know it or not....
So, what you need to do is first identify the order in which you are going to proceed, such as selecting points, etc.. Take into account if the room is square, round etc...
Select a starting point, and continue from there.
Inserting the blocks should be no problem, the rotation and points can be gathered from the object they will be near. When you have a little better idea of pseudo code, get back with us.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MDT

  • Guest
Help but please no code.
« Reply #2 on: March 02, 2004, 12:00:56 PM »
Since you want to be self-taught, here's what you
  should be doing:

  1. Open up AutoCAD and read the help files on
      AutoCAD Customization section particularly on
      Autolisp functions. Learn how each function works,
      and where to look for these functions.
  2. To be able to write a lisp routine, you have to know
      what the routine will do and you the author should
      be able to determine the required steps to do the
      task.
  3. For example, in the problem you have posted:
      If you're asked to make the drawing without using
      a lisp routine, how will  you do it?

  After these 3 steps, start writing your routine. Do it as
  you would draw it.....

daron

  • Guest
Help but please no code.
« Reply #3 on: March 02, 2004, 01:27:26 PM »
Look into the divide/measure commands. I wrote something similar to what you describe by using those commands. Hint: both commands can insert blocks and rotate them along the selected object.

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #4 on: March 02, 2004, 03:01:00 PM »
I thought about the divide/measure command, but the blocks i need to insert have attributes, and as far as i'm aware these commands can't do that.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Help but please no code.
« Reply #5 on: March 02, 2004, 03:46:04 PM »
I had a thought about how to gather the extreme points of a polygon in a closed area simply by selecting a point within the area. It would work only when the area was a completely closed polygon, but it would be a neat trick.

Here is my thought....
Using the hatch command, create a hatch transparently to the user, make the scale sufficiently large so that it does not show on the screen. Grab that hatch and put it into a variable and extract the boundary from it. Store the boundary points in a list, then erase the hatch.

You should have a points diagram of the boundary of the room to begin aligning objects to.

If you use divide or measure, you could
first grab the last object using entlast then
conceivably insert your blocks aligned (don't worry about the attributes as of yet) then using the last entity from before, grab all entities using entnext from entlast.
Finally starting with the first block you inserted with the command, have the program add the attributes as needed to each individual block.

Heck the more I think about it the more I like it...

I know there is code around too that you could scalp and use for adding the attributes to a block, grabbing all entities from a specific point in the drawing database isn't really a difficult proposition either. Divide and Measure do the insertion hard work for you, and all you need to do is make sure the room is a closed area.

Damn what a good idea, I am just sorry I had not thought of it before you did....

Incedently it would work great for me with the placement of required electrical outlets, much faster....
I can see a pretty good use for this program.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
Help but please no code.
« Reply #6 on: March 02, 2004, 04:12:02 PM »
The problem I find with hatch and/or boundary (essentially the same thing), is that if there is the slightest degree of objects not being connected, or if there are any arcs, connected or otherwise, then the hatch/boundary will fail. The function I wrote requires you to draw a polyline from point a to point b. This way you know way are always getting a polyline and the right one.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Help but please no code.
« Reply #7 on: March 02, 2004, 04:47:44 PM »
:P .....
Why oh why must you rain on my parade.....
I know that the objects must connect, I even know about problems with splines, but arcs haven't ever given me a problem. go figure....

Anyway, the way I see it, if you know that the lines MUST meet then you will be more diligent to see that they do. Incedently, if I have a drawing that the lines do not meet where they "appear" to meet, I will trash it and redraw it. Of course I always make my lines meet and I always have lines that meet....
I frequently find it easier and faster to completely redraw a plan than to attempt to fix inconsistencies.

So, draw it correctly from the beginning, and then you can use the program to it's fullest potential....

Sorry... got off on a tangent here....

It is still a good idea... we just need to figure out a workaround...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
Help but please no code.
« Reply #8 on: March 02, 2004, 05:14:42 PM »
I always use snaps to connect lines/arcs/etc. too, but often, we'll get plat drawings from engineers, who also, probably use snaps, but for some reason, this connection between lines and arcs gets lost in translation. Who knows why. I also wrote this routine so it lays down a pline on a specific layer, then divides the blocks onto the pline, then deletes it. Reason: I don't want an electrical outlet to be passed across a door object.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Help but please no code.
« Reply #9 on: March 02, 2004, 05:21:20 PM »
So.... you already have a proggie in place? .. please share the wealth man....I do electrical drawing every day...well, at least 3 or 4 a week ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

daron

  • Guest
Help but please no code.
« Reply #10 on: March 02, 2004, 05:27:52 PM »
It's kinda buggy. I wrote it a couple of years ago. I'll share it when hudster gives the okay. I'll send it to you if you like. Maybe you can improve on it.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Help but please no code.
« Reply #11 on: March 02, 2004, 05:34:51 PM »
Please send away... I don't mind putting in a pline to make my life a bit easier...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #12 on: March 03, 2004, 03:50:19 AM »
Post your code, i'm ok with that, from what you say your code doesn't do what i'm after anyway.

Basically what i need to do is.

1. find the lenght and width of a room.
2. input the desired amount of fittings for lenght and width.
3. insert an array of a selected block, at spacings decided by the number of fittings divided by lenght and width.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

daron

  • Guest
Help but please no code.
« Reply #13 on: March 03, 2004, 07:55:24 AM »
Let's see what you've got?

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #14 on: March 03, 2004, 08:47:28 AM »
and this is where my experience ends.

So, how do I go about specifing user inputs using lisp?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

SMadsen

  • Guest
Help but please no code.
« Reply #15 on: March 03, 2004, 09:14:49 AM »
Hey Hudster,
Nice little project you've given yourself there. Before you know it, you'll be writing routines to calculate and draw intensity curves in candela (or lux or lumen or .. )

Getting the geometry of a room can be done in various ways depending on your intentions. But I'd start off getting simple corner points as you suggest in your initial post - pretending it's always a square room. Later you can decide what to do with oddly shaped rooms and such.

Have a look at GETPOINT for a starter. Once having identified points, you'll need to do some calculations - getting some angles and subtract x's and y's - to get the geometry. Because points are lists of 3 reals, you'll probably need to look at some list handling stuff, such as CAR, CADR and CADDR.

Pretending rooms are always square, you could use GETDIST to have the user specify length and width, but you'd still need angles and it would be harder to adjust for oddly shaped rooms.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help but please no code.
« Reply #16 on: March 03, 2004, 09:17:09 AM »
How about expanding on the pseudo code a bit more.

Quote
1. find the length and width of a room.
2. input the desired amount of fittings for length and width.
3. insert an array of a selected block, at spacings decided by
the number of fittings divided by length and width.


You need to get closer to the code by being more specific about what
you want to do. As posted earlier, how would YOU actually draw it?
Then translate that into code.

Here is my version of pseudo code

Briefly display instructions
Get width of room & # of lights
Get depth of room & # of lights
Calculate layout, What is the formula
.   distance / (1+ # of lights) ??
Get the lower left corner of the room
Insert the first light @ (LLcorner + widthOffset + DepthOffset)
Use array command with entlast  widthOffset  DepthOffset
Done


Change this to suite your method.

Then start your codeing
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
Help but please no code.
« Reply #17 on: March 03, 2004, 10:52:48 AM »
Can I use the GETDIST function and use it to input the length?

i.e.

Code: [Select]
(setq L(getdist))

To give you a rundown of how the lights should be place, take your length L and divide it by the number of fittings, this gives you Distance B, then divide B by 2 to give you Distance A.

So you fittings would be spaced using the distances calculated
i.e. A B B B B B A, this ensures your lights are equally spaced across the room.

Does that make sense?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

SMadsen

  • Guest
Help but please no code.
« Reply #18 on: March 03, 2004, 11:19:54 AM »
Quote from: Hudster
Can I use the GETDIST function and use it to input the length?
Code: [Select]
(setq L(getdist))


Absolutely.

Code: [Select]

(setq len (getdist "\nInput length of room: "))
(setq wid (getdist "\nInput width of room: "))


This will give the user a choice of dragging a distance on screen or typing a distance at the command line.
Once having those, do your spacing arithmetic. E.g.
Code: [Select]

(setq equalSpace (/ len numOfFittings))
(setq wallToFitting (/ equalSpace 2.0))


.. or whatever you need

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #19 on: March 03, 2004, 03:12:45 PM »
Right I have made the code for inputing the lenght, width and fittings.

Code: [Select]
(defun c:ltg ()
;;;get the room length
(setq len (getdist "\nInput length of room: "))
 ;;;get the room width
(setq wid (getdist "\nInput width of room: "))
;;;get number of fittings across length
(setq fitlen (getint "\nInput No of fittings along LENGTH: "))
;;;Get number of fittings along WIDTH
  (setq fitwid (getint "\nInput No of fittings along WIDTH: "))
  )


now the hard part, working out the mathematics of setting the array points.

So QUESTION.

How do i get lisp to store the value of the co-ordinates of the first point i click on when I am setting the length and widths.

I figure if i have these coordinates, i hopefully will be able to set the intersection of these two points as being the 0,0 point of the room, and can work aout the insertion point of the first block from there.

or would it be easier to add a line in the lisp asking the user to click on the lower left hand corner of the room? :D
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help but please no code.
« Reply #20 on: March 03, 2004, 03:50:54 PM »
Take a look at this.

Code: [Select]
(setq pt (getvar "lastpoint"))
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.

daron

  • Guest
Help but please no code.
« Reply #21 on: March 03, 2004, 04:06:48 PM »
Don't know about you, but I personally happen to like using getpoint:
Code: [Select]
(setq len (getpoint "\nInput length of room: ")
  wid (getpoint len "\nInput width of room: "))
  fitlen (getint "\nInput No of fittings along LENGTH: ")
  fitwid (getint "\nInput No of fittings along WIDTH: ")
  )

Of course, it means you'd have to add more code and separate the coordinates returned, but that could be a good thing.

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #22 on: March 03, 2004, 04:13:33 PM »
I've went with getpoint

Code: [Select]
(setq zerpt (getpoint "\nClick on the lower left corner of room: "))

What did you mean by seperate out the co-ordinates? You kind of lost me there.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help but please no code.
« Reply #23 on: March 03, 2004, 04:14:31 PM »
The problem I see with using the pick points derived from
getdistance or that method is that the room may have offsets
and the pick points may need adjusting before use.
But that's why there are other methods to use.

Another problem not yet discussed is when the room is not
aligned with the x/y axis. many times I have rooms that
are set at 45 degrees.

If your rooms were always aligned with x/y you could pick
two points like when you use the rectangle command and
have all the point information you need.
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.

SMadsen

  • Guest
Help but please no code.
« Reply #24 on: March 03, 2004, 04:21:43 PM »
Excellent code.

Quote from: Hudster
How do i get lisp to store the value of the co-ordinates of the first point i click on when I am setting the length and widths.


You don't with GETDIST. If you're using that function, you'll need to have the user specify lower-left corner of room or something like that.

CAB, the GETxxx functions do not store input points in LASTPOINT.

However, there is a way to emulate GETDIST and get both points and distance. If you look up GETPOINT in the help files, you'll notice that it accepts an optional point as argument - as well as the normal prompt argument. That point is used for dragging a rubber-band just like GETDIST.

Try this out:

Code: [Select]
(defun getdrag ()
  (if (setq pt1 (getpoint "\nInput length of room: "))
    (if (setq pt2 (getpoint pt1 "Specify second point: "))
      (distance pt1 pt2)
    )
  )
)


This will store the start point, anchor to it when storing the end point and calculate the distance between the points. The reason for the two IF's is that the second GETPOINT will fail if pt1 is nil and that DISTANCE will fail if both points didn't get assigned.

Result is that the user won't notice a difference which method is used. BUT, there is a problem. If the user types a number at the command line, it will anchor at LASTPOINT and attempt to retrieve a second point. Not good.
There is no easy way to tell if GETPOINT recieved a number or a point (I think? umm) - in both instances it will return a point. But we can try to setup GETPOINT to recieve an arbitrary input. This means that typing a distance will be returned as a string, so we'll have to convert it to a number. It also means that if the user inputs anything else than a number, it'll have to be discarded. INITGET 128 allows for arbitrary input and DISTOF does the conversion (or returns nil if not):

Code: [Select]
(defun getdrag ()
  (initget 128)
  (if (setq pt1 (getpoint "\nInput length of room: "))
    (progn
      (if (listp pt1)
        (if (setq pt2 (getpoint pt1 "Specify second point: "))
          (setq dist (distance pt1 pt2))
        )
      )
      (if (= (type pt1) 'STR)
        (setq dist (distof pt1))
      )
    )
  )
  dist
)


Of course, the final comment is that you'll have to discard all of the above because what if the user do not click in the rooms corners but merely points out a distance in the screen somewhere??

Back to square one. Either get length/width AND a corner - or specify that the user NEEDS to click in the corners of the room.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help but please no code.
« Reply #25 on: March 03, 2004, 04:41:11 PM »
?? point or string

Code: [Select]
(initget 128)
(setq pt (getpoint))
(if (= (type pt) 'LIST)
  ;; got a point
  ;; else got a string
)


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

SMadsen

  • Guest
Help but please no code.
« Reply #26 on: March 03, 2004, 05:09:02 PM »
Nope, that would fail if GETPOINT returns nil. But yes, if GETPOINT is wrapped in an IF from the start then that would suffice. Once past the nil return, it would either be a list or a string.

daron

  • Guest
Help but please no code.
« Reply #27 on: March 03, 2004, 05:12:34 PM »
Would grread work, or is it too much?

SMadsen

  • Guest
Help but please no code.
« Reply #28 on: March 03, 2004, 05:19:27 PM »
GRREAD would be like using CADaver's hobby as a pest control.

I would recommend that Hudster either do the length/width/at-least-one-corner method or the explicit get-corners-of-the-room-or-doom method.

There's no guarantee the user will click at the corners if he/she is only asked for distances.

If it explicitly asks for corners then the user knows which points to input - and that it'll probably fail if some other points are clicked.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help but please no code.
« Reply #29 on: March 03, 2004, 07:12:10 PM »
Here is another to consider.

Code: [Select]
(if (and (setq LLcorner (getpoint "\nPick the lower left corner."))
         (setq WidthPt (getpoint LLcorner "\nPick a point for width."))
         (setq LengthPt (getpoint LLcorner "\nPick a point for length."))
     )
  (progn
    (setq wid (abs (- (abs (car LLcorner)) (abs (car WidthPt))))
    (setq len (abs (- (abs (cadr LLcorner)) (abs (cadr LengthPt))))

    ;; process code here
  )
); endif
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.

daron

  • Guest
Help but please no code.
« Reply #30 on: March 04, 2004, 07:57:45 AM »
What CAB's done with the value of wid and len is what I meant by separating out the values.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help but please no code.
« Reply #31 on: March 04, 2004, 09:52:17 AM »
Here is a visual example.

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.

DEVITG

  • Bull Frog
  • Posts: 480
Going far beyond
« Reply #32 on: March 05, 2004, 06:35:36 PM »
Could be "MINSERT"  a good way to draw the blocks on?

As defined length fractions distance as

Quote

ABBBBBA



The width could be
Quote


CDDDDDC



So the insert point should be the A and C distance  from origin

The row number =  by the previous user imput
The column number = by the same way

The row space A

The column space D

Even the angle could match the angle of the room .
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Help but please no code.
« Reply #33 on: March 05, 2004, 08:30:21 PM »
I don't know if minsert would be a good option since it inserts in a complete grid...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #34 on: March 31, 2004, 06:46:11 AM »
I've been working on this in my very limited free time and I've come up with this

Code: [Select]
;;;
;;;Lighting array lisp routine
;;;Created by Andy Hudson
;;;March 2004
;;;
(defun c:ltg (/ X1 Y1 FX FY P1 PX PY block PXA PYA) ;set as local variables
  (setq X1 (getdist "\nInput length of room along X Axis: ")) ;get length
 (setq Y1 (getdist "\nInput width of room along Y Axis: ")) ;Get width
  (setq FX (getint "\nInput No of fittings along X Axis: "))
  (setq FY (getint "\nInput No of Fittings along Y Axis: "))
  (setq P1 (getpoint "\nSelect the lower left hand corner: ")) (terpri) ;set the 0,0 point
  (command "UCS" "O" P1)
  (setq P1 (LIST 0 0))
  ;;;
  (setq PX (/ X1 FX)) ;;length divide by fittings
  (setq PXA (/ (/ X1 FX) 2.0)) ;;divided by 2
   (setq PY (/ Y1 FY)) ;;width divided by fittings
  (setq PYA (/ (/ Y1 FY) 2.0)) ;;divided by 2
  ;;;
  (setq block (getstring "Enter block name you wish to insert: ")) ;;get block
;;;
  (command "-insert" block (list PYA PXA) "1" "" "0") ;;insert block
;;;
  (COMMAND "-ARRAY" "LAST" "" "RECTANGULAR" FY FX PY PX)
  (COMMAND "UCS" "P")
  (COMMAND "UCS" "P")
 (princ) ;;clean exit
  )


it's almost there but it doesn't quite work right and I can't figure out why.

this is an image of how I want it to lay out the fittings but it's always off a wee bit.



Any Ideas?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

SMadsen

  • Guest
Help but please no code.
« Reply #35 on: March 31, 2004, 08:43:39 AM »
Andy, I haven't tried your routine but could running osnaps cause the UCS to snap to another point than P1? Just a thought.

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #36 on: March 31, 2004, 09:09:11 AM »
I've tried it with snaps off, but it's still out.

not by much only 50mm, but enough to annoy me. :cry:
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #37 on: March 31, 2004, 09:29:48 AM »
it was the snaps, I changed the osmode to 103 and it worked.

But it threw up another problem.  the routing only works in square grids, i.e 2X2 , 3X3, 4X4 etc.

if you try 2X4 it doesn't work.

Someone in my work suggested it may be to do with integers and real numbers.  but I don't know, I'm new to lisp and every function is a discovery to me.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

SMadsen

  • Guest
Help but please no code.
« Reply #38 on: March 31, 2004, 10:30:48 AM »
Nope, GETDIST returns reals so that part is fine. Just noticed that you've switched x and y in the INSERT command though:

(command "-insert" block (list PYA PXA) "1" "" "0")

should be

(command "-insert" block (list PXA PYA) "1" "" "0")

SMadsen

  • Guest
Help but please no code.
« Reply #39 on: March 31, 2004, 10:48:08 AM »
Try this minor alteration. Instead of messing with UCS, it merely offsets the point with the lower left point in P1.
Also, undo is added and osnaps are turned off temporarily.

Code: [Select]
(defun c:ltg (/ X1 Y1 FX FY P1 PX PY block PXA PYA osm)
  ;set as local variables
  (setq X1 (getdist "\nInput length of room along X Axis: ")) ;get length
  (setq Y1 (getdist "\nInput width of room along Y Axis: "))  ;Get width
  (setq FX (getint "\nInput No of fittings along X Axis: "))
  (setq FY (getint "\nInput No of Fittings along Y Axis: "))
  (setq P1 (getpoint "\nSelect the lower left hand corner: "))
;;;
  (setq PX (/ X1 FX))
  ;;length divide by fittings
  (setq PXA (+ (car P1) (/ PX 2.0)))
  ;;divided by 2
  ;; - plus X coord of P1
  (setq PY (/ Y1 FY))
  ;;width divided by fittings
  (setq PYA (+ (cadr P1) (/ PY 2.0)))
  ;;divided by 2
  ;; - plus Y coord of P1
;;;
  (setq block (getstring "Enter block name you wish to insert: ")) ;get block
;;;
  ;; - If block exists then go ahead
  (cond ((tblsearch "BLOCK" block)
         ;; - Done with user input -> set OSMODE to zero
         (setq osm (getvar "OSMODE"))
         (setvar "OSMODE" 0)
         ;; - Let user be able to undo
         (command "UNDO" "Begin")
         (command "-insert" block (list PXA PYA) "1" "" "0")
         ;;insert block
;;;
         (COMMAND "-ARRAY" "LAST" "" "RECTANGULAR" FY FX PY PX)
         (command "UNDO" "End")
         (setvar "OSMODE" osm)
        )
  )
  (princ)
  ;;clean exit
)

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #40 on: March 31, 2004, 01:53:13 PM »
That works a lot better than my version.

CAR and CADR are both new functions to me,  like I said, it's all new to me.

Now for stage two, working out how to insert arrays into rooms at a slant.
I'm looking at both the getangle and getorient functions to do this, am I on the right track?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

SMadsen

  • Guest
Help but please no code.
« Reply #41 on: March 31, 2004, 02:44:36 PM »
Yes, that would be the right track if it should ask for an angle. But it could still be asking for a distance (either with GETDIST as it is now, or with GETPOINT's) and then use ANGLE to calculate the angle.

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #42 on: April 11, 2004, 02:56:46 PM »
there is a problem with this lisp, it does work, until you try to put a row of fittings when there is only 1 row on the Y axis.  then it seems to fall down.

no matter how hard I look i can't see where it goes wrong.

Any ideas?

 :?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help but please no code.
« Reply #43 on: April 11, 2004, 04:51:15 PM »
This was without the angle.

Code removed
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
Help but please no code.
« Reply #44 on: April 11, 2004, 06:30:41 PM »
Here is some help with the angle. :)

Code: [Select]
(defun c:ltg (/ x1 y1 fx fy p1 px py block pxa pya osm newbies elast e ang eblk)
  (setq x1 (getdist "\nInput width of room along X Axis: "))
  (setq y1 (getdist "\nInput length of room along Y Axis: "))
  (setq fx (getint "\nInput No of fittings along X Axis: "))
  (setq fy (getint "\nInput No of Fittings along Y Axis: "))
  (setq p1 (getpoint "\nSelect the lower left hand corner: "))
  (setq ang (getangle p1 "\nSelect angle of room width (x-axis): <0>"))
  (if (null ang)
    (setq ang 0)
    (setq ang (* 180.0 (/ ang pi))) ; Radians to Degrees
  )

  (if (or (null fx) (< fx 2))
    (setq fx  1
          px  (/ x1 2)
          pxa (+ (car p1) px)
    )
    (setq px  (/ x1 fx) ;width divided by fittings
          pxa (+ (car p1) (/ px 2.0)) ;divided by 2 plus X coord of P1
    )
  )
  (if (or (null fy) (< fy 2))
    (setq fy  1
          py  (/ y1 2)
          pya (+ (cadr p1) py)
    )
    (setq py  (/ y1 fy) ;length divide by fittings
          pya (+ (cadr p1) (/ py 2.0)) ;divided by 2 plus Y coord of P1
    )
  )


  ;; get block name , default name if enter only
  (setq block
         (getstring "\nEnter block name you wish to insert: <RC-Light> ")
  )
  (if (or (= block "") (null block)) ; use default name
    (setq block "RC-Light")
  )

  ;; - If block exists then go ahead
  (cond ((tblsearch "BLOCK" block)
         (setq osm (getvar "OSMODE"))
         (command "UNDO" "Begin")
         (setvar "OSMODE" 0)
         (setq elast (@cv_entlast))
         (setq newbies (ssadd)) ;empty selection set
         (command "-insert" block (list pxa pya) "1" "" 0)
         (setq eblk (@cv_entlast))
         (ssadd  eblk newbies)
         (command "ARRAY" eblk "" "RECTANGULAR" fy fx)
         (if (> fy 1)
           (command py)
         )
         (if (> fx 1)
           (command px)
         )
         (if (/= ang 0)
           (progn
             (setq e (if elast
                       (entnext elast)
                       (entnext)
                     )
             )
             (while e
               (ssadd e newbies)
               (setq e (entnext e))
             )

             (command ".rotate" newbies "" p1 ang)
           )
         )
         (command "UNDO" "End")
         (setvar "OSMODE" osm)
        )
        ;;  ELSE =====================================
        ((prompt (strcat "\n" block " Block not found."))
        )
  )
  (princ) ; clean exit
)


;;------------------------------------------------------------
;; Function to get the absolutely last entity in the database:
;;
(defun @cv_entlast (/ e elast)
  (setq elast (entlast))
  (while (setq e (entnext elast))
    (setq elast e)
  )
  elast
)
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
Help but please no code.
« Reply #45 on: April 12, 2004, 05:32:23 AM »
when I try to run it does everything up to the array command then i get the following error message.

Code: [Select]
Command: ARRAY
Select objects: <Bad Entity name: 7EF70F78>
RECTANGULAR 3 2 5000.000000000000 2500.000000000000 UNDO End
Select objects: *Cancel*


so what am I doing wrong?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Help but please no code.
« Reply #46 on: April 12, 2004, 08:11:27 AM »
Try this version.

Code: [Select]
(defun c:ltg (/ x1 y1 fx fy p1 px py block pxa pya osm newbies elast e ang eblk)
  (setq x1 (getdist "\nInput width of room along X Axis: "))
  (setq y1 (getdist "\nInput length of room along Y Axis: "))
  (setq fx (getint "\nInput No of fittings along X Axis: "))
  (setq fy (getint "\nInput No of Fittings along Y Axis: "))
  (setq p1 (getpoint "\nSelect the lower left hand corner: "))
  (setq ang (getangle p1 "\nSelect angle of room width (x-axis): <0>"))
  (if (null ang)
    (setq ang 0)
    (setq ang (* 180.0 (/ ang pi))) ; Radians to Degrees
  )

  (if (or (null fx) (< fx 2))
    (setq fx  1
          px  (/ x1 2)
          pxa (+ (car p1) px)
    )
    (setq px  (/ x1 fx) ;width divided by fittings
          pxa (+ (car p1) (/ px 2.0)) ;divided by 2 plus X coord of P1
    )
  )
  (if (or (null fy) (< fy 2))
    (setq fy  1
          py  (/ y1 2)
          pya (+ (cadr p1) py)
    )
    (setq py  (/ y1 fy) ;length divide by fittings
          pya (+ (cadr p1) (/ py 2.0)) ;divided by 2 plus Y coord of P1
    )
  )


  ;; get block name , default name if enter only
  (setq block
         (getstring "\nEnter block name you wish to insert: <RC-Light> ")
  )
  (if (or (= block "") (null block)) ; use default name
    (setq block "RC-Light")
  )

  ;; - If block exists then go ahead
  (cond ((tblsearch "BLOCK" block)
         (setq osm (getvar "OSMODE"))
         (command "UNDO" "Begin")
         (setvar "OSMODE" 0)
         (setq elast (@cv_entlast))
         (setq newbies (ssadd)) ;empty selection set
         (command "-insert" block (list pxa pya) "1" "" 0)
         (setq eblk (entlast))
         ;(setq eblk (@cv_entlast))
         (ssadd  eblk newbies)
         (command "ARRAY" eblk "" "RECTANGULAR" fy fx)
         (if (> fy 1) (command py))
         (if (> fx 1) (command px))
         (if (/= ang 0)
           (progn
             (setq e (if elast
                       (entnext elast)
                       (entnext)
                     )
             )
             (while e
               (ssadd e newbies)
               (setq e (entnext e))
             )

             (command ".rotate" newbies "" p1 ang)
           )
         )
         (command "UNDO" "End")
         (setvar "OSMODE" osm)
        )
        ;;  ELSE =====================================
        ((prompt (strcat "\n" block " Block not found."))
        )
  )
  (princ) ; clean exit
)


;;------------------------------------------------------------
;; Function to get the absolutely last entity in the database:
;;
(defun @cv_entlast (/ e elast)
  (setq elast (entlast))
  (while (setq e (entnext elast))
    (setq elast e)
  )
  elast
)
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
Help but please no code.
« Reply #47 on: April 12, 2004, 09:27:42 AM »
that works.

Excellent work.
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

hudster

  • Gator
  • Posts: 2848
Help but please no code.
« Reply #48 on: April 29, 2004, 05:57:29 AM »
Stage Two.

I want to include an option for lights being in a ceiling grid.

So I need to do the following.

1. Determine whether a ceiling grid is present.
2. Determine the size of the ceiling tiles.
3. work out the insertion point of the lights dependant on the insertion point of the grid, i.e. full tile or intersection at room center.
4. Insert the lights using the information gained from above.

any hints or ideas?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue