Jump to content

Recommended Posts

Posted

Hi all,

Sorry, my English so so so bad

I have a centerline of road in the drawing. I want to create two polyline on left side and right side of that centerline from file .txt

 

File structure:

1st column: Station of centerline

2nd column: Perpendicular distance from the LEFT edge road to centerline at Station point

3rd column: Perpendicular distance from the RIGHT edge road to centerline at Station point

 

we select a polyline of centerline in the drawing, select a starting point, then select file .txt.

 

example please download the attach file.

Please help me!

Test.txt

example1.dwg

Posted

Hello .

 

Try this routine and let me know how would you get on with it .

 

(defun c:Test (/ _ps _lw f o st l p s st nd pt ang e lst len)
 ;;    Author : Tharwat 30. Mar. 2014        ;;
 (if (and (setq f (getfiled "Select txt file :" "" "txt" 16))
          (setq o (open f "r"))
          (setq p (getpoint "\n Specify point at start point of Polyline :"))
          (setq s (ssget p '((0 . "LWPOLYLINE"))))
     )
   (progn
     (defun _ps (st / p v)
       (while (setq p (vl-string-position 9 st))
         (setq v  (cons (substr st 1 p) v)
               st (substr st (+ 2 p) (strlen st))
         )
       )
       (if st
         (setq v (cons st v))
       )
       (reverse v)
     )
     (while (setq st (read-line o)) (setq l (cons (_ps st) l)))
     (setq l (reverse l))
     (close o)
     (if (< (distance p (setq st (vlax-curve-getstartpoint (setq e (ssname s 0)))))
            (distance p (setq nd (vlax-curve-getendpoint e)))
         )
       (progn
         (setq p st)
         (foreach d l
           (if (setq ang (angle '(0.0 0.0 0.0)
                                (vlax-curve-getfirstderiv
                                  e
                                  (vlax-curve-getparamatpoint e (setq pt (vlax-curve-getpointatdist e (atof (car d)))))
                                )
                         )
               )
             (setq lst
                    (cons
                      (list (polar pt (+ (/ pi 2.) ang) (atof (cadr d))) (polar pt (- ang (/ pi 2.)) (atof (caddr d))))
                      lst
                    )
             )
           )
         )
       )
       (progn (setq len (vlax-curve-getdistatpoint e nd))
              (foreach d l
                (if (setq
                      ang (angle
                            '(0.0 0.0 0.0)
                            (vlax-curve-getfirstderiv
                              e
                              (vlax-curve-getparamatpoint e (setq pt (vlax-curve-getpointatdist e (- len (atof (car d))))))
                            )
                          )
                    )
                  (setq lst
                         (cons
                           (list (polar pt (+ (/ pi 2.) ang) (atof (cadr d))) (polar pt (- ang (/ pi 2.)) (atof (caddr d))))
                           lst
                         )
                  )
                )
              )
       )
     )
     (if (and lst (> (length lst) 1))
       (progn (defun _lw (pts)
                (entmakex (append (list '(0 . "LWPOLYLINE")
                                        '(100 . "AcDbEntity")
                                        '(100 . "AcDbPolyline")
                                        (cons 90 (length lst))
                                        '(70 . 0)
                                  )
                                  (mapcar '(lambda (x) (cons 10 x)) pts)
                          )
                )
              )
              (mapcar '_lw (list (mapcar 'car lst) (mapcar 'cadr lst)))
       )
     )
   )
   (princ "\n Invalid file or Picked isn't on Polyline !!")
 )
 (princ)
)(vl-load-com)

Posted

Hi Tharwat, thank you very much for helping me. This routine worked!

But what happens when two (or >2) polylines have a common starting point if not selected a polyline in the drawing?

Posted

Nice job Tharwat. Can I ask you a question.

 

a)What happend if we have a file like this

b)If i want to select a specific point of road centerline with specific Station what happend ?

 

0,3.5,3.6
20,3.4,3.6
45,3.6,3.5
70,3.5,3.4
100,3.4,3.6

 

Thanks

Posted
Nice job Tharwat. Can I ask you a question.

 

a)What happend if we have a file like this

b)If i want to select a specific point of road centerline with specific Station what happend ?

 

