Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

More lisp issues

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
irishrandy26
379 Views, 13 Replies

More lisp issues

I am trying to model buildings for Title 24 compliance and I have to draw areas in AutoCAD to start this process. Anyway I am looking to create a simple lisp that would let me pick two points, select the direction on which I want to traw a box and then let me select a specified distance. Then it would draw a box based on that in the direction selected.

 

Any help on this would be great. I have started this process but haven't had time to get very far, now I have time again and am trying to push this command a little more.

 

(defun C:ad ()
(setq a (getpoint "\nEnter First Point : "))
(setq b (getpoint "\nEnter Second Point : "))
(command "Line" a b "")
)

13 REPLIES 13
Message 2 of 14
jggerth1
in reply to: irishrandy26

Set your UCS to that angle, then use the RECTANGLE command for the box, and AREA command to get area.

Message 3 of 14
irishrandy26
in reply to: jggerth1

Would you mind helping me with the actual lisp command to create this?

Message 4 of 14
Kent1Cooper
in reply to: irishrandy26


@irishrandy26 wrote:

... I am looking to create a simple lisp that would let me pick two points, select the direction on which I want to traw a box and then let me select a specified distance. Then it would draw a box based on that in the direction selected.

....


That can certainly be done without changing the UCS, but some questions:  Would the first two points define the direction and also the length along one pair of opposite sides of the box?  If not, I assume you would need to give two distances.  Or are you talking about a square box, so that one distance is enough?  Or would the first two points define the length but not the direction [since you say "select the direction" after "pick two points"]?  Also, the same size box can be built on either side of a given edge -- would the User need to pick a spot on the desired side?  If they're not easy to answer verbally, an image or sample drawing would be helpful.

Kent Cooper, AIA
Message 5 of 14
irishrandy26
in reply to: Kent1Cooper

The first two pick points would sugest the width of the area,

The second command would let you select the direction of the box by simply clicking your cursor in said direction

