Jump to content

LSP, LISP grade levels, point calculation, road levels


nosyparker

Recommended Posts

hello, everyboy,

 

LOOKING FOR LISP SOME ONE CAN HELP PLEASE.

 

I got to do a lot of work on my new project, this is something I had never done before...the task is to calculate certain grade levels based on given levels.

 

so, to move quickly and avoid routine calculations I would be grateful if some one can make lisp for me....

 

list should ask user a level-1 & level-2 input and then

ask for point of distance for d1, d2, d3.

 

I tried to attach a files, but office security system doesn't allowed me to attach.

 

so,

 

LEVEL-1 = 5.00

LEVEL-2 = 3.75

LEVEL-3 = x (THIS POINT FALL INLINE TO L1 & L2 ABOVE MID POINT,

FOR ASSUMPTION ONLY)

LEVEL-4 = ? (NEED TO FOUND THIS LEVEL)

 

DIST-1 = 10 (THIS IS DIST BETWEEN LEVEL-1 & LEVEL-2)

DIST-2 = 3.6 (THIS IS DIST BEWEEN LEVEL-3 & HIGHEST LEVEL i.e., LEVEL-1)

DIST-3 = 8.7 (THIS IS PERPENDICULAR DIST BETWEEN LEVEL-3 & LEVEL-4 FOLLOWING 2% SLOPE [WHICH WE NEED TO FOUND)....

 

 

 

FORMAULA WORKS LIKE THIS.

 

L1-L2/D1 = X

L1-(X * D2) = L3

L3-(0.02 * D3) = L4 (i.e., 4.376)

 

 

please its very urgent and importan.........thanking in advance.

Edited by nosyparker
Link to comment
Share on other sites

Try function

;x = any Distance along linear
;y = offset distance
;a = start Level
;b = end level 
;d = TotalDistance a to b
;g% = gradient of y (offset distance)

(defun level (x y a b d g%)
 (if (and a
   b
   (not (zerop d)))
   (+(+ (* (/ (- b a) d) x) a) (* y (/ g% 100.)))
   ) ;_ end of if
 ) ;_ end of defun

call: (level dist1 dist2 level1 level2 totalDist gradient%)

[color="red"][b]([/b][/color][color="blue"]level	[/color];
 [color="#006400"]3.6[/color]	[color="#696969"];Any distance from Level1[/color]
 [color="#006400"]8.7[/color]	[color="#696969"];offset Distance at Level3[/color]
 [color="#006400"]5.0[/color]	[color="#696969"];highest Level1[/color]
 [color="#006400"]3.75[/color][color="#696969"];lowest level2[/color]
 [color="#006400"]10[/color].	[color="#696969"];TotalDist Level1 to Level2[/color]
 [color="#006400"]-2.0[/color][color="red"][b])[/b][/color] [color="#696969"];slope eg: -2.0% = 0.020[/color]

;retval, Level4= [color="red"]4.376 [/color]

Edited by hanhphuc
Link to comment
Share on other sites

Hunhphuc,............

 

Thanks phuc............but i didnt got it.........

 

Firstly i didt understand what is command input.............

 

I tried as "level" as my command input but didnt worked............

 

And i coppied only above code do i need to copy the below too ?

 

Pl. Pl pl pl pl pl pl help me help

Edited by nosyparker
Link to comment
Share on other sites

sorry it was just function,

here's the Command: LEVEL

 

Level v1.1: 03/09/2014

>add text : pick on screen

>without text : [Enter] or [spacebar]

>fixed recall last *level-user* input

(if (or (not *level-param*) (not *level-user*))
  (setq *level-param* '(5.0 3.75 10. -2.) *level-user* '(3.6 8.7))  ; <-- this is your default value
  )


(defun c:level (/ level *error* txt)  ; v1.1


  (defun *error* (msg)

    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))

      (princ (strcat "\nError: " msg))

    ) 

    (graphscr)

    (princ)

  ) 


  (Prompt "\nInput the required parameters..\n")

  (setq level '((x y a b d g%)

                 (if

                   (and a b (not (zerop d)))

                   (+ (+ (* (/ (- b a) d) x) a) (* y (/ g% 100.)))

                 ) 

               )

        *level-param* (hp# 'getreal

                     '(0 0 6 0)

                     '( "A:Level1" "B:Level2" "Distance A~B " "Slope in %")

                     *level-param*

                ) ;_ end of hp#

  ) 
  
  (Prompt "\nRepeat user input distance & offset..")

  (while *level-param*

    (prompt "\n\nNext..")

    (setq txt (rtos (apply 'level

                           (append (setq *level-user* (hp# 'getdist '(4 4) '( "\nDistance from A?" "Offset Distance?") *level-user*))

                                   *level-param*

                           ) ;_ end of append

                    ) ;_ end of apply

                    2

                    3  ; <-- precision  0.000

              ) 

    ) 



    (if

      (setq p (getpoint "\nInsert text.. "))

      (entmake (list '(0 . "TEXT")

                     (cons 1

                           (strcat "RL: "           ;<-- prefix, without prefix just put: ""

                                   txt

                           )

                     )

                     (cons 10 (trans p 1 0))

                     (cons 40 (getvar "textsize"))  ;<--- default, manually can change in command: TEXTSIZE

                     (cons 8 "LEVEL")               ;<--- Layer
               )
      )

      (alert (strcat "\nLevel : " txt))             ;<--- show if null point

    )

    (princ)

  ) 

) 







;;;----------------------------------------------------		

;;;								

;; courtesy of the author's of "Inside AutoLisp"		

;; for rel. 10 published by New Riders Publications 		

;; Referenced to the his concept of UREAL UKWORD,		

;; also thanks to Irneb the way of handling variable in list	

;; 								



(defun hp# (_f _ini _msg _def / usr l)

  (if (and (member _f '(getreal getint getdist))

           (vl-every '(lambda (x) (= (type x) 'INT)) _ini)

      )

    (progn
      (setq usr (mapcar '(lambda (i a b) (initget i) ((eval _f) (strcat a " < " (rtos b) " > : ")))

                        _ini

                        _msg

                        _def

                ) 

      )  

      (while usr

        (setq l (cons (if (null (car usr))

                        (car _def)

                        (car usr)

                      ) 

                      l

                ) 

              usr (cdr usr)

              _def (cdr _def)

        ) 

        l

      ) 

      (reverse l)

    ) 

  ) 

) ;_ end of defun


