Align blocks to line

Align blocks to line

danielzoltan_kiss
Participant Participant
1,767 Views
18 Replies
Message 1 of 19

Align blocks to line

danielzoltan_kiss
Participant
Participant

Dear Community,

 

I have different blocks, which are along to polyline like a loop. The order of blocks are important along the polyline. Base point of blocks equal to breaking point of polyline.

I would like to align all of these blocks to a line with the same order.

This loop is on the blueprint of fire alarm system and I need to generate schematic drawing from this.

 

Thank you in advance, if you have solution for me.

 

BR,

Daniel

0 Likes
Accepted solutions (2)
1,768 Views
18 Replies
Replies (18)
Message 2 of 19

komondormrex
Mentor
Mentor

has a pline crossed all blocks?

0 Likes
Message 3 of 19

danielzoltan_kiss
Participant
Participant

Basically blocks are bind with polylines, so there are more polylines.

0 Likes
Message 4 of 19

Sea-Haven
Mentor
Mentor

Need a dwg to look at.

 

komondormrex has hinted if along the pline then they can be found easily using the "fence" option when selecting objects.

0 Likes
Message 5 of 19

danielzoltan_kiss
Participant
Participant

Sample DWG is attached. 

0 Likes
Message 6 of 19

komondormrex
Mentor
Mentor
Accepted solution

@Sea-Haven, sure thing

@danielzoltan_kiss, check the following

 

(defun c:block_in_line (/ block_list org_pline index)
	(setq block_list (vl-remove-if 'listp
			 	(mapcar 'cadr
						(ssnamex
							(ssget "_f"
							       (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 10 (car group)))
								 		  	       (entget (setq org_pline (car (entsel "\nPick pline with bound blocks:"))))
									    )
							       )
							       '((0 . "insert"))
							)
						)
				)
			 )
	)
  	(vla-put-layer (vla-addline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
				    (vlax-3d-point (setq start_point (trans (getpoint "\nPick starting point of horizontal straightener for blocks: ") 1 0)))
			  	    (vlax-3d-point (polar start_point 0 (* 1000 (1+ (length block_list)))))
		       )
	  	       (cdr (assoc 8 (entget org_pline))) 
        )
  	(setq index 0)
  	(foreach block (mapcar 'vlax-ename->vla-object block_list)
		(vla-move
			(vla-copy block)
			(vla-get-insertionpoint block)
			(vlax-3d-point (polar start_point 0 (* 1000 (setq index (1+ index)))))
		)
	)
  	(princ)
)
Message 7 of 19

danielzoltan_kiss
Participant
Participant

Dear @komondormrex,

 

I appreciate your help. It works fine. It will speed up my work. Thank you very much.

Can I have a favor? Could you help to write an LSP, which following:

Draw a polyline, which bind the blocks according to "ADDRESS" attribute. Order is important. Regarding to sample.dwg file, 1/1 block is the first and 1/8 is the last.

Thank you in advance.

 

BR,

Daniel

0 Likes
Message 8 of 19

haper74945
Explorer
Explorer

Try this:

 

