Add Block to Polyline Ends

Add Block to Polyline Ends

DGCSCAD
Collaborator Collaborator
351 Views
4 Replies
Message 1 of 5

Add Block to Polyline Ends

DGCSCAD
Collaborator
Collaborator

ronjonp's code taken from here: https://www.cadtutor.net/forum/topic/73618-auto-add-a-block-to-the-end-of-polylines/

 

How can I rotate the block placed at the pline end 180 degrees?  Solved: Removed + pi

Also, how would I use a variable in place of the hard coded 50 dxf in the entmake?

 

(defun ins_Term_R (/ _ang a ep p r s sp blk)
  ;; RJP » 2021-08-24
(setq blk "T2S_Straight_001")
  (defun _ang (e pt / a pa)
    (if	(and (setq pa (vlax-curve-getparamatpoint e pt))
	     (setq a (angle '(0 0 0) (vlax-curve-getfirstderiv e pa)))
	)
      a
    )
  )
  (cond	((null (tblobjname "block" blk)) (alert (strcat "Block " blk " needed!")))
	((setq s ss_center1);(ssget '((0 . "LWPOLYLINE"))))
	 (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))
	   ;(setq r (cons (list (setq sp (vlax-curve-getstartpoint e)) (_ang e sp)) r))
	   (setq r (cons (list (setq ep (vlax-curve-getendpoint e)) (+ pi (_ang e ep))) r))
	 )
	 (while	(setq p (car r)) (princ (cadr p))
	   (or (vl-some	'(lambda (x) (and (equal (car p) (car x) 1e-1) (setq a (cons x a))))
			(append a (setq r (cdr r)))
	       )
	       (entmake	(list '(0 . "INSERT")
			      '(100 . "AcDbEntity")
			      '(67 . 0)
			      '(8 . "CABLE 1")
			      '(48 . 0.0006)
			      '(100 . "AcDbBlockReference")
			      '(2 . "T2S_Straight_001")
			      (cons 10 (car p))
			      '(41 . 1.)
			      '(42 . 1.)
			      '(43 . 1.)
			      (cons 50 (cadr p))
			      '(70 . 0)
			      '(71 . 0)
			      '(44 . 0.)
			      '(45 . 0.)
			      '(210 0. 0. 1.)
			)
	       )
	   )
	 )
	)
  )
  (setq ss_term2 (ssget "l"))
  (princ)
)

 

 

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Accepted solutions (1)
352 Views
4 Replies
Replies (4)
Message 2 of 5

ronjonp
Mentor
Mentor

@DGCSCAD I'm not sure I understand your question. The 50 code is already formatted to use a variable (cons 50 (cadr p))

0 Likes
Message 3 of 5

DGCSCAD
Collaborator
Collaborator

My apologies, too many irons in the fire atm... I meant the block name: '(2 . "T1S_Straight_001")

 

I tried using a saved variable, which threw an error.

 

I tried removing the quote but no that wasn't it. Not sure what else to try?

AutoCad 2018 (full)
Win 11 Pro
0 Likes
Message 4 of 5

ronjonp
Mentor
Mentor
Accepted solution

@DGCSCAD 

You need to use CONS like so (cons 2 var).

0 Likes
Message 5 of 5

DGCSCAD
Collaborator
Collaborator

Ah! Thank you!

AutoCad 2018 (full)
Win 11 Pro
0 Likes