Jump to content

ssget radius within a range


jason_a

Recommended Posts

Hello,

 

I currently have a lisp routine that will look for a specific sized hole and change it to a different diameter. It also performs some layer management. I'm having a bit of trouble trying to modify the routine so that it will look for a range instead of a specific value. So in my case, i'd like to look for any holes that are between 5.1 to 5.3mm in diameter and change them to 5.0mm.

 

Thank you.

 


; Find 5.1mm hole and change to proper layer and 5mm diameter hole
(setq AA 5.1)
(setq BB 5.0000)
(if 
(ssget "_X" (list '(0 . "CIRCLE")(cons 40 (/ AA 2.0))))
(progn
(COMMAND "CHPROP" "P" "" "P" "LA" "VERTICAL15P00" "")
(setq ss1 (ssget "_X" (list '(0 . "CIRCLE")(cons 40 (/ AA 2.0)))))
(setq LE (sslength ss1))
(setq CNT 0)
(while (< CNT LE)
(progn
(setq OBJ (entget (ssname ss1 CNT)))
(setq NewScale (* (cdr (assoc 40 OBJ)) (/ BB AA)))
(setq OBJ (subst (cons 40 NewScale) (assoc 40 OBJ) OBJ ))
(entmod OBJ)
(setq CNT (+ CNT 1))
))))

Link to comment
Share on other sites

Try Changing

 

 

(setq AA 5.1)

to

(setq AA 5.1 AB 5.3)

and

(ssget "_X" (list '(0 . "CIRCLE")(cons 40 (/ AA 2.0))))

to

(ssget "_X" (list '(0 . "CIRCLE") '(-4 . "<OR") (cons 40 (/ AA 2.0)) (cons 40 (/ AB 2)) '(-4 . "OR>")))

CORRECTION: If you want to select the full range between AA and AB, it would be the following:

(ssget "_X" (list '(0 . "CIRCLE")
                   '(-4 . "<AND")
                      '(-4 . ">=") (cons 40 (/ AA 2.0))
                      '(-4 . "<=") (cons 40 (/ AB 2))
                   '(-4 . "AND>")
                ))

I'm not sure what you are doing here also but it would need to be changed I think:

(setq NewScale (* (cdr (assoc 40 OBJ)) (/ BB AA)))

based on your original description, would you not just want to do this?

(setq NewScale (/ BB 2))

Here is what I recommend for you code:

(setq AA 5.1 AB 5.3 BB 5.0 lyr "VERTICAL15P00")
(if (setq ss1 (ssget "_X"
                (list '(0 . "CIRCLE")
                   '(-4 . "<AND")
                      '(-4 . ">=") (cons 40 (/ AA 2.0))
                      '(-4 . "<=") (cons 40 (/ AB 2))
                   '(-4 . "AND>")
                )))
  (progn
     (setq LE (sslength ss1) CNT 0)
     (while (< CNT LE)
        (progn
           (setq OBJ (entget (ssname ss1 CNT))
                 OBJ (subst (cons 40 (/ bb 2)) (assoc 40 OBJ) OBJ) ; Change Radius
                 OBJ (subst (cons 8 lyr) (assoc 8 OBJ) OBJ) ;Change Layer Name
                 CNT (1+ CNT)
           )
           (entmod OBJ)
        )
     )
  )
)

 

 

EDIT: OOPS - I got the logic wrong so I am changing this to be helpful for someone else in the future.

Edited by pkenewell
Link to comment
Share on other sites

Thank you, this almost works as intended based on your code. The only problem is that it is converting all sized holes in the drawing, not just the ones within the range. So anything outside of the range is also affected. Any ideas?

 

EDIT.

 

I changed the OR functions to AND. Also added a few more lines of code. Seems to be working now. Thanks for your help!

 

; Find 5.1mm hole and change to proper layer and 5mm diameter hole
(setq AA 5.1 AB 5.3)
(setq BB 5.0000)
(if 
(ssget "_X" (list '(0 . "CIRCLE")
                   '(-4 . "<AND")
                      '(-4 . ">=") (cons 40 (/ AA 2.0))
                      '(-4 . "<=") (cons 40 (/ AB 2.0))
                   '(-4 . "AND>")
                ))
(progn
(COMMAND "CHPROP" "P" "" "P" "LA" "VERTICAL15P00" "")
(setq ss1 (ssget "_X" (list '(0 . "CIRCLE")
                   '(-4 . "<AND")
                      '(-4 . ">=") (cons 40 (/ AA 2.0))
                      '(-4 . "<=") (cons 40 (/ AB 2.0))
                   '(-4 . "AND>")
                )))
(setq LE (sslength ss1))
(setq CNT 0)
(while (< CNT LE)
(progn
(setq OBJ (entget (ssname ss1 CNT)))
(setq NewScale (/ BB 2))
(setq OBJ (subst (cons 40 NewScale) (assoc 40 OBJ) OBJ ))
(entmod OBJ)
(setq CNT (+ CNT 1))
))))

Edited by jason_a
Link to comment
Share on other sites

I changed the OR functions to AND. Also added a few more lines of code. Seems to be working now. Thanks for your help!

 

 

Oops - Well I am glad you figured out the logic. Glad to have helped.

 

 

BTW. Did you notice in my code that I eliminated the need for 2 SSGET calls and the CHPROP command? The 2nd SSGET call is not necessary as you can save the selection set on your first call. Also - unless CHPROP does something else for you besides changing the layer name of the Circles, it is better to avoid the command call for something so simple.

Link to comment
Share on other sites

Yes I now notice the elimination of the CHPROP command in your lisp routine. I've now incorporated your snippet of code into mine. As for the two ssget calls, i've kept them seperated just so it's easier for me to read and edit as I copy and expand the code to cover more hole sizes. Thanks again!

 

; Find holes in 4.8mm-5.3mm diameter range, convert to 5mm diameter and change to proper layer
(setq AA 4.8 AB 5.3) ;Diameter range
(setq BB 5.0 lyr "VERTICAL15P00") ;New diameter and layer name
(if 
(ssget "_X" (list '(0 . "CIRCLE")
                   '(-4 . "<AND")
                      '(-4 . ">=") (cons 40 (/ AA 2.0))
                      '(-4 . "<=") (cons 40 (/ AB 2.0))
                   '(-4 . "AND>")
                ))
(progn
(setq ss1 (ssget "_X" (list '(0 . "CIRCLE")
                   '(-4 . "<AND")
                      '(-4 . ">=") (cons 40 (/ AA 2.0)) ; greater than or equal to
                      '(-4 . "<=") (cons 40 (/ AB 2.0)) ; less than or equal to
                   '(-4 . "AND>")
                )))
(setq LE (sslength ss1))
(setq CNT 0)
(while (< CNT LE)
 (progn
     (setq LE (sslength ss1) CNT 0)
     (while (< CNT LE)
        (progn
           (setq OBJ (entget (ssname ss1 CNT))
                 OBJ (subst (cons 40 (/ BB 2)) (assoc 40 OBJ) OBJ) ; Change Radius
                 OBJ (subst (cons 8 lyr) (assoc 8 OBJ) OBJ) ; Change Layer Name
                 CNT (1+ CNT)
           )
           (entmod OBJ)
        )
     )
  ))))

Link to comment
Share on other sites

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