Author Topic: Need your help,Object Connect&Draw pline  (Read 8739 times)

0 Members and 1 Guest are viewing this topic.

xiaxiang

  • Guest
Need your help,Object Connect&Draw pline
« on: March 10, 2011, 08:57:04 PM »
Hi,All
I need to connect some LWPOLYLINES just like my animation.Maybe It's mentioned as the Alan's topic about grread :
http://www.theswamp.org/index.php?topic=33469.0
I just want some code to help me drawing such a closed pline.I've try it by myself several days,but I found that I can do nothing.
Is there some useful code or idea?
Need your help!Thanks to all!
And I will stay online and keep Refreshing the  Screen and waiting for your suggestion (code) .


xiaxiang

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #1 on: March 10, 2011, 09:10:45 PM »
And ,It's my code to draw pline.It's not what I want! Because I must to do that for several steps as my animation.
The code is used from QJCHENhttp://www.xdcad.net/forum/showthread.php?postid=2278579#post2278579
AND VVA http://www.theswamp.org/index.php?topic=26664.0.
« Last Edit: March 10, 2011, 09:40:58 PM by xiaxiang »

LE3

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #2 on: March 10, 2011, 09:18:26 PM »
1. Make a selection of the polylines, that form the letter shape.
2. Explode them and make a selection of those lines.
3. Loop into all those lines, and find the ones that are collinear and make a set of lists of those groups.
4. Loop into the sets of collinear groups and find the extreme points and make a pair of points lists.
5. Then just draw lines from each pair of points.

HTH.

xiaxiang

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #3 on: March 10, 2011, 09:45:14 PM »
1. Make a selection of the polylines, that form the letter shape.
2. Explode them and make a selection of those lines.
3. Loop into all those lines, and find the ones that are collinear and make a set of lists of those groups.
4. Loop into the sets of collinear groups and find the extreme points and make a pair of points lists.
5. Then just draw lines from each pair of points.

HTH.
Thanks Luis
Can you make this routine for me?
 :roll: :wink: I'm shy to say that...

pkohut

  • Bull Frog
  • Posts: 433
Re: Need your help,Object Connect&Draw pline
« Reply #4 on: March 10, 2011, 10:10:03 PM »
1. Make a selection of the polylines, that form the letter shape.
2. Explode them and make a selection of those lines.
3. Loop into all those lines, and find the ones that are collinear and make a set of lists of those groups.
4. Loop into the sets of collinear groups and find the extreme points and make a pair of points lists.
5. Then just draw lines from each pair of points.

HTH.

alternative
2a. remove duplicates, ie. if line 1 is a duplicate of line 2 remove both lines. This will get rid of the interior lines. There could be more than 1 duplicate of a line, get rid of those too.
3a. pedit join the selection, shape outline is a polyline.
     3b. iterate new pline, checking segment angle, remove segment runs that have the same angle. Repeat for rest of pline segments.

LE3

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #5 on: March 10, 2011, 10:15:26 PM »
1. Make a selection of the polylines, that form the letter shape.
2. Explode them and make a selection of those lines.
3. Loop into all those lines, and find the ones that are collinear and make a set of lists of those groups.
4. Loop into the sets of collinear groups and find the extreme points and make a pair of points lists.
5. Then just draw lines from each pair of points.

HTH.
Thanks Luis
Can you make this routine for me?
 :roll: :wink: I'm shy to say that...

Nope, sorry I can't.

