jason_a Posted May 13, 2016 Share Posted May 13, 2016 I'm having a problem getting a math equation to work within an ssget line of code.(highlighted in red). I'm trying to calculate the radius by using the AA diameter variable and dividing it by 2. My variables work further down in the routine (highlighted in blue) but I can't figure out the areas in red. Can anyone please help? Thanks. ; Find 5.0015mm hole and change to proper layer and 5mm diameter hole (setq AA 5.0015) (setq BB 5.0000) (if (ssget "_X" '((0 . "CIRCLE")(40 . [color="red"](/ AA 2)[/color]))) (progn (COMMAND "CHPROP" "P" "" "P" "LA" "VERTICAL15P00" "") (setq ss1 (ssget "_X" '((0 . "CIRCLE")(40 . [color="red"](/ AA 2)[/color])))) (setq LE (sslength ss1)) (setq CNT 0) (while (< CNT LE) (progn (setq OBJ (entget (ssname ss1 CNT))) (setq NewScale (* (cdr (assoc 40 OBJ)) [color="royalblue"](/ BB AA)[/color])) (setq OBJ (subst (cons 40 NewScale) (assoc 40 OBJ) OBJ )) (entmod OBJ) (setq CNT (+ CNT 1)) )))) Oh and I tried this too but didn't work either. ; Find 5.0015mm hole and change to proper layer and 5mm diameter hole (setq AA 5.0015) (setq BB 5.0000) (setq CC / AA 2) (if (ssget "_X" '((0 . "CIRCLE")[color="red"](40 . CC)[/color])) (progn (COMMAND "CHPROP" "P" "" "P" "LA" "VERTICAL15P00" "") (setq ss1 (ssget "_X" '((0 . "CIRCLE")[color="red"](40 . CC)[/color]))) (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)) )))) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 13, 2016 Share Posted May 13, 2016 Hi, A hint: (ssget "_X" (list '(0 . "CIRCLE")(cons 40 (/ AA 2.0)))) Quote Link to comment Share on other sites More sharing options...
jason_a Posted May 13, 2016 Author Share Posted May 13, 2016 Excellent, thank you very much! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 13, 2016 Share Posted May 13, 2016 Excellent, thank you very much! You are most welcome. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 13, 2016 Share Posted May 13, 2016 Why are you calculating the new radius when you already have the value you require? Quote Link to comment Share on other sites More sharing options...
jason_a Posted May 13, 2016 Author Share Posted May 13, 2016 Hi Lee, Because i'm not well versed in AutoLisp, my routines are usually a combination of my own limited lisp knowlege combined with snippets of code I copy and paste from my research on the net. I'm basically looking for specific sized holes, doing some layer management and then changing the diameter to what it should be. I searched the net looking for a routine that would change the diameter and the best thing I could find was the above code with the scaling function. There's definitely a better way to write the code, I just haven't figured it out yet. Because time is also tight, there's only so much time the higher ups at work will allow me to invest into thoroughly learning autolisp. Once I get it fine tuned, i'll be using it for many different sized holes, therefore the routine will be very long. It's for cnc purposes. There's a more thorough explanation of the routine in the previous post you helped me in. If there's a better way to find a specific hole diameter and changing it to a different hole diameter, i'd love to see it. Every little bit helps. Thanks again. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 13, 2016 Share Posted May 13, 2016 Because i'm not well versed in AutoLisp, my routines are usually a combination of my own limited lisp knowlege combined with snippets of code I copy and paste from my research on the net. I'm not particularly questioning your knowledge of AutoLISP (we all have to start somewhere), I was rather questioning the logic of multiplying the existing radius by some factor, as opposed to directly using the value that you require. To demonstrate why this seems odd, consider that your code is performing the following: "if there are circles with radius equal to 2.50075 then multiply 2.50075 by 2.5/2.50075 to yield 2.5 and set the radius to this value" Whereas, the code could equally be written: "if there are circles with radius equal to 2.50075 then set the radius to 2.5" I searched the net looking for a routine that would change the diameter and the best thing I could find was the above code with the scaling function. There's definitely a better way to write the code, I just haven't figured it out yet. If there's a better way to find a specific hole diameter and changing it to a different hole diameter, i'd love to see it. Every little bit helps. Thanks again. I've already provided an example here. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 14, 2016 Share Posted May 14, 2016 This question was asked a few days ago trying to find here it may have been at AUGI.com. My suggestion was to use a tolerance on the circle diameter and change input +-0.0001 25 and use a cond to check 24.9999 - 25.0001 etc Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 14, 2016 Share Posted May 14, 2016 Jason dont post twice this is a continuation of http://www.cadtutor.net/forum/showthread.php?96829-Lisp-routine-problem-with-if-statement Moderator please join. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 14, 2016 Share Posted May 14, 2016 In your other post you have actually given the very simple answer of how to do it and clarified exactly what it is your trying to do. If you posted that you would have had probably the answer in the 1st responce. Just take the value 8.0016 and use (fix dia) = 8 then (- dia (fix dia)) = 0.0016 multply by 10000 and you have 16 then its a simple check layer name exist or make a new one. The only rule is thickness must be a decimal there is various ways to retrieve the value 0.16 0.016 0.0016 all return 16. You can also put in place rules 8.2516 = 8.25 & 16 but this must be adhered to by all. example (strcat "VERTICAL" (rtos (* (-dia (fix dia)) 10000) 2 0) "P00") ="VERTICAL15P00" The one routine can search all circles and dia is not relevant in search criteria. Quote Link to comment Share on other sites More sharing options...
jason_a Posted May 14, 2016 Author Share Posted May 14, 2016 Basically this is what i'm shooting for. take hole diameter 8.0015 put on layer called VERTICAL 15P00 change diameter to 8 take hole diameter 8.0016 put on layer called VERTICAL 16P00 change diameter to 8 take hole diameter 8.0017 put on layer called VERTICAL 17P00 change diameter to 8 etc.. I don't fully grasp the answers but i'm giving it a shot come Monday when i'm back at work. Thanks again for everyone's help! Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 15, 2016 Share Posted May 15, 2016 This is close ran out of time to debug (vl-load-com) (defun mlayer (lay ) (vlax-for each lays (setq lname (vla-get-name each)) (if (= lname lay) (princ "\nLayer exists") (command "-layer" "N" lay "") ; add LT and colour ) ) ) (defun c:test ( / doc lays ss dia objc lay thick) (setq doc (vla-get-activedocument (vlax-get-acad-object)))(setq doc (vla-get-activedocument (vlax-get-acad-object))); open database (setq lays (vla-get-layers doc)) (setq ss (ssget "_X" '((0 . "CIRCLE")))) (repeat (setq x (sslength ss)) (setq objc (vlax-ename->vla-object (ssname ss (setq x (- x 1))))) (setq dia (vla-get-diameter objc)) (setq diat (fix dia)) ; true diameter as integer (setq thick (rtos (* (- dia diat) 10000.0) 2 0)) (if (/= "0" thick) ; dia is already an integer (progn (mlayer (strcat "VERTICAL" (rtos thick 2 0) "POO")) (vla-put-diameter objc diat) (vla-put-layer objc lay) ) ) ) ; repeat ) ; defun Quote Link to comment Share on other sites More sharing options...
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.