What i Mistake I Want Polyline not Intersect

What i Mistake I Want Polyline not Intersect

jaimuthu
Advocate Advocate
574 Views
6 Replies
Message 1 of 7

What i Mistake I Want Polyline not Intersect

jaimuthu
Advocate
Advocate
(defun c:c1 ( / ss blk insPt ptList count)
  (setq ss (ssget '((0 . "INSERT")))) 
  (if ss
    (progn
      (setq ptList '() count 1) 
      (repeat (sslength ss)
        (setq blk (ssname ss 0)) 
        (setq insPt (cdr (assoc 10 (entget blk)))) 
        (setq ptList (cons insPt ptList)) 
        
        
        (command "_.TEXT" "_J" "MC" insPt 1000.0 0 (itoa count))
        
        (setq count (1+ count)) 
        (ssdel blk ss)
      )
      (if ptList
        (progn
          (setq ptList (reverse ptList)) 
          (command "_.PLINE")
          (foreach pt ptList
            (command pt)
          )
          (command "") 
        )
        (princ "\nNo insertion points found.")
      )
    )
    (princ "\nNo blocks selected.")
  )
  (princ)
)

i attached dwg file what i need this

 

0 Likes
Accepted solutions (3)
575 Views
6 Replies
Replies (6)
Message 2 of 7

ec-cad
Collaborator
Collaborator

What you have is a random order issue, based on when each block gets inserted, follows the doc database.

Here's a modification to get you closer, Finishes pline back to first point (lower left). I'll let you handle that.

Cheers:

;; C1.lsp

(defun c:c1 ( / ss blk insPt ptList count)

;; Sort Insertion Points X / Y

      (setq ss (ssget "X" '((0 . "INSERT"))))
      (setq ptList (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
      (setq ptList (vl-sort ptList '(lambda ( a b ) (if (equal (car (cdr (assoc 10 (entget a)))) (car (cdr (assoc 10 (entget b)))) 1e-6)
                                        (> (cadr (cdr (assoc 10 (entget a)))) (cadr (cdr (assoc 10 (entget b)))))
                                        (< (car (cdr (assoc 10 (entget a)))) (car (cdr (assoc 10 (entget b)))))
                                    )
                    )
        )
      )
;; Insert MText each Insertion Point as sorted
      (if ptList
        (progn
         (setq count 0)
         (foreach entname ptList
          (setq InsPt (cdr (assoc 10 (entget entname))))
          (command "_.TEXT" "_J" "MC" InsPt 1000.0 0 (itoa (+ count 1)))
          (setq count (+ count 1))
          (setq ptLst (cons InsPt ptLst))
         ); foreach
;; Draw the Pline from the sorted points
          (command "_.PLINE")
          (foreach pt ptLst
            (command pt)
          )
          (command "") 
        )
        (princ "\nNo insertion points found.")
      )
    )

ECCAD

0 Likes
Message 3 of 7

jaimuthu
Advocate
Advocate

but its show zigzag polylines

0 Likes
Message 4 of 7

ec-cad
Collaborator
Collaborator
Accepted solution

Yes, I know. There will be no way to sort' those, to a smooth path, unfortunately.

Best you can do, is to pick first, and keep on picking blocks, one at a time, to follow

your favorite direction, like in your sample drawing. Maybe if you were to pick the first,

and get 'nearest' (next block), continue until it doesn't pick the correct next, one, then

Undo (1), pick the 'next' correct one, and so on. Programming nightmare.

 

ECCAD

0 Likes
Message 5 of 7

jaimuthu
Advocate
Advocate

thank you for your quick reply

0 Likes
Message 6 of 7

john.uhden
Mentor
Mentor
Accepted solution

@jaimuthu ,

OR

Draw the polyline first from inspt to inspt to inspt (setq your running snap mode).

Then use the points as a fence, as in (setq ss (ssget "_F" ptList '((0 . "INSERT"))))

That way the count will be in the same order.

In fact, you don't even need to ssget anything.  Just use the polyline points.

John F. Uhden

0 Likes
Message 7 of 7

Sea-Haven
Mentor
Mentor
Accepted solution

Something like this. Very rough needs extra info text style, layers etc.

 

 

 

(defun c:plpts ( / plpts plent co-ord x oldsnap)
(defun plpts ( / pt)
(setq pt (getpoint "\nStarting point of Pline Enter to stop : "))
(command "_pline" pt)
(while (= (getvar "cmdactive") 1 )
  (command (getpoint (getvar 'lastpoint)))
)
)

(setq oldsnap (getvar 'osmode))
(setvar 'osmode 64)

(plpts)

(setq plent (entlast))
(setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget plent))))

(setq x 1)
(foreach pt co-ord
  (command "text" pt 2000 0.0 (rtos x 2 0))
  (setq x (1+ x))
)

(setvar 'osmode oldsnap)

(princ)

)
(c:plpts)

 

 

 Very rough