Jump to content

Labeling polyline (elements from text file)


Kevin Malone

Recommended Posts

Posted

I left office 10 min ago. Will test it when I get home. I'm sure it's correct, but still can't wait to see how it works

  • Replies 38
  • Created
  • Last Reply

Top Posters In This Topic

  • Kevin Malone

    19

  • Tharwat

    16

  • BIGAL

    4

Top Posters In This Topic

Posted Images

Posted
I left office 10 min ago. Will test it when I get home. I'm sure it's correct, but still can't wait to see how it works

 

Would be waiting for your test.

Posted
This lisp, for tertiary network works like a charm!

 

http://gph.is/2bjMTch

 

Excellent.:)

 

As I said before, you can select as much as you want of polyline objects and not only one.

Posted

Is it possible to modify lisp for primary and secondary network? If not, I was thinking, maybe to create lisp with next lines:

 

Select polyline

Enter slope for first segment

Enter diameter for first segment

Enter slope for next segment

Enter diameter for next segment

Enter slope for next segment

Enter diameter for next segment

........

 

And I will create text file to look (for example) like this:

 

1

218

1

218

0.6

218

0.3

218

....

 

which is:

 

slope

radius

slope

radius

.......

 

So after selecting polyline, I would just copy/paste this into command line.

 

Only problem would be to determine direction of labeling.

 

What do you think?

How can I solve this label rotation I'm getting from lisp?

Posted

Edit: I have found lisp for rotating blocks around their base point:

 

;* Rotate Multiple
;* Rotates many entities around their respective basepoints
;* allows selection by AUTOCAD selection sets or SSX.
;* Written by David Husch, January 1991

(defun c:rotmult ()
 (prompt "Select Entities to Rotate, <ENTER> for SSX.")
 (setq ss (ssget))
 (if (not ss) (setq ss (ssx)))
 (setq num (sslength ss))
 (setq x 0)
 (if ss 
 	(if (setq ang (getreal "Enter Rotation Angle: "))
  	(repeat num
	  	(setq ename (ssname ss x))
	    (setq elist (entget ename))
		(setq pnt (cdr(assoc 10 elist)))
		(command "Rotate" ename "" pnt ang)
		    (setq x (1+ x))
    	)
  	)
   )
 )

 

So this solves rotation problem I mentioned. Even though it's not most elegant solution, still does the job.

Posted
Edit: I have found lisp for rotating blocks around their base point:

 

There is no need for any program to work around this simple issue, just replace the following:

 

Replace this:

(angle (car lst) (cadr lst))

With this:

(angle (cadr lst) (car lst))

 

EDIT: the rotation of the block is following the polyline direction and if you run reverse command on the polyline and try the program again , you would know why.

Posted

This is great, now I can print labels in both direction. Sometimes is required for labels to be printed in slope direction.

 

What about labeling primary and secondary? Is it possible to work it out?

Posted

I would go back to you tomorrow for the second issue because I am a bit tired to start with a new program for now, so hope you don't mind.

Posted

Off course! I don't have words to thank you enough for what you did so far.

 

Edit: just tried with reversing pline, BEAUTIFUL!

Posted

Only problem would be to determine direction of labeling.

 

What do you think?

How can I solve this label rotation I'm getting from lisp?

 

Hi Kevin,

 

Yes sure there is and I modified the program to suit all sorts of angles (rotations) CLICK HERE

 

Is it possible to modify lisp for primary and secondary network? If not, I was thinking, maybe to create lisp with next lines:

I don't think it would be in one program so just need to write a new program and this should not allow the user to pick more than one polyline in every call of the program.

 

So after selecting polyline, I would just copy/paste this into command line.

Can you explain this a bit more?

Posted

I't doesn't have to be able to label more then one polyline at the time, since one polyline is 3+ km long.

 

What I have tried to say is, it would be easier to create lisp that first prompts for polyline to be selected, after that it asks for slope, radius, slope, radius (one line at the time). Then I would copy file containing for example:

 

1

218

0.6

218

0.3

218

....

 

And it would fill prompted values for slope and radiuses of each segment.

 

