Jump to content

Labeling polyline (elements from text file)


Kevin Malone

Recommended Posts

Hello,

 

I'm working on sewer planning, so I have to label a ton of 2D polyline segments with its length, slope, pipe type (material), and pipe profile (radius in mm). All of these information's are stored in .dat file (text file, input file extension for AutoCAD module I'm using). Module is based on AutoCAD Map 2008, also I use Civil 3D 2010.

 

This is how it's supposed to look:

lI9LQqE

 

As you can see, above line segment is printed segment length with suffix "L=", under the segment is slope (in percentage) with suffix "i=" and prefix "%" and type material (PVC SN8).

 

I would format .dat file to contain only necessary data, and to be .txt off course.

Is it possible to do this in Civil 3D somehow, or it requires writing a LISP?

 

(I've attached cleaned .txt file. First column is segment length, second pipe material, third pipe radius (profile), and fourth is slope).

 

Any help is welcome. I'm loosing a lot of time on doing this by hand. I have less then 30 days to finish, so any hour saved is

significant.

 

Thank you

sewer_S6.txt

sewer_s6.dwg

Link to comment
Share on other sites

  • Replies 38
  • Created
  • Last Reply

Top Posters In This Topic

  • Kevin Malone

    19

  • Tharwat

    16

  • BIGAL

    4

Top Posters In This Topic

Posted Images

All of the modules for surveying and planing are in Map 3D 2008, so I'm using it in 9/10 cases. Civil 3D is mainly used for surveying tools (import/export points, creating surfaces, calculating volume...). I mentioned Civil, because I thought there is some Labeling tool to do this.

 

I've never used Pipe Network for planing. Also, (if I understood correctly) I need to do all the planning I have done so far, again using Pipe Network in order to be able to label the pipes the way I want?

Link to comment
Share on other sites

Maybe I understand a bit more now. Take a pline co-ords lsp this will give all the pline vertices you can then read your dat file and draw the text at the correct location.

eg middle of pt2 pt3 and 3 below same angle as pt2-pt3. I would make a few defuns one for each part of the labelling. I dont have any code that matches a google for "label plines" may help find something that can be patched together quickly. I am in middle of a major project at moment so time is not something I have.

Link to comment
Share on other sites

This morning, on my way to work, i got same idea. I think I have a lisp for exporting vertices coord in txt file, somewhere. My idea was to create a lisp (lets call it printAbove) that requires several parameters to print text. For example: text alignment X, text alignment Y, angle, text, layer (or height, color, font). I could easily format my output file to contain these data. Then, use MULTIPLE function on printAbove. Same to do for printUnder. What do you think?

 

I have been searching for "label polylines", but could't find anything I can use. I appreciate your time you are taking each time to reply. Right now, I'm working on two projects, it takes more then 12 hours of my day, that is why I don't reply immediately, and I apologize for that.

 

I don't know AutoLISP, started to learn 2/y ago, but could'n manage to find time. I can read most of the code, and do some minor modifications.

 

Again, thank you for replies

 

Edit:

 

I have found that lisp for exporting vertices coord to txt file:

 

(defun vert (/		 filterlist  vla-obj-list
     lwlist	 2dlist	     ptlist	 vlist1
     vlist2	 vlist3
    )
 (vl-load-com)
 (setq	filterlist   (make-filter)
vla-obj-list (get-objects filterlist)
lwlist	     (nth 0 vla-obj-list)
2dlist	     (nth 1 vla-obj-list)
ptlist	     (nth 2 vla-obj-list)
vlist1	     nil
vlist2	     nil
vlist3	     nil
 ) ;_ end-of setq
 (if lwlist
   (setq vlist1 (make-list lwlist 2))
 ) ;_ end of if
 (if 2dlist
   (setq vlist2 (make-list 2dlist 3))
 ) ;_ end of if
 (if ptlist
   (setq vlist3 (make-list ptlist 3))
 ) ;_ end of if
 (write-text vlist1 vlist2 vlist3)
 (princ)
) ;_ end of vert

(defun make-list (p-list n / i vlist obj coords ca j x y z xy)
 (setq	i (- 1)
vlist nil
 ) ;_ end of setq
 (repeat (length p-list)
   (setq obj	 (nth (setq i (1+ i)) p-list)
  coords (vlax-get-property obj "coordinates")
  ca	 (vlax-variant-value coords)
  j	 (- 1)
   ) ;_ end-of setq
   (repeat (/ (length (vlax-safearray->list ca)) n)
     (setq x (vlax-safearray-get-element ca (setq j (1+ j))))
     (setq y (vlax-safearray-get-element ca (setq j (1+ j))))
     (if (= n 2)
(setq xy (list x y))
(progn
  (setq z (vlax-safearray-get-element ca (setq j (1+ j))))
  (setq xy (list x y z))
) ;_ end of progn
     ) ;_ end of if
     (setq vlist (append vlist (list xy)))
   ) ;_ end-of repeat
 ) ;_ end-of repeat
) ;_ end-of make-list

(defun make-filter (/ filter)
 (setq	filter '((-4 . "<OR")
	 (0 . "LWPOLYLINE")
	 (0 . "POLYLINE")
	 (0 . "POINT")
	 (-4 . "OR>")
	)
 ) ;_ end of setq
) ;_ end of make-filter

(defun get-objects (filter  /	    ss	    k	    lwp-list
	    2dp-list	    pt-list no-ent  obj	    pl
	    2d	    pt
	   )
 (setq no-ent 1)
 (while no-ent
   (setq ss	   (ssget filter)
  k	   (- 1)
  lwp-list nil
  2dp-list nil
  pt-list  nil
  obj	   nil
  pl	   "AcDbPolyline"
  2d	   "AcDb2dPolyline"
  pt	   "AcDbPoint"
   ) ;_ end-of setq
   (if	ss
     (progn
(setq no-ent nil)
(repeat	(sslength ss)
  (setq	ent (ssname ss (setq k (1+ k)))
	obj (vlax-ename->vla-object ent)
  ) ;_ end-of setq
  (cond
    ((= (vlax-get-property obj "ObjectName") pl)
     (setq lwp-list (append lwp-list (list obj)))
    )
    ((= (vlax-get-property obj "ObjectName") 2d)
     (setq 2dp-list (append 2dp-list (list obj)))
    )
    ((= (vlax-get-property obj "ObjectName") pt)
     (setq pt-list (append pt-list (list obj)))
    )
  ) ;_ end-of cond
) ;_ end-of repeat
     ) ;_ end-of progn
     (prompt "\nNo polylines or points selected, try again.")
   ) ;_ end-of if
 ) ;_ end-of while
 (list lwp-list 2dp-list pt-list)
) ;_ end-of get-objects

(defun write-text (vl1 vl2 vl3)
 (setq	fn (getfiled "Text File" "" "txt" 1)) 
 (setq f (close (open fn "w")))
 (setq msg "Points from LW-Polylines")
 (do-points fn vl1 msg 2)
 (setq msg "Points from 2d-Polylines")
 (do-points fn vl2 msg 3)
 (setq msg "Points from Point entities")
 (do-points fn vl3 msg 3)
 (princ)
) ;_ end of write-text

(defun do-points (fn vl msg n)
 (setq f (open fn "a"))
 (write-line msg f)
 (write-line "  x,  y,  z" f)
 (write-line "" f)
 (foreach point vl
   (setq x (nth 0 point)
  y (nth 1 point)
   ) ;_ end of setq
   (if	(= n 2)
     (setq str (strcat (rtos x) "," (rtos y)))
     (progn
(setq z (nth 2 point))
(setq str (strcat (rtos x) "," (rtos y) "," (rtos z)))
     ) ;_ end of progn
   ) ;_ end of if
   (write-line str f)
 ) ;_ end of foreach
 (setq f (close f))
 (princ)
) ;_ end of defun

(defun c:pts ()
 (vert)
 (princ)
) ;_ end-of defun

(prompt "PLIST.LSP by Tony Hotchkiss - enter PTS to start ")

Edited by Kevin Malone
Link to comment
Share on other sites

Bit long winded, the co-ords are saved as a list in the variable co-ordsxy.

 

 

sample result of a 2d pline 3 lines

Command: !co-ordsxy

((316.186 303.015) (433.333 303.015) (433.333 371.628) (275.147 371.628))

 

 

 

; pline co-ords example
; By Alan H
(defun getcoords (ent)
 (vlax-safearray->list
   (vlax-variant-value
     (vlax-get-property
   (vlax-ename->vla-object ent)
   "Coordinates"
     )
   )
 )
)

(defun co-ords2xy ()
; convert now to a list of xy as co-ords are x y x y x y if 3d x y z x y z
(setq len (length co-ords))
(setq numb (/ len 2)) ; even and odd check required
(setq I 0)
(repeat numb
(setq xy (list (nth i co-ords)(nth (+ I 1) co-ords) ))
; odd (setq xy (list (nth i co-ords)(nth (+ I 1) co-ords)(nth (+ I 2) co-ords) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)
)
; program starts here
(setq co-ords (getcoords (car (entsel "\nplease pick pline"))))
(co-ords2xy) ; list of 2d points making pline

Link to comment
Share on other sites

Something isn't working properly. As you can see in screenshot, x and y are not grouped in parenthesis in every case. Sometimes there are only X coord, and Y coord is 0.0, and vice versa.

 

idA3j

 

(4.97316e+006 0.0) (0.0 6.41379e+006) should probably be: (6.41379e+006 4.97316e+006)

Link to comment
Share on other sites

Hi,

 

Firstly please modify your post #5 and add CODE TAGS as shown in THIS LINK

 

Secondly I will not promise that I can help you as best as you looking forward but I will do my best if you can explain your issues very clearly.

 

So can you explain what is the purpose of the .txt file attached in the first post? Because I can not see anything in common between the txt fie and the attached drawing.

 

Should the user be asked to select a .txt file then write these data into attributed block as shown in the drawing ?

Link to comment
Share on other sites

kevin sorry your correct the output is x y x y x y or if 3d x y z x y z x y z

 

I agree with Tharwat your dwg does not really reflect what your saying I think what your implying is to work out all the invert levels and label.

Link to comment
Share on other sites

Tharwat

 

text file I' attached is "refined" .dat file (.dat file is file dreated for importing in AutoCAD, then used to draw pipe profile view). I made mistake defining column content. Firs column ist length of segment, second AND third are pipe material, fourth is pipe profile, and fifth is slope. Only connection between txt and dwg is segment length, so my idea was to export pline vertices coord in txt, create file for print (in Excel for example, one row to look like: text alignment X, text alignment Y, angle, text, layer (or height, color, font)). Also, profile view (you can see it in UPR Layout of attached dwg in this post) contains information on pipe (2 red parallel lines in "niveleta" Layer represents pipe).

 

I have deleted attributed block, as they are irrelevant to this matter. To simplify problem: I need to label 2D pline with its length and informations I have in text file. On this project I need do this for 50-60 kilometers of primary Network, hundreds of secondary, and hundreds of tertiary. So it requires a lot of time to be done by hand.

PIPELINE_example6.dwg

Link to comment
Share on other sites

Hi,

So the first line of text represents the length of the each segment of the polyline ? and the two lines of texts should be imported from the txt file ?

 

Since the last two lines of texts are the same, why don't we just add them immediately to the oncoming program without bothering users to select that txt file? unless you have different information for each process.

 

It is not a good way to write diameter symbol via ZERO number crossed with a line, you can just include these three chars like this %%C

 

Have a look at the following image for more information:

Dia.JPG

Link to comment
Share on other sites

Tharwat,

 

I didn't understood question. First line, you probably meant column, or vertical line. Yes, first column is length of segment.

 

PVC SN8 is type of material and it is always the same (in 99%), 218 (fourth line) is diameter of pipe profile and it is different for each pipeline, last line is slope, and as you can see it is different for each pipeline (it even changes within one pipeline).

 

 

 

Solution you have presented in .gif is great, just missing "L=" prefix on length label. Can you explain me bit more, or walk me thru the process?

 

 

Thank you

Link to comment
Share on other sites

Here is the draft codes for you to test and let me know what are the needed changes for a complete program.

 

NOTE: the following drawing has the Attributed Block entitled [ labeling Block ] and it should be in any drawing you want to run the program with.

Test.dwg

label.LSP

Link to comment
Share on other sites

This is good, only problem is slopes are constantly 0.6% (while in the file they vary between 1 and 0.6, on longer pipelines they can have tens of different values) and pipe profile radius is also constant (in this case it is constant all the way, because it's short example, but on longer lines it changes 2-3 times). That is why I need text file for labelling.

 

This lisp you have attached will be very useful, as tertiary Network (more then hundred km's) will be done with constant slopes and pipe radiuses. I'm just going to need to be prompted for slope and radius which will be used, but I'll try to modify it by myself.

Link to comment
Share on other sites

To label from slopes and radiuses from text? No, I haven't.

 

I can use this lisp for tertiary network (as I mentioned), and that's great piece of work (more the a 1/3). I just need to be prompted for slope and radius input.

 

Still, for primary and secondary I need slopes and radiuses from file.

Link to comment
Share on other sites

Keep the file aside at the mean time for the second job and let us finish your current project with that tertiary Network.

So if this tertiary work needs to change the radius & Slope value here is the final program, try it and let me know.

 

NOTE: I just changed the way to select polyline so with this program you can select as much of polylines as you want.

 

(defun c:Test (/ *error* s i e atts sp sty lay l p bk lst ang)
 ;; Tharwat - Date: 11.Aug.2016 ;;
 (defun *error* (msg)
   (if atts
     (mapcar 'setvar '(ATTREQ ATTDIA) atts)
   )
   (and msg
        (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
        (princ (strcat "\nError => " msg))
   )
   (princ)
 )
 (if
   (and
     (if (tblsearch "BLOCK" "Labeling Block")
       t
       (progn
         (alert
           "Attributed Block name <Labeling Block> is not found in drawing !"
         )
         nil
       )
     )
     (setq *LabRadii*
            (cond
              ((getint
                 (strcat "\nSpecify radius "
                         (if *LabRadii*
                           (strcat "<" (itoa *LabRadii*) "> :")
                           ":"
                         )
                 )
               )
              )
              (*LabRadii*)
            )
     )
     (setq *LabSlope*
            (cond ((getreal
                     (strcat
                       "\nSpecify Slope "
                       (if *LabSlope*
                         (strcat "<" (rtos *LabSlope* 2 2) "> :")
                         ":"
                       )
                     )
                   )
                  )
                  (*LabSlope*)
            )
     )
     (princ "\nSelect polylines to label :")
     (setq s (ssget "_:L" '((0 . "POLYLINE"))))
   )
    (progn
      (setq atts (mapcar 'getvar '(ATTREQ ATTDIA))
            sp   (vlax-get (vla-get-activelayout
                             (vla-get-activedocument (vlax-get-acad-object))
                           )
                           'Block
                 )
            sty  (if (tblsearch "STYLE" "tablicni")
                   "tablicni"
                   "Standard"
                 )
            lay  (if (tblsearch "LAYER" "FRONTOVI")
                   "FRONTOVI"
                   (getvar 'CLAYER)
                 )
      )
      (mapcar 'setvar '(ATTREQ ATTDIA) '(1 0))
      (repeat (setq i (sslength s))
        (setq e (ssname s (setq i (1- i))))
        (while (and (setq e (entnext e))
                    (= "VERTEX" (cdr (assoc 0 (setq l (entget e)))))
                    (setq lst (cons (cdr (assoc 10 l)) lst))
               )
        )
        (repeat (1- (length lst))
          (setq p  (mapcar '(lambda (j k) (/ (+ j k) 2.))
                           (car lst)
                           (cadr lst)
                   )
                ang (angle (car lst) (cadr lst))
                bk (vla-insertblock
                     sp
                     (vlax-3d-point p)
                     "Labeling Block"
                     1.0
                     1.0
                     1.0
                     (if (and (> ang (* pi 0.5)) (<= ang (* pi 1.5))) (setq ang (+ ang pi)) ang)
                   )
          )
          (vla-put-layer bk lay)
          (mapcar
            '(lambda (a)
               (vla-put-textstring
                 a
                 (nth
                   (vl-position (vla-get-tagstring a) '("A" "B" "C"))
                   (list
                     (strcat "L="
                             (rtos (distance (car lst) (cadr lst)) 2 2)
                     )
                     (strcat "i=" (rtos *LabSlope* 2 2) "% PVC SN8")
                     (strcat "%%C " (itoa *LabRadii*))
                   )
                 )
               )
             )
            (vlax-invoke bk 'getattributes)
          )
          (setq lst (cdr lst))
        )
        (setq lst nil)
      )
    )
 )
 (*error* nil)
 (princ)
)(vl-load-com)

Edited by Tharwat
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...