Wrong line coordinates

hseeda
Explorer
Explorer

Wrong line coordinates

hseeda
Explorer
Explorer

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

0 Likes
Reply
Accepted solutions (1)
1,180 Views
7 Replies
Replies (7)

ВeekeeCZ
Consultant
Consultant

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

(setvar 'osmode 0)

0 Likes

dlanorh
Advisor
Advisor

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

0 Likes

dbhunia
Advisor
Advisor
Accepted solution

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

Moshe-A
Mentor
Mentor

@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

 

0 Likes

hseeda
Explorer
Explorer

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

0 Likes

hseeda
Explorer
Explorer

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.

0 Likes

ВeekeeCZ
Consultant
Consultant

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.

0 Likes