In Command line it would look like:

 

Select polyline:

Selected object: 1 found

Define slope: 1 -at this line I paste values from file

Define radius: 218

Define slope: 0.6

Define radius: 218

...

 

Hope I was clear.

 

This lisp should ask for polyline to be selected, then ask for slope, and then for radius. After inputting these values it should label first segment, then asks for next slope and radius.... Line by line, slope and radius prompts would be filled with values copied from file.

Posted

Something like this?

(defun c:Test (/ *error* s i e atts sp sty lay l p bk lst ang vals data
              f o
             )
 ;; Tharwat - Date: 13.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)
 )
 (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))
 (if
   (and
     (if (tblsearch "BLOCK" "Labeling Block")
       t
       (progn
         (alert
           "Attributed Block name <Labeling Block> is not found in drawing !"
         )
         nil
       )
     )
     (princ "\nPick on single polyline to label :")
     (setq s (ssget "_+.:S:E" '((0 . "POLYLINE"))))
     (progn
       (setq e (ssname s 0))
       (while (and (setq e (entnext e))
                   (= "VERTEX" (cdr (assoc 0 (setq l (entget e)))))
                   (setq lst (cons (cdr (assoc 10 l)) lst))
              )
       )
       lst
     )
   )
    (while (and lst
                (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*)
                       )
                )
           )
      (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
                   )
                 )
            vals (list
                   (strcat "L=" (rtos (distance (car lst) (cadr lst)) 2 2))
                   (strcat "i=" (rtos *LabSlope* 2 2) "% PVC SN8")
                   (strcat "%%C " (itoa *LabRadii*))
                 )
            data (cons vals data)
      )
      (vla-put-layer bk lay)
      (mapcar
        '(lambda (a)
           (vla-put-textstring
             a
             (nth (vl-position (vla-get-tagstring a) '("A" "B" "C"))
                  vals
             )
           )
         )
        (vlax-invoke bk 'getattributes)
      )
      (setq lst (cdr lst))
      (if (< (length lst) 2)
        (setq lst nil)
      )
    )
 )
 (if (and data
          (setq f (getfiled "Specify File name..." "" "txt" 1))
          (setq o (open f "w"))
     )
   (progn
     (mapcar
       '(lambda (u)
          (write-line
            (apply 'strcat (mapcar '(lambda (x) (strcat x " ")) u))
            o
          )
        )
       (reverse data)
     )
     (close o)
   )
 )
 (*error* nil)
 (princ)
)(vl-load-com)

Posted

http://gph.is/2aZPA0x

 

Works perfectly!

Thank you a lot!

 

Tomorrow I'm starting to work on this, it will be 1000 times faster.

 

Once again, I can't thank you enough!

Posted
http://gph.is/2aZPA0x

 

Works perfectly!

Thank you a lot!

 

Tomorrow I'm starting to work on this, it will be 1000 times faster.

 

Once again, I can't thank you enough!

 

Excellent. You are most welcome.

Posted

Just to clarify one thing:

 

I added an option to codes to allow you to save the input data to an external new txt file so if you don't want this option just remove the related codes.

  • 2 weeks later...
Posted

Tharwat

 

I need your help again. As I said, LISP for labelling tertiary works perfectly, but now I'm facing different problem. Many of them are consists out of short segments, so when I run LISP they get overlapped.

This is example how it looks now (segments are way shorter in project)

gbWQiEq.jpg

 

My first idea was to delete all labels on one pline, except one, since slope and radius are constant. But then I realised length should be labelled with pline total length, not one segment length. My project supervisor approved this idea, even though LISP right now works by all standards.

 

Label should look like this:

AJYCmm7.jpg?1

(in red rectangle should be total length of pline)

 

Is it possible to work this out? Problem here, in my opinion, is to determine pline segment on which label will be printed, and my idea is to take longest segment for labeling.

 

I honestly hope you'll find time for this

Posted

Tharwat,

 

I hope you can help me with my new problem, it's becoming really big time-consuming operation.

Posted

Sorry Kevin, I don't have that much time to work on another custom program as I did for the first one for you in this thread.

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...