harimaddddy Posted November 10 Posted November 10 (edited) ;crank value based on bar dia only (defun c:Z1 ( / s p a q r below-dia above-dia z cushion k-multiplier) ;; Define bar diameters within the command (setq diameters '((3 . 0.375) (4 . 0.5) (5 . 0.625) (6 . 0.75) (7 . 0.875) (8 . 1.0) (9 . 1.270) (10 . 1.310))) ;; Helper function to get diameter value based on input key (defun get-diameter-value (key) (cdr (assoc key diameters))) ;; Define default values if not previously set (if (not (boundp 'crank:prev-below)) (setq crank:prev-below 8)) (if (not (boundp 'crank:prev-above)) (setq crank:prev-above 4)) (if (not (boundp 'crank:prev-z)) (setq crank:prev-z 0)) ; Length of extension (if (not (boundp 'crank:prev-multiplier)) (setq crank:prev-multiplier 6)) ; Default K multiplier ;; 1. Set the K multiplier (setq k-multiplier (getint (strcat "\nEnter Crank Ratio <" (rtos crank:prev-multiplier 2 0) ">: ")) k-multiplier (if k-multiplier k-multiplier crank:prev-multiplier)) ;; Store the multiplier for future use (setq crank:prev-multiplier k-multiplier) ;; 2. Prompt for below and above level bar numbers (3-10) with previous values as defaults (setq below-dia (getint (strcat "\nSpecify below level bar number (3-10) <" (itoa crank:prev-below) ">: ")) below-dia (if below-dia below-dia crank:prev-below)) (setq above-dia (getint (strcat "\nSpecify above level bar number (3-10) <" (itoa crank:prev-above) ">: ")) above-dia (if above-dia above-dia crank:prev-above)) ;; Display warning if any of the bar diameters is below 5 (if (or (< below-dia 5) (< above-dia 5)) (progn (princ "\nWarning: #5 vert. is minimum for Column.") (princ "\nPlease consult your TL (Team Leader) if bar dia is below 5."))) ;; Store the current values as previous values (setq crank:prev-below below-dia crank:prev-above above-dia) ;; 3. Calculate H and K with cushion value and the user-defined multiplier for K (setq cushion 0.25) (setq crank:prev-y (+ (get-diameter-value below-dia) (get-diameter-value above-dia) cushion)) ; H Distance (setq crank:prev-x (* crank:prev-y k-multiplier)) ; K Distance using multiplier ;; Display current H and K values (print (strcat "*** Calculated H Distance is " (rtos crank:prev-y 2 2) "***")) (print (strcat "*** Calculated K Distance is " (rtos crank:prev-x 2 2) "***")) ;; 4. Get length of extension (setq z (if (= nil (setq z (getreal (strcat "\nSpecify length of extension <" (rtos crank:prev-z 2 2) ">: ")))) crank:prev-z z)) ;; Store the extension value for next time (setq crank:prev-z z) ;; Prompt user for line selection and calculate points (if (and (setq s (entsel "\nSelect line close to end: ")) (setq p (osnap (cadr s) "end")) (setq a (angle (osnap (cadr s) "nea") p)) (setq q (polar (polar p a crank:prev-x) (+ a (/ pi 2)) crank:prev-y)) (setq r (polar q a z))) ;; Create polyline (progn (command "_.pline" "_non" p "_non" q "_non" r "") ;; Join the original line with the new polyline (initcommandversion) (command "_.join" (car s) "_l" ""))) ;; Exit gracefully (princ) ) ;Crank with user given value (defun c:Z2 ( / s p a y x z q r) ;; Define global variables to store previous values (if (not (boundp 'crank:prev-y)) (setq crank:prev-y 0)) (if (not (boundp 'crank:prev-x)) (setq crank:prev-x 0)) (if (not (boundp 'crank:prev-z)) (setq crank:prev-z 0)) ;; Display current values (print (strcat "*** Current H Distance is " (rtos crank:prev-y 4 2) "***")) (print (strcat "*** Current k Distance is " (rtos crank:prev-x 4 2) "***")) (print (strcat "*** Current Length of Extension is " (rtos crank:prev-z 4 2) "***")) ;; Prompt user for line selection (if (and (setq s (entsel "\nSelect line close to end: ")) (setq p (osnap (cadr s) "end")) (setq a (angle (osnap (cadr s) "nea") p)) ;; Get perpendicular distance ;; Use previous value if Enter is pressed (setq y (if (= nil (setq y (getreal (strcat "\nSpecify H distance <" (rtos crank:prev-y 2 2) ">: ")))) crank:prev-y y)) ;; Get tangent distance ;; Use previous value if Enter is pressed (setq x (if (= nil (setq x (getreal (strcat "\nSpecify K distance <" (rtos crank:prev-x 2 2) ">: ")))) crank:prev-x x)) ;; Get length of extension ;; Use previous value if Enter is pressed (setq z (if (= nil (setq z (getreal (strcat "\nSpecify length of extension <" (rtos crank:prev-z 2 2) ">: ")))) crank:prev-z z)) ;; Calculate points (setq q (polar (polar p a x) (+ a (/ pi 2)) y)) (setq r (polar q a z))) ;; Store entered values for next time (progn ;; Only update stored values if new values were provided ;; This ensures we keep the last used values if Enter was pressed. (if (/= y crank:prev-y) (setq crank:prev-y y)) (if (/= x crank:prev-x) (setq crank:prev-x x)) (if (/= z crank:prev-z) (setq crank:prev-z z)) ;; Create polyline (command "_.pline" "_non" p "_non" q "_non" r "") ;; Join the original line with the new polyline (initcommandversion) (command "_.join" (car s) "_l" ""))) ;; Exit gracefully (princ) ) ;bar dia with offset (defun c:Z3 ( / diameters below-dia above-dia h k z offset multiplier cushion p a q r s) ;; Define the bar diameters within the command (setq diameters '((3 . 0.375) (4 . 0.5) (5 . 0.625) (6 . 0.75) (7 . 0.875) (8 . 1.0) (9 . 1.27) (10 . 1.31))) ;; Retrieve previous values or set defaults (if (not (boundp 'crank:prev-multiplier)) (setq crank:prev-multiplier 6)) (if (not (boundp 'crank:prev-below)) (setq crank:prev-below 8)) (if (not (boundp 'crank:prev-above)) (setq crank:prev-above 4)) (if (not (boundp 'crank:prev-offset)) (setq crank:prev-offset 0.0)) (if (not (boundp 'crank:prev-z)) (setq crank:prev-z 36.0)) ;; 1. Prompt for multiplier for K, with previous as default (setq multiplier (getreal (strcat "\nSpecify Crank Ratio <" (rtos crank:prev-multiplier 2 2) ">: ")) multiplier (if multiplier multiplier crank:prev-multiplier)) ;; Store multiplier for future use (setq crank:prev-multiplier multiplier) ;; 2. Prompt for below bar diameter with default (setq below-dia (getint (strcat "\nSpecify below level bar number (3-10) <" (itoa crank:prev-below) ">: ")) below-dia (if below-dia below-dia crank:prev-below)) ;; 3. Prompt for above bar diameter with default (setq above-dia (getint (strcat "\nSpecify above level bar number (3-10) <" (itoa crank:prev-above) ">: ")) above-dia (if above-dia above-dia crank:prev-above)) ;; Display warning if any of the bar diameters is below 5 (if (or (< below-dia 5) (< above-dia 5)) (progn (princ "\nWarning: #5 vert. is minimum for Column.") (princ "\nPlease consult your TL (Team Leader) if bar dia is below 5."))) ;; Store current bar values for next use (setq crank:prev-below below-dia) (setq crank:prev-above above-dia) ;; 4. Get offset value with default (setq offset (getreal (strcat "\nSpecify additional offset for H distance <" (rtos crank:prev-offset 2 2) ">: ")) offset (if offset offset crank:prev-offset)) ;; Store offset for future use (setq crank:prev-offset offset) ;; 5. Get length of extension with default (setq z (getreal (strcat "\nSpecify length of extension <" (rtos crank:prev-z 2 2) ">: ")) z (if z z crank:prev-z)) ;; Store length of extension for next use (setq crank:prev-z z) ;; Calculate H and K values (setq cushion 0.25) (setq h (+ (cdr (assoc below-dia diameters)) (cdr (assoc above-dia diameters)) cushion offset)) (setq k (* h multiplier)) ;; Display calculated H and K values (print (strcat "*** Calculated H Distance is " (rtos h 2 2) "***")) (print (strcat "*** Calculated K Distance is " (rtos k 2 2) "***")) ;; Prompt user for line selection and calculate points (setq s (entsel "\nSelect line close to end: ")) (if (and s (setq p (osnap (cadr s) "end")) (setq a (angle (osnap (cadr s) "nea") p))) (progn ;; Calculate the next two points (setq q (polar (polar p a k) (+ a (/ pi 2)) h)) (setq r (polar q a z)) ;; Create polyline (command "_.pline" "_non" p "_non" q "_non" r "") ;; Join the original line with the new polyline (initcommandversion) (command "_.join" (car s) "_l" "") ) (princ "\nError: No valid line selected.") ) ;; Exit gracefully (princ) ) ;Crank based on Client H and K values (defun c:Z4 ( / s p a q r bar-dia z h-value k-value) ;; Define pre-defined H and K values for each bar diameter (setq diameters '((3 . (0.375 . 2)) (4 . (0.5 . 2.5)) (5 . (0.625 . 3)) (6 . (0.75 . 3.5)) (7 . (0.875 . 4)) (8 . (1.0 . 4.5)) (9 . (1.270 . 5)) (10 . (1.310 . 5.5)))) ;; Helper function to get H and K values based on bar diameter (defun get-h-k-values (key) (cdr (assoc key diameters))) ;; Define default values if not previously set (if (not (boundp 'crank:prev-bar-dia)) (setq crank:prev-bar-dia 8)) ; Default bar diameter ;; Prompt for bar diameter (3-10) with the previous value as the default (setq bar-dia (getint (strcat "\nSpecify bar diameter (3-10) <" (itoa crank:prev-bar-dia) ">: ")) bar-dia (if bar-dia bar-dia crank:prev-bar-dia)) ;; Store the bar diameter for future use (setq crank:prev-bar-dia bar-dia) ;; Get H and K values based on the selected bar diameter (setq h-value (car (get-h-k-values bar-dia))) ; H value for the selected diameter (setq k-value (cdr (get-h-k-values bar-dia))) ; K value for the selected diameter ;; Display the calculated H and K values (print (strcat "*** Calculated H Distance for bar diameter " (itoa bar-dia) " is " (rtos h-value 2 2) "***")) (print (strcat "*** Calculated K Distance for bar diameter " (itoa bar-dia) " is " (rtos k-value 2 2) "***")) ;; Get length of extension (setq z (if (= nil (setq z (getreal (strcat "\nSpecify length of extension <" (rtos crank:prev-z 2 2) ">: ")))) crank:prev-z z)) ;; Store the extension value for future use (setq crank:prev-z z) ;; Prompt user for line selection and calculate points (if (and (setq s (entsel "\nSelect line close to end: ")) (setq p (osnap (cadr s) "end")) (setq a (angle (osnap (cadr s) "nea") p)) (setq q (polar (polar p a k-value) (+ a (/ pi 2)) h-value)) (setq r (polar q a z))) ;; Create polyline (progn (command "_.pline" "_non" p "_non" q "_non" r "") ;; Join the original line with the new polyline (initcommandversion) (command "_.join" (car s) "_l" ""))) ;; Exit gracefully (princ) ) Hi every friends Base code Source: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/req-polyline-crank/td-p/11808942 I could really use some help or suggestions. I'm currently using multiple commands to draw a crank bar, but I’d like to combine all those commands into one single command. I’ve seen how Lee Mac does it with his ATC command, and I’m hoping to achieve something similar. If you have any ideas on how I can do this, please share! Also, if you have suggestions for alternatives other than just combining all the commands, I’d love to hear those too. Thanks in advance to all. Edited November 10 by harimaddddy Quote
Steven P Posted November 12 Posted November 12 You might have a 'wrapper' LISP to run the other commands: (defun c:test ( / ) (c:Z1) ) which will run the command Z1. To make this more useful you might want to put all the 'get' commands into test LISP and pass the values to the next one: (defun c:test ( / k-multiplier ) (setq k-multiplier (getint (strcat "\nEnter Crank Ratio <" (rtos crank:prev-multiplier 2 0) ">: ")) k-multiplier (if k-multiplier k-multiplier crank:prev-multiplier) ) ; end setq (c:Z1 k-multiplier) ) and to receive a value in Z1: (defun c:Z1 ( k-multiplier / s p..... obviously disabling the questions you place in the wrapper to stop them being asked twice. I haven't looked through the code to see what you can replace but maybe this might give you a hint of a direction to head in? Once you have placed all the 'get' questions in the wrapper you might be able to use an if statement to run the correct code according to what information has been entered 1 Quote
BIGAL Posted November 12 Posted November 12 Can you post a sample dwg with some cranks. If I am looking at this correctly then can have one command but options in the command for crank directions via a dcl something like this. 1 Quote
harimaddddy Posted November 13 Author Posted November 13 Hi @BIGAL sorry for the late reply, Currently I'm out of home.I’m trying to simplify drawing crank bars on column elevations, which I usually do manually. Ideally, I’d like everything to work through the command prompt, but a DCL dialog box could be helpful to learn about for future reference. Z1: Calculates H as the sum of the level 1 and level 2 bar diameters plus a cushion (1/4”), and K as H * 6 (using a 1:6 crank ratio). Z2: Allows manual entry of H and K values. Z3: Similar to Z1, but includes an offset in the H calculation. Z4: Uses predefined values for H and K. I initially tried to make the crank ratio universal across Z1 and Z3 in a single command but ended up separating them for simplicity. I’m also try to adding a feature to the Z4 command to allow non-coders to update H and K values through the command prompt, instead of having to open and edit the LISP file directly but this was optional. 1 Quote
harimaddddy Posted November 13 Author Posted November 13 (edited) Thanks @Steven P I'll try. Could you suggest me any other websites to get useful lisp codes? Edited November 13 by harimaddddy Quote
BIGAL Posted November 13 Posted November 13 Some others. Forums/autodesk https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bd-p/130 Theswamp https://www.theswamp.org/ 1 Quote
Steven P Posted November 14 Posted November 14 From my last answer, maybe use BigAls pop-up to collect the information and work it out from there 1 Quote
harimaddddy Posted November 14 Author Posted November 14 Hi @BIGAL @Steven P . I'm bit late today. Attached cad file has Crank bar examples. Thank you very much for your help Crank Bar.dwg 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.