brawleyman Posted May 25, 2012 Posted May 25, 2012 I am trying to create a LISP routine that when a drawing opens and it isn't set to an approved scale on my list, it will alert the user and set the scale to the default 1/8". This is the portion that I have so far but cannot get it to work properly. I think I am needing mapcar or something, but it is Friday afternoon and I am dreaming of a 3 day weekend. I would like to get this finished before the end of the day. Thanks for any help! (setq approvedscales '(0.125 0.25 0.333 0.5 0.667 1 1.33 2 1.25 2.5 3.75 5 6.25 7.5 8.75 10 11.25 12.5)) (if (/= (getvar "dimscale") approvedscales) (progn (alert "No usable scale has been detected in this drawing!\nThis drawing has been set to the default 1/8\" scale.") (setq thehfscale "1/8") );end progn );end if Quote
BlackBox Posted May 25, 2012 Posted May 25, 2012 Consider the vl-Position Method. (if (vl-position (getvar 'dimscale) myDimScaleList) T nil ) Quote
pBe Posted May 26, 2012 Posted May 26, 2012 Another option: (if (member (getvar "dimscale") approvedscales) T nil ) Quote
brawleyman Posted May 29, 2012 Author Posted May 29, 2012 Thanks so much guys for the suggestions! I ended up using pBe's "member" format and it worked great! Quote
BlackBox Posted May 29, 2012 Posted May 29, 2012 (edited) Thanks so much guys for the suggestions! I ended up using pBe's "member" format and it worked great! FWIW - vl-Position is f a s t e r Sample code.... (setq dimScales '(0.125 0.25 0.333 0.5 0.667 1 1.33 2 1.25 2.5 3.75 5 6.25 7.5 8.75 10 11.25 12.5)) (defun _member ( dimScales ) (member (getvar "dimscale") dimScales) ) (defun _vl-position ( dimScales ) (vl-position (getvar 'dimscale) dimScales) ) (bench '( _member _vl-position ) (list dimScales) 10000) Speed test.... _MEMBER Elapsed: 62 Average: 0.0062 _VL-POSITION Elapsed: 31 Average: 0.0031 Edited May 29, 2012 by BlackBox Code revised Quote
Lee Mac Posted May 29, 2012 Posted May 29, 2012 Curious, why the: (if <something> t nil ) structure? Since any non-nil value is considered True, the IF statement becomes redundant, so the test can be simply: (defun _member ( dimScales ) (member (getvar 'dimscale) dimScales) ) Quote
BlackBox Posted May 29, 2012 Posted May 29, 2012 Curious, why the: (if <something> t nil ) structure? Since any non-nil value is considered True, the IF statement becomes redundant, so the test can be simply: (defun _member ( dimScales ) (member (getvar 'dimscale) dimScales) ) Simple answer... User error. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.