(defun c:foo ( / l pl blks ip tag dist sp p )
  (setq precision 4)
  (setq dist 1000)
  (princ "\nSelect Polyline: ")
  (setq pl (massoc (entget (car (entsel))) 10))
  (setq pl (mapcar '(lambda (x) (mapcar '(lambda (y) (rtos y 2 precision)) x)) pl))
  (setq pl (mapcar '(lambda (x) (mapcar 'atof x)) pl))
  (princ "\nSelect Blocks: ")
  (setq blks (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "insert")))))))
  (setq ip (mapcar '(lambda (x) (mapcar '(lambda (y) (rtos y 2 precision)) x)) (mapcar '(lambda (z) (reverse (cdr (reverse (cdr (assoc 10 (entget z))))))) blks)))
  (setq ip (mapcar '(lambda (x) (mapcar 'atof x)) ip))
  (setq blks (mapcar 'vlax-ename->vla-object blks))
  (setq ip (mapcar '(lambda (x y) (cons x y)) ip blks))  
  (foreach x pl
    (if (assoc x ip)  
      (setq l (cons (assoc x ip) l))
    )
  )
  (setq l (reverse l))
  (setq sp (getpoint "Pick Insertion Point: "))  
  (setq tag 1)
  (foreach x l
    (command "_line" "_none" sp "_none" (setq p (list (+ (car sp) dist) (cadr sp))) "")
    (vla-put-layer (vlax-ename->vla-object (entlast)) "FAS_Fire alarm cable")
    (vla-put-color (vlax-ename->vla-object (entlast)) 256)
    (command "_copy" (vlax-vla-object->ename (cdr x)) "" "_none" (car x) "_none" p)
    (setq dist (1+ dist))
    (setq sp (list (+ (car sp) 1000) (cadr sp)))
    (setq tag (1+ tag))
  )  
  (command "_line" "_none" sp "_none" (setq p (list (+ (car sp) dist) (cadr sp))) "")
  (vla-put-layer (vlax-ename->vla-object (entlast)) "FAS_Fire alarm cable")
  (vla-put-color (vlax-ename->vla-object (entlast)) 256)
)

 

0 Likes
Message 9 of 19

komondormrex
Mentor
Mentor

same as previous, but blocks aligned according to 'address' attribute?

0 Likes
Message 10 of 19

danielzoltan_kiss
Participant
Participant

Yes, it's right. In generally one loop include 70-100 pcs. of devices (block) on the blueprint and I bind these with lines. If the loop is ready, I have to create schematic drawing, which your previus solution solved. For this reason would be easier if a lisp could draw a polyline according to ADDRESS attribute, because I could apply your previous solution easier and I wouldn't need draw a polyline at first step.

0 Likes
Message 11 of 19

komondormrex
Mentor
Mentor

check if it is what you want.

(defun c:block_in_pline (/ block_list org_pline index start_point end_point address_attribute)
	(setq block_list (mapcar
			   'vlax-ename->vla-object
				 (vl-remove-if 'listp
				 	(mapcar 'cadr
							(ssnamex
								(ssget "_f"
								       (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 10 (car group)))
									 		  	       (entget (setq org_pline (car (entsel "\nPick pline with bound blocks:"))))
										    )
								       )
								       '((0 . "insert"))
								)
							)
					)
				 )
			 )
	     block_list (mapcar '(lambda (block) (cons (if (vl-some '(lambda (attribute) (= "ADDRESS" (vla-get-tagstring (setq address_attribute attribute))))
								      (vlax-invoke block 'getattributes)
							    )
							    (vla-get-textstring address_attribute)
							    "0/0"
							)
							block
						  )
				  )
				  block_list
			 )
  	     block_list (vl-sort block_list '(lambda (block_1 block_2) (< (atof (vl-string-translate "/" "." (car block_1)))
									  (atof (vl-string-translate "/" "." (car block_2)))
								       )
					      )
			)
        )
  	(setq start_point (trans (getpoint "\nPick starting point of horizontal pline straightener for blocks: ") 1 0)
	      end_point (polar start_point 0 (* 1000 (1+ (length block_list))))
	      lw_pline_points_array (vlax-make-safearray vlax-vbdouble '(0 . 3))
	)
  	(vla-put-layer (vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
			 			   (vlax-safearray-fill lw_pline_points_array (list (car start_point) (cadr start_point)
												    (car end_point) (cadr end_point)
											      )
						   )
		       )
	  	       (cdr (assoc 8 (entget org_pline))) 
        )
  	(setq index 0)
  	(foreach block (mapcar 'cdr block_list)
		(vla-move
			(vla-copy block)
			(vla-get-insertionpoint block)
			(vlax-3d-point (polar start_point 0 (* 1000 (setq index (1+ index)))))
		)
	)
  	(princ)
)
0 Likes
Message 12 of 19

danielzoltan_kiss
Participant
Participant

@komondormrex 

Sorry, perhaps I explained it false. Sample DWG is attached.

0 Likes
Message 13 of 19

komondormrex
Mentor
Mentor

just like that?

;************************************************************************************************************

(defun crd (_list)
	(reverse (cdr (reverse _list)))
)

;************************************************************************************************************

(defun c:block_in_pline (/ block_list org_pline start_point address_attribute connecting_line index pline_vertices_list pline_vertices_raw_list lw_pline_points_array)
	(setq block_list (mapcar
			   'vlax-ename->vla-object
				 (vl-remove-if 'listp
				 	(mapcar 'cadr
							(ssnamex
								(ssget "_f"
								       (mapcar 'cdr (vl-remove-if-not '(lambda (group) (= 10 (car group)))
									 		  	       (entget (setq org_pline (car (entsel "\nPick pline with bound blocks:"))))
										    )
								       )
								       '((0 . "insert"))
								)
							)
					)
				 )
			 )
	     block_list (mapcar '(lambda (block) (cons (if (vl-some '(lambda (attribute) (= "ADDRESS" (vla-get-tagstring (setq address_attribute attribute))))
								      (vlax-invoke block 'getattributes)
							    )
							    (vla-get-textstring address_attribute)
							    "0/0"
							)
							block
						  )
				  )
				  block_list
			 )
  	     block_list (vl-sort block_list '(lambda (block_1 block_2) (< (atof (vl-string-translate "/" "." (car block_1)))
									  (atof (vl-string-translate "/" "." (car block_2)))
								       )
					      )
			)
  	     start_point (trans (getpoint "\nPick starting point of horizontal pline straightener for blocks: ") 1 0)
	     pline_vertices_list (list start_point)
	     index 0
	)
  	(repeat (1+ (length block_list))
		(setq pline_vertices_list (append pline_vertices_list (list (polar start_point 0 (* 1000 (setq index (1+ index)))))))
	)
	(setq lw_pline_points_array (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length (setq pline_vertices_raw_list (apply 'append (mapcar 'crd pline_vertices_list)))))))) 
  	(vla-put-layer (vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
			 			   (vlax-safearray-fill lw_pline_points_array pline_vertices_raw_list)
		       )
	  	       (cdr (assoc 8 (entget org_pline))) 
        )
  	(setq index 0)
  	(foreach block (mapcar 'cdr block_list)
		(vla-move
			(vla-copy block)
			(vla-get-insertionpoint block)
			(vlax-3d-point (polar start_point 0 (* 1000 (setq index (1+ index)))))
		)
	)
  	(princ)
)

