Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP for drawing a polyline by entering X,Y coordinate from a baseline

7 REPLIES 7
Reply
Message 1 of 8
Shaiki_
3572 Views, 7 Replies

LISP for drawing a polyline by entering X,Y coordinate from a baseline

Hi,

 

I understand the title is unclear so let me try explain what I want. My old company had a LISP that did this so I know its possible, I just don't know how to write LISP.

 

This routine is very useful for drawing the slope of site grading in elevation or section. Generally we'll get a civil plan that has eg. the center of the road marked with spot elevations in plan view, so to accurately produce the slope of the road in an elevation or section I need to math out the change of each spot elevation and its distance from the previous one and go on that way. 

The LISP routine works as follows:

 

Once the plan view is oriented along the X-Axis, the user runs the LISP. The first prompt is to set a baseline elevation, eg 0,0 (either by clicking that location or typing it.) Once this is done the user simply clicks the spot elevations on the plan view along the X axis, and for every location the routine prompts for an elevation, where the user types in the elevation noted on the plan, and the LISP creates that point in the polyline based on the X-coordinate selected and the Y coordinate inputed. After all points are inputed, hit enter to end the command and place the polyline.

It's a simple concept, but hard to explain! Hopefully someone understands what I mean, and if not I'll do my best to clarify!

 

Thanks in advance.

7 REPLIES 7
Message 2 of 8
pbejse
in reply to: Shaiki_


@Shaiki_ wrote:

 

.... n I need to math out the change of each spot elevation and its distance from the previous one and go on that way. 


It sounds easy enough, show me the math, we will incorporate that into the code.


Once the plan view is oriented along the X-Axis, the user runs the LISP. The first prompt is to set a baseline elevation, eg 0,0 (either by clicking that location or typing it.) Once this is done the user simply clicks the spot elevations on the plan view along the X axis, and for every location the routine prompts for an elevation, where the user types in the elevation noted on the plan, and the LISP creates that point in the polyline based on the X-coordinate selected and the Y coordinate inputed. After all points are inputed, hit enter to end the command and place the polyline.


I don't quite get what that means, Is that pick a point on the screen horizontally?  

 

** Years ago, I got a similar request, the main purpose of the program is labeling the site plan composed of 3Dpolylines, so picking a point on an object gives the correct elevation.

 

Another program one prompts for 2 (high and low) elevation value via selection or user prompt, the program will derive the coordinates based on the given elevations.

 

Do you mind posting a sample drawing? [ before & after]

 

Message 3 of 8
Shaiki_
in reply to: pbejse

Yes, pick spots horizontally.

Haha, when an autocad user says "math" how often do they really mean math with numbers! Typically what i would do is just draw my baseline, and copy it up for every different elevation, and then shoot rays down from the spot elevations on the plan to create a grid. After this I'd simply go through and connect all the intersections with a polyline.

 

It sounds more like the first option you mentioned, however instead of locating a Z-coordinate it ascribes a Y-coordinate to a given X-coordinate. Trust me, it makes sense in my head!

 

Hopefully the screenshots below help. The horizontal yellow line at the top is the line that i'd get from a plan with the elevations marked an 'random' intervals. The LISP would allow me to click at each elevation and type the elevation noted, and when I'm finished I'd have a polyline like the purple line.

 

Note: My drawings are in Imperial, and Civil drawings are in metric, so if you could somehow allow me to input meters and convert it to inches (conversion 39.3701) that would be even better!

 

Thanks for helping

Message 4 of 8
pbejse
in reply to: Shaiki_


@Shaiki_ wrote:

Yes, pick spots horizontally 


What type of object is those "elevation" (0.00m, 25.00m... ) on the top row? TEXT / MTEXT? Attributes? Are the circles a separate entity?

The user can select the "numbers" removing the need to type in the values.

 

 

Message 5 of 8
Shaiki_
in reply to: pbejse

In this case its just mtext, a line, and a circle. But the drawings we get from other consultants could be anything, depending on their standards. Most often I think they would be a block with an attribute for the text.

 

The option to select the numbers would be pretty cool, however I'd still like the option to manually type them for that flexibility.

 

 

Message 6 of 8
pbejse
in reply to: Shaiki_


@Shaiki_ wrote:

In this case its just mtext, a line, and a circle. But the drawings we get from other consultants could be anything, depending on their standards. Most often I think they would be a block with an attribute for the text. 


In that case, post both types, we can proceed to write a code that works for those conditions.  A drawing file is preferred shaiki53.

 

Message 7 of 8
Anonymous
in reply to: Shaiki_

Are you trying to draw a profile view of the road?

 

When you receive the spot elevations, do they give you points, or cogo points, or something similar? 

Message 8 of 8
Anonymous
in reply to: Shaiki_

Run this and let me know if this is a start,

 

;;Draw road profile

(defun c:roadprofile ( / BASEELEV NEXTELEV NEXTPOINT POINTLIST STARTPOINT TOTALDISTANCE)


  ;; Start Undo  -  Lee Mac
;; Opens an Undo Group.

(defun LM:startundo ( doc )
    (LM:endundo doc)
    (vla-startundomark doc)
)

;; End Undo  -  Lee Mac
;; Closes an Undo Group.

(defun LM:endundo ( doc )
    (while (= 8 (logand 8 (getvar 'undoctl)))
        (vla-endundomark doc)
    )
)

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)

  (defun LWPoly (lst cls)
  (entmakex (append (list (cons 0 "LWPOLYLINE")
                          (cons 100 "AcDbEntity")
                          (cons 100 "AcDbPolyline")
                          (cons 90 (length lst))
                          (cons 70 cls))
                    (mapcar (function (lambda (p) (cons 10 p))) lst))))

  (LM:startundo (LM:acdoc))

  
  (if (And(setq startpoint (getpoint "\nSelect the first centerpoint in your road: "))
	  (setq baseElev (getreal "\nEnter the elevation of the point: "))
	  (setq totaldistance 0))
    (progn

      (setq pointlist (list (list 0 0 0)))
      (while (And (setq nextpoint (getpoint startpoint "\nSelect the next centerpoint in your road: "))
		  (setq NextElev (getreal "\nEnter the elevation of the point: ")))
	(setq totaldistance (+ totaldistance (distance startpoint nextpoint)))
	(setq pointlist (cons (list totaldistance (- NextElev baseElev) 0) pointlist ))
	(setq startpoint nextpoint))
      (if (> (length pointlist) 1)
	(LWPoly pointlist 0))))
	
  (LM:endundo (LM:acdoc))
  )

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

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report