Replacing object with block lisp

Replacing object with block lisp

Anonymous
Not applicable
8,894 Views
14 Replies
Message 1 of 15

Replacing object with block lisp

Anonymous
Not applicable

I have got a drawing with lots of rund objects representing bolts.

I want to replace these objects with a certain block.

Anybody have a lisp for that?

The objects are rund polylines so it is difficult to extract any center point. That is a big problem!

0 Likes
Accepted solutions (3)
8,895 Views
14 Replies
Replies (14)
Message 2 of 15

Patchy
Mentor
Mentor

What is a rund polyline? can you attach your drawing?

0 Likes
Message 3 of 15

Anonymous
Not applicable

Hi, I don´t know how those are created!

I can change thicknes to 0,0 and it is a polyline yet!

 

0 Likes
Message 4 of 15

Kent1Cooper
Consultant
Consultant

They're Donuts [the Donut command makes LWPolylines] with zero inside radius.  A routine could certainly be made that would filter the selection to allow only closed LWPolylines with a global width and two vertices, and only on a certain Layer [it seems you have one just for those], so it should be possible to narrow it down to just those, possibly without even involving the User selecting anything.  Since Donuts are always made with two equal half-circle arc segments, it could find the center of each by [among other ways] averaging the locations of those two vertices.  It could then use that location from each one to Insert your Block, and delete the bolt if desired.

 

That is probably not a difficult thing to build a routine to do.  What is your Block name, and would it be Inserted at scale factors of 1 and rotation of 0?  And would the bolts always be all the same size as each other, and always the same size in different drawings?  Would they always all be on that same Layer?

Kent Cooper, AIA
0 Likes
Message 5 of 15

Patchy
Mentor
Mentor

Explode them, then put a point in center of the arc, then replace point with block lisp (many on the internet)

 

points.JPG

 

 

0 Likes
Message 6 of 15

Anonymous
Not applicable

There are almost 800 of them!

Lots of houres to explode and extract center point of each one!

 

Best Regards Akmah

0 Likes
Message 8 of 15

Kent1Cooper
Consultant
Consultant

@Patchy wrote:

Explode them, then put a point in center of the arc, then replace point with block lisp....


Presumably a routine is wanted to do this [otherwise you'd need to go around with CENter-Osnap and the Point command and try to catch all of them].  So if such a routine needs to find the center of each bolt anyway, it may as well just put the Block there directly, and avoid a bunch of intermediary Points.  [Or if you do it manually, Insert the Block once, then Copy it with the Multiple option and running CENter Osnap -- neither Exploding nor Points are needed.]  It would also make the deleting of the bolt Polylines easier for a routine to do, if they are left un-Exploded.

Kent Cooper, AIA
0 Likes
Message 9 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

.... 

That is probably not a difficult thing to build a routine to do. ....


For instance [very basic and tested all of once in your sample drawing]:

 

(vl-load-com)
(defun C:BoltSub (/ ss n bolt verts ctr)
  (setq ss (ssget "_X" '((0 . "LWPOLYLINE") (8 . "BULT") (90 . 2))))
  (repeat (setq n (sslength ss))
    (setq
      bolt (ssname ss (setq n (1- n)))
      verts (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget bolt))
      ctr (mapcar '/ (mapcar '+ (cdar verts) (cdadr verts)) '(2 2 2))
    ); setq
    (command "_.insert" "YourBlockName" "_none" ctr "" "" "")
    (entdel bolt)
  ); repeat
); defun

Puts them on the current Layer, at a scale of 1 and rotation of 0.  Could be faster using (entmake) [in which case the 10 could be left in the vertex entity-data entries, because that will be applicable to the insertion-point entry for the Block], could use the usual enhancements, etc.

 

Kent Cooper, AIA
Message 10 of 15

Anonymous
Not applicable
How did you place the point at the center of each exploded donuts?
0 Likes
Message 11 of 15

Anonymous
Not applicable
Basically the problem is to extract the center point and use it to insert the block. I never seen this donuts object before, the file must be an old drawing! when I explode them I get two arcs for every donuts and those can be joined together as a circle but only if I select two at a time ! So no select A and join is possible! But thanks anyway!
0 Likes
Message 12 of 15

Patchy
Mentor
Mentor
Accepted solution

I used this:

 

(defun c:Test (/ ss)
  (if (setq ss (ssget "_x" '((0 . "ARC"))))
    ((lambda (i / sn e)
       (while (setq sn (ssname ss (setq i (1+ i))))
          (entmakex (list '(0 . "POINT") (assoc 10 (setq e (entget sn)))(assoc 8 e)))))
      -1
    )
    (princ)
  )
  (princ)
)

Message 13 of 15

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:
Basically the problem is to extract the center point and use it to insert the block. I never seen this donuts object before, the file must be an old drawing! when I explode them ....
....

Donut is not an object type, it's a command which makes donut-shaped Polylines, and it's been around for ages and still is, so it may not be an old drawing, on that account.  But the fact that the one big coursing thing that looks like a Hatch pattern is a *X-named Block makes me think it's old, anyway -- it's been a mighty long time since Hatch patterns were a special variety of Blocks, and weren't their own object type.

 

I don't know whether you tried the routine in Post 9 before your Reply quoted here, but it does it without any Exploding or Points.

Kent Cooper, AIA
Message 14 of 15

Anonymous
Not applicable
Thanks! I am going to try it tomorrow! Sure it will work! I been looking around this forum for over ten years! I am still looking for a function reading coordinates from an excel sheet in order to place blocks or other objects in a drawing. I know this is included in Civil 3D (takes time to master it!) but it should be a part of vanilla AutoCAD too! I run ArcGIS too and this function is ridiculously easy to use there. I made it first time I used it. Thank you all!
0 Likes
Message 15 of 15

Anonymous
Not applicable
 
0 Likes