AutoCAD Civil 3D General Discussion

Reply
Valued Contributor
PatrickManson
Posts: 67
Registered: ‎09-21-2004
Message 1 of 10 (572 Views)
Accepted Solution

Label Polyline/Feature line with Layer Name

572 Views, 9 Replies
02-23-2014 01:42 PM

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

*Expert Elite*
doni49
Posts: 1,399
Registered: ‎12-22-2012
Message 2 of 10 (535 Views)

Re: Label Polyline/Feature line with Layer Name

02-24-2014 06:50 AM 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



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.


Forum links:
AutoCAD 2013/2014/2015
AutoCAD 2010/2011/2012

AutoLISP, VB and other AutoCAD customization


Civil 3D General
Civil 3d Cusomization

*Expert Elite*
Joe-Bouza
Posts: 4,778
Registered: ‎12-15-2008
Message 3 of 10 (516 Views)

Re: Label Polyline/Feature line with Layer Name

02-24-2014 12:58 PM 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) Civil 3D 2012 & 2013
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 Win7 OS
Valued Contributor
PatrickManson
Posts: 67
Registered: ‎09-21-2004
Message 4 of 10 (510 Views)

Re: Label Polyline/Feature line with Layer Name

02-24-2014 01:01 PM in reply to: PatrickManson

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

*Expert Elite*
Jeff_M
Posts: 4,194
Registered: ‎07-22-2003
Message 5 of 10 (501 Views)

Re: Label Polyline/Feature line with Layer Name

02-24-2014 01:14 PM in reply to: PatrickManson

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

Jeff_M, also a frequent Swamper
Contributor
don.ireland
Posts: 13
Registered: ‎04-01-2013
Message 6 of 10 (500 Views)

Re: Label Polyline/Feature line with Layer Name

02-24-2014 01:26 PM 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

 

 

*Expert Elite*
Joe-Bouza
Posts: 4,778
Registered: ‎12-15-2008
Message 7 of 10 (499 Views)

Re: Label Polyline/Feature line with Layer Name

02-24-2014 01:29 PM 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) Civil 3D 2012 & 2013
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 Win7 OS
*Expert Elite*
Jeff_M
Posts: 4,194
Registered: ‎07-22-2003
Message 8 of 10 (476 Views)

Re: Label Polyline/Feature line with Layer Name

02-24-2014 04:12 PM 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
Valued Contributor
PatrickManson
Posts: 67
Registered: ‎09-21-2004
Message 9 of 10 (467 Views)

Re: Label Polyline/Feature line with Layer Name

02-24-2014 05:55 PM in reply to: Jeff_M

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

 

Cheers

Valued Contributor
PatrickManson
Posts: 67
Registered: ‎09-21-2004
Message 10 of 10 (465 Views)

Re: Label Polyline/Feature line with Layer Name

02-24-2014 05:57 PM in reply to: PatrickManson
don't worry - like I said ignore my ignorance - I have got it!! works fantastic. cheers

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Civil 3D Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for AutoCAD Civil 3D helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Civil 3D

Twitter

Facebook

Blogs