Jump to content

get intersection points and draw rectangles


jasonle215

Recommended Posts

hi all,

 

I am using autocad 2010 and new to autolisp and I hope you guys could give me a hand here.

 

If i have a series of horizontal lines and one vertical line (like the 1st photo attached below).

 

How do I make an autolisp command that let me select the red line, then select all horizontal lines, then it will draw rectangles with length is user input and height is distance between the black lines. the program also needs to work out the intersection of red lines and black lines to place the corner of rectangles at the intersections (please see picture 2 for clearance)

 

Thanks for the tips

 

1.jpg

 

 

3.jpg

Link to comment
Share on other sites

Sorry mate, the notification from forum was sent to my junk mail. If you don't mind, could you please upload the code again? I'm really sorry, I didn't mean to ignore the post. :)

 

Welcome to CADTutor.

 

Try this program and let me know.

 

Removed due to ignorance from the OP

Link to comment
Share on other sites

It can be done by using a ssget and a fence method this will select the cross lines in correct order and hence you can build your rectangs, (setq ss (ssget "F" (list pt1 pt2))), pt1 pt2 are from red line, need some time busy at moment.

 

(defun c:rectangs ( / tpp1 pt1 pt2 intpt1 intpt2 intpt3 intpt4 ss)
(setq width (getreal "enter width"))
(setq obj (entsel "pick crossing line"))
(setq obj2 (vlax-ename->vla-object (car obj))) ;convert pick line to vl object
(setq tpp1 (entget (car obj) ) )
(setq pt1 (cdr (assoc 10 tpp1) ) ) 
(setq pt2 (cdr (assoc 11 tpp1) ) )
(setq ss (ssget "F" (list pt1 pt2)))

(setq x (- (sslength ss)1))
(setq obj1 (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq intpt1 (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity))
(repeat (sslength ss)

(setq obj3 (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq intpt2 (vlax-invoke obj2 'intersectWith obj3 acExtendThisEntity))

(setq intpt3 (polar intpt1 0.0 width))
(setq intpt4 (polar intpt2 0.0 width))

(command "pline" intpt1 intpt2 intpt3 intpt4 "C")
(setq intpt1 intpt2)

) ; repeat
) 

Edited by BIGAL
Link to comment
Share on other sites

It can be done by using a ssget and a fence method this will select the cross lines in correct order and hence you can build your rectangs, (setq ss (ssget "F" (list pt1 pt2))), pt1 pt2 are from red line, need some time busy at moment.

 

(defun c:rectangs ( / tpp1 pt1 pt2 intpt1 intpt2 intpt3 intpt4 ss)
(setq width (getreal "enter width"))
(setq obj (entsel "pick crossing line"))
(setq obj2 (vlax-ename->vla-object (car obj))) ;convert pick line to vl object
(setq tpp1 (entget (car obj) ) )
(setq pt1 (cdr (assoc 10 tpp1) ) ) 
(setq pt2 (cdr (assoc 11 tpp1) ) )
(setq ss (ssget "F" (list pt1 pt2)))

(setq x (- (sslength ss)1))
(setq obj1 (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq intpt1 (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity))
(repeat (sslength ss)

(setq obj3 (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
(setq intpt2 (vlax-invoke obj2 'intersectWith obj3 acExtendThisEntity))

(setq intpt3 (polar intpt1 0.0 width))
(setq intpt4 (polar intpt2 0.0 width))

(command "pline" intpt1 intpt2 intpt3 intpt4 "C")
(setq intpt1 intpt2)

) ; repeat
) 

 

Hi BIGAL,

 

Thanks for the code. I'm just wondering, with the (ssget "F"), it will consider all the horizontal lines intersecting with the vertical line. Is there a way to adjust the code to allow you to only select specific horizontal lines that you want the rectangles to be created in?

Link to comment
Share on other sites

I thought you wanted to do all, the problem is going to be, need to do pick two lines repeatedly so rectang is drawn between picked pair can have a line in middle also. A different approach using entsel for 2 lines. Maybe pick 1st point then perp top pt then pick 2 lines ? saves drawing a line. Ps I drew a crooked line and it still worked !

 

(defun c:rectangs2 ( / tpp1 pt1 pt2 intpt1 intpt2 intpt3 intpt4 ss)
(if (not AH:getval) (load "getval"))
(ah:getval "Enter width.." "     edit_width = 10;" "     edit_limit = 8;")
(setq width (Atof item))
(setq pt1 (getpoint "\nPick 1st point"))
(setq pt2 (getpoint "\nPick 2nd point"))

(command "line" pt1 pt2 "")
(setq obj (entlast))
(setq obj2 (vlax-ename->vla-object obj)) ;convert pick line to vl object

(alert "Pick 2 lines press Enter to exit on 1st line")
(while
(setq obj1 (vlax-ename->vla-object (car (entsel "pick 1st line"))))
(setq intpt1 (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity))

(setq obj3 (vlax-ename->vla-object (car (entsel "pick 2nd line"))))
(setq intpt2 (vlax-invoke obj2 'intersectWith obj3 acExtendThisEntity))

(setq intpt3 (polar intpt1 0.0 width))
(setq intpt4 (polar intpt2 0.0 width))

(command "pline" intpt1 intpt2 intpt3 intpt4 "C")
(vla-delete obj2)
) ; while
)

 

You will need this also

;; Input  Dialog box with variable title
;; By Ah June 2012
;; code (ah:getval title)

(defun AH:Getval (title width limit / fo)
(setq fname "C://acadtemp//getval.dcl")
(setq fo (open fname "w"))
(write-line "ddgetval : dialog {" fo)
(write-line " : row {" fo)
(write-line ": edit_box {" fo)
(write-line (strcat "    key = "  (chr 34) "sizze" (chr 34) ";") fo)
(write-line  (strcat " label = "  (chr 34) title (chr 34) ";"  )   fo)
; these can be replaced with shorter value etc
;(write-line "     edit_width = 18;" fo) 
;(write-line "     edit_limit = 15;" fo)
(write-line width fo) 
(write-line limit fo)
(write-line "   is_enabled = true;" fo)        
(write-line "    }" fo)
(write-line "  }" fo)
(write-line "ok_cancel;}" fo)
(close fo)

(setq dcl_id (load_dialog  "c:\\getval")) ; make this a directory of your choosing
(if (not (new_dialog "ddgetval" dcl_id))
(exit))
(action_tile "sizze" "(setq item  $value)(done_dialog)")
(mode_tile "sizze" 3)
(start_dialog)
; returns the value of item
)

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...