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

Annotating objects - label along polyline

13 REPLIES 13
Reply
Message 1 of 14
jagielski
4159 Views, 13 Replies

Annotating objects - label along polyline

I am trying to figure out a way to create an annotation template that will label a polyline based off of object data attached to the line that will align with the polyline. I can create the annotation template and label the line with the label straight across the screen or however I specify the rotation of the label to show up, but I can't figure out how to make it align with the polyline (in this case roads and streams). Any help would be appreciated.

 

Thank you.

13 REPLIES 13
Message 2 of 14
CADaSchtroumpf
in reply to: jagielski

Hi,

If you want, try this!

 

(vl-load-com)
(defun str2lst (str sep / pos)
  (if (setq pos (vl-string-search sep str))
    (cons
      (substr str 1 pos)
      (str2lst (substr str (+ (strlen sep) pos 1)) sep)
    )
    (list str)
  )
)
(defun ListBox (title msg keylab flag / tmp file dcl_id choice)
  (setq
    tmp (vl-filename-mktemp "tmp.dcl")
    file (open tmp "w")
  )
  (write-line
    (strcat "ListBox:dialog{label=\"" title "\";")
    file
  )
  (if (and msg (/= msg ""))
    (write-line (strcat ":text{label=\"" msg "\";}") file)
  )
  (write-line
    (cond
      ((= 0 flag) "spacer;:popup_list{key=\"lst\";")
      ((= 1 flag) "spacer;:list_box{key=\"lst\";")
      (T "spacer;:list_box{key=\"lst\";multiple_select=true;")
    )
    file
  )
  (write-line "}spacer;ok_cancel;}" file)
  (close file)
  (setq dcl_id (load_dialog tmp))
  (if (not (new_dialog "ListBox" dcl_id))
    (exit)
  )
  (start_list "lst")
  (mapcar 'add_list (mapcar 'cdr keylab))
  (end_list)
  (action_tile
    "accept"
    "(or (= (get_tile \"lst\") \"\")
      (if (= 2 flag)
        (progn
          (foreach n (str2lst (get_tile \"lst\") \" \")
            (setq choice (cons (nth (atoi n) (mapcar 'car keylab)) choice))
          )
          (setq choice (reverse choice))
        )
        (setq choice (nth (atoi (get_tile \"lst\")) (mapcar 'car keylab)))
      )
    )
    (done_dialog)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (vl-file-delete tmp)
  choice
)
(defun c:OD2Label_Side ( / js obj ename htx AcDoc Space nw_style lst_tabl_def inc_key lst_def desc_od str msg pt deriv rtx  nw_obj dxf_ent tmp)
  (princ "\nSelect a curvilinear object (POLYLINE,LINE,ARC,CIRCLE,ELLIPSE,SPLINE).")
  (while
    (null
      (setq js
        (ssget "_+.:E:S"
          (list
            '(0 . "*POLYLINE,LINE,ARC,CIRCLE,ELLIPSE,SPLINE")
            (cons 67 (if (eq (getvar "CVPORT") 1) 1 0))
            (cons 410 (if (eq (getvar "CVPORT") 1) (getvar "CTAB") "Model"))
          )
        )
      )
    )
    (princ "\nIsn't available object for this fonction!")
  )
  (setq
    obj (ssname js 0)
    ename (vlax-ename->vla-object obj)
  )
  (cond
    ((ade_odgettables obj)
      (initget 6)
      (setq htx (getdist (getvar "VIEWCTR") (strcat "\nSpecify text height <" (rtos (getvar "TEXTSIZE")) ">: ")))
      (if htx (setvar "TEXTSIZE" htx))
      (setq
        AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
        Space
        (if (= 1 (getvar "CVPORT"))
          (vla-get-PaperSpace AcDoc)
          (vla-get-ModelSpace AcDoc)
        )
      )
      (cond
        ((null (tblsearch "LAYER" "Label"))
          (vlax-put (vla-add (vla-get-layers AcDoc) "Label") 'color 96)
        )
      )
      (cond
        ((null (tblsearch "STYLE" "Romand-Label"))
          (setq nw_style (vla-add (vla-get-textstyles AcDoc) "Romand-Label"))
          (mapcar
            '(lambda (pr val)
              (vlax-put nw_style pr val)
            )
            (list 'FontFile 'Height 'ObliqueAngle 'Width 'TextGenerationFlag)
            (list "romand.shx" 0.0 (/ (* 15.0 pi) 180) 1.0 0.0)
          )
        )
      )
      (setq lst_tabl_def (mapcar 'ade_odtabledefn (ade_odgettables obj)) inc_key 0)
      (foreach n lst_tabl_def
        (foreach el n
          (if (listp (cdr el))
            (foreach sel (cdr el)
              (foreach msel sel
                (if (eq (car msel) "ColName")
                  (setq lst_def (cons (cons (strcat "key" (itoa (setq inc_key (1+ inc_key)))) (cdr msel)) lst_def))
                )
              )
            )
          )
        )
      )
      (if (not desc_od)
        (setq desc_od (cdr (assoc (listbox "Object data" "Select a data object" lst_def 1) lst_def)))
      )
      (setq str (ade_odgetfield obj (car(ade_odgettables obj)) desc_od 0))
      (setq nw_obj
        (vla-addMtext Space
          (vlax-3d-point (setq pt (polar '(0.0 0.0 0.0) (* pi 0.5) (getvar "TEXTSIZE"))))
          (setq rtx 0.0)
          str
        )
      )
      (mapcar
        '(lambda (pr val)
          (vlax-put nw_obj pr val)
        )
        (list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
        (list 5 (getvar "TEXTSIZE") 5 pt "Romand-Label" "Label" rtx)
      )
      (setq dxf_ent (entget (entlast)))
      (while (or (= 5 (car (setq tmp (grread t 5 1)))) (/= (car tmp) 25) (= (car tmp) 3))
        (cond
          ((= 5 (car tmp))
            (setq
              pt (vlax-curve-getClosestPointTo ename (trans (cadr tmp) 1 0))
              deriv (vlax-curve-getFirstDeriv ename (vlax-curve-GetParamAtPoint ename pt))
              rtx (- (atan (cadr deriv) (car deriv)) (angle '(0 0 0) (getvar "UCSXDIR")))
            )
            (if (or (> rtx (* pi 0.5)) (< rtx (- (* pi 0.5)))) (setq rtx (+ rtx pi)))
            (entmod
              (subst
                (cons 50 rtx)
                (assoc 50 dxf_ent)
                (subst (cons 10 (polar pt (+ rtx (* pi 0.5)) (getvar "TEXTSIZE"))) (assoc 10 dxf_ent) dxf_ent)
              )
            )
            (entupd (cdar dxf_ent))
          )
          ((= 3 (car tmp))
            (setq nw_obj
              (vla-addMtext Space
                (vlax-3d-point (setq pt (polar '(0.0 0.0 0.0) (* pi 0.5) (getvar "TEXTSIZE"))))
                (setq rtx 0.0)
                str
              )
            )
            (mapcar
              '(lambda (pr val)
                (vlax-put nw_obj pr val)
              )
              (list 'AttachmentPoint 'Height 'DrawingDirection 'InsertionPoint 'StyleName 'Layer 'Rotation)
              (list 5 (getvar "TEXTSIZE") 5 pt "Romand-Label" "Label" rtx)
            )
            (setq dxf_ent (entget (entlast)))
          )
          (T (princ "\nAnormal stop command "))
        )
      )
      (entdel (entlast))
    )
    (T (princ "\nData object is empty."))
  )
  (prin1)
)

 

Message 3 of 14
braudpat
in reply to: jagielski

 

Hello

 

Here the same French Routine (ONLY for ACAD MAP or ACAD CIVIL) but translated a minimum ...

 

;;
;; MAP (or CIVIL) Routine :  OD2Label_Side  by Bruno V.
;; Can be used with : POLYLINE,LINE,ARC,CIRCLE,ELLIPSE,SPLINE
;;
;; Write & Place Dynamically a "Static" Text from an Object Data MAP Field  
;;
;; Texts are written on a specific layer   : LABEL
;; Texts depend from a specifig Text Style : Label-Text  (using ISOCP.shx)
;;
;; Minimum US Translation by Patrice (braudpat) + Micro-Micro-Update
;;

Thks to Bruno V. for this nice MAP Routine ("OD2Label_Side") that I use sometimes ...

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 4 of 14
jagielski
in reply to: braudpat

Thank you for the replies. This is a nice lsp routine and I will surely use this. My main problem for my particular situation now is that I have hundreds if not thousands of lines to be labeled. For now I have just connected to the shapefile, labeled the features and converted those label features to text. That sort of works but I would rather have the text follow the lines better.

 

I have a toolpac command that will label text along an object and follows a bending polyline very well, but I can't manually label hundreds of polylines this way and I have to type the text instead of using OD attached to the polylines.

 

My guess is there is no good way to accomplish (or no way at all) what I was thinking might be possible - to utilize the functionality of the toolpac label object commant in an automated process using OD attached to the polylines.

 

I am going to save and use the attached lsp's (thank you again) and move on to more pressing tasks for now.

 

 

Message 5 of 14
braudpat
in reply to: jagielski

 

Hello from France

 

QUESTION : Which MAP 20xx are you using ???

 

This routine "OD2Label_Side" is working fine on ACAD Entity (NOT on FDO entity) but one bye one and let you place many Text dynamically along ONE entity !

 

So of course if you have hundred / thousands objects to label, it is not the solution ! Sorry !!

 

If I understand well : today, you are using a SHP file and the FDO Label Engine to place automatically hundred / thousands objects Labels "along" object, then you export the FDO Map as standard DWG and then inserting the Text/Mtext layer in your current DWG !?

 

But you are not satisfied by the automatic placement of the FDO Label Engine ?

 

Let me know if I understand well ?

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 6 of 14
jagielski
in reply to: braudpat

Pat,

 

The lsp you posted does work as designed and I will surely use it from time to time (thank you), but just not for this application.

 

I am currently using Autocad Map 3d 2012, soon to be switching to 2014.

 

You are understaning correctly. The placement from the way I ended up doing it just doesn't quite follow the polylines as well as I would like, and to use it I end up doing a lot of manual manipulating to make it look okay.

 

Thank you very much for your help.

 

Kraig

Message 7 of 14
braudpat
in reply to: jagielski

 

Hello Kraig

 

Maybe a stupid remark : have you installed the SP 2 on your MAP 2012 ?

http://knowledge.autodesk.com/support/autocad-map-3d/downloads/caas/downloads/content/autocad-map-3d...

 

It will not solve your problem, but it's better ...

 

Can you give me a small SHP (a few complex Lines/Plines) with your attributes ?

and say me which attributes you want to see along ... Better: your expression line in the FDO Label Engine of MA 2012 ...

Maybe (I don't think so !?) MAP 2014/2015 will do a better placement ??

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 8 of 14
jagielski
in reply to: braudpat

Spoiler
 

Pat,

 

I do have SP 2 installed.

 

I've attached an ACAD file with the polylines and how I have them labeled currently (using the Name OD field from the Plines). This works okay, and is probably what I have to settle for. You can see some of the labels cross the lines or are further from the line than they really should be. This isn't the SHP file but is the ACAD file that I produced from labeling the SHP file and then converting to mtext and bringing that into the autocad file where I imported the shapefile too.

 

I've circled a label that I did manually from toolpac - text - on object command that is a manual process that is kind of my idea of what I would really like to see done automatically somehow from using the name OD field, but I'm guessing this is an unreasonable demand.

 

Thank you for your time.

 

Kraig

Message 9 of 14
parkr4st
in reply to: jagielski

Using Map3d 2015, SP1; Just a quick mapexport to sdf and style labels did this.

 

I would skip 2014 if you can.

 

dave

Message 10 of 14
jagielski
in reply to: parkr4st

Dave,

 

Why do you suggest trying to skip 2014 going straight to 2015?

 

I probably don't have a lot of say in what we go to but I can bring up the argument.

 

Thank you,

Kraig

Message 11 of 14
parkr4st
in reply to: jagielski

Odd number versions work, evens don't work very good 🙂  Seems to be history since 2004 when I started with AD.

 

2014 was full of half done things most of which 2015 has corrected. Some of the processes like creating the labels take fewer steps in 15. 

 

It works smoother, loads faster, processes changes faster.  Saves time.  Go to the subscription and then you can get 2015 and updates as they come available. And it recognizes the commands so you get things done the easy way.

 

I have subscription so keep up with the latest verson generally.

 

Explain it is money and time; Time and money.   Your time, their money.  Your time costs them money.  You can always ask for a birthday present, beg plead, load the trial version and show them.

 

dave

Message 12 of 14
olivier.eckmann
in reply to: parkr4st

Hi,

 

perhaps it's true for MAP, but for AutoCAD core it's exactly opposite. Odd version are bad, and even are good.

2004 Good,

2005 with framework 1.0 =>Bad

2007 not to bad but 2008 greater

2009 horrible => memory usage and render was catastrophic

2010 very stable and good

2011 not really good

2012 OK

2013 very bad, very slow

2014 not enough used to say anything 

2015 very slow, latency 2s to 4s between command entered in command line and response of AutoCAD, bad graphic issue...

so before a real good SP1 of MAP 2015 was out, i'm not sure it's a good solution to go to 2015.

 

Olivier

Message 13 of 14
braudpat
in reply to: olivier.eckmann

 

Hello Olivier

 

I agree for AutoCAD MAP 20xx : 2004/2006/2008/2010/2012 were OK !

For Me : 2011 / 2014 not too bad ...

 

 

Patrice ( Supporting Troops ) - Autodesk Expert Elite
If you are happy with my answer please mark "Accept as Solution" and if very happy please give me a Kudos (Felicitations) - Thanks

Patrice BRAUD

EESignature


Message 14 of 14
larrysands
in reply to: jagielski

Has anyone tried using a background mask with the mapanntext? if so how without bursting the command creating a mtext

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

Post to forums  

Autodesk Design & Make Report

”Boost