Jump to content

Recommended Posts

Posted

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

Posted

Consider the vl-Position Method.

 

(if (vl-position (getvar 'dimscale) myDimScaleList)
 T
 nil
 )

Posted

Another option:

 (if (member (getvar "dimscale") approvedscales)
     T
     nil
     )

Posted

Thanks so much guys for the suggestions! I ended up using pBe's "member" format and it worked great!

Posted (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 :thumbsup:

 

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

:geek:

Edited by BlackBox
Code revised
Posted

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)
)

Posted
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. :lol:

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...