0,3.5,3.6
20,3.4,3.6
45,3.6,3.5
70,3.5,3.4
100,3.4,3.6

 

Thanks

 

Try to replace this in the routine and let me know .

 

Replace this .

 

(while (setq p (vl-string-position 9 st))

 

With this .

 

(while (setq p (vl-string-position 44 st))

Posted
Hi Tharwat, thank you very much for helping me. This routine worked!

But what happens when two (or >2) polylines have a common starting point if not selected a polyline in the drawing?

 

Only one would be considered .

Posted (edited)

Ok i change it.

If i want to select a specific point of road centerline with specific Station what happend ? I want to give any time the beginning Station not to be all the times 0 ,and is not nessesary all the times to be the start or the end of the polyline ,must be any point of a polyline.

 

Example

 

I have a road from 4+500 to 8+400 and i want to offset lines from 4+500 to 6+200 .First i pick the point to 4+500 , i give the beginning Station 4+500 and then i load the file from 4+500 --> 6+200

 

Look the attach file

(defun c:Test (/ _ps _lw f o st l p s st nd pt ang e lst len)
 ;;    Author : Tharwat 30. Mar. 2014        ;;
 (if (and (setq f (getfiled "Select txt file :" "" "txt" 16))
          (setq o (open f "r"))
          (setq p (getpoint "\n Specify point at start point of Polyline :"))
          (setq s (ssget p '((0 . "LWPOLYLINE"))))
     )
   (progn
     (defun _ps (st / p v)
       (while (setq p (vl-string-position 44 st))
         (setq v  (cons (substr st 1 p) v)
               st (substr st (+ 2 p) (strlen st))
         )
       )
       (if st
         (setq v (cons st v))
       )
       (reverse v)
     )
     (while (setq st (read-line o)) (setq l (cons (_ps st) l)))
     (setq l (reverse l))
     (close o)
     (if (< (distance p (setq st (vlax-curve-getstartpoint (setq e (ssname s 0)))))
            (distance p (setq nd (vlax-curve-getendpoint e)))
         )
       (progn
         (setq p st)
         (foreach d l
           (if (setq ang (angle '(0.0 0.0 0.0)
                                (vlax-curve-getfirstderiv
                                  e
                                  (vlax-curve-getparamatpoint e (setq pt (vlax-curve-getpointatdist e (atof (car d)))))
                                )
                         )
               )
             (setq lst
                    (cons
                      (list (polar pt (+ (/ pi 2.) ang) (atof (cadr d))) (polar pt (- ang (/ pi 2.)) (atof (caddr d))))
                      lst
                    )
             )
           )
         )
       )
       (progn (setq len (vlax-curve-getdistatpoint e nd))
              (foreach d l
                (if (setq
                      ang (angle
                            '(0.0 0.0 0.0)
                            (vlax-curve-getfirstderiv
                              e
                              (vlax-curve-getparamatpoint e (setq pt (vlax-curve-getpointatdist e (- len (atof (car d))))))
                            )
                          )
                    )
                  (setq lst
                         (cons
                           (list (polar pt (+ (/ pi 2.) ang) (atof (cadr d))) (polar pt (- ang (/ pi 2.)) (atof (caddr d))))
                           lst
                         )
                  )
                )
              )
       )
     )
     (if (and lst (> (length lst) 1))
       (progn (defun _lw (pts)
                (entmakex (append (list '(0 . "LWPOLYLINE")
                                        '(100 . "AcDbEntity")
                                        '(100 . "AcDbPolyline")
                                        (cons 90 (length lst))
                                        '(70 . 0)
                                  )
                                  (mapcar '(lambda (x) (cons 10 x)) pts)
                          )
                )
              )
              (mapcar '_lw (list (mapcar 'car lst) (mapcar 'cadr lst)))
       )
     )
   )
   (princ "\n Invalid file or Picked isn't on Polyline !!")
 )
 (princ)
)(vl-load-com)

EXAMPLE.dwg

Edited by prodromosm

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