Jump to content

3d line length


Tom Matson
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

Good morning, could you upload a dwg with a before and after of what you want?

  • Like 1
Link to comment
Share on other sites

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 :beer:

Edited by Kreaten_vhar
  • Like 2
Link to comment
Share on other sites

@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

  • Thanks 1
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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 8)              ;; 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 8)              ;; 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

Link to comment
Share on other sites

@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 by mhupp
YZ angle code update
Link to comment
Share on other sites

@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

Link to comment
Share on other sites

4 minutes ago, Tom Matson said:

can we modify it to get the angle in the "Z" axis?

 

In ref to witch plain XY?

Link to comment
Share on other sites

like that? calculating angled from right side y axis is 0 degrees

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

No I wasn't clear. I updated the code above to calculate the angle on the YZ axis like you asked.

 

image.png.e5c15303d5c2654ea20d604189e50ff2.png

 

image.png.8b57930a92d8dd4f5f69d737a37f4878.png

Edited by mhupp
  • Like 2
Link to comment
Share on other sites

That's It!

From there I can format the information for how I will use it.

Thanks again

 

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...