Jump to content

Select polylines with 3 vertices only and copy to the ends


CADWORKER

Recommended Posts

Hi all,

I have a cad file where there are many polylines with 3 vertices(not exactly 90d), and I have to copy the same polyline and paste to the start and end.

its like creating closed polygons.

Any code, help or advise will be appreicated very much.

Thanks

Link to comment
Share on other sites

Something like this ?

(defun c:Test (/ sel int ent)
  ;; Tharwat - 19.Nov.2020		;;
  ;; Close opened 3 vertices polylines.	;;
  (and (princ "\nSelect polylines with THREE vertices : ")
       (setq int -1 sel (ssget '((0 . "*POLYLINE")
                                 (90 . 3)
                                 (-4 . "<NOT")
                                 (-4 . "&=")
                                 (70 . 1)
                                 (-4 . "NOT>")
                                 )
                               )
             )
       (while (setq int (1+ int) ent (ssname sel int))
         (vlax-invoke (vlax-ename->vla-object ent) 'Mirror
           (vlax-curve-getstartpoint ent) (vlax-curve-getendpoint ent)
           )
         )
       )
  (princ)
  ) (vl-load-com)

 

Link to comment
Share on other sites

Tharwat Thanks for your efforts and response.  

Might be my request was not clear so I have attached a snap for better understanding of my requirement.

 

Thanks once again

 

Capture.PNG

Edited by CADWORKER
Link to comment
Share on other sites

The outcome can be of three possibilities (if on the same plane, otherwise infinite possibilities). You need to be clearer. What you want seems to be the parallelogram rule. I could be wrong.

 

image.thumb.png.51fea8834e536207c04d178438447ca0.png

Edited by Jonathan Handojo
Link to comment
Share on other sites

You said that the objects are polylines in the post and the program that I posted in my first reply also mirror the polylines as shown into your image as the final result unless you are referring now to line objects and not polylines !

Link to comment
Share on other sites

Alright, this one for two connected lines. :) 

(defun c:Test (/ int sel ent get rtn new lst pt1 pt2 bs1 bs2)
  ;;------------------------------------;;
  ;; Tharwat - Date: 19.Nov.2020	;;
  ;;------------------------------------;;
  (and
    (princ "\nSelect lines to mirror the two conected lines : ")
    (setq int -1
          sel (ssget "_:L" '((0 . "LINE")))
    )
    (while (setq int (1+ int)
                 ent (ssname sel int)
           )
      (setq get (entget ent)
            lst (cons (list (cdr (assoc 10 get)) (cdr (assoc 11 get)) get)
                      lst
                )
      )
    )
    (foreach grp lst
      (setq pt1 (car grp)
            pt2 (cadr grp)
            new (cdr lst)
            rtn nil
      )
      (while (and new
                  (not (if (cond ((equal pt1 (caar new) 1e-4)
                                  (setq bs1 pt2
                                        bs2 (cadar new)
                                  )
                                 )
                                 ((equal pt2 (caar new) 1e-4)
                                  (setq bs1 pt1
                                        bs2 (cadar new)
                                  )
                                 )
                                 ((equal pt1 (cadar new) 1e-4)
                                  (setq bs1 pt2
                                        bs2 (caar new)
                                  )
                                 )
                                 ((equal pt2 (cadar new) 1e-4)
                                  (setq bs1 pt1
                                        bs2 (caar new)
                                  )
                                 )
                           )
                         (setq rtn (car new))
                       )
                  )
             )
        (setq new (cdr new))
      )
      (and
        rtn
        (not (equal bs1 bs2 1e-4))
        (setq lst (vl-remove rtn lst))
        (mapcar (function
                  (lambda (o)
                    (vlax-invoke
                      (vlax-ename->vla-object (cdr (assoc -1 (caddr o))))
                      'Mirror
                      bs1
                      bs2
                    )
                  )
                )
                (list grp rtn)
        )
      )
    )
  )
  (princ)
) (vl-load-com)

 

Link to comment
Share on other sites

On 11/19/2020 at 3:11 PM, Tharwat said:

You said that the objects are polylines in the post and the program that I posted in my first reply also mirror the polylines as shown into your image as the final result unless you are referring now to line objects and not polylines !

Its my wrong, Actually its not lines its a polyline.

Link to comment
Share on other sites

29 minutes ago, CADWORKER said:

Its my wrong, Actually its not lines its a polyline.

 

You already now have two programs, the first program that I posted works for polylines with three vertices and the last one with work with connected two lines.

Have not you tried any of them to know how they work?

Link to comment
Share on other sites

14 hours ago, Tharwat said:

 

You already now have two programs, the first program that I posted works for polylines with three vertices and the last one with work with connected two lines.

Have not you tried any of them to know how they work?

I tried, both the codes; what I was looking was copy from mid to start and end of the plines and not the mirror.

Thanks a lot for your cooperation.

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