Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Wrong line coordinates

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
hseeda
1181 Views, 7 Replies

Wrong line coordinates

Hello there,

 

I wrote the following lsp to make a grid of vertical lines and bounding box with an input stp.

My problem is the lines not in correct position,lthough I printed point coordinates p3, p4 to make sure calculations are correct. they appear to be so.

here is my lsp. Any help??

thank you

 

;------------------------------------------
(defun hpromptr (textq default_value)
(setq tmp (getreal ( strcat "\n" textq "[" (rtos default_value) "]" )))
(if (= tmp nil) (setq tmp default_value))
(setq tmp tmp)
)
;-------------------------------------------
;-------------------------------------------
;-------------------------------------------
;-------------------------------------------

(defun c:ooo(/ i nw xd stp p1 p2 p3 p4 w width
x1 y1 x2 y2 pp)
; (hinit)
; (hlayer "_Grid")

(setq stp (hpromptr "Step:" 100.0 ))
(setq w (hpromptr "Fram Width:" 0.1))


(setq p1 (getpoint "\nPick first point: "))
(setq p2 (getcorner p1 "\nPick second point: "))
(command "rectang" "w" w p1 p2)
(command "rectang" "w" w p1 p2)

(setq width (- (car p2) (car p1)))
(setq nw (fix (/ width stp)))

(p nw)

(setq xd (car p1))
(setq i 0)

(setq y1 (cadr p1))
(setq y2 (cadr p2))

(repeat nw

(setq pp (+ xd stp))
(setq xd pp)
(setq p3 (list pp y1 0.0))
(setq p4 (list pp y2 0.0))

(command "line" p3 p4 "")

)

; (hprev_layer)
; (hend)
)

 

acad_2019-04-27_07-41-11.jpg

7 REPLIES 7
Message 2 of 8
ВeekeeCZ
in reply to: hseeda

Looks like you need to turn off osnaps for your routine.

(setvar 'osmode 0)

Message 3 of 8
dlanorh
in reply to: hseeda

Try this

 

;------------------------------------------
(defun hpromptr (textq default_value / tmp)
(initget 6)
(setq tmp (cond ( (getreal (strcat "\n" textq " <" (rtos default_value) "> : "))) (default_value)))
)
;-------------------------------------------
;-------------------------------------------
;-------------------------------------------
;-------------------------------------------

(defun c:ooo(/ osm stp w p1 p2 nw xd y1 y2 p3 p4)
; (hinit)
; (hlayer "_Grid")
(cond ( (/= (getvar 'osmode) 0) (setq osm (getvar 'osmode)) (setvar 'osmode 0)))

(setq stp (hpromptr "Step" 100.0 ))
(setq w (hpromptr "Frame Width" 0.1))


(setq p1 (getpoint "\nPick first point: "))
(setq p2 (getcorner p1 "\nPick second point: "))
;(command "rectang" "w" w p1 p2)
(command "rectang" "w" w p1 p2)

(setq nw (fix (/ (- (car p2) (car p1)) stp)))

;(p nw)

(setq xd (car p1))
(setq y1 (cadr p1))
(setq y2 (cadr p2))

(repeat nw
  (setq xd (+ xd stp))
  (setq p3 (list xd y1 0.0))
  (setq p4 (list xd y2 0.0))
  (command "line" p3 p4 "")
)

(if osm (setvar 'osmode osm))
; (hprev_layer)
; (hend)
)

I am not one of the robots you're looking for

Message 4 of 8
dbhunia
in reply to: hseeda

You can also try by this change only (without manipulating "OSMODE").......

 

 

(command "line" "_none" p3 "_none" p4 "")

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 5 of 8
Moshe-A
in reply to: hseeda

@hseeda hi,

 

follow the good advises you got here but if you want to upgrade it a little more, make it support draw the rectangle from any direction meaning from upper right corner down to bottom left (and any other direction) this may easily implemented with (polar) function to calculate the points accordingly.

 

moshe

 

Message 6 of 8
hseeda
in reply to: dbhunia

Great. Thanks. but why? what is the _none in the command?

Message 7 of 8
hseeda
in reply to: Moshe-A

Thanks for the reply. Alot of ideas can be implemented, but I was buzzled by the missalignment. NOw I figure out its the osnap settings.

Message 8 of 8
ВeekeeCZ
in reply to: hseeda

Why you have to turn the osnaps off? Because of this setting of yours:

image.png

 

Why putting non prior all point user inputs within command works? Because of THIS feature, specifically the last item in the list.

BTW  None you should also add prior points defying the rectangle.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report