Jump to content

Draw PLINE between Circles center point (using FENCE)


RashidAziz

Recommended Posts

Hi

I need AutoLISP to make PLINE between Center Point of all selected CIRCLES (with FENCE option)

 

Like

PIC-01 (Select CIRCLES with Fence option and also use the same Sequence to Draw PLINE in Center of Circles)

PIC-02 (Showing Pline Path)

PIC-03 (Showing final Result. Start of Pline from First Selected Circle, then Continue as selected)

 

Thanks so much in Advance

001.jpg

002.jpg

003.jpg

Link to comment
Share on other sites

Try this. It asks you to construct a pline using grread and grdraw, and uses the coordinates from this to generate a list that can be fed into the fence selection of a selection set. You don't need to click inside every circle, just crossing part of it will do. The generated pline imitates the order of the previous line but connects the centres of the circles.

 

(defun c:ssf_grl (/ *error* c_doc c_spc sv_lst sv_vals pt p_lst flg gr ss cnt v_lst ent)

	(defun *error* ( msg )
		(mapcar 'setvar sv_lst sv_vals)
		(if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
		(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
		(princ)
	);end_*error*_defun
	
  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_spc (vlax-get-property c_doc (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace))
		sv_lst (list 'osmode 'cmdecho)
		sv_vals (mapcar 'getvar sv_lst)
        pt (getpoint "\nSelect the Start Point : ")
        p_lst (list pt)
        flg T
  );end_setq
  
  (mapcar 'setvar sv_lst '(0 0))
  
  (princ "\nSelect the Next Point (or right click to exit) : ")
  (while (and (setq gr (grread T 12 0)) flg) ;;loops until flg = nil tracking cursor position
    (redraw)
    (grvecs (cons -1 (apply 'append (mapcar 'list p_lst (cdr p_lst))))) 
    (cond ( (= 5 (car gr)) (grdraw (car p_lst) (cadr gr) 3 1)) 
          ( (= 3 (car gr))
            (setq p_lst (cons (cadr gr) p_lst))
            (princ "\nSelect the Next Point (or right click to exit) : ")
          )
          (T (redraw) (setq flg nil))
    );end_cond
  );end_while

  (setq ss (ssget "F" (reverse p_lst) '((0 . "CIRCLE"))))

  (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  (vla-startundomark c_doc)

  (cond (ss 
          (repeat (setq cnt (sslength ss))
            (setq v_lst (cons (cdr (assoc 10 (entget (ssname ss (setq cnt (1- cnt)))))) v_lst))
          );end_repeat
          (entmake (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") (cons 90 (1+ (length v_lst))))
                            (mapcar '(lambda (x) (cons 10 x)) v_lst)
                    );end_append
          );end_entmakex
        )
  );end_cond
  
  (if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_defun

 

Edited by dlanorh
  • Like 1
Link to comment
Share on other sites

(vl-load-com)

(defun t1 (/ adoc selset)
  (if (= (type (setq selset (vl-catch-all-apply (function (lambda () (ssget '((0 . "circle"))))))))
         'pickset
         ) ;_ end of =
    (progn (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
           (setq selset ((lambda (/ tab item)
                           (repeat (setq tab  nil
                                         item (sslength selset)
                                         ) ;_ end setq
                             (setq tab (cons (assoc 10 (entget (ssname selset (setq item (1- item))))) tab))
                             ) ;_ end of repeat
                           ) ;_ end of lambda
                         )
                 ) ;_ end of setq
           (entmakex (append '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline"))
                             (list (cons 90 (length selset)))
                             selset
                             ) ;_ end of append
                     ) ;_ end of entmakex
           (vla-endundomark adoc)
           ) ;_ end of progn
    ) ;_ end of if
  (princ)
  ) ;_ end of defun

 

Link to comment
Share on other sites

Your LISP working fine.

Thanks so much dlanorh.

 

Sir kpblc

Thanks so much. I add c:T1 and using "F" for selection and now working fine.

 

Thanks again both of you.

Edited by RashidAziz
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...