The third command would let you input the height of the room (ie.10'-0")

 

That is really all I need. I am new to creating lispertines and am trying to creat simple lisps first so I can start to understand it. Thank you for your time!

Message 6 of 14
Kent1Cooper
in reply to: irishrandy26


@irishrandy26 wrote:

The first two pick points would sugest the width of the area,

The second command would let you select the direction of the box by simply clicking your cursor in said direction

The third command would let you input the height of the room (ie.10'-0")

....


That suggests to me that you're talking about room sections.  If so, would the first two points always be on the floor, and at the same level, with the "direction" always upward?  That could be built in, so the User wouldn't need to select the direction.

 

(setq

  pt1 (getpoint "\nSelect one end of floor line: ")

  pt2 (getpoint pt1 "\nOther end: ")

  ht (getdist pt1 "\nRoom height: ")

); setq

(command "_.rectangle" pt1 (polar pt2 (/ pi 2) ht))

 

They can specify the room height by either picking a point relative to pt1 or typing in a value.

Kent Cooper, AIA
Message 7 of 14
irishrandy26
in reply to: Kent1Cooper

So this is what I have com eup with. But I am failing to get this to work...

 

 

(defun C:ad()
(setq
pt1 (getpoint "\nSelect one end of floor line: ")
pt2 (getpoint "\nOther End: ")
ht (getdist pt1 "\nRoom height: ")
😞
(setq
(command "_.rectangle" pt1 (polar pt2 (/ pi 2) ht)))

 

I took what you had and tried to impliment this in to my command. I want to be able to type "ad" to start the command.

Message 8 of 14
irishrandy26
in reply to: irishrandy26

And to answer your question, no the direction would change every time because with a standard square room you would have 4 boxes to draw. one for each side. if you have more angles and what not then it gets much more complicated. But I could still use this command.

Message 9 of 14
Kent1Cooper
in reply to: irishrandy26


@irishrandy26 wrote:

So this is what I have com eup with. But I am failing to get this to work...

 

 

(defun C:ad()
(setq
pt1 (getpoint "\nSelect one end of floor line: ")
pt2 (getpoint "\nOther End: ")
ht (getdist pt1 "\nRoom height: ")
):
(setq
(command "_.rectangle" pt1 (polar pt2 (/ pi 2) ht)))

 

I took what you had and tried to impliment this in to my command. I want to be able to type "ad" to start the command.


Here's the right way to format that [the blue parts above are off-kilter], including localizing the variables [it would work without that, but it's better to do it]:

(defun C:ad (/ pt1 pt2 ht)
  (setq
    pt1 (getpoint "\nSelect one end of floor line: ")
    pt2 (getpoint "\nOther End: ")
    ht (getdist pt1 "\nRoom height: ")
  ); setq
  (command "_.rectangle" pt1 (polar pt2 (/ pi 2) ht))

); defun

Kent Cooper, AIA
Message 10 of 14
Kent1Cooper
in reply to: irishrandy26

@irishrandy26 wrote:

And to answer your question, no the direction would change every time because with a standard square room you would have 4 boxes to draw. one for each side. if you have more angles and what not then it gets much more complicated. But I could still use this command.


Okay, so the boxes are apparently built outboard of the wall lines in plan view.  Here's a shot at one way of doing it:

 

(defun C:AD (/ pt1 pt2 ht lin1 lin2 ldata)
  (setq
    pt1 (getpoint "\nSelect one end of floor line: ")
    pt2 (getpoint pt1 "\nOther end: ")
    ht (getdist pt1 "\nRoom height: ")
  ); setq
  (command "_line" "_none" pt1 "_none" pt2 "")
  (setq lin1 (entlast))
  (command "_.offset" ht "@" (getpoint "\nSide on which to build box: ") "")
  (setq lin2 (entlast))
  (command
    "_.pline"
      "_none" pt1 "_width" 0 0 "_none" pt2
      "_none" (cdr (assoc 11 (setq ldata (entget lin2))))
      "_none" (cdr (assoc 10 ldata))
      "_close"
    "_.erase" lin1 lin2 ""
  ); command
); defun

It could be spruced up in various ways.  It could save the current Object-Snap mode(s), turn them off to avoid all those "_none" calls, and reset Osnap afterwards.  It could save and reset the current Polyline width [if non-zero] and/or Offset distance settings.  It could turn Ortho on and align the Snap angle with the first two points so that you can pick the room height as a point along a perpendicular axis from the wall line, even on non-orthogonal edges.  It could suppress echoing of the command prompts along the way.  It could have error handling added, so that it will reset anything it changes, and get rid of the temporary Lines, if you cancel before it gets to that.  It could be made to repeat automatically, so you can do multiple boxes in one running of the command.  It could save the ceiling height and offer it as a default on subsequent use.  It could offer some standard initial default ceiling height on first use.  It could allow for the selection of a Line or a Polyline line segment for a room edge, if your walls are drawn with those, in lieu of picking two points.  Etc., etc.

Kent Cooper, AIA
Message 11 of 14
irishrandy26
in reply to: Kent1Cooper

I hate to keep bugging you guys but I am now wanting to tweak this command now that I have had a little bit of time to mess around with it. I am wanting to add a layer for this to automatically be put on. My question is where do I input the command line for the layer in the lisp? I do know what to type, just unsure of where to place it.

 

Here is the lisp I am using;

 

(defun C:AD (/ pt1 pt2 ht lin1 lin2 ldata)
(setq
pt1 (getpoint "\nSelect one end of floor line: ")
pt2 (getpoint pt1 "\nOther end: ")
ht (getdist pt1 "\nRoom height: ")
); setq
(command "_line" "_none" pt1 "_none" pt2 "")
(setq lin1 (entlast))
(command "_.offset" ht "@" (getpoint "\nSide on which to build box: ") "")
(setq lin2 (entlast))
(command
"_.pline"
"_none" pt1 "_width" 0 0 "_none" pt2
"_none" (cdr (assoc 11 (setq ldata (entget lin2))))
"_none" (cdr (assoc 10 ldata))
"_close"
"_.erase" lin1 lin2 ""
); command
); defun

 

 

 

And what I want to add is;

 

(command "-layer" "s" "MP-AREA")

Message 12 of 14
irishrandy26
in reply to: irishrandy26

And then I also want to get the area of the "box" i had just created, but I want to put it in a "dtext" and be able to select where to place the text.

Message 13 of 14
Kent1Cooper
in reply to: irishrandy26


@irishrandy26 wrote:

.... I am wanting to add a layer for this to automatically be put on. My question is where do I input the command line for the layer in the lisp?

.... 

And what I want to add is;

 

(command "-layer" "s" "MP-AREA")


One way is to incorporate that Layer command within the same (command) function that draws the box and erases the temporary Lines [and you'll need an Enter to complete the Layer command]:

 

(command

  "_.layer" "_set" "MP-AREA" ""
  "_.pline"
....
  "_.erase" lin1 lin2 ""

  "_.layerp" ; if you want to set it back to what it was without needing to save that first
); command

 

It can also be done with

(setvar 'clayer "MP_AREA")

anywhere prior to the beginning of the (command) function.  You could still use Layerp to return it if you want, or save the current Layer when you start and reset it later -- that's the way to go if you decide to add an error handler, because it's the only way to ensure the Layer setting is returned if something goes wrong.

 

Or, you can use CHPROP after drawing the box, to change it to the desired Layer, rather than change the current Layer setting.  That has the advantage of not requiring any resetting:

 

(command
  "_.pline"
....
  "_.erase" lin1 lin2 ""

  "_.chprop" "_last" "" "_layer" "MP_AREA" ""
); command

Kent Cooper, AIA
Message 14 of 14
Kent1Cooper
in reply to: irishrandy26


@irishrandy26 wrote:

And then I also want to get the area of the "box" i had just created, but I want to put it in a "dtext" and be able to select where to place the text.


If you Search these Forums, and/or Cadalyst CAD Tips website, and/or probably lots of other places I'm less involved in such as The Swamp, you will find many routines to label the areas of Polylines, that you could incorporate.  Some will let you put the Text where you want, some will put it at the centroid or the center-of-bounding-box of the Polyline for you, and there are other variant possibilities.

 

[And by the way, there's no such thing as 'a "dtext"' as an entity type.  DTEXT is a command, almost completely obsolete now as being almost purely equivalent to the TEXT command for many years (there's only a tiny difference that I'm aware of -- it's a long story), but what it makes is just Text.]

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost