Community
Civil 3D Forum
Welcome to Autodesk’s Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Label Polyline/Feature line with Layer Name

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
PatrickManson
6867 Views, 15 Replies

Label Polyline/Feature line with Layer Name

Does anybody know of a way to lebel a polyline or a feature line with its layer name without using mtext and fields/objects.

 

Basically i would like to be able to add a label, select the polyline/feature line and it will label it with the layer name at appropriate offset and also be orientated along the line.

 

Thanks for your help, Patrick

15 REPLIES 15
Message 2 of 16
doni49
in reply to: PatrickManson

I think the option of a field would probably be the best idea because if you change the assigned layer, the field will update.

 

But to answer the question as asked, you could probably do what you're looking for with a lisp routine (and if you go that route, you could even include a reactor that will recognize the layer change and update the label accordingly).  This would be a lot more complex than using a field though.



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

Message 3 of 16
Joe-Bouza
in reply to: PatrickManson


@PatrickManson wrote:

Does anybody know of a way to lebel a polyline or a feature line with its layer name without using mtext and fields/objects.

 

Basically i would like to be able to add a label, select the polyline/feature line and it will label it with the layer name at appropriate offset and also be orientated along the line.

 

Thanks for your help, Patrick


What is you adversion to mtext fields for this task? If you cannot use them you will need to find a lisp routine. But as Doni states fields would be the way to go.

Thank you

Joseph D. Bouza, P.E. (one of 'THOSE' People)

HP Z210 Workstation
Intel Xeon CPU E31240 @ 3.30 Hz
12 GB Ram


Note: Its all Resistentialism, so keep calm and carry on

64 Bit Win10 OS
Message 4 of 16

Thanks for the replies. the main reason for trying to find a better way to label the line without using the fields, is that it is a labourious process to do so. I need to copy the mtext, edit the field, then rotate the text appropriately.

 

Cheers

Message 5 of 16
Jeff_M
in reply to: PatrickManson

Or find/write a lisp routine to automate it....

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 16
don.ireland
in reply to: Jeff_M

There is a board specifically for Autolisp questions.  You could easily write a routine that will prompt the user for a pline, find out the angle at that location, and place the mtext object with the field in it (at the appropriate angle).  Putting the field in the mtext object will be the most difficult portion of this task and I could figure out how, I just don't have time right now to get into that.

 

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/bd-p/130

 

 

Message 7 of 16
Joe-Bouza
in reply to: PatrickManson

Thats fair enough reasoning.

perhaps consider a slightly different workflow. Use a dynamic block with a blockplaceholder field for layer, include an alignment parameter and when you insert it will auto align to the line with the correct layer name
Thank you

Joseph D. Bouza, P.E. (one of 'THOSE' People)

HP Z210 Workstation
Intel Xeon CPU E31240 @ 3.30 Hz
12 GB Ram


Note: Its all Resistentialism, so keep calm and carry on

64 Bit Win10 OS
Message 8 of 16
Jeff_M
in reply to: PatrickManson

Here's a very quickly written lisp to label an objects' layer. No error checking provided, so will fail on non-curve objects (a 'curve' object is a line, arc, polyline, spline, ray, etc.). But the meat of the needed items are here.

 

(defun c:labelobjlayer(/ LM:objectid model ent obj DIR INSPT MTEXT OFFSET PARM PT TEXT VEC)
  ;; ObjectID  -  Lee Mac lee-mac.com & theswamp.org
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems
  (defun LM:objectid ( obj )
    (eval
        (list 'defun 'LM:objectid '( obj )
            (if
                (and
                    (wcmatch (getenv "PROCESSOR_ARCHITECTURE") "*64*")
                    (vlax-method-applicable-p (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))) 'getobjectidstring)
                )
                (list 'vla-getobjectidstring (vla-get-utility (vla-get-activedocument (vlax-get-acad-object))) 'obj ':vlax-false)
               '(itoa (vla-get-objectid obj))
            )
        )
    )
    (LM:objectid obj)
)
  (setq model (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
  (while (setq ent (entsel "\nSelect object to label with layer name: "))
    (setq obj (vlax-ename->vla-object (car ent))
	  pt (vlax-curve-getclosestpointto obj (cadr ent))
	  parm (vlax-curve-getparamatpoint obj pt)
	  vec (vlax-curve-getfirstderiv obj parm)
	  dir (angle '(0 0 0) vec)
	  offset 2.0 ;;adjust to desired offset may want to scale this based on annoscale
	  inspt (polar pt (+ dir (* pi 0.5)) offset)
	  )
    (setq text (strcat "%<\\AcObjProp Object(%<\\_ObjId " (LM:objectid obj) ">%).Layer>%"))
    (setq mtext (vlax-invoke model 'addmtext inspt 0 text))
    (vla-put-rotation mtext dir)
    (vla-put-attachmentpoint mtext acbottomcenter)
    )
  (princ)
  )

 

Jeff_M, also a frequent Swamper
EESignature
Message 9 of 16
PatrickManson
in reply to: Jeff_M

Thanks Jeff, have loaded it - excuse my ignorance, but what command do i use to start the lisp?

 

Cheers

Message 10 of 16

don't worry - like I said ignore my ignorance - I have got it!! works fantastic. cheers
Message 11 of 16
szemese_gis
in reply to: Jeff_M

Is it possible to use this command for all the objects in my drawing? I mean select all lines and label them automatically...

Message 12 of 16
jmayo-EE
in reply to: Jeff_M

Why didn't you nme it LOL?  LOL 🙂

John Mayo

EESignature

Message 13 of 16
Jeff_M
in reply to: szemese_gis

It would be fairly simple to edit the code to select all 'curve' objects then loop through and perform the operation on each one. Not something that I have the time to do myself right now.
Jeff_M, also a frequent Swamper
EESignature
Message 14 of 16
jmayo-EE
in reply to: Jeff_M

I bet your customers would like this and would like to see it work through an xref as well when the time is right. 🙂

John Mayo

EESignature

Message 15 of 16
AllenJessup
in reply to: szemese_gis

This is a 20 year old lisp that I still use sometimes. No error checking or much of anything else. It also inserts the text parallel to the current view.

 

Allen

 

(defun c:laylab ()
        (setq ENT (car (entsel)))
        (setq ENL (entget ENT))
        (setq LN (cdr (assoc 8 ENL)))
        (setq IPT (getpoint "\nInsertion Point?"))
        (setq CL (getvar "clayer"))
        (setq VT (getvar "viewtwist"))
        (setvar "clayer" LN)
        (command "text" IPT "" pause LN)
        (setvar "clayer" CL)
)


Allen Jessup
Engineering Specialist / CAD Manager

Message 16 of 16
symoin
in reply to: PatrickManson

is there any way to add the selected text or mtext to the selected feature line(s). similar to attaching table or attributes to line in acadmap.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report