PDA

View Full Version : Calculating Wall Heights


imblueflies
2005-10-20, 06:50 PM
Hello all,

I have learned a lot about lisp from this site but I've wasted too much time trying to get this last bit of my routine to work and I'm asking for help.

We have callouts that have a top of wall elevation above and a finish grade or finish surface grade below and then below that we callout the height of the wall based on those two numbers. For example...

1505.27 T.W.
--------------------
1501.12 F.S.
H=4.15'

My lisp asks the user to select the TW elevation, then the FS, then the H= text object. It then (I think somewhere in there) calculates the difference which should then be placed in the H= text object. I can't get it to place the calculated height into that last H= text object. I've cut and pasted so much code yesterday that I think I confused myself. I need this lisp to work on text objects for now, I'll get our blocks fixed up some more and then try to do this again for blocks later. FYI, the "T.W." and "F.S." are separate text objects so you can just disregard them. Sometimes we change our grades afterwards and so I'd like it to be able to just replace whatever values are currently in the H= object with the new height and somehow put "H=" in front of the value and the feet symbol (') after the value.

Any help is greatly appreciated, thanks!!

Opie
2005-10-20, 07:25 PM
You will need to change your real or integer values to strings to place them into objects containing string values. Look into rtos for real numbers and itoa for integer numbers. These two functions convert numbers to strings. There are other number to string functions you might want to look into for other applications.

imblueflies
2005-10-20, 07:30 PM
You will need to change your real or integer values to strings to place them into objects containing string values. Look into rtos for real numbers and itoa for integer numbers. These two functions convert numbers to strings. There are other number to string functions you might want to look into for other applications.

Thanks Richard, I'll read some more about those functions. What functions do I need to make the swap and replace whatever H= says with the new calculated wall height value?

CAB2k
2005-10-20, 07:47 PM
This will get you started.
;;CURRENT ORDER OF OPERATIONS
;;
;;Select Top of Wall elevation
;;Select FS or FG elevation
;;Select the existing wall height text object
;;Select where to place wall height


;;If there are any ways to streamline this code I'm open to suggestions


(defun c:wallh ()

(cond
((not
(and ; skip if any are nil
(setq topofwall (nentsel "\nSelect Top of Wall Elevation: "))
(setq list1 (entget (car topofwall)))
(setq TW (cdr (assoc 1 list1)))
(wcmatch TW "*TW*") ; string contains this, case sensitive
)
)
(alert "Error TW not found")
)

((not
(and ; skip if any are nil
(setq grade (nentsel "\nSelect FS or FG Elevation: "))
(setq list2 (entget (car grade)))
(setq FG (cdr (assoc 1 list2)))
(wcmatch FG "*FG*") ; string contains this, case sensitive
)
)
(alert "Error FG not found")
)

((not (and
(setq extext (nentsel "\nSelect TEXT object to place height in: "))
(setq list3 (entget (car extext)))
(setq H (cdr (assoc 1 list3)))
(wcmatch H "*H=*") ; string contains this, case sensitive
)
)
(alert "Error H= not found")

)
)

(if (and TW FG H)
(progn ; all were (not nil) so ok to proceed
(setq FGNum (atof FG))
(setq TWNum (atof TW))
(setq newH (strcat "H=" (rtos (- TWnum FGnum)))) ; change to string
;; read up on rtos and distof format options

(setq ed2 (subst (cons 1 newH) (assoc 1 list3) list3)) ; subst newitem olditem lst)
(entmod ed2)
)
)

(princ)
)

imblueflies
2005-10-20, 08:02 PM
Thanks for the quick reply ab2draft (sorry, don't know you're name). I took out the lines that used the wcmatch functions because they were looking for "TW" but as I mentioned before, the "T.W." and "F.S." are separate text entities. After taking those lines out it worked great. I just added the symbol for feet to the end of this line:

(setq newH (strcat "H=" (rtos (- TWnum FGnum))"'"))

It works great now! Thanks again.

CAB2k
2005-10-20, 08:21 PM
Glad it worked for you.
You should leave the wcmatch lines in there just change to this

(wcmatch TW "*T.W.*")

and

(wcmatch FG "*F.G.*")

it will keep the user honest.

If there is a chance lower case is used "t.w.)
use this
(wcmatch (strcase TW) "*T.W.*")

(wcmatch (strcase FG) "*F.G.*")

make sure you look at the distof function too. :)

Alan

imblueflies
2005-10-21, 01:07 AM
I did check out the distof function, I was not aware of that before but it looks very usefull for some other ideas I have in the future.

In regards to the TW and FG's, I had to take them out because the TW and/or FG are not in the same text string as the elevation so the error message would pop up every time. See the attached reference drawing to see what I mean. Use the lisp file you gave me and I think understand better. The object in the reference drawing used to be a block but sometimes it just doesn't display properly so most of the time our TW/FG callouts are exploded and that separates the elevation from the TW or FG. I've been using this lisp so much today, it's nice to get something done for a change. I can't thank you enough for your help on this.

imblueflies
2005-10-25, 05:19 AM
Here is the final wall height lisp routine for anyone else who might find it usefull. Thank you to all who helped me through it.

CAB2k
2005-10-25, 05:51 AM
Good job.

One more thing to consider, if the FG & TW are picked out of order the
result will be a negative number. You can compensate for that with this.

(setq newH (strcat "H=" (rtos (abs (- TWnum FGnum)))"'")) ; change to string

imblueflies
2005-10-25, 06:23 PM
Thanks for that little update, I was wondering about that. Now it makes it easier for my drafters to get good results no matter how they pick the numbers.