Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Close

Visual LISP, AutoLISP and General Customization

- Autodesk Community
- >
- AutoCAD Customization
- >
- Visual LISP, AutoLISP and General Customization
- >
- Polyline areas

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-23-2013 09:58 AM in reply to:
Kent1Cooper

Kent1Cooper wrote:But the same can be accomplished by having a rounding function that

onlyrounds up.

But it should

notround up if the starting value is an exact multiple. If the largest Polyline is 500 square units, with a divided value of 100, that shouldnotbe increased to 105, because the un-increased size of 100 will make a top category from 400 to 500, which will include the size of that largest Polyline.

Nice explanation Kent.

perhaps

(defun roundup (num near / v) (if (<= (setq v (* (fix (/ (+ num (/ near 2.0)) near)) near)) num ) (+ near v) v ) )

On the last code i posted . i tested the ** n** value multiplied by number of range if it encompass the max value , if not then add the extra range to

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-23-2013 10:55 AM in reply to:
pbejse

pbejse wrote:

...

perhaps

(defun roundup (num near / v) (if (<= (setq v (* (fix (/ (+ num (/ near 2.0)) near)) near)) num ) (+ near v) v ) )

On the last code i posted . i tested the

value multiplied by number of range if it encompass the max value , if not then add the extra range tonThe adding of the extra range will be done outside the rounding routine. Not sure how that approach fairs with straigth round-up only routine [posted snippet]n.

That's probably a little more work than needed, mostly because the whole *adding-half-the-nearest-multiple-number* thing is there specifically to make it round* either up or down*. Think of it in terms of rounding to the nearest *whole number* ['near' = 1], where a number with a .5 or greater decimal part should be rounded up, but with less than that should be rounded down. It adds .5 [half of 1] to the number, and uses (fix) to strip off any decimal portion from the result. So if the decimal component is .5 or more, adding .5 to it *sends it up to or above the next whole number*, and that's where (fix) leaves it. But if the decimal component is less than .5, adding .5 *leaves it still below that next whole number*, so (fix) takes it downward.

When you want to round* up only*, there's no purpose in messing around with half the value of the nearest-multiple number that way.

Here's the way it's done [split into more lines here] in my latest attached routine, after calculating 'areainc' as the *unrounded* quotient from dividing the largest area by the number of categories:

(setq areainc ; replacing previously calculated value

(if (= (rem areainc mult) 0); if it's an *exact multiple*

(fix areainc); then -- leave it alone

(* (1+ (fix (/ areainc mult))) mult); else -- round it up to the next-

; higher multiple; that is, round the number of times 'mult' goes

; into it *down*, then *add one*, and multiply that by 'mult'

); if

); setq

That's based on the use of *integers* for the nearest-multiple-of number [the 'mult' variable; in our examples, 5], and the resulting category sizes. But the same approach could be used with *non-integer* values. For instance, if you want to round something to the nearest multiple of 2.5 but upward only, you would use 2.5 for 'mult' and *omit the (fix) wrapper* in the 'then' argument:

(setq areainc

(if (= (rem areainc mult) 0); if it's an exact multiple

**areainc**; then -- leave it alone [*without* (fix)]

(* (1+ (fix (/ areainc mult))) mult); else -- round it up to the next-higher multiple

); if

); setq

So I think a simpler generic round-up-only-and-only-if-not-already-an-exact-mul

(defun roundup (num near)

(if (= (rem num near) 0)

num ; then [use (fix num) if dealing in integers only]

(* (1+ (fix (/ num near))) near); else

); if

); defun

Kent Cooper

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-24-2013 07:57 PM in reply to:
Kent1Cooper

Kent1Cooper wrote:

**When you want to round up only, there's no purpose in messing around with half the value of the nearest-multiple number** that way.

So I think a simpler generic round-up-only-and-only-if-not-already-an-exact-mul

(defun roundup (num near)

(if (= (rem num near) 0)

num ; then [use (fix num) if dealing in integers only]

(* (1+ (fix (/ num near))) near); else

); if

); defun

By george I think i got it. It took me a while to understand the reasoning behind the round-up, only after reading again your last post that it clicks.

Thank you for the lesson Kent. Math was never my greatest strength

Cheers

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-25-2013 01:10 AM in reply to:
sean.keohane

Thank you Pbejse and Kent. I haven't used your code yet but I had to thank you both for your help. I need to copy this down now and study it to come close to understanding it 'cause I sure don't understand it at first glance.( I've got the tortoise approach to lisp!)

Regards

Sean

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-25-2013 06:35 AM in reply to:
sean.keohane

sean.keohane wrote:Thank you Pbejse and Kent. I haven't used your code yet but I had to thank you both for your help. I need to copy this down now and study it to come close to understanding it 'cause I sure don't understand it at first glance.( I've got the tortoise approach to lisp!)

....

You're welcome -- use it in good health. I threw in some further EXPLanatory notes in the attached version, to help you understand what it's doing.

Kent Cooper

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-25-2013 06:50 AM in reply to:
pbejse

Hi Kent,

That is seriously cool to do that for me! You are a gentleman.

Best Regards

Sean

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements

Start with some of our most frequented solutions to get help installing your software.

Upgrading to a 2015 product? Make sure to check these out 1st!

- Privacy | Legal Notices & Trademarks | Report Noncompliance | Site map | © Copyright 2014 Autodesk Inc. All rights reserved

Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Please see the Autodesk Creative Commons FAQ for more information.