Jump to content

Recommended Posts

Posted

i need to insert a block on many polylines at one time .

image.png.863476c95fbfc1998b0dc305a5390489.png

Posted
(defun c:pp()
  (setq ssp (ssget '((0 . "LWPOLYLINE"))))
  (repeat (setq i (sslength ssp))
    (setq p1 (ssname ssp (setq i (1- i)))
	  a (assoc 10 (entget p1)))
    (entmake (list (cons 0 "INSERT") a (cons 2 "sample_block")))
    )
  )

Define a block named "sample_block", launch this lisp and select the polylines (all at once)

  • Like 1
  • Thanks 1
Posted (edited)

Worked well my friend thank you. But is it possible to modify it so that the block is defined within AutoCAD itself, so that when a command is given, it asks for the name of the block, and then it is executed?,and to be align on polylines at mid of this.

@fuccaro

 

 

 

21 hours ago, fuccaro said:
(defun c:pp()
  (setq ssp (ssget '((0 . "LWPOLYLINE"))))
  (repeat (setq i (sslength ssp))
    (setq p1 (ssname ssp (setq i (1- i)))
	  a (assoc 10 (entget p1)))
    (entmake (list (cons 0 "INSERT") a (cons 2 "sample_block")))
    )
  )

 

image.png.874922018eacc6f0d6954fffe4a53d31.png

 

Edited by land
Posted
(defun c:pp()
  (setq BlockName (getstring "Enter a block name: " ))
  (setq ssp (ssget '((0 . "LWPOLYLINE"))))
  (repeat (setq i (sslength ssp))
    (setq p (entget (ssname ssp (setq i (1- i))))
	  a (assoc 10 p)
	  b (assoc 10 (cdr (member a p)))
	  c (mapcar '(lambda (x y) (* 0.5 (+ x y))) (setq a (cdr a)) (setq b (cdr b)))
	  )    
    (entmake (list (cons 0 "INSERT") (cons 10 c) (cons 2 BlockName)(cons 50 (angle a b))))
    )
  )

Not sure what "align on polylines" means. I use the first two points of polylines to place the block. This could be wrong if the polyline starts with an arc...

There is no error trap in this Lisp, so when prompted, enter a valid block name.

 

  • Thanks 1
Posted

Worked well thank you.

 

2 hours ago, fuccaro said:
(defun c:pp()
  (setq BlockName (getstring "Enter a block name: " ))
  (setq ssp (ssget '((0 . "LWPOLYLINE"))))
  (repeat (setq i (sslength ssp))
    (setq p (entget (ssname ssp (setq i (1- i))))
	  a (assoc 10 p)
	  b (assoc 10 (cdr (member a p)))
	  c (mapcar '(lambda (x y) (* 0.5 (+ x y))) (setq a (cdr a)) (setq b (cdr b)))
	  )    
    (entmake (list (cons 0 "INSERT") (cons 10 c) (cons 2 BlockName)(cons 50 (angle a b))))
    )
  )

Not sure what "align on polylines" means. I use the first two points of polylines to place the block. This could be wrong if the polyline starts with an arc...

There is no error trap in this Lisp, so when prompted, enter a valid block name.

 

 

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...