LISP won't take variable value less than 20 unit.

LISP won't take variable value less than 20 unit.

unggansu2
Contributor Contributor
751 Views
7 Replies
Message 1 of 8

LISP won't take variable value less than 20 unit.

unggansu2
Contributor
Contributor

Hello.

I re-created a routine that creates a simple polyline rectangle, based on the distance of two input points, in a set width. The problem is, when the width value is less than 20 unit, it only create a straight polyline.

I'm new to AutoLISP-ing, where did I go wrong?

Here is the file...

0 Likes
Accepted solutions (2)
752 Views
7 Replies
Replies (7)
Message 2 of 8

Moshe-A
Mentor
Mentor
Accepted solution

@unggansu2 ,

 

Probably the issue is with object snap. you can turn it off before calling (command) like (setvar "osmode" 0)

and reset it back afterword or add "_none" args before any point.

 

(command "_.PLINE" "_none" pl1 "_none" pl2 "_none" pl3 "_none" pl4 "c")

 

Moshe

 

Message 3 of 8

unggansu2
Contributor
Contributor
It worked! Thank you!

P.S. : If I set the snap off in the routine, will it come back on after it or do I have to manually activate it again?
0 Likes
Message 4 of 8

Moshe-A
Mentor
Mentor

@unggansu2 ,

 

take a look to this sample 😀

 

(defun c:test (/ savOSmode)

 ; start program 
 (setq savOSmode (getvar "osmode")) ; save osmode value
 (setvar "osmode" 0)  ; turn it off

 ; your program body code here
 ; ...........
 ; ..........
 ; .......
 ; .... 

 (command "._pline" pt1 pt2 pt3 pt4 "_close") 

 ; about to exit 
 (setvar "osmode" savOSmode); restore osmode value

 (princ) 
)

 

Message 5 of 8

calderg1000
Mentor
Mentor

Regards @unggansu2 

Try this code, I made some small changes to it. Enter the reference to point 1 to display the location of point 2 . In some cases it is better to use "Entmake" instead of "Command"

(defun c:wall ()
;****************************************
;searching for input point
  (setq otm (getvar 'orthomode))
  (setvar 'orthomode 1)
  (setq p1 (getpoint "\nFirst point of height : "))
  (setq p2 (getdist p1 "\nSecond Point of height: "))
  (setq tb (getdist "\nWidth : "))
;;;  (setq dis (distance p1 p2))
;****************************************	
;start sistem dtr
  (defun dtr (x)
    (* pi (/ x 180.00))
  )
  (princ)
;****************************************
;start looking for polyline point
  (setq pl1 (polar p1 (dtr 180) (/ tb 1)))
  (setq pl2 (polar pl1 (dtr 270) dis))
  (setq pl3 (polar pl2 (dtr 0.0) (/ tb 1)))
  (setq pl4 (polar pl3 (dtr 90) dis))
;****************************************
;start creating polyline
;;;  (command "_.PLINE" pl1 pl2 pl3 pl4 "c")
  (entmake (list '(0 . "LWPOLYLINE")
               (cons 100 "AcDbEntity")
               (cons 410 (getvar 'ctab))
               (cons 100 "AcDbPolyline")
               (cons 90 4)
               (cons 10 pl1)
	       (cons 10 pl2)
               (cons 10 pl3)
               (cons 10 pl4)
               (cons 70 1)
               )
         )
  (setvar 'orthomode otm)
  (princ)
)

Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Message 6 of 8

Sea-Haven
Mentor
Mentor
Accepted solution

My $0.05 corrects non ortho Wall.

 

(defun c:wall ( / p1 p2 tb dis)
(setq oldsnap (getvar 'osmode))

	(setq p1 (getpoint "\nFirst Point : "))
	(setq p2 (getpoint "\nSecond Point : "))
	(setq tb (getdist "\nWidth : "))
	(setq dis (distance p1 p2))
  (setq ang (angle p1 p2))
  (setvar 'osmode 0)
(command "_.PLINE"
p1
p2
(polar p2 (+ ang (/ pi 2.)) tb)
(polar p1 (+ ang (/  pi 2.)) tb)
  "c"
)
(setvar 'osmode oldsnap)
	(princ)
)
(c:wall)
Message 7 of 8

unggansu2
Contributor
Contributor

Oh God yes!! You finally fixed my angle problem! Thank you!!

Edit: I'm a bit lost when trying to understand the following:

(polar p2 (+ ang (/ pi 2.)) tb)

 
What does the (/ pi 2) means? 

Edit 2: Nevermind I got it. Thanks.

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor
(polar p2 (+ ang (/ pi 2.)) tb)

If we break it down

Using Polar is work out a new point from p2  using angle and distance

We have the angle of the p1 p2 picked points, (angle p1 p2)

As lisp works in radians I have avoided using DTR & RTD funtions, 90 degress is Pi / 2, 180 = pi, 360= 2*pi, 45= pi / 4

The tb is your offset distance.

The points in the pline are done in correct order.

Hope this helps explain