Author Topic: I am looking for a lisp to label lines with layer name  (Read 9438 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
I am looking for a lisp to label lines with layer name
« on: December 13, 2006, 06:03:38 PM »
I seem to recall seeing something like this somewhere but not sure if it was in the swamp or not. I need desperately lisp lisp which would label what layer each line is on. I am trying to revamped a program we use for drawing assemblies to put certain elements on specified layers creating in effect subassemblies but in order to understand everything i need to be able to tell one from the other so i know what to put on the same layer in my code. Does anyone have something that will put a layer label beside every line selected
Thanks

« Last Edit: December 21, 2006, 10:29:05 AM by CmdrDuh »

ronjonp

  • Needs a day job
  • Posts: 7531
Re: I am looking for a lisp
« Reply #1 on: December 13, 2006, 06:57:04 PM »
Try this Dan,

Code: [Select]
(defun rjp-addtext (ins hgt text / doc x)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-addText
    (if (= (getvar 'cvport) 1)
      (vla-get-paperspace doc)
      (vla-get-modelspace doc)
    )
    text
    (vlax-3d-point ins)
    (* (getvar 'dimscale) hgt)
  )
)


(defun c:x (/ index ss obj lyr ept spt mpt)
  (setq index -1)
  (if (setq ss (ssget "x" '((0 . "LINE"))))
    (progn
      (while (< (setq index (1+ index)) (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss index))
      lyr (vla-get-layer obj)
      ept (vlax-get obj 'endpoint)
      spt (vlax-get obj 'startpoint)
      mpt (polar ept (angle ept spt) (/ (distance ept spt) 2.0))
)
(rjp-addtext mpt 1 lyr)
      )
      (princ)
    )
  )
  (princ)
)

Puts the layername at the end of the line.
« Last Edit: December 14, 2006, 11:39:29 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Re: I am looking for a lisp
« Reply #2 on: December 13, 2006, 07:20:21 PM »
i will try it tomorrow and let you know ron thanks a bunch. this will help me trememndously. i have about 115 items i need to identify phewwww

ronjonp

  • Needs a day job
  • Posts: 7531
Re: I am looking for a lisp
« Reply #3 on: December 13, 2006, 07:24:02 PM »
i will try it tomorrow and let you know ron thanks a bunch. this will help me trememndously. i have about 115 items i need to identify phewwww

Glad to help :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: I am looking for a lisp
« Reply #4 on: December 13, 2006, 07:24:02 PM »
Nice starter Ron !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: I am looking for a lisp
« Reply #5 on: December 13, 2006, 07:40:41 PM »
I like it, good job Ron. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: I am looking for a lisp
« Reply #6 on: December 14, 2006, 11:10:08 AM »
Thanks Guys :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

LE

  • Guest
Re: I am looking for a lisp
« Reply #7 on: December 14, 2006, 11:20:44 AM »
Yes...

And take the day off please, it will be on theswamp account...

ronjonp

  • Needs a day job
  • Posts: 7531
Re: I am looking for a lisp
« Reply #8 on: December 14, 2006, 11:35:36 AM »
Dan,

I updated the code above to place the text on the midpoint of the line.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Re: I am looking for a lisp
« Reply #9 on: December 20, 2006, 06:15:15 PM »
ron i was using it and it works good but what would be ideal would be if the text would run vertically it it is labelling a vertical line because when i have lines intersecting i have labels on top of eachother. i also have some lines whose layers weren't labelled. it worked good for what i need it for but would need to be improved if i were to use it more. that aside i am very grateful for your help it made the job i was doing alot easier. presh

CADmium

  • Newt
  • Posts: 33
Re: I am looking for a lisp to label lines with layer name
« Reply #10 on: December 22, 2006, 02:26:27 AM »
here is a Lisp, integrating Layernames in Linetypedefinitions..
"Bei 99% aller Probleme ist die umfassende Beschreibung des Problems bereits mehr als die Hälfte der Lösung desselben."

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: I am looking for a lisp to label lines with layer name
« Reply #11 on: December 22, 2006, 03:52:37 PM »
Hey Ron,
How about aligning the text with the lines?
Code: [Select]
(defun rjp-addtext (ins hgt text ang / doc x)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq txtObj (vla-addtext
                 (if (= (getvar 'cvport) 1)
                   (vla-get-paperspace doc)
                   (vla-get-modelspace doc)
                 )
                 text
                 (vlax-3d-point ins)
                 hgt
               )
  )
  (vla-put-rotation txtObj ang)
  (vla-put-alignment txtObj acalignmentbottomcenter)
  (vla-put-textalignmentpoint txtobj (vlax-3d-point ins))
)


(defun c:x (/ index ss obj lyr ept spt mpt txtht)
  (setq index -1)
  ;;(if (setq ss (ssget "x" '((0 . "LINE"))))
  (if (setq ss (ssget '((0 . "LINE"))))
    (progn
      (while (< (setq index (1+ index)) (sslength ss))
        (setq obj (vlax-ename->vla-object (ssname ss index))
              lyr (vla-get-layer obj)
              ept (vlax-get obj 'endpoint)
              spt (vlax-get obj 'startpoint)
              ang (angle spt ept)
              mpt (polar ept (angle ept spt) (/ (distance ept spt) 2.0))
        )
        (if (and (> ang (* 0.5 pi)) (< ang (* 1.5 pi)))
          (setq ang (+ ang pi))
        )
        (setq mpt (polar mpt (+ ang (/ pi 2.0)) (* (getvar 'dimscale) (getvar 'dimgap))))
        (if (zerop (setq txtht (getvar 'textsize)))
          (setq txtht 5)
        )
        (rjp-addtext mpt txtht lyr ang)
      )
    )
  )
  (princ)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7531
Re: I am looking for a lisp to label lines with layer name
« Reply #12 on: December 26, 2006, 03:00:19 PM »
Hey Ron,
How about aligning the text with the lines?
Code: [Select]
(defun rjp-addtext (ins hgt text ang / doc x)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq txtObj (vla-addtext
                 (if (= (getvar 'cvport) 1)
                   (vla-get-paperspace doc)
                   (vla-get-modelspace doc)
                 )
                 text
                 (vlax-3d-point ins)
                 hgt
               )
  )
  (vla-put-rotation txtObj ang)
  (vla-put-alignment txtObj acalignmentbottomcenter)
  (vla-put-textalignmentpoint txtobj (vlax-3d-point ins))
)


(defun c:x (/ index ss obj lyr ept spt mpt txtht)
  (setq index -1)
  ;;(if (setq ss (ssget "x" '((0 . "LINE"))))
  (if (setq ss (ssget '((0 . "LINE"))))
    (progn
      (while (< (setq index (1+ index)) (sslength ss))
        (setq obj (vlax-ename->vla-object (ssname ss index))
              lyr (vla-get-layer obj)
              ept (vlax-get obj 'endpoint)
              spt (vlax-get obj 'startpoint)
              ang (angle spt ept)
              mpt (polar ept (angle ept spt) (/ (distance ept spt) 2.0))
        )
        (if (and (> ang (* 0.5 pi)) (< ang (* 1.5 pi)))
          (setq ang (+ ang pi))
        )
        (setq mpt (polar mpt (+ ang (/ pi 2.0)) (* (getvar 'dimscale) (getvar 'dimgap))))
        (if (zerop (setq txtht (getvar 'textsize)))
          (setq txtht 5)
        )
        (rjp-addtext mpt txtht lyr ang)
      )
    )
  )
  (princ)
)

I like :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Fatty

  • Guest
Re: I am looking for a lisp to label lines with layer name
« Reply #13 on: December 26, 2006, 05:39:08 PM »
You can try this also
This will be to label lines with fields

Code: [Select]
(defun C:llb (/ acsp   adoc     end_pt    line_ang
      mid_pt obj_field obj_id    ss       start_pt
      str_field txt_pt
     )
  (if (< (atoi (substr (getvar "acadver") 1 2)) 15)
    (progn
      (alert
"Programm wiil be works in\n
    AutoCAD 2000 and higher versions"
      )
      (exit)
      (princ)
    )
  )

  (or (vl-load-com))

  (defun *error* (msg)
    (princ msg)
    (vla-endundomark
      (vla-get-activedocument
(vlax-get-acad-object)
      )
    )
    (princ)
  )

  (or adoc
      (setq adoc (vla-get-activedocument
   (vlax-get-acad-object)
)
      )
  )
  (or acsp
      (setq acsp (if (= (getvar "CVPORT") 1)
   (vla-get-paperspace
     adoc
   )
   (vla-get-modelspace
     adoc
   )
)
      )
  )

  (vla-endundomark
    adoc
  )
  (vla-startundomark
    adoc
  )
  (setq ss (ssget (list (cons 0 "LINE"))))
  (vlax-for line_obj
     (vla-get-activeselectionset adoc)
    (setq obj_id    (vla-get-ObjectID line_obj)
  str_field (strcat "%<\\AcObjProp Object(%<\\_ObjId "
    (itoa obj_id)
    ">%).Layer>%"
    )
    )
    (setq start_pt (vlax-get line_obj 'Startpoint)
  end_pt   (vlax-get line_obj 'Endpoint)
  line_ang (angle start_pt end_pt)
  mid_pt   (mapcar (function (lambda (a b) (* (+ a b) 0.5)))
   start_pt
   end_pt
   )
    )
    (if (and (> line_ang (/ pi 2))
     (< line_ang (* pi 1.5))
)
      (setq line_ang (+ pi line_ang))
    )
    (setq txt_pt (polar mid_pt
(+ line_ang (/ pi 2.0))
(* (getvar "DIMTXT") 0.5)
)
    )
    (setq obj_field (vlax-invoke acsp 'AddMText txt_pt 0.0 str_field))
    (vlax-put obj_field 'Rotation line_ang)
    (vlax-put obj_field 'Layer (vlax-get line_obj 'Layer))
    (vlax-put obj_field 'Color 256)
  )
  (vla-regen adoc acactiveviewport)
  (*error* nil)
  (princ)
)
[code]

~'J'~
[/code]

ELOQUINTET

  • Guest
Re: I am looking for a lisp to label lines with layer name
« Reply #14 on: January 02, 2007, 09:20:09 PM »
hmmm hadn't looked in this thread since the new year and you guys have been busy. the main thing i need to acheive in this project at this point is to seperate the shade roll lines onto shade1 or shade2 layers accordingly. if you look in vba forum you can see where we left off. hmmm maybe i should look myself as someone may have posted something. i will review the other solutions posted here too thanks