(princ "\nCommand: LEVEL") (princ)

;hanhphuc
 

you still can pick the screen for distance & offset

Edited by hanhphuc
BBCode removed
Link to comment
Share on other sites

THNKS PHUC IT WORKED PERFECT & GREAT JOB.........

 

SORRY, BUT NEEDS TO EDIT SOME THING.....

 

THE CALCULATED LEVEL TO BE ABLE TO PLACE THE TEXT IN PARTICUALR LAYER SAY LEVELS....

 

HERE IS AN EXAMPLE OF LISP PLACING THE PIPE SLOPE....

 

 

example code

 

(defun c:demo3 (/ decs ;|diff|; elist level osm p1 p2 slope strlevel txtelev txthgt txtpt)
(setq osm (getvar 'osmode))
(while (and
(or (not
(setq txtelev (entsel "\nSelect starting level text : ")))
(not
(eq "TEXT"
(cdr (assoc 0 (setq elist (entget (car txtelev)))))))))
(princ
"\n Nothing selected or wrong object type selected, try again")
)
(setq strlevel (cdr (assoc 1 elist))
decs (- (strlen strlevel) (1+ (vl-string-position 46 strlevel)))
level (atof strlevel)
txthgt (cdr (assoc 40 elist))
)
(initget 6)
(setq slope (getreal "\n Enter slope ratio (1:X) <250> : "))
(if (not slope)
(setq slope 250))
(setq slope (/ 1 slope))
(setvar 'osmode 516)
(setq p1 (getpoint "\nPick first point: "))
;;; (setq diff (mapcar '- (cdr (assoc 10 elist)) p1))
(while (setq p2 (getpoint "\nPick next point (or press Enter to Exit): "))
(setq level (- level (* (distance p1 p2) slope))
strlevel (rtos level decs)
txtpt (getpoint "\nPick a text point: "); (mapcar '+ p2 diff)
)
(entmake
(list
'(0 . "TEXT")
'(100 . "AcDbEntity")
'(100 . "AcDbText")
(cons 10 txtpt)
(cons 11 (list 0.0 0.0 0.0))
(cons 40 txthgt)
(cons 1 strlevel)
'(50 . 0.0)
'(41 . 1.0)
'(51 . 0.0)
'(7 . "Standard")
'(71 . 0)
'(72 . 0)
(cons 210 (list 0.0 0.0 1.0))
'(73 . 0))
)
(setq p1 p2)
)
(setvar 'osmode osm)
(princ)
)

 

THIS ONE ALSO I DOWNLOADED FROM CADTUTUR...

 

THANKS YOU VERY MUCH

Edited by nosyparker
Link to comment
Share on other sites

Hi, hanhphuc, thanks for replying, you made perfectly no further explanation is required to make you understand (FYI, I need it in plan view, those are levels civil survey grade levels, their are some manholes, so find the cover level of the manhole we are approaching this way, in this exercise level 4 is our manhole cover level.

 

my request to you was, after calculations it should be able place a text on screen in a particular layer,

 

now already I am using your code, u cant believe how much its helping to me,

 

but, your cade is displaying level on screen, I am writing on a paper then placing in a drawing.

 

so, to avoid writing on paper I am requesting you....

Link to comment
Share on other sites

hi, hanh phuc..................

 

its looks smiling oops to me.........yet I have not yet executed this one..........as you said It can select from scree the distance and offset...........because, levels are always provided in this manner "GPL 3+.052" I don't thinks lsp's will read from the format.......any I have no authority to say as I am dummy to programming. lets try my luck with this new version.

 

thanks a lot I will reply back what had happened............bye.

Link to comment
Share on other sites

hi, hanhphuc..................great great great really great skills its working perfectly..............thanks for everything.

 

I have a query, just a query not required to edit the code that's fine with me.

 

now we are doing (-) minus 2% slope, in future if same job needs to be done by adding (+) 2% can we use the same code...........

 

once again, thanks a ton.....now I am thinking to learn lsp online...hope I will succeed. but never learned any programming before.

 

best of luck to me. and bye to you.

Link to comment
Share on other sites

  • 1 month later...

hi,

 

how r doing hanhphuc...........I have one small request..

 

can you edit the lsp you made for me..........

 

I like DISTANCE BETWEEN A & B SHOULD BE measure from point instead of manual input that it.

 

currently after giving level-A and level-B LSP is asking to input distance between A~B I need to be done

by two clicks.

 

 

here is the code which you made for me.........

 


(if (or (not *param*) (not *user*))
(setq *param* '(5.0 3.75 10. -2.)  *user*  '(3.6 8.7))) ; <-- this is your default value
(defun c:CL (/ level *error* txt ); v1.1
 
 (defun *error* (msg)
   (if (not (wcmatch (strcase msg) "*CANCEL*,*EXIT*"))
     (princ (strcat "\nError: " msg))
     ) ;_ end of if
 (graphscr)
   (princ)
   ) ;_ end of defun
;;;  (textpage)
 (Prompt "\nInput the required parameters..\n") 
 (setq level '((x y a b d g%)
 (if
  (and a b (not (zerop d)))
  (+ (+ (* (/ (- b a) d) x) a) (* y (/ g% 100.)))
  ) ;_ end of if
 )
*param* (hp# 'getreal
    '(0 0 6 0)
    '("A:Level1" "B:Level2" "Distance A~B " "Slope in %")
    *param*
    ) ;_ end of hp#
) ;_ end of setq
(Prompt "\nRepeat user input distance & offset..")
 
(while *param*
(prompt "\n\nNext..")
 
(setq txt (rtos (apply 'level
        (append (setq *user* (hp# 'getdist '(4 4) '("\nDistance from A?" "Offset Distance?") *user*))
         *param*
         ) ;_ end of append
        ) ;_ end of apply
 2
 3   ; <-- precision  0.000
 ) ;_ end of rtos
     ) ;_ end of setq
(if 
(setq p (getpoint "\nInsert text.. "))
(entmake (list '(0 . "TEXT")
(cons 1
     (strcat "CL: " ;<-- prefix, without prefix just put: ""
      txt
      ) 
     ) 
       (cons 10 (trans p 1 0))
       (cons 40 (getvar "textsize"))  ;<--- default, manually can change in command: TEXTSIZE
       (cons 8 "RFL")))   ;<--- Layer 
 (alert (strcat "\nLevel : " txt ))  ;<--- show if not pick point, eg: [spacebar] 
   )
   (princ)
   ) ;_ end of while
 ) ;_ end of defun

;;;----------------------------------------------------  
;;;        
;; courtesy of the author's of "Inside AutoLisp"  
;; for rel. 10 published by New Riders Publications   
;; Referenced to the his concept of UREAL UKWORD,  
;; also thanks to ymg the way of handling variable in list 
;;         
 (defun hp# (_f _ini _msg _def  / usr l)
 (if (and(member _f '(getreal getint getdist))
         (vl-every ''((x) (= (type x) 'INT)) _ini )
  )
   (progn (setq usr (mapcar '(lambda (i a b) (initget i) ((eval _f) (strcat a " < "(rtos b) " > : ")))
       _ini
       _msg
       _def
       ) ;_ end of mapcar
  ) ; setq
   (while usr
     (setq l (cons (if (null (car usr))
   (car _def)
   (car usr)
   ) ;_ end of if
        l
        ) ;_ end of cons
    usr (cdr usr)
    _def (cdr _def)
    ) ;_ end of setq
     l
     ) ;_ end of while
   (reverse l)
   ) ;_ end of progn
   ) ;_ end of if
 ) ;_ end of defun
(princ "\nCommand: CL")(princ)
;hanhphuc
you still can pick the screen for distance & offset 

 

 

thanking in advance.

 

regards.

Link to comment
Share on other sites

hi,

 

how r doing hanhphuc...........I have one small request..

 

can you edit the lsp you made for me..........

 

I like DISTANCE BETWEEN A & B SHOULD BE measure from point instead of manual input that it.

 

currently after giving level-A and level-B LSP is asking to input distance between A~B I need to be done

by two clicks.

 

regards.

 

hi nosyparker welcome back :)

could you please let me know which step should be modified?

note: please refer the comment in red

 

Example steps :

Command: CL

Input the required parameters..
A:Level1 < 5.0000 > :
B:Level2 < 5.0000 > :
Distance A~B  < 10.0000 > :     [color="red"];<---- Do you mean here?[/color]
Slope in % < -2.0000 > :

Repeat user input distance & offset..

Next..
Distance from A? < 5.0000 > : 
Offset Distance? < 10.0000 > : 

Insert text..
...
...

if so..

you can replace 'getreal to 'getdist

...
...
...
(Prompt "\nInput the required parameters..\n") 
 (setq level '((x y a b d g%)
 (if
  (and a b (not (zerop d)))
  (+ (+ (* (/ (- b a) d) x) a) (* y (/ g% 100.)))
  ) ;_ end of if
 )
*param* (hp# [color="red"]'getreal[/color]  ;<--- here [color="red"]'getdist[/color]
    '(0 0 6 0)
    '("A:Level1" "B:Level2" "Distance A~B " "Slope in %")
    *param*
    ) ;_ end of hp#
) ;_ end of setq
...
...

Link to comment
Share on other sites

hi, hanhphuc.................

 

one more thing phuc...........after the command has done........can we turn it into one of the two options..

 

1. either the command should end.

2. or if at all it continued to calculate for next then instead of asking "Distance from A? "

it should start the whole process from beginning itself.

 

( I mean it should prompt for A:LEVEL & B:LEVEL )

 

thanks & regards

Link to comment
Share on other sites

im pleased issue solved.

your new request is not user friendly if keep inputting parameters,

however you can opt yourself..

...
...
[color="red"](while  *param*[/color] [color="blue"]<---- 2. move here[/color]

 (Prompt "\nInput the required parameters..\n") 
 (setq level '((x y a b d g%)
 (if
  (and a b (not (zerop d)))
  (+ (+ (* (/ (- b a) d) x) a) (* y (/ g% 100.)))
  ) ;_ end of if
 )
*param* (hp# 'getreal
    '(0 0 6 0)
    '("A:Level1" "B:Level2" "Distance A~B " "Slope in %")
    *param*
    ) ;_ end of hp#
) ;_ end of setq
(Prompt "\nRepeat user input distance & offset..")
 
[color="gray"];;;(while  *param*[/color]   [color="blue"]<---- 1. prefix semi-colon or remove this line[/color]

(prompt "\n\nNext..")
...
...

in fact the existing step, user can just keep [ENTER] to skip, there's no need to input value.

 

HTH

Link to comment
Share on other sites

Hi,

 

That fine friend........and i'm sorry troubling you with that one..........

 

actually its my instinct that forces me to go beyond.......

 

what so ever I love this LSP coding and want to learn it,.............

 

but not getting free time..........if you have any good source pl. provide me a link so I can try..........

 

& thanks for all you favor hope next time I will come with new and query ;) and the same one.

 

THanks & regards

Link to comment
Share on other sites

we are happy if you are initiative to learn.

i'm still learning like others, as you are beginner just familiar with the lisp function in HELP (developer documentation), understanding how functions work.

There're many very useful link like Lee Mac, afralisp, theswamp,

as well as cadtutor's forum, etc.. be active in the forum practicing here, many gurus & senior members will guide you to the right directions.

:fishing:

Link to comment
Share on other sites

  • 3 years later...
  • 1 year later...

Hello hanhphuc , i hope you are fine .... Thanks for lisp , your lisp helped me a lot to get finish work faster ... i just ask for small edit if you have time

 

instead of writing ( A Level ) and ( B level ) ... can i choose it by clicking on text contain the level

 

Check this lisp for example :

 

(defun c:plevel (/ decs ;|diff|; elist level osm p1 p2 slope strlevel txtelev txthgt txtpt)
 (setq osm (getvar 'osmode))
 (while (and
   (or (not
  (setq txtelev (entsel "\nSelect Starting Level Text : ")))
       (not
  (eq "TEXT"
      (cdr (assoc 0 (setq elist (entget (car txtelev)))))))))
   (princ
     "\n Nothing selected or wrong object type selected, try again")
   )
 (setq strlevel (cdr (assoc 1 elist))
decs  (- (strlen strlevel) (1+ (vl-string-position 46 strlevel)))
level  (atof strlevel)
txthgt  (cdr (assoc 40 elist))
)

 (initget 6)
 (setq slope (getreal "\n Enter Slope Like ==> 0.005 : "))
 (if (not slope)
   (setq slope 0.005))
 (setvar 'osmode 516)
 (setq p1 (getpoint "\nPick 1st Point: "))
;;;  (setq diff (mapcar '- (cdr (assoc 10 elist)) p1))

 (while (setq p2 (getpoint "\nPick Next Point (Or Press Enter To Exit): "))
   (setq level    (- level (* (distance p1 p2) slope))
  strlevel (rtos level decs)
  txtpt   (getpoint "\nPick Text Place For Point Level: "); (mapcar '+ p2 diff)
  )
   (entmake
     (list
'(0 . "TEXT")
'(100 . "AcDbEntity")
'(100 . "AcDbText")
(cons 10 txtpt)
(cons 11 (list 0.0 0.0 0.0))
(cons 40 txthgt)
(cons 1 strlevel)
'(50 . 0.0)
'(41 . 1.0)
'(51 . 0.0)
'(7 . "Standard")
'(71 . 0)
'(72 . 0)
(cons 210 (list 0.0 0.0 1.0))
'(73 . 0))
     )
   (setq p1 p2)
   )

 (setvar 'osmode osm)
 (princ)
 )

 

Thanks for lisp again 😍

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