INSERTING A BLOCK ON THE MIDPOINT OF MANY LINES/POLYLINES ALIGNED TO THE LINE

INSERTING A BLOCK ON THE MIDPOINT OF MANY LINES/POLYLINES ALIGNED TO THE LINE

b_gokgoz
Explorer Explorer
4,812 Views
11 Replies
Message 1 of 12

INSERTING A BLOCK ON THE MIDPOINT OF MANY LINES/POLYLINES ALIGNED TO THE LINE

b_gokgoz
Explorer
Explorer

Hi everyone,

 

I am trying to insert a block (my WallTag Block) on the middle of all the wall lines all at once. Normally I can insert that block with an "alignment" parameter one by one but as there are thousands of lines,  I guess AutoCAD has a way to save that time, hopefully with the help of a lisp 🙂

 

I looked for "divide command on multiple lines" hoping that the divide command would insert my selected block

on multiple lines however I could not find.

 

I am attaching a drawing to explain what I am trying to get.

 

All help is appriciated. Thanks.

 

 

0 Likes
Accepted solutions (2)
4,813 Views
11 Replies
Replies (11)
Message 2 of 12

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Hi,

Try this!

(defun c:Insert@MidLine (/ js n ent dxf_ent)
	(princ "\nSelect lines to insert block at middle")
	(setq js (ssget '((0 . "LINE"))))
	(cond
		(js
			(repeat (setq n (sslength js))
				(setq
					ent (ssname js (setq n (1- n)))
					dxf_ent (entget ent)
				)
				(entmake
					(list
						'(0 . "INSERT")
						'(100 . "AcDbEntity")
						(assoc 67 dxf_ent)
						(assoc 410 dxf_ent)
						(assoc 8 dxf_ent)
						(if (assoc 62 dxf_ent) (assoc 62 dxf_ent) '(62 . 256))
						(if (assoc 6 dxf_ent) (assoc 6 dxf_ent) '(6 . "ByLayer"))
						(if (assoc 48 dxf_ent) (assoc 48 dxf_ent) '(48 . 0.0))
						(if (assoc 370 dxf_ent) (assoc 370 dxf_ent) '(370 . 0))
						'(100 . "AcDbBlockReference")
						'(2 . "B")
						(cons 10 (mapcar '* (mapcar '+ (cdr (assoc 10 dxf_ent)) (cdr (assoc 11 dxf_ent))) '(0.5 0.5 0.5)))
						(if (assoc 39 dxf_ent) (assoc 39 dxf_ent) '(39 . 0.0))
						'(41 . 1.0)
						'(42 . 1.0)
						'(43 . 1.0)
						(cons 50 (angle (cdr (assoc 10 dxf_ent)) (cdr (assoc 11 dxf_ent))))
						'(70 . 0)
						'(71 . 0)
						'(44 . 0.0)
						'(45 . 0.0)
						(assoc 210 dxf_ent)
					)
				)
			)
		)
		(T (princ "\nNothing selected."))
	)
	(prin1)
)
Message 3 of 12

b_gokgoz
Explorer
Explorer

Great job, thank you very much.

 

That lisp works good for my defined block "B". Is it possible for the lisp to ask the name of the block?

 

Thanks.

0 Likes
Message 4 of 12

devitg
Advisor
Advisor
'(2 . "B")

Change B to YOUR-NAME-BLOCK
0 Likes
Message 5 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

@b_gokgoz wrote:

.... I am trying to insert a block (my WallTag Block) on the middle of all the wall lines all at once. ....


 

Attached is my way of doing that, MarkMidPoints.lsp with its MMP command.  [There are earlier versions of it on this site and elsewhere, but this is the newer version with multiple-object selection.]  It marks the mid-points of objects of any  of the types with linearity [Line, Arc, Circle, Polyline of any kind, Spline, Ellipse].

 

Under the Block option [you can mark with various other things], it asks for a Block name, and if you've used the command before, offers the same name as default, and if you haven't, offers Insert's default Block name if there is one.  It can find an external drawing file  of that name if it's in a Search Path list location.  If you type in a name that isn't either a Block in the current drawing or a drawing the Search Path list, it asks again.

 

In the case of a Polyline as a path, you have the choice of whether to mark the overall  mid-point, or the mid-point of each segment.

 

You have more options about the rotation of the Blocks relative to the path objects than DIVIDE gives you, and you can even specify the scale factor.

Kent Cooper, AIA
Message 6 of 12

b_gokgoz
Explorer
Explorer

That was exactly what I was looking for, thank you very much.

 

You guys are great 👍

0 Likes
Message 7 of 12

256B1-09A001-P101A
Explorer
Explorer

great lisp

there is anyway that u could change it to work with attribute block?

0 Likes
Message 8 of 12

Kent1Cooper
Consultant
Consultant

@256B1-09A001-P101A wrote:

great lisp

there is anyway that u could change it to work with attribute block?


How would you imagine using it?

 

You can simply change this:

...

  ((= _mmp-type_ "Blocks")
    (command
      "_.insert" _mmp-blk_

...

to this:

...

  ((= _mmp-type_ "Blocks")
    (command-s
      "_.insert" _mmp-blk_

...

and if ATTREQ=1, it will ask you for values for the Attributes as it puts the Blocks in [at the command line or in a dialog box, depending on the ATTDIA setting].  But you can't see where it's putting each Block [it doesn't appear until after the Attributes are filled in].  That wouldn't matter if you're always doing it on one path object that isn't a multi-segment Polyline.

 

It might be possible to have it put some kind of indication of where it's putting a Block, if that matters to the Attribute values for each one.

 

If you set ATTREQ=0, with or without the above change, it will put all the Blocks in, and you can then pick each and fill in Attribute values in Properties [including more than one at a time if the same Attribute value(s)], or double-click on each and fill in its Attributes.

Kent Cooper, AIA
0 Likes
Message 9 of 12

256B1-09A001-P101A
Explorer
Explorer

thx for the help

Getting

"Error: no function definition: COMMAND-S"

0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant

You must be using an older version of AutoCAD.  I think (command-s) came in the low twenty-teens somewhere [it began to be required in *error* handlers in place of (command) in 2015].  Try not making that change, but setting ATTREQ to 0 and assigning Attributes after the Blocks are placed.

 

Or, change this:

....

    ); command
  ); Blocks condition

....

to add a line like this:

....

    ); command
    (while (> (getvar 'cmdactive) 0) (command pause))
  ); Blocks condition

....

which I find in minimal trial works only if ATTDIA=1.  Same problem of not being able to tell which location it's asking for Attributes for, if there's more than one.

 

Kent Cooper, AIA
0 Likes
Message 11 of 12

nviktor01
Community Visitor
Community Visitor

OMG, MY LORD AND SAVIOR YOU ARE! I've spent days trying to write this, no success

0 Likes
Message 12 of 12

nviktor01
Community Visitor
Community Visitor

You sir! Saved lives! I've spent day trying to write this.. no success. Have a nice life!  THX

0 Likes