Jump to content

Marking Level on the plan autocad


Baber62

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Thanks BIGAL, appreciated. :thumbsup:

 

I also placed the second while loop just after the (setq slp (/ slp1 d)) and it worked as well.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :notworthy:

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