Jump to content

Autolisp for contour lines


tony farrar

Recommended Posts

Have map data imported into autocad, contains hundreds of contour lines that all have elevation levels of 0.

Need to enter real elevation values of each polyline ( contour line), can do this by clicking polyline and changing elevation in properties, this can take days of laborious work depending on the size map data. Is it possible to write code through lisp where by I can click on a polyline set the increase in elevation, then from there I click on the next polyline and automatically that polylines elevation is move one higher than the previous selected polyline. The purpose is to have a 3d model of contour lines for civil based software.

Link to comment
Share on other sites

And here is my answer:

(defun c:pp()
  (setq current (getreal "starting elevation? ")
	step (getreal "step? "))
  (princ "\n keep selecting or ESC to terminate")
  (setq pl t)
  (while pl
    (princ (strcat "\nSelect polyline for elevation: " (rtos current)))
    (setq pl (entget (car (entsel)))
	  pl (subst (cons 38 current) (assoc 38 pl) pl)
  	  pl (entmod pl)
	  current (+ current step))
    )  
  )

 

Link to comment
Share on other sites

With the polylines are there any height markers referencing what is at what height - if there is one for each contour it might be possible to select all contours and height texts for a little more automation. We'd need to see a sample drawing though to work that out.

 

Fuccaros LISP should save a lot of time I think.

Link to comment
Share on other sites

Probable OP forgot his password for this site :)

I wrote a Lisp to help even more the creation of the 3D terrain model.

It works when a contour contains exactly one contour at the next elevation. As shown in the image, the program can process the white polylines. For the red ones you will need to run it again. It’s the user’s responsibility to make the right selection when the program prompts.

So, enter the step, the elevation for the first contour and select at once all the objects, the selection order doesn’t count. The program will place the largest contour line at the starting elevation and will rise the others, each one with one step.

Enjoy!

contour.gif.ee74bad1817a3a4d2113d85b1cd87ab2.gif

(defun c:pp()
  (setq step (getreal "\nStep? ")
	current_elev (- (getreal "Starting elevation? ") step)
	ss (ssget)
	list1 nil)
  (repeat (setq i (sslength ss))
    (setq list1 (cons (list (setq ent (ssname ss (setq i (1- i))))  (vla-get-area (vlax-ename->vla-object ent))) list1))
    )
  (setq ss nil
	list1 (vl-sort list1 '(lambda(x y) (> (cadr x) (cadr y)))))
  (foreach elem list1
    (setq poly (entget (car elem))
	  poly (subst (cons 38 (setq current_elev (+ current_elev step))) (assoc 38 poly) poly)
	  poly (entmod poly)
	  )    
    )
  (strcat "Ended at elevation " (rtos current_elev))
  )
Link to comment
Share on other sites

Did you bring these contours in by using Civil 3D and import a .shp file?

 

You can tell if these contours are from an imported shape file if you select them and you see extra properties in the bottom of the properties palette. One of the properties will be "Elevation"

 

If so, refer to this article using C3D and Map 3D commands to apply the elevation to the contours:

https://blogs.rand.com/civil/2010/03/using-esri-contours-from-a-shp-file-to-create-a-civil-3d-surface.html

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