Author Topic: Here's a good challenge for ya  (Read 3340 times)

0 Members and 1 Guest are viewing this topic.

Andrew H

  • Guest
Here's a good challenge for ya
« on: August 02, 2004, 11:50:13 AM »
Needed...

Lisp that will calculate the percentage of one area to another.

Example...
I have the overall property lines at 50'-0" x 143'-0" and need to calculate the area of the roof in relation to the area of the overall property. (roof area approximately 3085.1551 sqft)

Let me know what additional information you need.

sinc

  • Guest
Here's a good challenge for ya
« Reply #1 on: August 02, 2004, 12:00:39 PM »
Isn't it just:

percentCoverage = (* (/ areaRoof areaProperty) 100)

If you need to do more complex calculations, you can check into the cal routine...

Andrew H

  • Guest
Here's a good challenge for ya
« Reply #2 on: August 02, 2004, 12:11:41 PM »
That is the correct calculation, but how do I get that in a lisp, so that I can select the pl of one area, then the pl of the other area and have it dump the 42.99867735% to the screen?

I don't need to know what the actual areas are, I just need the percentage.

Would it be along the lines of...
in the lisp invoke the area command with the "object" option selected (labeled as the "Roof Area"). Multiple that number by 100. Then re-invoke the area command with the "object" options selected (labeled "Property Area"). Then divide the property area from the recalculated roof area and have the answer dumped onto the screen ending in "%".

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Here's a good challenge for ya
« Reply #3 on: August 02, 2004, 12:33:00 PM »
Code: [Select]

(defun c:funcname (/ ent roof_area lot_area ans)
(if (setq ent (car (entsel "\nSelect roof line: ")))
  (command "_.area" "Object" ent)
  (exit)
  )

(setq roof_area (getvar 'area))


(if (setq ent (car (entsel "\nSelect property line: ")))
  (command "_.area" "Object" ent)
  (exit)
  )

(setq lot_area (getvar 'area)
 ans (* (/ roof_area lot_area) 100)
 )
  (princ (strcat "Answer: "(rtos ans) "%"))
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Here's a good challenge for ya
« Reply #4 on: August 02, 2004, 12:34:48 PM »
Code: [Select]

(defun c:funcname (/ ent roof_area lot_area ans)
(if (setq ent (car (entsel "\nSelect roof line: ")))
  (command "_.area" "Object" ent)
  (exit)
  )

(setq roof_area (getvar 'area))


(if (setq ent (car (entsel "\nSelect property line: ")))
  (command "_.area" "Object" ent)
  (exit)
  )

(setq lot_area (getvar 'area)
 ans (* (/ roof_area lot_area) 100)
 )
  (princ (strcat "Answer: "(rtos ans) "%"))
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

Andrew H

  • Guest
Here's a good challenge for ya
« Reply #5 on: August 02, 2004, 12:46:52 PM »
Mark,

The lisp works great. But one suggetion. If the units are set to "Architectural" then it returns the % as 4'-8"%. Is there a way to store the current units setting before the lisp starts, change the units to "Decimal" then restore the original setting after the lisp has dumped the answer to the screen?

As always thank you for the help.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Here's a good challenge for ya
« Reply #6 on: August 02, 2004, 01:03:29 PM »
Sure. just change the line
(princ (strcat "Answer: "(rtos ans) "%"))
to
(princ (strcat "Answer: "(rtos ans 2 4) "%"))
TheSwamp.org  (serving the CAD community since 2003)

Andrew H

  • Guest
Here's a good challenge for ya
« Reply #7 on: August 02, 2004, 01:06:30 PM »
Worked perfectly. Thanks yet again for your help.