Centreline for walls without selection

Centreline for walls without selection

gayathrin.bmsce
Explorer Explorer
256 Views
1 Reply
Message 1 of 2

Centreline for walls without selection

gayathrin.bmsce
Explorer
Explorer

Hi All,

AutoLISP noob here. I am trying to drawing centre lines between lines in a particular layer. (Iterating and comparing one entity with all other entities in a layer) and then drawing only between lines within wall thickness.

 

 

(defun c:cenline (/ cencord i j)

  (setq I 0)
  (setq j 0)
  (while (< i (sslength (SSGET "_X" '((0 . "LINE") (8 . "Column")))))
    (progn
      (setq
	s1
	 (cdr
	   (assoc
	     10
	     (entget
	       (SSNAME
		 (SSGET "_X" (list (cons 0 "line") (cons 8 "Column")))
		 I
	       )
	     )
	   )
	 )
      )
      (setq e1
	     (cdr
	       (assoc 11 (entget (SSNAME (SSGET "_X" '((0 . "LINE"))) I)))
	     )
      )
      (setq i (+ 1 i))
      (while
	(< j (sslength (ssget "_x" '((0 . "line") (8 . "Column")))))
	 (progn
	   (setq s2
		  (cdr
		    (assoc 10
			   (entget (SSNAME (SSGET "_X" '((0 . "LINE"))) j))
		    )
		  )
	   )

	   (setq e2
		  (cdr
		    (assoc 11
			   (entget (SSNAME (SSGET "_X" '((0 . "LINE"))) j))
		    )
		  )
	   )
	   (setq j (+ 1 j))


	   (if
	     (and (= (nth 0 s1) (nth 0 s2)) (/= (nth 1 s1) (nth 1 s2)) (= (rtoi (distance s1 s2)) 9))
	      (PROGN
		(setq
		  cencord (list	(mapcar '/ (mapcar '+ s1 s2) '(2 2 2))
				(mapcar '/ (mapcar '+ e1 e2) '(2 2 2))
			  )
		)
		(command "line" (nth 0 cencord) (nth 1 cencord) "")

	      )
	   )
	   (if
	     (and (/= (nth 0 s1) (nth 0 s2)) (= (nth 1 s1) (nth 1 s2)) (= (rtoi (distance s1 s2)) 9)))

	      (progn
		(setq
		  cencord (list	(mapcar '/ (mapcar '+ s1 s2) '(2 2 2))
				(mapcar '/ (mapcar '+ e1 e2) '(2 2 2))
			  )
		)
		(setq osmode 0)
		(command "line" (nth 0 cencord) (nth 1 cencord) "")
	      )

	   )
	   (princ)
	 )
      )
    )
  )
)

 

 

 but I am not able to get it to stop after i hits the sslength (goes into infinite loop) or pick the correct points and then cencord changing according to the iterations.

 

Please let me know what I am missing

0 Likes
257 Views
1 Reply
Reply (1)
Message 2 of 2

ВeekeeCZ
Consultant
Consultant

@gayathrin.bmsce wrote:

Hi All,

AutoLISP noob here. I am trying to drawing centre lines between lines in a particular layer. (Iterating and comparing one entity with all other entities in a layer) and then drawing only between lines within wall thickness.

 

 

(defun c:cenline (/ cencord i j)

  (setq I 0)
  (setq j 0)
  (while (< i (sslength (SSGET "_X" '((0 . "LINE") (8 . "Column")))))    
; select this just once. save it to a variable. Selection is the slowest thing!!!
; for selection set, I would prefer to use REPEAT. See 2a method HERE . All the indexing is done at beginning. You don't forget it. (progn ; progn is unnecessary (setq s1 (cdr (assoc 10 (entget (SSNAME (SSGET "_X" (list (cons 0 "line") (cons 8 "Column"))) ; use a variable! I ) ) ) ) ) (setq e1 (cdr (assoc 11 (entget (SSNAME (SSGET "_X" '((0 . "LINE"))) I))) ; again... and again. ) ) (setq i (+ 1 i)) (while (< j (sslength (ssget "_x" '((0 . "line") (8 . "Column"))))) (progn (setq s2 (cdr (assoc 10 (entget (SSNAME (SSGET "_X" '((0 . "LINE"))) j)) ) ) ) (setq e2 (cdr (assoc 11 (entget (SSNAME (SSGET "_X" '((0 . "LINE"))) j)) ) ) ) (setq j (+ 1 j)) (if (and (= (nth 0 s1) (nth 0 s2)) (/= (nth 1 s1) (nth 1 s2)) (= (rtoi (distance s1 s2)) 9)) ; Unknown function. Autolisp has FIX. (PROGN (setq cencord (list (mapcar '/ (mapcar '+ s1 s2) '(2 2 2)) (mapcar '/ (mapcar '+ e1 e2) '(2 2 2)) ) ) (command "line" (nth 0 cencord) (nth 1 cencord) "") ) ) (if (and (/= (nth 0 s1) (nth 0 s2)) (= (nth 1 s1) (nth 1 s2)) (= (rtoi (distance s1 s2)) 9))) Too many parents. (progn (setq cencord (list (mapcar '/ (mapcar '+ s1 s2) '(2 2 2)) (mapcar '/ (mapcar '+ e1 e2) '(2 2 2)) ) ) (setq osmode 0) (command "line" (nth 0 cencord) (nth 1 cencord) "") ) ) (princ) ) ) ) ) )

 

 

 but I am not able to get it to stop after i hits the sslength (goes into infinite loop) or pick the correct points and then cencord changing according to the iterations.

 

Please let me know what I am missing


 

Did not check the algorithm. Just the systax.

 

My version [spoiler alert]:

 

(defun c:cenline ( / s i e j f e1 e2 f1 f2)

  (if (and (setq s (ssget "_x" '((0 . "LINE") (8 . "Column"))))
	   (setq w (getdist "Wall thickness: "))
	   )

    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))

      (repeat (setq j (sslength s))
	(setq f (ssname s (setq j (1- j))))

	(if (and (not (equal e f))
		 (setq e1 (cdr (assoc 10 (entget e))))
		 (setq e2 (cdr (assoc 11 (entget e))))
		 (setq f1 (cdr (assoc 10 (entget f))))
		 (setq f2 (cdr (assoc 11 (entget f))))
		 (equal (distance e1 f1) w 0.01)
		 (equal (distance e2 f2) w 0.01)
		 )
	  (command "_.line" "_non" (mapcar '/ (mapcar '+ e1 f1) '(2 2 2)) "_non" (mapcar '/ (mapcar '+ e2 f2) '(2 2 2)) "")))))
  (princ)
  )

 

0 Likes