Author Topic: 3d Polyline with Elevation  (Read 3676 times)

0 Members and 1 Guest are viewing this topic.

DanB

  • Bull Frog
  • Posts: 367
3d Polyline with Elevation
« on: July 26, 2006, 08:45:33 AM »
I am trying to put together a lisp to allow a user to draw a 3d Polyline and enter elevations at each vertice. (There was a command in LDD>>Terrain that would do this, however we are currently moving to Civil 3d 2006/2007)(If/when I get this working I plan on adding slope/grade options as well) I have a working code although when I utilize osnaps, the user elevations are not used (vertice set to Zero). Any ideas or suggestions would be appreciated...

Thanks,
Dan

Code: [Select]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                       7/25/06                               ;;
;;        3d Polyline with User defined Elevations             ;;
;;                                                             ;;
;;    PROGRAM PROVIDED "AS IS" AND WITH ALL FAULTS,            ;;
;;    AND DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM   ;;
;;    WILL BE UNINTERRUPTED OR ERROR FREE.                     ;;
;;                                                             ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun c:plel (/ oldecho pnt1 elev1 pnt1e pntx elevx)
 (setq oldecho (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 
 (setq pnt1 (getpoint "\nSpecify start point of polyline: "))
 (setq elev1 (getreal "\nStart elevation: "))
 (setq pnt1e (subst elev1 (last pnt1) pnt1))

 (command ".3dpoly")
  (while
   (if (= pntx nil)
    (progn
     (command pnt1e)
     (setq pntx (getpoint pnt1e "Pick point: "))
    ) ;end progn
    (setq pntx (getpoint pntx "Pick Point: "))
   ) ;end if
   (command pntx)
   (setq elevx (getreal "\nElevation: "))
   (setq pntx (subst elevx (last pntx) pntx))
   (command "undo")
   (command pntx)
  ) ;end while
 (command "")
 
 (setvar "cmdecho" oldecho)
 (princ)
)


Joe Burke

  • Guest
Re: 3d Polyline with Elevation
« Reply #1 on: July 26, 2006, 09:33:00 AM »
Dan,

I think you want turn running osnaps off/on like this within the while loop.

   (command "undo")
   (setq osm (getvar "osmode"))
   (setvar "osmode" 0)
   (command pntx)
   (setvar "osmode" osm)

DanB

  • Bull Frog
  • Posts: 367
Re: 3d Polyline with Elevation
« Reply #2 on: July 26, 2006, 10:06:16 AM »
Thank You.

I assume the running command was snapping back to the original coordinates, still not too sure about this. However, your suggestion got me back in the game, looks to be running smoothly. Now to add a few more options...

Thanks,
Dan

Below is the revised code (no slope/grades option just yet):

Code: [Select]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                       7/25/06                               ;;
;;        3d Polyline with User defined Elevations             ;;
;;                                                             ;;
;;    PROGRAM PROVIDED "AS IS" AND WITH ALL FAULTS,            ;;
;;    AND DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM   ;;
;;    WILL BE UNINTERRUPTED OR ERROR FREE.                     ;;
;;                                                             ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun c:plel (/ oldecho oldos pnt1 elev1 pnt1e pntx elevx)
 (setq oldecho (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 
 (setq pnt1 (getpoint "\nSpecify start point of polyline: "))
 (setq elev1 (getreal "\nStart elevation: "))
 (setq pnt1e (subst elev1 (last pnt1) pnt1))
             
 (command ".3dpoly")
  (while
   (if (= pntx nil)
    (progn
     (setq oldos (getvar "osmode"))
     (setvar "osmode" 0)
     (command pnt1e)
     (setvar "osmode" oldos)
     (setq pntx (getpoint pnt1e "Pick point: "))
    ) ;end progn
    (setq pntx (getpoint pntx "Pick Point: "))
   ) ;end if
   (command pntx)
   (setq elevx (getreal "\nElevation: "))
   (setq pntx (subst elevx (last pntx) pntx))
   (command "undo")
   (setq oldos (getvar "osmode"))
   (setvar "osmode" 0)
   (command pntx)
   (setvar "osmode" oldos)
  ) ;end while
 (command "")
 
 (setvar "cmdecho" oldecho)
 (princ)
)


Joe Burke

  • Guest
Re: 3d Polyline with Elevation
« Reply #3 on: July 26, 2006, 12:11:20 PM »
Dan,

You're welcome.

Also condiser this, which I think does the same thing, while avoiding pitfalls of (command...)

Code: [Select]
(defun c:3DPline ( / pt elev ptlst mspace)
  (if
    (and
      (setq pt (getpoint "\nPick fisrt point: "))
      (setq elev (getreal "\nElevation: "))
    )
    (progn
      (setq pt (subst elev (last pt) pt)
            ptlst (cons pt ptlst)
      )     
      (while (setq pt (getpoint pt "\nPick next point: "))
        (setq elev (getreal "\nElevation: ")
              pt (subst elev (last pt) pt)
              ptlst (cons pt ptlst)
        )
      )
      (setq mspace
        (vla-get-ModelSpace
          (vla-get-ActiveDocument
            (vlax-get-acad-object))))
      (vlax-invoke mspace 'Add3dPoly (apply 'append (reverse ptlst)))
    )
  )
) ;end

T.Willey

  • Needs a day job
  • Posts: 5251
Re: 3d Polyline with Elevation
« Reply #4 on: July 26, 2006, 12:17:12 PM »
Joe,

  I think you will need to use this function I wrote to reverse you point list.  If you have a list like
(x1 y1 z1 x2 y2 z2)
and you reverse it, you will get
(z2 y2 x2 z1 y1 x1)
With my routine, you will get
(x2 y2 z2 x1 y1 z1)
Code: [Select]
(defun ReverseBy (List Num / tmpList cnt1 RtnList)
; Retrun the list reversed by the number supplied.
; ie: (ReverseBy '(1 2 3 4) 2) -> (3 4 1 2)

(foreach i List
 (setq tmpList (cons i tmpList))
 (if (= (length tmpList) Num)
  (progn
   (setq cnt1 0)
   (repeat Num
    (setq RtnList (cons (nth cnt1 tmpList) RtnList))
    (setq cnt1 (1+ cnt1))
   )
   (setq tmpList nil)
  )
 )
)
RtnList
)
Can't test right now (the reverse idea of your code), but I think my logic is right (I know my code is).
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Joe Burke

  • Guest
Re: 3d Polyline with Elevation
« Reply #5 on: July 26, 2006, 12:42:07 PM »
Hi Tim.

I appreciate the thought. But if you run the code as posted, I think you'll find it works as expected.

Of course, I might be wrong.  :-)

Regards

T.Willey

  • Needs a day job
  • Posts: 5251
Re: 3d Polyline with Elevation
« Reply #6 on: July 26, 2006, 12:50:08 PM »
Okay, I will when I can.  Right now my Acad is busy doing work, ewwww.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: 3d Polyline with Elevation
« Reply #7 on: July 26, 2006, 03:21:55 PM »
Hi Tim.

I appreciate the thought. But if you run the code as posted, I think you'll find it works as expected.

Of course, I might be wrong.  :-)

Regards
You are correct Joe (finally got my Acad back).   :-)  Now I will have to see why, because I wrote that function for this type of situation. :lol:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: 3d Polyline with Elevation
« Reply #8 on: July 26, 2006, 03:27:22 PM »
Hi Tim.

I appreciate the thought. But if you run the code as posted, I think you'll find it works as expected.

Of course, I might be wrong.  :-)

Regards
You are correct Joe (finally got my Acad back).   :-)  Now I will have to see why, because I wrote that function for this type of situation. :lol:
I see what you did, very nice I might add.  You took the points, as there own point lists, and added them to one big list, and then reversed them.  Since they are still there own list inside of the main list, they revers in order, and then you did an append on them to make them all one list, instead of a list of lists.  I like.  I might have to steal the idea.  Thanks Joe.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.