why is the next code running on only one line?

why is the next code running on only one line?

Anonymous
Not applicable
964 Views
3 Replies
Message 1 of 4

why is the next code running on only one line?

Anonymous
Not applicable
I wanted four lines will be drawn in order. but I can't.... ( I want to draw a rectangle by only putting values not by shaping directly) please help me.  
 
(defun c:myrec ()
        
(setq a (getint "\n width:"))
(setq b (getint "\n height:"))
                 
(command "line" (list 0 0) (list a 0)) ;line 1 
(command "line" (list a 0) (list a b)) ;line 2
(command "line" (list a b) (list 0 b)) ;line 3
(command "line" (list 0 b) (list 0 0)) ;line 4
  )
0 Likes
Accepted solutions (3)
965 Views
3 Replies
Replies (3)
Message 2 of 4

doaiena
Collaborator
Collaborator
Accepted solution

You need to end the "line" command like this:
(command "line" (list 0 0) (list a 0) "")

 

It's also a good idea to turn off snaps, because they might cause problems.

0 Likes
Message 3 of 4

_gile
Consultant
Consultant
Accepted solution

Hi,

You can also specify succesively all the points in the same (command "_line" ...) expression.

As said @doaiena you should take care of possible running osnaps. This can be done using the "NONE" osnap to deactivate all running osnaps before specifying each point.

You can end the command by using the "_close" option, this avoid specifying the first point as last point.

Last, it's a good practice to use global command names (and option names) so the your code works whatever the culture version of AutoCAD (this is simply done by prefixing the English command names with an underscore).

 

  (command "_line"			; global command name (prefixed with underscore)
	   "_non"			; none osnap
	   (list 0 0)
	   "_non"			; none osnap
	   (list a 0)			; line 1 
	   "_non"			; none osnap
	   (list a b)			; line 2
	   "_non"			; none osnap
	   (list 0 b)			; line 3
	   "_close"			; line 4
  )

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 4 of 4

Sea-Haven
Mentor
Mentor
Accepted solution

2 suggestions

 

1 use Pline 

 

2 use Rectang only need the two corners.

 

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(command "pline" (list 0 0) (list a 0) (list a b) (list 0 b) "c")
(setvar 'osmode oldsnap)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(command "rectang" (list 0 0) (list a b))
(setvar 'osmode oldsnap)

 

Need to add pick point again 2 ways add to x y values or move "last" 

 

An extra

; simple draw a box and dimension it
; By Alan H March 2019
' info@alanh.com.au

 

0 Likes