each polyline square to individual same block

each polyline square to individual same block

Anonymous
Not applicable
1,027 Views
13 Replies
Message 1 of 14

each polyline square to individual same block

Anonymous
Not applicable

Hi, i am newbie to lisp and cannot search my usable lisp code from internet.

 

Please Help!!>__<

 

the procedure of the code are as follow:

 

1. select a particular area and highlight all the rectangular polyline ( in same layer , same size)

2. the programe will return the coodinates of each square polyline.

3. and programe ask u to choose a block ( by entering the block name)

4. finally , all the block is drawn over the rectanguler box

 

thanks!!

0 Likes
Accepted solutions (1)
1,028 Views
13 Replies
Replies (13)
Message 2 of 14

Kent1Cooper
Consultant
Consultant

Some questions:

 

By the "coordinates" of each Polyline, do you mean all four corners of each, or just one location in each, for the insertion of a Block over it?

 

If one location in each, should it be one of its vertex locations, such as the starting vertex, or perhaps the midpoint of the rectangle [which is not actually among its coordinates, but can be calculated easily]?

 

Are all rectangles on that Layer always going to be the same size, so that the routine can just find all closed four-sided Polylines?  Or should it ask the User what size rectangles they want it to find?

 

You use both the word "rectangular" and the word "square."  Should the routine test each Polyline to determine whether it's a square?  Would it ever find any Polylines that are closed and four-sided but neither rectangular or square?  If it might, should it ignore them?

 

A small sample drawing or image would be helpful.

Kent Cooper, AIA
0 Likes
Message 3 of 14

Anonymous
Not applicable

Sorry for the mistakes i caused.

 

The revised procedure are as follow:

 

the procedure of the code are as follow:

 

1. select a particular area and highlight all the square polyline ( in same layer , same size)

2. ask the User what size rectangles they want it to find

3. the programe will return the one of its vertex locations of coodinates of each square polyline.

4. and programe ask u to choose a block ( by entering the block name)

5. finally , all the block is drawn over the square box

 

(all rectangle polyline = square poly line)

(should ask the size of sqaure)

0 Likes
Message 4 of 14

Kent1Cooper
Consultant
Consultant

Some more questions:

Will all the squares be drawn in the same way, that is, with their starting vertex at the same corner, and proceeding in the same direction around the square?  Will they all be orthogonal, or would Block rotations need to account for the way a particular square is drawn?  Where would the insertion point of the Block(s) be, and would that be the same for all Blocks a User might ask for?  It matters, because if I make certain assumptions [having no idea what your Blocks look like]:

 

BlocksOnSquares.png

 

If they are all orthogonal, a routine could find the lower left corner, whether or not it is the starting vertex, or any other particular corner you choose.  If they may not be, and especially if they may not all be drawn in the same direction, it gets a lot trickier [though whatever you need can probably be calculated].

 

These kinds of questions are the reason that a sample drawing would be helpful.

Kent Cooper, AIA
0 Likes
Message 5 of 14

Anonymous
Not applicable

The attached file is uploaded. All the square are polyline that need to be replaced by a speaker ( are being circled in the file).

 

 

0 Likes
Message 6 of 14

Anonymous
Not applicable

the block is trapezium in shape and it would help a lot it the block is excatly in the middle of the square polyline.

0 Likes
Message 7 of 14

Kent1Cooper
Consultant
Consultant

This kind of relationship?

BlockOnSquare.png

 

EDIT:  Or [seeing Post 6] this?

 

BlockOnSquare2.png

 

It appears all those squares are drawn the same way, with their starting vertices in the same position.  That makes it pretty easy, if you can count on that always being the case.

Kent Cooper, AIA
0 Likes
Message 8 of 14

Anonymous
Not applicable

Nice!! nice to heard that you say easy! but i don't know how to write the code, please help!

0 Likes
Message 9 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

the block is trapezium in shape and it would help a lot it the block is excatly in the middle of the square polyline.


Would you be willing to redefine the Block so that its insertion point is in the center, rather than at the midpoint of an edge?  That would make it much easier to insert them centered in the squares if my "Or this?" image is correct.

Kent Cooper, AIA
0 Likes
Message 10 of 14

Anonymous
Not applicable

The two photo are same to me, choose the one you found is easier. ^V^

0 Likes
Message 11 of 14

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

The two photo are same to me, choose the one you found is easier. ^V^


The difference is that the top one has the Block insertions point [in the middle of the long edge of the trapezoid] at the midpoint of the first segment of the Polyline, whereas the bottom one has the top and bottom edges of the trapezoid equally distant from the top and bottom edges of the Polyline.  Do you have a preference?

Kent Cooper, AIA
0 Likes
Message 12 of 14

Anonymous
Not applicable
I prefer the one that the top one that has the Block insertions point [in the middle of the long edge of the trapezoid] at the midpoint of the first segment of the Polyline,
0 Likes
Message 13 of 14

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:
I prefer the one that the top one that has the Block insertions point [in the middle of the long edge of the trapezoid] at the midpoint of the first segment of the Polyline,

Good -- that's easier.  This is kind of basic, and minimally tested, but it worked for me in your sample drawing:

 

(vl-load-com); in case it hasn't been done already
(defun C:BOS (/ ss blk len n sq); = Blocks On Squares
  (defun ptpar (par); = point at parameter value of square
    (vlax-curve-getPointAtParam sq par)
  ); defun -- ptpar
  (prompt "\nTo place Blocks On Squares,")
  (if
    (setq ss (ssget '((0 . "LWPOLYLINE") (90 . 4) (-4 . "&") (70 . 1))))
      ;; finds all 4-sided closed LWPolylines among User selection
    (progn
      (setq
        blk (getstring "\nName of Block to Insert at each square: ")
        len (getdist "\nEdge length of squares to Insert Blocks on: ")
; type a value or better yet, Osnap between corners of one of the squares ); setq (repeat (setq n (sslength ss)) (setq sq (ssname ss (setq n (1- n)))); step through selection (if (and ; fuzz factors of 5 units about 1% of edge length in sample dwg; EDIT as desired (equal (vlax-curve-getDistAtParam sq (vlax-curve-getEndParam sq)) (* 4 len) 5); correct size (equal (distance (ptpar 0) (ptpar 2)) (distance (ptpar 1) (ptpar 3)) 5); diagonals equal (equal (distance (ptpar 0) (ptpar 1)) (distance (ptpar 1) (ptpar 2)) 5); 2 edges equal ); and (command ; then [it's a square of the right size] "_.insert" blk "_scale" 1 (ptpar 0.5); insertion point [midpoint of first segment] (ptpar 1.0); rotation [second vertex] ); command ); if ); repeat ); progn ); if (princ) ); defun -- C:BOS

It could use error handling, Undo begin/end wrapping, verification that the Block exists, command-echo suppression, remembering your Block name and/or edge length to offer as default on subsequent use, perhaps Layer control, etc.

Kent Cooper, AIA
0 Likes
Message 14 of 14

Anonymous
Not applicable
many thanks! it works!!
0 Likes