ASH71 Posted June 23, 2016 Posted June 23, 2016 Hi newbie here, I'm looking for help to create a lisp file that will calculate the versine of an arc then insert the answer as text into a drawing. (I'm useless at explaining). for example if I have an arc 9500mm long with a radius of 300M the versine caculates at 37.5mm (to one decimal point). I want the text to show the following:- Length 9500 Radius - 300000 Versine = 37.5 Direction of Curvature = UP/DOWN Sorry if I haven't explained it very well - at the moment I use a seperate calculator spreadsheet then edit text in my drawings. Thanks for any advice. Quote
Lee Mac Posted June 23, 2016 Posted June 23, 2016 This will get you most of the way there - (defun c:arcdata ( / ang arc enx ins rad ) (while (progn (setvar 'errno 0) (setq arc (car (entsel "\nSelect arc: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null arc) nil) ( (/= "ARC" (cdr (assoc 0 (setq enx (entget arc))))) (princ "\nSelected object is not an arc.") ) ) ) ) (if (and (= 'ename (type arc)) (setq ins (getpoint "\nSpecify point for text: "))) (progn (setq rad (cdr (assoc 40 enx)) ang (rem (+ pi pi (- (cdr (assoc 51 enx)) (cdr (assoc 50 enx)))) (+ pi pi)) ) (entmake (list '(000 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 010 (trans ins 1 0)) (cons 001 (strcat "Length: " (rtos (* ang rad)) "\\P" "Radius: " (rtos rad) "\\P" "Versine: " (rtos (* rad (- 1 (cos (/ ang 2.0))))) ) ) ) ) ) ) (princ) ) Not sure what you mean by a curvature being 'up' or 'down'. Quote
ReMark Posted June 23, 2016 Posted June 23, 2016 Re: Direction of Curvature = UP/DOWN Could we be talking about vertical curves in which case the curve is UP (smile) or DOWN (frown)? Quote
ASH71 Posted June 23, 2016 Author Posted June 23, 2016 Cheers for that. I'll try it In the morning As remark says the up down is to indicate the direction of curvature Thanks again! Quote
ASH71 Posted June 24, 2016 Author Posted June 24, 2016 Hi Lee Mac, I've ran the routine and although it's not exactly what I was after it is still very useful for me. What I was after is for a routine that asks me for the length - which for example I would type 9500. Then ask for the radius - say 300000. then direction of curvature - UP or Down. Then it would calculate the versine and allow me to insert the information into the drawing as follows -: Length - 9500 Radius - 300000 Versine = 37.5 Direction of Curvature = UP Thanks again for your help. Quote
Lee Mac Posted June 24, 2016 Posted June 24, 2016 (defun c:arcdata ( / crv ins len rad ) (if (and (progn (initget 6) (setq len (getdist "\nSpecify arc length: ")) ) (progn (initget 6) (setq rad (getdist "\nSpecify arc radius: ")) ) (progn (initget "Up Down") (setq crv (cond ((getkword "\nSpecify curvature direction [up/Down] <Up>: ")) ("Up")) ins (getpoint "\nSpecify point for text: ") ) ) ) (entmake (list '(000 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 010 (trans ins 1 0)) (cons 001 (strcat "Length: " (rtos len) "\\P" "Radius: " (rtos rad) "\\P" "Versine: " (rtos (* rad (- 1 (cos (/ len rad 2.0))))) "\\P" "Direction of Curvature: " (strcase crv) ) ) ) ) ) (princ) ) Quote
ASH71 Posted June 27, 2016 Author Posted June 27, 2016 Thats exactly what I wanted. Cheers Lee:D Quote
ASH71 Posted August 10, 2023 Author Posted August 10, 2023 I know this is from a while ago, Lee Mac made a lisp file for me which I have been able to modify slightly to give an additional line (versine over 7m). Can anyone help / show me how to remove the bottom line if the length of the arc selected is shorter than 7m please? I will insert the code below. (defun c:versine ( / ang arc enx ins rad ) (while (progn (setvar 'errno 0) (setq arc (car (entsel "\nSelect arc: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null arc) nil) ( (/= "ARC" (cdr (assoc 0 (setq enx (entget arc))))) (princ "\nSelected object is not an arc.") ) ) ) ) (if (and (= 'ename (type arc)) (setq ins (getpoint "\nSpecify point for text: "))) (progn (setq rad (cdr (assoc 40 enx)) ang (rem (+ pi pi (- (cdr (assoc 51 enx)) (cdr (assoc 50 enx)))) (+ pi pi)) ) (entmake (list '(000 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 010 (trans ins 1 0)) (cons 001 (strcat "Length: " (rtos (* ang rad)) "\\P" "Radius: " (rtos rad) "\\P" "Versine: " (rtos (* rad (- 1 (cos (/ ang 2.0))))) "\\P" "Versine over 7M: " (rtos (* rad (- 1 (cos (/ 7000 rad 2.0))))) ) ) ) ) ) ) (princ) ) Example.pdf Quote
Steven P Posted August 10, 2023 Posted August 10, 2023 (edited) Keeping with Lee Mac,,, I think you need a sub-function to calculate the arc length and I dug this out: ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-me-find-arc-length (defun arclen ( ent / enx ) (setq enx (entget ent)) (* (cdr (assoc 40 enx)) (rem (+ pi pi (- (cdr (assoc 51 enx)) (cdr (assoc 50 enx)))) (+ pi pi) ) ) ) in your code to get arc length you'd use this, putting it in before the entmake portion: (setq ArcLength (arclen arc)) After than in the entmake part of your code you can put in an 'if' statement in the strcat bit: (entmake (list '(000 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 010 (trans ins 1 0)) (cons 001 (strcat "Length: " (rtos (* ang rad)) "\\P" "Radius: " (rtos rad) "\\P" "Versine: " (rtos (* rad (- 1 (cos (/ ang 2.0))))) "\\P" (if (> ArcLength 7) "Versine over 7M: " (rtos (* rad (- 1 (cos (/ 7000 rad 2.0))))) ) ; end if ) ; end strcat ) ; end cons 001 (create text) ) ; end list ) ; end entmake Edited August 10, 2023 by Steven P Quote
ASH71 Posted August 10, 2023 Author Posted August 10, 2023 Thanks Steven, I was getting this 'malformed list on input' managed to sort that but now I'm getting 'error syntax error' Any ideas? Ash Quote
Steven P Posted August 10, 2023 Posted August 10, 2023 Malformed list on input usually mean a list isn't quite in the right format error: syntax error is a function isn't quite right Often for both it is a bracket in the wrong place for me try this, a small change in the 'if' statement and added in the arclen function (defun c:versine ( / ang arc enx ins rad ) ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-me-find-arc-length (defun arclen ( ent / enx ) (setq enx (entget ent)) (* (cdr (assoc 40 enx)) (rem (+ pi pi (- (cdr (assoc 51 enx)) (cdr (assoc 50 enx)))) (+ pi pi) ) ; end * ) ; end setq ) ; end defun (while (progn (setvar 'errno 0) (setq arc (car (entsel "\nSelect arc: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null arc) nil) ( (/= "ARC" (cdr (assoc 0 (setq enx (entget arc))))) (princ "\nSelected object is not an arc.") ) ) ; end conds ) ; end progn ) ; end while (if (and (= 'ename (type arc)) (setq ins (getpoint "\nSpecify point for text: "))) (progn (setq ArcLength (arclen arc)) (setq rad (cdr (assoc 40 enx)) ang (rem (+ pi pi (- (cdr (assoc 51 enx)) (cdr (assoc 50 enx)))) (+ pi pi)) ) ; end setq (entmake (list '(000 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 010 (trans ins 1 0)) (cons 001 (strcat "Length: " (rtos (* ang rad)) "\\P" "Radius: " (rtos rad) "\\P" "Versine: " (rtos (* rad (- 1 (cos (/ ang 2.0))))) "\\P" (if (> ArcLength 7) (strcat "Versine over 7M: " (rtos (* rad (- 1 (cos (/ 7000 rad 2.0)))))) ; versine over 7 (strcat "") ; versine under 7 ) ; end if ) ; end strcat ) ; end cons 001 (create text) ) ; end list ) ; end entmake ) ; end progn ) ; end if (princ) ) 1 Quote
Lee Mac Posted August 10, 2023 Posted August 10, 2023 (edited) @Steven P just a tip, this: (strcat "") ; versine under 7 Can be simply: "" ; versine under 7 Edited August 10, 2023 by Lee Mac 2 Quote
ASH71 Posted August 11, 2023 Author Posted August 11, 2023 Thankyou both - I will try today and let you know how I get on. Thanks again Ash 1 Quote
ASH71 Posted August 11, 2023 Author Posted August 11, 2023 That works brilliantly - thanks again! Ash Quote
ASH71 Posted February 6 Author Posted February 6 Hi lads, sorry to drag this one up again. This lisp works great and I don't know if this mod / addition is possible but I have attached a sample of what the lisp does and also a sample of an additional line if it is possible - no worries if it isn't. I've just been adding the additonal direction of curvature manually. Hope this makes sense. Below is the lisp (defun c:versine ( / ang arc enx ins rad ) ;;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/help-me-find-arc-length (defun arclen ( ent / enx ) (setq enx (entget ent)) (* (cdr (assoc 40 enx)) (rem (+ pi pi (- (cdr (assoc 51 enx)) (cdr (assoc 50 enx)))) (+ pi pi) ) ; end * ) ; end setq ) ; end defun (while (progn (setvar 'errno 0) (setq arc (car (entsel "\nSelect arc: "))) (cond ( (= 7 (getvar 'errno)) (princ "\nMissed, try again.") ) ( (null arc) nil) ( (/= "ARC" (cdr (assoc 0 (setq enx (entget arc))))) (princ "\nSelected object is not an arc.") ) ) ; end conds ) ; end progn ) ; end while (if (and (= 'ename (type arc)) (setq ins (getpoint "\nSpecify point for text: "))) (progn (setq ArcLength (arclen arc)) (setq rad (cdr (assoc 40 enx)) ang (rem (+ pi pi (- (cdr (assoc 51 enx)) (cdr (assoc 50 enx)))) (+ pi pi)) ) ; end setq (entmake (list '(000 . "MTEXT") '(100 . "AcDbEntity") '(100 . "AcDbMText") (cons 010 (trans ins 1 0)) (cons 001 (strcat "Length: " (rtos (* ang rad)) "\\P" "Radius: " (rtos rad) "\\P" "Versine: " (rtos (* rad (- 1 (cos (/ ang 2.0))))) "\\P" (if (> ArcLength 7000) (strcat "Versine over 7M: " (rtos (* rad (- 1 (cos (/ 7000 rad 2.0)))))) ; versine over 7 (strcat "") ; versine under 7 ) ; end if ) ; end strcat ) ; end cons 001 (create text) ) ; end list ) ; end entmake ) ; end progn ) ; end if (princ) ) 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.