Jump to content

lisp to get the station and coordinates of a polyline at pick location


Recommended Posts

Posted

Dear All.

I am looking for a lisp code that will give a station and the coordinates of selected polyline at the required locations.

Something like I select a polyline and then  I pick at the required location at the polyline and then pick the location where the station and coordinates are placed and it will have a arrow from the first location to the second. and then I continue to pick and place the station and coordinates multiple times without selecting the polyline again.

 

St. 01+234.567

E 100000.000

N 50000.000

I googled a lot and I could get only coordinate lisps.

 

Thanks in advance.

Posted

Did you post this question elsewhere? There is a CIV3D request for this task over at forums/autodesk in the Lisp section.

 

The answer for a pline is in using these two VL functions. vlax-curve-getclosestpointto and vlax-curve-getdistatpoint. These will return offset and distance along the pline. 

 

 

Posted

No I haven't posted any thing in civil3d, though I have made a different request I have made request in autodesk in lisp section.

Posted (edited)

This will get you what you needed, if you want something fancy, it will cost you a cup of coffee.

;;; Program 'sap' Station At Point
;;; By Isaac A 20241228
;;; https://www.cadtutor.net/forum/topic/95474-lisp-to-get-the-station-and-coordinates-of-a-polyline-at-pick-location/
(vl-load-com)
(defun c:sap (/ a b c d dw o oe s)
   (setq oe (getvar 'cmdecho)
         o  (getvar 'osmode)
   )
   (setvar 'cmdecho 0)
   (vla-startundomark (setq dw (vla-get-activedocument (vlax-get-acad-object))))
   (setvar 'osmode 0)
   (alert "Program  to put a mtext containing the Station and coordinates in a polyline. ")
   (princ "\nSelect a polyline. ")
   (setq s (ssget ":S:E" '((0 . "LWPOLYLINE"))))
   (while (= s nil)
      (princ "\nSelect a polyline. ")
      (setq s (ssget ":S:E" '((0 . "LWPOLYLINE"))))
   )
   (setq a (ssname s 0))
   (setq b (vlax-ename->vla-object a)
         c (list 0 0 0)
   )
   (setvar 'osmode 545)
   (setvar 'pdmode 35)
   (setvar 'pdsize 0.6)
   (while (setq c (getpoint "\nSelect a point on the polyline: "))
          (setq d (vlax-curve-getDistAtPoint b c))
          (entmake (list '(0   . "MTEXT")
                         '(100 . "AcDbEntity")
                         '(100 . "AcDbMText")
                         '(8   . "Stations")
                         '(40  . 1.)
                          (cons 10 c)
                          (cons 1  (strcat "St." (rtos d 2 3) "\nE " (rtos (car c) 2 3) "\nN " (rtos (cadr c) 2 3)))
                   )
          )
          (entmake (list '(0   . "point")
                         '(100 . "AcDBpoint")
                         '(8   . "Stations")
                         '(62  . 1)
                          (cons 10 c)
                   )
          )
   )
   (setvar 'cmdecho oe)
   (setvar 'osmode  o)
   (vla-endundomark dw)
   (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;				End of file					;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

Edited by Isaac26a
  • Like 1
Posted
On 12/26/2024 at 12:03 PM, Isaac26a said:

This will get you what you needed, if you want something fancy, it will cost you a cup of coffee.

;;; Program 'sap' Station At Point
;;; By Isaac A 20241226
;;; https://www.cadtutor.net/forum/topic/95474-lisp-to-get-the-station-and-coordinates-of-a-polyline-at-pick-location/
(vl-load-com)
(defun c:sap (/ a b c d dw o oe s)
   (setq oe (getvar 'cmdecho)
         o  (getvar 'osmode)
   )
   (setvar 'cmdecho 0)
   (vla-startundomark (setq dw (vla-get-activedocument (vlax-get-acad-object))))
   (setvar 'osmode 0)
   (alert "Program  to put a text containing the distance (Station) in a polyline. ")
   (princ "\nSelect a polyline. ")
   (setq s (ssget ":S:E" '((0 . "LWPOLYLINE"))))
   (while (= s nil)
      (princ "\nSelect a polyline. ")
      (setq s (ssget ":S:E" '((0 . "LWPOLYLINE"))))
   )
   (setq a (ssname s 0))
   (setq b (vlax-ename->vla-object a)
         c (list 0 0 0)
   )
   (setvar 'osmode 545)
   (setvar 'pdmode 35)
   (setvar 'pdsize 0.6)
   (setq c (vlax-curve-getClosestPointTo b (getpoint "\nSelect a point on the polyline: "))
         d (vlax-curve-getDistAtPoint b c)
   )
   (entmake (list '(0   .  "TEXT")
                  '(100 .  "AcDbEntity")
                  '(100 .  "AcDbText")
                   (cons 8  "Stations")
                   (cons 10 c)
                   (cons 40 1.)
                   (cons 1  (strcat "St." (rtos d 2 2)))
            )
   )
   (entmake
      (list (cons 0   "point")
            (cons 100 "AcDBpoint")
            (cons 8   "Stations")
            (cons 62  1)
            (cons 10  c)
      )
   )
   (setvar 'cmdecho oe)
   (setvar 'osmode  o)
   (vla-endundomark dw)
   (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;				End of file					;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 

THANKS ISAAC26A,

This code works good for the station, can I get it along the coordinates. Like a mtext with the first line as Station, second line as Easting and Third line as Northing as per my request.

Posted

Ok, the code up there is updated as per your request.

Posted
18 hours ago, Isaac26a said:

Ok, the code up there is updated as per your request.

Thanks Isaac26a,

This code is good, can there be loop where after the selection of the polyline it should only ask to select a point and keep going until I cancel by escape....

Once again thanks for the help..

Posted

The code is updated as the last wish of the list.

Posted
19 hours ago, Isaac26a said:

The code is updated as the last wish of the list.

Thanks a lot, exactly ...

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