Baber62 Posted March 15, 2017 Share Posted March 15, 2017 Hi, Found this little lisp routine at http://www.autocadproblems.com/2014/09/marking-level-on-plan-autocad.html However, when tried it doesn't seem to work. Here's the coding, ;Marking Levels in a Horizontal plan ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:lm() (while (not (setq GL1 (entsel "\nFirst Value :")) )) (setq Lvl1 (entget (car GL1))) (if (> (length Lvl1) 22) (setq G_val1 (nth 13 Lvl1)) (setq G_Val1 (nth 11 Lvl1)) ) (while (not (setq GL2 (entsel "\nSecond Level :")) )) (setq Lvl2 (entget (car GL2))) (if (> (length Lvl2) 22) (setq G_val2 (nth 13 Lvl2)) (setq G_Val2 (nth 11 Lvl2)) ) (setq p1 (getpoint "Pick Range from :")) (setq d (getdist p1 "Pick Range to :")) (setq d (float d)) (setq slp1 (- (atof(cdr G_val2)) (atof(cdr G_val1)))) (setq slp (/ slp1 d)) (while (setq Txt_Pnt (getpoint "\nPick Text Point:")) (setq d1 (distance p1 Txt_pnt)) (setq new_lvl (+ (atof(cdr G_val1)) (* d1 slp))) (setq val1 (rtos new_lvl 2 3)) (command "text" Txt_pnt "" "" val1) ) ) It gives following error "; error: bad argument type: stringp 1" Any help appreciated. Quote Link to comment Share on other sites More sharing options...
jonathann3891 Posted March 15, 2017 Share Posted March 15, 2017 Works fine on my machine. ;Marking Levels in a Horizontal plan ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:lm() (while (not (setq GL1 (entsel "\nFirst Value :")) )) (setq Lvl1 (entget (car GL1))) (if (> (length Lvl1) 22) (setq G_val1 (nth 13 Lvl1)) (setq G_Val1 (nth 11 Lvl1)) ) (while (not (setq GL2 (entsel "\nSecond Level :")) )) (setq Lvl2 (entget (car GL2))) (if (> (length Lvl2) 22) (setq G_val2 (nth 13 Lvl2)) (setq G_Val2 (nth 11 Lvl2)) ) (setq p1 (getpoint "Pick Range from :")) (setq d (getdist p1 "Pick Range to :")) (setq d (float d)) (setq slp1 (- (atof(cdr G_val2)) (atof(cdr G_val1)))) (setq slp (/ slp1 d)) (while (setq Txt_Pnt (getpoint "\nPick Text Point:")) (setq d1 (distance p1 Txt_pnt)) (setq new_lvl (+ (atof(cdr G_val1)) (* d1 slp))) (setq val1 (rtos new_lvl 2 3)) (command "text" Txt_pnt "" "" val1) ) ) Quote Link to comment Share on other sites More sharing options...
Baber62 Posted March 15, 2017 Author Share Posted March 15, 2017 I tried it again and found out that the routine only picks up text and not MText. Is there anyway that it could pick up either? Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 16, 2017 Share Posted March 16, 2017 Change this you should be using ASSOC 1 which is the text string (setq G_val1 (nth 13 Lvl1)) (setq G_val1 (cdr (assoc 1 Lvl1))) Quote Link to comment Share on other sites More sharing options...
Baber62 Posted March 16, 2017 Author Share Posted March 16, 2017 Hi BIGAL, Tried it but without success, changed line as suggested. It seems to be picking up the levels and points but once that part completes it gives the following error: First level : Second Level :Pick Range from :Pick Range to :; error: bad argument type: consp "4.234" My first level is 4.234 and the second is 3.956 distance between them is 5m. Here's the amended coding changed line in red: ;Marking Levels in a Horizontal plan ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:marklevel() (while (not (setq GL1 (entsel "\nFirst level :")) )) (setq Lvl1 (entget (car GL1))) (if (> (length Lvl1) 22) [color="red"](setq G_val1 (cdr (assoc 1 Lvl1)))[/color] (setq G_Val1 (nth 11 Lvl1)) ) (while (not (setq GL2 (entsel "\nSecond Level :")) )) (setq Lvl2 (entget (car GL2))) (if (> (length Lvl2) 22) [color="red"](setq G_val2 (cdr (assoc 1 Lvl1)))[/color] (setq G_Val2 (nth 11 Lvl2)) ) (setq p1 (getpoint "Pick Range from :")) (setq d (getdist p1 "Pick Range to :")) (setq d (float d)) (setq slp1 (- (atof(cdr G_val2)) (atof(cdr G_val1)))) (setq slp (/ slp1 d)) (while (setq Txt_Pnt (getpoint "\nPick Text Point:")) (setq d1 (distance p1 Txt_pnt)) (setq new_lvl (+ (atof(cdr G_val1)) (* d1 slp))) (setq val1 (rtos new_lvl 2 3)) (command "text" Txt_pnt "" "" val1) ) ) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 17, 2017 Share Posted March 17, 2017 Have a look at this ;Marking Levels in a Horizontal plan ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:marklevel() (while (/= nil (setq Lvl1 (entget (car (entsel "\nFirst level :"))))) (setq GL2 (entget (car (entsel "\nSecond Level :")))) (setq G_val1 (cdr (assoc 1 Lvl1))) (setq G_val2 (cdr (assoc 1 Gl2))) (setq p1 (getpoint "Pick Range from :")) (setq d (getdist p1 "Pick Range to :")) (setq d (float d)) (setq slp1 (- (atof G_val2) (atof G_val1))) (setq slp (/ slp1 d)) (setq Txt_Pnt (getpoint "\nPick Text Point:")) (setq d1 (distance p1 Txt_pnt)) (setq new_lvl (+ (atof G_val1) (* d1 slp))) (command "text" Txt_pnt "" "" (rtos new_lvl 2 3)) ) ; while ) ; defun Quote Link to comment Share on other sites More sharing options...
Baber62 Posted March 17, 2017 Author Share Posted March 17, 2017 Hi BIGAL, Tested it but somehow's routine has lost its functionality, where it would allow you to pick successive point along the line between the two points until cancelled. It now only marks the level for a single point and then asks for first level and second level again. Having a look at the coding you only have a single while loop running which is why after marking level for a single point along a line it reverts back to asking for first level. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 17, 2017 Share Posted March 17, 2017 I thought that was what you were trying to do. Have a go at fixing it by adding a (while in correct spot and an extra ) to end it. Quote Link to comment Share on other sites More sharing options...
Baber62 Posted March 19, 2017 Author Share Posted March 19, 2017 Hi BIGAL Ok here's where I've tried the (while and ) but it keeps looping around the first part of the routine in that it keeps asking for first point etc. This is where my battles with AutoLISP lie. The points I had placed the while loop and closed the first while loop were where it seemed logical to place them . The red highlights shows where I have included them. Please can you point out where I am making the mistake even though it might seem obvious as I cannot work it out. ;Marking Levels in a Horizontal plan ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:marklevel() (while (/= nil (setq Lvl1 (entget (car (entsel "\nFirst level :"))))) (setq GL2 (entget (car (entsel "\nSecond Level :")))) (setq G_val1 (cdr (assoc 1 Lvl1))) (setq G_val2 (cdr (assoc 1 Gl2))) (setq p1 (getpoint "Pick Range from :")) (setq d (getdist p1 "Pick Range to :")) (setq d (float d)) (setq slp1 (- (atof G_val2) (atof G_val1))) (setq slp (/ slp1 d)) [color="red"]) (While[/color] (setq Txt_Pnt (getpoint "\nPick Text Point:")) (setq d1 (distance p1 Txt_pnt)) (setq new_lvl (+ (atof G_val1) (* d1 slp))) (command "text" Txt_pnt "" "" (rtos new_lvl 2 3)) ) ; while ) ; defun Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 20, 2017 Share Posted March 20, 2017 So close just needed a bit further down glad to see you had a go. Just need to think about where you are picking the extra points ;Marking Levels in a Horizontal plan ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:marklevel() (while (/= nil (setq Lvl1 (entget (car (entsel "\nFirst level :"))))) (setq GL2 (entget (car (entsel "\nSecond Level :")))) (setq G_val1 (cdr (assoc 1 Lvl1))) (setq G_val2 (cdr (assoc 1 Gl2))) (setq p1 (getpoint "Pick Range from :")) (While (setq d (getdist p1 "Pick Range to :")) (setq d (float d)) (setq slp1 (- (atof G_val2) (atof G_val1))) (setq slp (/ slp1 d)) (setq Txt_Pnt (getpoint "\nPick Text Point:")) (setq d1 (distance p1 Txt_pnt)) (setq new_lvl (+ (atof G_val1) (* d1 slp))) (command "text" Txt_pnt "" "" (rtos new_lvl 2 3)) ) ; while ) ; while ) ; defun Quote Link to comment Share on other sites More sharing options...
Baber62 Posted March 20, 2017 Author Share Posted March 20, 2017 Thanks BIGAL, appreciated. I also placed the second while loop just after the (setq slp (/ slp1 d)) and it worked as well. Quote Link to comment Share on other sites More sharing options...
Baber62 Posted March 20, 2017 Author Share Posted March 20, 2017 Hi BIGAL, The point where the label for the text inserted is either on the line or too close to the original line, so I tried my hand at coding and managed to add a leader that points to the location where the new level is, however, when the leader is placed on there with the new level I get 15 decimal places. How do I change this to be only three decimal places. Is it via the global setting for precision or can the precision be encoded as well? Any advice would be gratefully received. Here's the coding with the lines added highlighted in red. ;Marking Levels in a Horizontal plan ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:marklevel() (while (/= nil (setq Lvl1 (entget (car (entsel "\nFirst level :"))))) (setq GL2 (entget (car (entsel "\nSecond Level :")))) (setq G_val1 (cdr (assoc 1 Lvl1))) (setq G_val2 (cdr (assoc 1 Gl2))) (setq p1 (getpoint "Pick Range from :")) (setq d (getdist p1 "Pick Range to :")) (setq d (float d)) (setq slp1 (- (atof G_val2) (atof G_val1))) (setq slp (/ slp1 d)) (While (setq Txt_Pnt (getpoint "\nPick Text Point:")) [color="red"](Setq textloc (getpoint "\n Pick Label Location: ")) (setq x (rtos (car Txt_Pnt))) (setq y (rtos (cadr Txt_Pnt)))[/color] (setq d1 (distance p1 Txt_pnt)) (setq new_lvl (+ (atof G_val1) (* d1 slp))) ;(command "text" Txt_Pnt "" "" (rtos new_lvl 2 3)) [color="red"](command "_LEADER" Txt_Pnt textloc "" new_lvl "")[/color] ) ; while ) ; while ) ; defun Quote Link to comment Share on other sites More sharing options...
Baber62 Posted March 20, 2017 Author Share Posted March 20, 2017 Solved it after looking at the coding more closely. changed the line (command "_leader" Txt_Pnt textloc "" new_lvl "") to (command "_leader" Txt_Pnt textloc "" rtos( new_lvl 2 3) "") Thanks for your advice and assistance BIGAL Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 21, 2017 Share Posted March 21, 2017 No worries good to see people having a go as well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.