Modify the ruller LSP script to draw in Y axis from up to down ?

Modify the ruller LSP script to draw in Y axis from up to down ?

Gobel_A
Enthusiast Enthusiast
1,051 Views
6 Replies
Message 1 of 7

Modify the ruller LSP script to draw in Y axis from up to down ?

Gobel_A
Enthusiast
Enthusiast

Hello, I found this script form @ronjonp on https://www.cadtutor.net/forum/topic/65111-framing-ruller/?do=findComment&comment=536574 - the basic ruller scipt on top (function foo). 

 

How to modify this script to draw the same but not in X axis left to right but in Y axis top to bottom ? At the best automatically by choosing the direction during picking the distance. 

 

Original code from author:

(defun c:foo (/ a d i n p p2)
 ;; RJP - 04-10-2018
 ;; Creates a simple ruler
 (cond	((and (not (initget 7))
      (setq i (getint "\nEnter spacing: "))
      (setq p (getpoint "\nPick start point: "))
      (setq d (getdist p "\nPick Distance: "))
 )
 (setq n 0)
 (while	(<= n d)
   (entmakex (list '(0 . "LINE")
		   (cons 10 (setq p2 (polar p 0. n)))
		   (cons 11
			 (list (car p2)
			       (- (cadr p2)
				  (cond	((setq a (= 0 (rem n 5))) 2.)
					(1.)
				  )
			       )
			 )
		   )
		   (cons 62
			 (if a
			   1
			   2
			 )
		   )
	     )
   )
   (if a
     (entmakex (list '(0 . "TEXT")
		     '(100 . "AcDbEntity")
		     '(67 . 0)
		     '(8 . "0")
		     '(62 . 4)
		     '(100 . "AcDbText")
		     (cons 10 (list (car p2) (- (cadr p2) 3.)))
		     '(40 . 2.0)
		     (cons 1 (itoa (fix (/ (distance p p2) i))))
		     '(41 . 1.0)
		     '(7 . "Standard")
		     '(71 . 0)
		     '(72 . 1)
		     (cons 11 (list (car p2) (- (cadr p2) 3.)))
		     '(100 . "AcDbText")
		     '(73 . 3)
	       )
     )
   )
   (setq n (+ n i))
 )
)
 )
 (princ)
)
0 Likes
Accepted solutions (1)
1,052 Views
6 Replies
Replies (6)
Message 2 of 7

diagodose2009
Collaborator
Collaborator

I answer pure-teoretically;

You replace   (cons 10 (setq p2 (polar p 0. n)))

-- with (list 10 (car p)  (+ (cadr p) n) 0.0)   ;; for up-to-top

-- with (list 10 (car p)  (- (cadr p) n) 0.0)   ;; for up-to-down

-- with (list 10 (car p)  (+ (cadr p) n) 0.0)   ;; for up-to-top

-- with (list 10 0.0 (car p)  (- (cadr p) n) )   

-- with (cons 10 0.0 (car p)  (- (cadr p) n) )   

I other version/s of AutoCad; (cons 10 (list 1.0 2.0 0.0)) Or (list 10  3.0 1.2 0.0) - work fine>

(setq n 0)
(while (<= n d)
(entmakex (list '(0 . "LINE")
(cons 10 (setq p2 (polar p 0. n)))
(cons 11

  -- 

 

(while (<= n d)  
  (setq p2 (list (car p) (+ (cadr p n) 0,0))
  (setq p3 (list (car p) (+ (cadr p n) 0,0))
   (entmakex (list '(0 . "LINE")
         (cons 10 p2)
         (cosn 11 p3)

-------------------
(while (<= n d)  
  (setq p2 (list (car p) (cadr p) (+ (last p) n))
  (setq p3 (list (car p) (cadr p2) (+ (last p) n)) ;;you growing on Z
   (entmakex (list '(0 . "LINE")
         (cons 10 p2)
         (cosn 11 p3)
--------

 

0 Likes
Message 3 of 7

Kent1Cooper
Consultant
Consultant

[You could also just do the horizontal one and MIRROR it across an axis at a 315° angle.  Make sure the MIRRTEXT System Variable is set to 0.]

Kent Cooper, AIA
0 Likes
Message 4 of 7

Gobel_A
Enthusiast
Enthusiast

Thanks to both of you @diagodose2009  and @Kent1Cooper . The tip with mirroring does not solve the order of entities (first text, then line) but is very good workaround (the easiest) and is usable. 

The proposed code change.. maybe I did not edit it right, but does not work for me. Could you please post a whole part of (while) loop ?

0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

@Gobel_A wrote:

.... The tip with mirroring does not solve the order of entities (first text, then line) ....


I don't understand why that matters, but in any case, if I do repeated Erase Last operations, for me it removes them from the Mirrored version in exactly the same order as in the un-Mirrored original.

Kent Cooper, AIA
0 Likes
Message 6 of 7

CADaSchtroumpf
Advisor
Advisor
Accepted solution

@Gobel_A 

Same function for Y

(defun c:foo (/); a d i n p p2)
 ;; RJP - 04-10-2018
 ;; Creates a simple ruler
 (cond	((and (not (initget 7))
      (setq i (getint "\nEnter spacing: "))
      (setq p (getpoint "\nPick start point: "))
      (setq d (getdist p "\nPick Distance: "))
 )
 (setq n 0)
 (while	(<= n d)
	(setq p2 (polar p (* pi 0.5) n))
   (entmakex (list '(0 . "LINE")
		   
		   (cons 10
			 (list
			 (- (car p2)
				  (cond	((setq a (= 0 (rem n 5))) 2.)
					(1.)
				  )
			       )
			  (cadr p2)
			       
			 )
		   )
		   (cons 11 p2)
		   (cons 62
			 (if a
			   1
			   2
			 )
		   )
	     )
   )
   (if a
     (entmakex (list '(0 . "TEXT")
		     '(100 . "AcDbEntity")
		     '(67 . 0)
		     '(8 . "0")
		     '(62 . 4)
		     '(100 . "AcDbText")
		     (cons 10 (list (- (car p2) 3.) (cadr p2)))
		     '(40 . 2.0)
		     (cons 1 (itoa (fix (/ (distance p p2) i))))
		     '(41 . 1.0)
		     '(7 . "Standard")
		     '(71 . 0)
		     '(72 . 1)
		     (cons 11 (list (- (car p2) 3.) (cadr p2)))
		     '(100 . "AcDbText")
		     '(73 . 2)
	       )
     )
   )
   (setq n (+ n i))
 )
)
 )
 (princ)
)
0 Likes
Message 7 of 7

Gobel_A
Enthusiast
Enthusiast

@CADaSchtroumpf 

This is exactly what I was looking for. The main idea which I did not find was the calculation with radians on line 11. As a novice I did not know about it and always got some angled line instead of "ortho". Many thanks for learning me something new and of course also for a whole code.

I only edited - to + on line 16 to avoid text overlapping over the line and used function getreal instead of getint to be more flexible in my scale format (f.e. M1:400 means spacing factor 2.5)

0 Likes