Kiko Posted February 1 Posted February 1 (edited) Hello, I'm a beginner in autocad, I got a plugin from a Korean colleague with this code. could someone advise me how to fix this plugin so that it rounds numbers up? ; ˝ĘÁřąý Çü˝ÄŔÇ °˘µµ¸¦ ¶óµđľČ Çü˝ÄŔ¸·Î şŻČÇĎ´Â ÇÔĽö (defun @dtr(&angle) (setq &angle (* pi (/ &angle 180.0)))) ; ¶óµđľČ Çü˝ÄŔÇ °˘µµ¸¦ ˝ĘÁřąý Çü˝ÄŔ¸·Î şŻČÇĎ´Â ÇÔĽö (defun @rtd(&angle) (setq &angle (* 180.0 (/ &angle pi)))) ; angle ÇÔĽö »çżë˝Ă °˘µµ şŻČŻŔÇ ąř°Ĺ·ÎżňŔ» ÇÇÇϱâ Ŕ§ÇŘ ¸¸µç ÇÔĽö (defun @angle(&pt1 &pt2) (@rtd (angle &pt1 &pt2))) ; polar ÇÔĽö »çżë˝Ă angleŔ» degree °˘µµ·Î ˝±°Ô ŔÔ·ÂÇϱâ Ŕ§ÇŘ ¸¸µç ÇÔĽö (defun @polar (&pt &angle &dist) (polar &pt (@dtr &angle) &dist)) ;¦Ł¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦¤ ;¦˘ˇá Ŭ¸ŻÇŃ µÎ Áˇ »çŔĚŔÇ °Ĺ¸®¸¦ ±¸ÇĎ°í ĂÖÁľ °á°ú°ŞŔ» Ăâ·ÂÇĎ´Â ÇÁ·Î±×·Ą ¦˘ ;¦˘ ˘ş ĽŇĽýÁˇŔÇ Ľöġ°ˇ 0.2 ŔĚÇĎŔÎ °ćżě ł»¸˛Ŕ¸·Î ÇĎ°í 0.8 ŔĚ»óŔÎ °ćżě żĂ¸˛Ŕ¸·Î ÇÔ ¦˘ ;¦˘ ÇĎÁö¸¸ 1ş¸´Ů ŔŰŔş 0.2 Áď, 200mm ŔĚÇĎŔÎ °ćżě 0Ŕ¸·Î ÇŇĽö´Â ľřŔ¸ąÇ·Î ±×´ë·Î 0.2·Î Ăâ·ÂµÇ°Ô ÇÔ ¦˘ ;¦˘ ˘ş ĂѰŸ®ŔÇ ÇŐŔĚ łŞĹ¸łŻ Ŕ§Äˇ¸¦ Ŭ¸ŻÇĎ¸é ±¸°Łş° °Ĺ¸®°ŞŔ» łŞĹ¸ł˝ ą®ŔÚŔÇ 1.5ąč Ĺ©±â·Î Ăâ·ÂµĘ ¦˘ ;¦¦¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦Ą (defun C:DD1(/ !layer !addtext !end !pt1 !pt2 !dist !text !sum !TextSize !ssadd) (setq !layer "¶óŔΰŸ®»ęĂâ") (if (tblsearch "layer" !layer) (setvar "clayer" !layer) (command "layer" "m" !layer "c" 7 !layer "") ) (command "-style" "°Ĺ¸®" "hyżď¸Şµµm" 0 1 0 "n" "n") ; ˝şĹ¸ŔĎ ŔŰĽş (setq !addtext "" !end "N" !sum 0 !TextSize (getvar "userr1") !ssadd (ssadd)) (if (= !TextSize 0) (setq !TextSize (getreal (strcat "\ną®ŔÚ Ĺ©±â¸¦ ŔÔ·ÂÇĎĽĽżä<" (rtos (getvar "userr1")) ">: "))) ) (setvar "userr1" !TextSize) (while (= !end "N") (initget 128) (setq !pt1 (getpoint (strcat "\ną®ŔÚ Ĺ©±â<" (rtos (getvar "userr1")) "> / ˝ĂŔŰÁˇ: "))) (if (= 'STR (type !pt1)) (progn (setq !TextSize (atof !pt1)) (setvar "userr1" !TextSize) (setq !pt1 (getpoint "\n˝ĂŔŰÁˇ: ")) ) ) (setq !pt2 (getpoint !pt1 "\n´ŮŔ˝Áˇ: ")) (while !pt2 (setq !dist (distance !pt1 !pt2)) (setq !text (rtos (/ !dist 1000.0) 2 1)) (if (<= (rem (atof !text) 1) 0.2) ; ĽŇĽýÁˇ ŔĚÇĎ Ľöġ°ˇ 0.2ş¸´Ů ŔŰ°ĹłŞ °°Ŕ» °ćżě (progn (if (<= (atof !text) 0.2) ; żř·ˇ°ŞŔĚ 0.2ş¸´Ů ŔŰ°ĹłŞ °°Ŕş °ćżě 0Ŕ¸·Î ÇĎ¸é ľČµÇąÇ·Î (setq !text (rtos (atof !text) 2 1)) ; ±¸ÇŘÁř °Ş ±×´ë·Î Ăâ·ÂµÇ°Ô ÇÔ (setq !text (rtos (atof !text) 2 0)) ; łŞ¸ÓÁöŔÇ °ćżěżˇ´Â Ľöġ¸¦ Ŕ߶ó Á¤Ľö·Î ¸¸µë(ł»¸˛ Čż°ú) ) (setq !addtext (strcat !addtext "+" !text)) ) (if (>= (rem (atof !text) 1) 0.8) ; ĽŇĽýÁˇ ŔĚÇĎ Ľöġ°ˇ 0.8ş¸´Ů Ĺ©°ĹłŞ °°Ŕ» °ćżě (progn (setq !text (rtos (+ (atoi !text) 1) 2 0)) ; ĽŇĽýÁˇ ŔĚÇĎ Ľöġ¸¦ ŔÚ¸Ł°í 1Ŕ» ´őÇŘ Á¤Ľö·Î ¸¸µë(żĂ¸˛ Čż°ú) (setq !addtext (strcat !addtext "+" !text)) ) (setq !addtext (strcat !addtext "+" !text)) ; Ŕ§ µÎ °ˇÁö °ćżěżˇ ÇŘ´çµÇÁö ľĘŔ» °ćżě ĽŇĽýÁˇ ŔĚÇϱîÁö ±¸ÇÔ ) ) (command "text" "m" (@polar !pt1 (@angle !pt1 !pt2) (/ !dist 2)) !TextSize 0 !text) (command "line" !pt1 !pt2 "") (setq !ssadd (ssadd (entlast) !ssadd)) (setq !sum (+ !sum (atof !text))) (setq !pt1 !pt2) (setq !pt2 (getpoint !pt1 "\n´ŮŔ˝Áˇ: ")) ) (setq !end (strcase (getstring "Áľ·áÇұîżä?(Y/N) <N>: "))) (if (= !end "") (progn (setq !end "N") (command "pedit" (entlast) "y" "j" !ssadd "" "w" (/ !TextSize 10.0) "x") ; lineŔ» pline °´ĂĽ·Î ąŮ˛Ů°í µÎ˛˛¸¦ ą®ŔÚ Ĺ©±âŔÇ 10şĐŔÇ 1·Î şŻ°ćÇÔ (setq !ssadd (ssadd)) ) ) ) (command "pedit" (entlast) "y" "j" !ssadd "" "w" (/ !TextSize 10.0) "x") (command "text" (getpoint "\n°á°ú°ŞŔ» Ăâ·ÂÇŇ Ŕ§Äˇ¸¦ Ŭ¸ŻÇĎĽĽżä: ") (* !TextSize 1.5) 0 (strcat (rtos !sum 2 2) " = " (substr !addtext 2))) ) ;¦Ł¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦¤ ;¦˘ˇá Ŭ¸ŻÇŃ µÎ Áˇ »çŔĚŔÇ °Ĺ¸®¸¦ ±¸ÇĎ°í ĂÖÁľ °á°ú°ŞŔ» Ăâ·ÂÇĎ´Â ÇÁ·Î±×·Ą ¦˘ ;¦˘ ˘ş DD1°ú ´Ţ¸® ĽŇĽýÁˇ ŔĚÇϱîÁö ¸đµç Ľöġ°ˇ ±×´ë·Î Ăâ·ÂµÇ°Ô ÇÔ ¦˘ ;¦˘ ˘ş ĂѰŸ®ŔÇ ÇŐŔĚ łŞĹ¸łŻ Ŕ§Äˇ¸¦ Ŭ¸ŻÇĎ¸é ±¸°Łş° °Ĺ¸®°ŞŔ» łŞĹ¸ł˝ ą®ŔÚŔÇ 1.5ąč Ĺ©±â·Î Ăâ·ÂµĘ ¦˘ ;¦¦¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦ˇ¦Ą (defun C:DD2(/ !addtext !end !pt1 !pt2 !dist !text !sum !TextSize !ssadd) (setq !layer "¶óŔΰŸ®»ęĂâ") (if (tblsearch "layer" !layer) (setvar "clayer" !layer) (command "layer" "m" !layer "c" 7 !layer "") ) (command "-style" "°Ĺ¸®" "hyżď¸Şµµm" 0 1 0 "n" "n") ; ˝şĹ¸ŔĎ ŔŰĽş (setq !addtext "" !end "N" !sum 0 !TextSize (getvar "userr1") !ssadd (ssadd)) (if (= !TextSize 0) (setq !TextSize (getreal (strcat "\ną®ŔÚ Ĺ©±â¸¦ ŔÔ·ÂÇĎĽĽżä<" (rtos (getvar "userr1")) ">: "))) ) (setvar "userr1" !TextSize) (while (= !end "N") (initget 128) (setq !pt1 (getpoint (strcat "\ną®ŔÚ Ĺ©±â<" (rtos (getvar "userr1")) "> / ˝ĂŔŰÁˇ: "))) (if (= 'STR (type !pt1)) (progn (setq !TextSize (atof !pt1)) (setvar "userr1" !TextSize) (setq !pt1 (getpoint "\n˝ĂŔŰÁˇ: ")) ) ) (setq !pt2 (getpoint !pt1 "\n´ŮŔ˝Áˇ: ")) (while !pt2 (setq !dist (distance !pt1 !pt2)) (setq !text (rtos (/ !dist 1000.0) 2 1)) (setq !addtext (strcat !addtext "+" !text)) (command "text" "m" (@polar !pt1 (@angle !pt1 !pt2) (/ !dist 2)) !TextSize 0 !text) (command "line" !pt1 !pt2 "") (setq !ssadd (ssadd (entlast) !ssadd)) (setq !sum (+ !sum (atof !text))) (setq !pt1 !pt2) (setq !pt2 (getpoint !pt1 "\n´ŮŔ˝Áˇ: ")) ) (setq !end (strcase (getstring "Áľ·áÇұîżä?(Y/N) <N>: "))) (if (= !end "") (progn (setq !end "N") (command "pedit" (entlast) "y" "j" !ssadd "" "w" (/ !TextSize 10.0) "x") ; lineŔ» pline °´ĂĽ·Î ąŮ˛Ů°í µÎ˛˛¸¦ ą®ŔÚ Ĺ©±âŔÇ 10şĐŔÇ 1·Î şŻ°ćÇÔ (setq !ssadd (ssadd)) ) ) ) (command "pedit" (entlast) "y" "j" !ssadd "" "w" (/ !TextSize 10.0) "x") (command "text" (getpoint "\n°á°ú°ŞŔ» Ăâ·ÂÇŇ Ŕ§Äˇ¸¦ Ŭ¸ŻÇĎĽĽżä: ") (* !TextSize 1.5) 0 (strcat (rtos !sum 2 2) " = " (substr !addtext 2))) ) Edited February 1 by SLW210 Added Code Tags! Quote
SLW210 Posted February 1 Posted February 1 Please use Code Tags in the future. (click the <> in the editor toolbar) Quote
pkenewell Posted February 1 Posted February 1 @Kiko What value to you want to roundup ? The "SUM" value? If so, Add Lee Mac's (LM:roundup) function to the end of the file: ;; Round Up - Lee Mac ;; Rounds 'n' up to the nearest 'm' ;; https://www.lee-mac.com/round.html#roundupm (defun LM:roundup ( n m ) ((lambda ( r ) (cond ((equal 0.0 r 1e-8) n) ((< n 0) (- n r)) ((+ n (- m r))))) (rem n m)) ) Then add this after line #151; insert a line just before the line that starts with (command "pedit" (entlast) "y" "j"... ;; round the sum up to the nearest whole number. Change 2nd value to desired round value if different (setq !sum (LM:roundup !sum 1.0)) Let me know if this is want you intended. PLEASE NOTE: I recommend you get permission for making alterations with your Korean friend author before doing so. Quote
Kiko Posted February 1 Author Posted February 1 (edited) @pkenewell yes i have permission with the fact that he gave it to me that I can't figure out how to round it up. Edited February 1 by Kiko Quote
pkenewell Posted February 1 Posted February 1 1 hour ago, Kiko said: @pkenewell yes i have permission with the fact that he gave it to me that I can't figure out how to round it up. @Kiko I gave you a solution - did you try it? Quote
pkenewell Posted February 2 Posted February 2 @Kiko Thanks - I am glad it worked for you! 22 hours ago, Kiko said: yes i have permission with the fact that he gave it to me FYI - just because an author gives you code does not mean that you have permission to edit it, redistributed it, etc. Many Authors give their code freely here, but some also expect that the code remain unaltered, and with original comments and authorship intact unless they give expressed permission to do so. I have learned that from experience. 1 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.