Abrasive Posted June 24, 2022 Posted June 24, 2022 Looked for, even tried myself.... I need a function where I can single click/select a line drawn in 3d, display as text its length in fractions rounded to the nearest 1/8". Text needs to be rotated 90deg. Then be able to place that text manually? trying to learn LISP but I have projects due soon. any help would be appreciated Thank You Tom Quote
Edison CB Posted June 24, 2022 Posted June 24, 2022 Good morning, could you upload a dwg with a before and after of what you want? 1 Quote
Kreaten_vhar Posted June 24, 2022 Posted June 24, 2022 (edited) Just taking a shot and what I assume you're looking for: edit: forgot about the rounding part oops. Gonna see what I can do there if anything. edit2: Threw in Lee Mac's roundm function, but I haven't tested it. Still no fractions edit3: I think I broke it... You can change DISTR to DIST to just get the length with no rounding for now if you'd like, it'll work in that way. edit4: Fix'd-er up, and it displays fractions! (I'm also pretty sure the code could be a bit better. I change the data-type of DIST and DISTR probably needlessly) (defun LM:roundm (n m) ;gotta love Lee Mac (http://www.lee-mac.com/round.html) (* m (fix ((if (minusp n) - +) (/ n (float m)) 0.5))) ) (defun c:linelength (/ s e) ;function taken from helpful post by Tharwat @ https://www.cadtutor.net/forum/topic/55856-lisp-to-get-length-of-single-line/ (princ "\n Pick on one line to get its length :") (if (setq s (ssget "_+.:S:E" '((0 . "LINE")))) (progn (setq DIST (rtos (distance (cdr (assoc 10 (setq e (entget (ssname s 0))))) (cdr (assoc 11 e))) 2)) (setq DISTR (LM:roundm (distof DIST) 0.125)) (setq DISTR (rtos DISTR 5)) (command "TEXT" PAUSE PAUSE 90 DISTR) (princ) ) ) ) You select the line, then select where you want the text of the length to be placed, then choose a size for the text. It then plops it where you set with the 90* rotation applied. Hope that helps Edited June 24, 2022 by Kreaten_vhar 2 Quote
Abrasive Posted June 24, 2022 Author Posted June 24, 2022 @Kreaten_vhar That's what I'm looking for! Is there a way to display the numbers in fractions, rounded to the nearest 1/8"...? Thanks Tom 1 Quote
Kreaten_vhar Posted June 24, 2022 Posted June 24, 2022 Yeah I forgot about the rounding and fraction part you wanted. I just broke the code trying (see the edits lol) but I'll try to fixer up. Quote
Kreaten_vhar Posted June 24, 2022 Posted June 24, 2022 @Tom Matson There you are. Should do what you need it to Quote
Abrasive Posted June 24, 2022 Author Posted June 24, 2022 @Kreaten_vhar !!!! Perfect! Works exactly like I need Thank You very Much Tom 1 Quote
Abrasive Posted June 25, 2022 Author Posted June 25, 2022 @Kreaten_vhar Is there a way to also get the degree of the line angle and the "z" height? Also, I modified your code to add mtext instead of just a simple text. Still works perfectly. Got some of the code from another user and would give credit but lost where I was...lol (defun LM:roundm (n m) ;gotta love Lee Mac (http://www.lee-mac.com/round.html) (* m (fix ((if (minusp n) - +) (/ n (float m)) 0.5))) ) (defun c:linelength3 (/ s e) ;function taken from helpful post by Tharwat @ https://www.cadtutor.net/forum/topic/55856-lisp-to-get-length-of-single-line/ (princ "\n Pick on one line to get its length :") (if (setq s (ssget "_+.:S:E" '((0 . "LINE")))) (progn (setq DIST (rtos (distance (cdr (assoc 10 (setq e (entget (ssname s 0))))) (cdr (assoc 11 e))) 2)) (setq DISTR (LM:roundm (distof DIST) 0.125)) (setq DISTR (rtos DISTR 5)) (entmake (list (cons 0 "MTEXT") ;; Entity Name (cons 100 "AcDbEntity") ;; Subclass Marker (cons 410 "Layout") ;; Space ;;(cons 8 "0") ;; Layer (cons 100 "AcDbMText") ;; Subclass Marker (cons 10 (getpoint)) ;; Insertion Point ;;(cons 10 '(5.0 1.0 0)) ;; Insertion Point (cons 40 ;; Text Height (cons 50 1.5708) ;; rotation angle in radians (cons 71 5) ;; Justify (Mid-Cent) (cons 1 DISTR) ;; Text (cons 7 "STANDARD"))) ;; Text Style (princ) ) ) ) So far I have written this to display degrees, but would like it to tie into your routine?..... ; converts radians to degrees (defun RtD (r) (* 180.0 (/ r pi))) ; round to the nearest multiple (defun LM:roundm (n m) (* m (fix ((if (minusp n) - +) (/ n (float m)) 0.5)))) (defun c:ll3 () (setq Deg (atan 48.5 84)) ;;Degrees in Radians (setq Deg2 (RtD Deg)) (setq Deg2 (LM:roundm Deg2 0.25)) (setq DISTR (rtos Deg2 5)) (entmake (list (cons 0 "MTEXT") ;; Entity Name (cons 100 "AcDbEntity") ;; Subclass Marker (cons 410 "Layout") ;; Space ;;(cons 8 "0") ;; Layer (cons 100 "AcDbMText") ;; Subclass Marker (cons 10 (getpoint)) ;; Insertion Point ;;(cons 10 '(5.0 1.0 0)) ;; Insertion Point (cons 40 ;; Text Height (cons 50 0) ;; rotation angle in radians(1.5708 = 90) (cons 71 5) ;; Justify (Mid-Cent) (cons 1 DISTR) ;; Text (cons 7 "STANDARD") ;; Text Style ) ) (princ) ) And of course thanks to Lee Mac and others.... thnaks again Tom Quote
mhupp Posted June 25, 2022 Posted June 25, 2022 (edited) @Tom Matson use the <> to post code so smiley faces and such dont show up. --edit While its good to have a rounding routine. in this instance you can just handle it with (rtos num 4 3) Also changed the if to while so you can select multiple lines without having to repeat the command. to exit just don't select anything or hit esc Will create mulit line mtext. Distance: 1'-8 5/8" Angle: 140.26 Min Elev: 2.500 Max Elev: 5.000 Commands: LineInfo or LI (defun C:LineInfo (/ s line len ang spt ept mini maxx *Dist) (vl-load-com) (princ "\n Select line for info: ") (while (setq ss (ssget "_+.:S:E" '((0 . "LINE")))) (setq line (vlax-ename->vla-object (ssname ss 0))) (setq len (rtos (vla-get-length line) 4 3)) (setq ang (rtos (* 180.0 (/ (vla-get-angle line) pi))2 2)) (setq spt (vlax-get line 'StartPoint)) (setq ept (vlax-get line 'EndPoint)) (if (< (caddr spt) (caddr ept)) (setq mini (rtos (caddr spt)2 3) maxx (rtos (caddr ept)2 3) spt (cdr spt) ept (cdr ept)) (setq mini (rtos (caddr ept)2 3) maxx (rtos (caddr spt)2 3) spt (cdr spt) ept (cdr ept)) ) (setq ang (rtos (* 180.0 (/ (angle spt ept) pi))2 2)) (setq str (strcat "\nDistance: " len "\\PYZ Angle: " ang "\\PMin Elev: " mini "\\PMax Elev: " maxx)) (entmake (list '(0 . "MTEXT") ;; Entity Name '(100 . "AcDbEntity") ;; Subclass Marker '(100 . "AcDbMText") '(410 . "Layout") ;; Space (cons 10 (getpoint)) ;; Insertion Point '(40 . 8) ;; Text Height '(71 . 5) ;; Justify (Mid-Cent) (cons 1 str) ;; Text '(7 . "STANDARD") ;; Style ) ) ) (princ) ) (defun C:LI () (C:LineInfo)) Edited June 25, 2022 by mhupp YZ angle code update Quote
Abrasive Posted June 25, 2022 Author Posted June 25, 2022 @mhupp Works nicely. can we modify it to get the angle in the "Z" axis? And I do like to be able to select multiple times. That will come in handy. Thanks Again Tom Quote
mhupp Posted June 25, 2022 Posted June 25, 2022 4 minutes ago, Tom Matson said: can we modify it to get the angle in the "Z" axis? In ref to witch plain XY? Quote
mhupp Posted June 25, 2022 Posted June 25, 2022 like that? calculating angled from right side y axis is 0 degrees Quote
Abrasive Posted June 25, 2022 Author Posted June 25, 2022 I'M still trying to learn LISP and trying to get my jobs done too... I must not be explaining myself, NONAME_1.dwg This drawing has a single line drawn at 30deg. in the "Z" axis. Not all the lines are going to be 90deg vertical (y dir) or 90deg horiz(x dir). Not sure if i'm making sense? Thanks again Quote
mhupp Posted June 25, 2022 Posted June 25, 2022 (edited) No I wasn't clear. I updated the code above to calculate the angle on the YZ axis like you asked. Edited June 25, 2022 by mhupp 2 Quote
Abrasive Posted June 25, 2022 Author Posted June 25, 2022 That's It! From there I can format the information for how I will use it. Thanks again 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.