;************************************************************************************************************
0 Likes
Message 14 of 19

danielzoltan_kiss
Participant
Participant

Sorry, my sample dwg file was maybe misleading. I attached the correct version.

0 Likes
Message 15 of 19

komondormrex
Mentor
Mentor

komondormrex_0-1686857805998.png

 

 

0 Likes
Message 16 of 19

danielzoltan_kiss
Participant
Participant

Yes, you are right.  

0 Likes
Message 17 of 19

komondormrex
Mentor
Mentor
Accepted solution

well, then check this.

 

;************************************************************************************************************

(defun crd (_list)
	(reverse (cdr (reverse _list)))
)

;************************************************************************************************************

(defun c:block_in_pline (/ block_list start_point address_attribute index pline_vertices_list pline_vertices_raw_list lw_pline_points_array)
	(prompt "Select blocks with attribute \"Address\" you would like to place on pline by its order.")
  	(setq block_list (mapcar 'vlax-ename->vla-object (vl-remove-if 'listp (mapcar 'cadr (ssnamex (ssget '((0 . "insert")))))))
	      block_list (mapcar '(lambda (block) (cons (if (vl-some '(lambda (attribute) (= "ADDRESS" (vla-get-tagstring (setq address_attribute attribute))))
								      (vlax-invoke block 'getattributes)
							    )
							    (vla-get-textstring address_attribute)
							    "0/0"
							)
							block
						  )
				  )
				  block_list
			 )
  	      block_list (vl-sort block_list '(lambda (block_1 block_2) (< (atof (vl-string-translate "/" "." (car block_1)))
									  (atof (vl-string-translate "/" "." (car block_2)))
								       )
					      )
			)
  	     start_point (trans (getpoint "\nPick starting point of horizontal pline straightener for blocks: ") 1 0)
	     pline_vertices_list (list start_point)
	     index 0
	)
  	(repeat (1+ (length block_list))
		(setq pline_vertices_list (append pline_vertices_list (list (polar start_point 0 (* 1000 (setq index (1+ index)))))))
	)
	(setq lw_pline_points_array (vlax-make-safearray vlax-vbdouble (cons 0 (1- (length (setq pline_vertices_raw_list (apply 'append (mapcar 'crd pline_vertices_list)))))))) 
  	(vla-put-layer (vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
			 			   (vlax-safearray-fill lw_pline_points_array pline_vertices_raw_list)
		       )
	  	       "Fas_Fire Alarm Cable" 
        )
  	(setq index 0)
  	(foreach block (mapcar 'cdr block_list)
		(vla-move
			(vla-copy block)
			(vla-get-insertionpoint block)
			(vlax-3d-point (polar start_point 0 (* 1000 (setq index (1+ index)))))
		)
	)
  	(princ)
)

;************************************************************************************************************
Message 18 of 19

danielzoltan_kiss
Participant
Participant

Dear @komondormrex,

 

It works fine. Thank you very much again. Previously tried it, only I tried call with "crd" command and it didn't work, but this was only my fault. Could you recommend me a source, where could I learn the autolisp programming from? (Previously I learned python, if it is matter whatever)

 

BR,

Daniel

0 Likes
Message 19 of 19

Sea-Haven
Mentor
Mentor

Lots of places to learn lisp, plenty of Ebooks now, start with Afralisp tutorials. Look at code here and if have questions about what it is doing don't be afraid to ask. You get more help having a go, often via PM. 

 

Others will offer suggestions where to learn.

0 Likes