Author Topic: Lisp macro for labelling a curved line  (Read 1791 times)

0 Members and 1 Guest are viewing this topic.

Onetrack

  • Guest
Lisp macro for labelling a curved line
« on: November 16, 2007, 12:19:19 PM »
Hi folks, I'd like to take this script - which labels a line in distance metric @ 90 degrees to a line on a specified layer/font style and have it apply to curved lines.
Can anyone guide me on such a modification?

------------------
(defun c:me2 ( / ss f l n f end1 end2 dist dist2 distm mx my m r ro Ro R m2)
; end1,end2 - endpoints

   (setq ht (cdr (assoc 40 (tblsearch "style" (getvar "textstyle")))))
   (setq hta ht)
   (setvar "textstyle" "L60")
        (setvar "clayer" "hdim")
   (setvar "cmdecho" 0)
   (princ "\nSelect the line to Label: ")
   (setq ss (ssget))
   (if ss (progn
      (setq l 0)
      (setq n (sslength ss))
      (while (< l n)
 
      (setq f (entget (ssname ss l)))
      (setq end1 (cdr (assoc 10 f)))
      (setq end2 (cdr (assoc 11 f)))
      (setq dist (distance end1 end2))
      (setq dist2 (/ dist 0.3048))
;3      (setq distm (rtos dist 2 3))
      (setq distm (rtos dist 2 2))
      (setq mx (/ (+ (car end1) (car end2)) 2))   ;midpt x
      (setq my (/ (+ (cadr end1) (cadr end2)) 2)) ;midpt y
      (setq m (list mx my)) ;midpoint

; ro - 90d offset bearing
   (setq r (* (angle end1 end2) (/ 180.0 pi)))
   (setq ro r)
   (setq Ro (+ Ro 90.0))
   (if (and (> ro 180.0) (<= ro 360.0)) (setq ro (+ 180.0 ro)) )
   (setq ro (* ro (/ pi 180.0)))
   (setq R (- 90.0 R))
   (if (and (>= r -180.0) (< r 0.0)) (setq r (+ 180.0 r)) )
   (if (< r 0.0) (setq r (+ 360.0 r)) )
   (setq m2 (list (/ (+ (car end1) (car end2)) 2) (/ (+ (cadr end1) (cadr end2)) 2)))
   (command "text" "m" (polar m2 ro hta) r distm)
   (setq l (+ 1 l)) 
   );endwhile
   );endprogn
   );endif
(princ)           
)
----------------------

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Lisp macro for labelling a curved line
« Reply #1 on: November 16, 2007, 01:29:07 PM »
I'm not sure if this is what you are trying to do....but maybe it will give you some ideas:

Code: [Select]
(defun c:me2 (/ LEN MPT MS OBJ SS X)
  (setq ss (ssget '((0 . "*POLYLINE,LINE,SPLINE,ARC")))
ms (vla-get-modelspace
     (vla-get-ActiveDocument (vlax-get-acad-object))
   )
  )
  (if ss
    (progn
      (setq
ss (mapcar 'vlax-ename->vla-object
   (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
   )
      )
      (mapcar '(lambda (x)
(setq mpt (vlax-curve-getPointAtParam
     x
     (/ (vlax-curve-getEndParam x) 2)
   )
       len (vlax-curve-getdistatparam
     x
     (vlax-curve-getendparam x)
   )
)
(vla-addText
   ms
   (rtos len)
   (vlax-3d-point mpt)
   (* (getvar 'dimscale) 0.125)
)
       )
      ss
      )
    )
  )
  (princ)
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Onetrack

  • Guest
Re: Lisp macro for labelling a curved line
« Reply #2 on: November 16, 2007, 03:02:50 PM »
Thanks for the quick assist.. when running the application I get this:
Command: mc2
Select objects: 1 found
Select objects:
; error: bad 3D point: nil

(I changed the defunc to mc2 from me2 so it wouldn't interrupt my other application.)

Basically my app labels lines, with static distance labels, but does not do curved labels and I havn't figured that out yet - it keeps complaining that 2d/3d point is nil.

Thanks for the code, please let me know if you come up with any other ideas

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Lisp macro for labelling a curved line
« Reply #3 on: November 16, 2007, 05:44:47 PM »
In the code above,

Change:

(ssget '((0 . "*POLYLINE,LINE,SPLINE,ARC")))

to

(ssget '((0 . "LINE")))

I'm have no idea what curved labels are, I thought you wanted a length of a curved object.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Onetrack

  • Guest
Re: Lisp macro for labelling a curved line
« Reply #4 on: November 16, 2007, 06:33:19 PM »
Thanks - essentially what I'm looking for is a radius and area on a specific layer and specific style for curves :)