Copy block on just one midpoint (between any segmet/vertex) of multiple polylines

Copy block on just one midpoint (between any segmet/vertex) of multiple polylines

sazurich
Participant Participant
835 Views
5 Replies
Message 1 of 6

Copy block on just one midpoint (between any segmet/vertex) of multiple polylines

sazurich
Participant
Participant

Hi

So basically i am looking for lisp that can copy( like copy selection function does) a single block on multiple polylines on just one midpoint on any segment. best case scenario would be if i can first select all polylines and then start function that will just insert selected block on midpoint(keep the layer of that block) are there any lisps that i can search for that exist or i would need help with lisp couse i dont know how to write ones. here is image.
It doesnt matter which segment, first, last or random, but i just need one midpoint of each polyline not all midpoints of all segments for block to be inserted(copied).

 

help would be greatly appriciated . thx in advance

0 Likes
Accepted solutions (1)
836 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant

Possibly something like this. Copy at mid pnt of each segment.

 

(vl-load-com)

(defun c:BlockToMids ( / b s i j m e)

  (if (and (setq b (car (entsel "\nSelect block: ")))
	   (setq b (entget b))
	   (= "INSERT" (cdr (assoc 0 b)))
	   (princ "Select polylines, ")
	   (setq s (ssget '((0 . "LWPOLYLINE"))))
	   )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    m (vlax-curve-getendparam e)
	    j -0.5)
      (while (< (setq j (1+ j)) m)
	(entmake (append b (list (cons 10 (vlax-curve-getpointatparam e j))))))))
  (princ)
  )

 

0 Likes
Message 3 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

EDITED -- Another approach:

 

(defun C:BPM (/ bsel ss); = Block at Polyline Midpoint
  (if
    (and
      (setq bsel (entsel "\nBlock to Copy: "))
      (not (prompt "\nFor Polylines to Copy it to,"))
      (setq ss (ssget '((0 . "*POLYLINE"))))
    ); and
    (progn ; then
      (command "_.copybase" "_non" (cdr (assoc 10 (entget (car bsel)))) (car bsel) "")
      (repeat (setq n (sslength ss))
        (command "_.pasteclip" "_non" (vlax-curve-getPointAtParam (ssname ss (setq n (1- n))) 0.5))
      ); repeat
    ); progn
  ); if
  (prin1)
)

 

Kent Cooper, AIA
0 Likes
Message 4 of 6

sazurich
Participant
Participant

this one on first look and small sample size works great. few things that i dont get. is it possible to create block in its original layer(not that important), can i keep scaling of my block(so its not set to 1, not that important), and only important: it asks me to input all attributes for each block, so my question is can i copy block and keep the same attributes as original so i dont get asked over and over to type for each new block attributes. thx

 

EDIT: your 2nd approach works perfectly. thx a bunch

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@sazurich wrote:

.... it asks me to input all attributes for each block, so my question is can i copy block and keep the same attributes as original ....


[I would never have guessed from your original image that Attributes would be an issue, but the copy/paste approach instead of the Insert approach overcomes that anyway.]

 

Another thing that may be worth adding is a check that what was selected to Copy is, in fact, a Block.  Or, maybe a check that it is at least something with a DXF-10-code entry, and it can be used with Text/Mtext/Circle/Arc, etc., not just with a Block.

Kent Cooper, AIA
0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

If ask for attribute values 1st save to variables, then can insert block as many times as required yes may not be as efficient as copy but much easier to code.

0 Likes