chlh_jd

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #6 on: March 11, 2011, 12:09:03 PM »
hi you can use the TSP way to get it . if you just to get a bold text frame , you can use wmfout&in then tanslate into regions , union , andthen trans... into PLine .
Code: [Select]
;;;by ElpanovEvgeniy
;;;From  http://www.theswamp.org/index.php?topic=30434.75
;;;edit by GSLS(SS) 2010.2
(defun c:TSP (/  D D0 D1 E ENT EP LL LS P m pt) ;_(setq l ptlst)
  (setq  
    l (my-getpt)  
    m (vlex-extents l)
    pt (list (+ (caadr m) 100.0) (- (cadar m) 100.0))
    l (cons pt l)
    ll (Graham-scan l)  
    ent (entmakex
 (append (list '(0 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(8 . "temp")
'(62 . 1)
'(100 . "AcDbPolyline")
(cons 90 (length l))
'(70 . 1)
 ) ;_  list
 (mapcar (function (lambda (a) (cons 10 a))) ll)
 ) ;_  append
) ;_  entmakex  
    l (mapcar
 (function cddr)
 (vl-sort
   (mapcar
     (Function
(lambda (a / b)
 (cons
   (distance a
     (setq b (vlax-curve-getClosestPointTo ent a))
   )
   (cons (vlax-curve-getParamAtPoint ent b) a)
 ) ;_  cons
) ;_  lambda
     ) ;_  Function
     l
   ) ;_  mapcar
   (function (lambda (a b)
(if (equal (car a) (car b) 1)
 (<= (cadr a) (cadr b))
 (< (car a) (car b))
) ;_  if
     ) ;_  lambda
   ) ;_  function
 ) ;_  vl-sort
) ;_  mapcar
    ls l
  ) ;_  setq
  (foreach a ll (setq ls (vl-remove a ls)))
  (foreach a ls
    (setq p (vlax-curve-getParamAtPoint
     ent
     (vlax-curve-getClosestPointTo ent a)
   )
 p (if (zerop (rem p 1.))
     (if (zerop p)
(vlax-curve-getEndParam ent)
(1- p)
     ) ;_  if
     (fix p)
   ) ;_  if
 p (vlax-curve-getPointAtParam ent p)
 p (list 10 (car p) (cadr p))
    ) ;_  setq
    (entmod (append (reverse (member p (reverse (entget ent))))
   (list (cons 10 a))
   (cdr (member p (entget ent)))
   ) ;_  append
    ) ;_  entmod
  ) ;_  foreach
  (foreach a l (setq ll (vl-remove a ll)))
  (entmod (vl-remove-if
   (function (lambda (a) (member (cdr a) ll)))
   (entget ent)
 )
  )
  (setq l  (mapcar (function cdr)
  (vl-remove-if-not
    (function (lambda (a) (= (car a) 10)))
    (entget ent)
  )
  ) ;_  mapcar
l  (mapcar (function list) (cons (last l) l) l)
ep (length l)
  ) ;_  setq
  (defun f1 (a ent / p)
    (setq p (vlax-curve-getPointAtParam
     ent
     (fix (vlax-curve-getParamAtPoint
    ent
    (vlax-curve-getClosestPointTo ent a)
  )
     )
   ) ;_  vlax-curve-getPointAtParam
 p (list 10 (car p) (cadr p))
    ) ;_  setq ;_  setq
    (entmod (append (reverse (member p (reverse (entget ent))))
   (list (cons 10 a))
   (cdr (member p (entget ent)))
   ) ;_  append
    ) ;_  entmod
  ) ;_  defun
  (setq d0 (vlax-curve-getDistAtParam ent ep))
  (while
    (> d0
       (progn
(foreach a l
  (setq e (entget ent)
d (vlax-curve-getDistAtParam ent ep)
  ) ;_  setq
  (entmod (vl-remove (cons 10 (car a))
     (vl-remove (cons 10 (cadr a)) e)
  )
  )
  (f1 (car a) ent)
  (f1 (cadr a) ent)
  (if (<= d
  (setq d1 (vlax-curve-getDistAtParam
     ent
     (vlax-curve-getEndParam ent)
   )
  )
      )
    (entmod e)
    (setq d d1
  e (entget ent)
    ) ;_  setq
  ) ;_  if
  (entmod (vl-remove (cons 10 (car a))
     (vl-remove (cons 10 (cadr a)) e)
  )
  )
  (f1 (cadr a) ent)
  (f1 (car a) ent)
  (if (<= d
  (setq d1 (vlax-curve-getDistAtParam
     ent
     (vlax-curve-getEndParam ent)
   )
  )
      )
    (entmod e)
    (setq d d1
  e (entget ent)
    ) ;_  setq
  ) ;_  if
) ;_  foreach
d
       ) ;_  progn
    ) ;_  <
     (setq d0 d)
  ) ;_  while
  (entmod (vl-remove (cons 10 pt)
     (entget ent)
  )
  )
  (setq d (vlax-curve-getDistAtParam
     ent
     (vlax-curve-getEndParam ent)
   )
  )
  (princ (strcat "\nPolyline Length: " (rtos d 2 4) " mm."))
  (princ)
)
;;; get BL UR points
(defun vlex-extents (plist)
  (list (apply
 'mapcar
 (cons 'min plist)
)
(apply
 'mapcar
 (cons 'max plist)
)
  )
)
;;;
(defun my-getpt (/ ss i s1 ptlst)
  (setq ss (ssget '((0 . "CIRCLE,*LINE*,POINT,ARC,ELLIPSE,TEXT"))))
  (setq ptlst nil
i -1
  )
  (while (setq s1 (ssname ss (setq i (1+ i))))
    (setq ptlst (append ptlst (ss-assoc 10 (entget s1))))        
  )
  ptlst
)
;;;Use Scanning Method convex hull points
;;;by highflybird
(defun Graham-scan (ptl / hPs rPs PsY Pt0 sPs P Q)
  (if (< (length ptl) 4) ;3点以下
    ptl ;是本集合
    (progn
      (setq rPs (mapcar (function (lambda (x)
      (if (= (length x) 3)
(cdr x)
x
      )
    )
  )
  (mapcar 'reverse ptl)
  ) ;点_表的X和Y交换
   PsY (mapcar 'cadr ptl) ;_点表的Y值的表
   Pt0 (reverse (assoc (apply 'min PsY) rPs)) ;_最下面的点      
   sPs (sort-ad ptl Pt0) ;_按角度距离排序点集
   hPs (list (caddr sPs) (cadr sPs) Pt0) ;_开始的三点
      )
      (foreach n (cdddr sPs) ;从第4点开始
(setq hPs (cons n hPs) ;把Pi加入到凸集
     P     (cadr hPs) ;Pi-1
     Q     (caddr hPs) ;Pi-2
)
(while (and q (> (det n P Q) -1e-6)) ;如果左转
 (setq hPs (cons n (cddr hPs)) ;删除Pi-1点
P      (cadr hPs) ;得到新的Pi-1点
Q      (caddr hPs) ;得到新的Pi-2点
 )
)
      )
      hPs ;返回凸集
    )
  )
)
;;;Anchored to the bottom point, angle and distance classification in accordance with point set
(defun sort-ad (ptlist pt / Ang1 Ang2)
  (vl-sort ptlist
  (function
    (lambda (e1 e2)
      (setq ang1 (angle pt e1)
    ang2 (angle pt e2))
      (if (equal ang1 ang2 1e-6)
(< (distance pt e1) (distance pt e2))
(< ang1 ang2)
      )
    )
  )
  )
)

« Last Edit: March 12, 2011, 07:23:54 AM by chlh_jd »

LE3

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #7 on: March 11, 2011, 12:17:57 PM »
That's nice, but guess it is better to allow the OP to try it first, post his/her code/efforts, then show or provide hints, pseudo code, semi solutions, that way he/she/all can learn, not just to simply providing an out of box solution and do his/her homework, have seen these type of posting lately here, instead why not post those on the 'show your stuff', that way at least they can look good.

Maybe it is me, but take it as there it is just two cents.

chlh_jd

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #8 on: March 11, 2011, 12:26:37 PM »
I just think people can not do too much duplication of effort, the Giants always stand on the shoulders of great men, I hope we are all giants.

xiaxiang

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #9 on: March 12, 2011, 04:56:14 AM »
I just think people can not do too much duplication of effort, the Giants always stand on the shoulders of great men, I hope we are all giants.


Thanks chlh_jd !
I will try that .The idea your posted is good for me. I couldn't find this way before.
非常感谢!

xiaxiang

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #10 on: March 12, 2011, 05:09:26 AM »
That's nice, but guess it is better to allow the OP to try it first, post his/her code/, then show or provide hints, pseudo code, semi solutions, that way he/she/all can learn, not just to simply providing an out of box solution and do his/her homework, have seen these type of posting lately here, instead why not post those on the 'show your stuff', that way at least they can look good.

Maybe it is me, but take it as there it is just two cents.
Hi Luis
The idea that you bring to me is good .I just think that I couldn't do this work with one step.The efforts is just like my second post in this topic.I'm not satisfied with it.
As the fact ,I really try all by myself.
Thanks.
xiax

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Need your help,Object Connect&Draw pline
« Reply #11 on: March 12, 2011, 05:33:44 AM »
hi you can use the TSP way to get it . if you just to get a bold text frame , you can use wmfout&in then tanslate into regions , union , andthen trans... into PLine .
< ... >

Good solution !!
Would be nice if you could credit the original author :)

You are correct ; we all stand on the shoulders of giants to some degree.

Regards
 
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

chlh_jd

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #12 on: March 12, 2011, 07:10:58 AM »
Thanks Kerry !
I'll find the 'TSP' code author , and modify the reply .

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: Need your help,Object Connect&Draw pline
« Reply #13 on: March 12, 2011, 07:16:43 AM »
Thanks Kerry !
I'll find the 'TSP' code author , and modify the reply .

From the coding style it looks like Evgeniy, but I could be way off  ;-)

chlh_jd

  • Guest
Re: Need your help,Object Connect&Draw pline
« Reply #14 on: March 12, 2011, 07:28:19 AM »
You are right , Lee .
The 'TSP' code I got it before I came in TheSwamp , So I'm sorry to forget the author .
by the way , I test the code again and again , it take wrong result , when the points is much .
I try to use the General genetic algorithm , but up to now, I have not done it .