Place XLINE into the selection set objects

Place XLINE into the selection set objects

Anonymous
Not applicable
1,072 Views
5 Replies
Message 1 of 6

Place XLINE into the selection set objects

Anonymous
Not applicable

Dear All,

I am trying to put "XLINE" in all the "CENTER" lines. For that i an trying the way of like Selection set > get the starting point and end point then placing the XLINE. Below are my code. But i am facing problrm in that.

 

Could anybody can solve this and teach me where i put wrongly ?? will be appreciated.

 

(defun c:xlines()
	(command "FILEDIA" 0)	;;Making command line process
	(setvar "CMDECHO" 0)	;;Turn off the SNAP
	(command "TILEMODE" "1")
		(if (setq cL(ssget '((0 . "LINE")(8 . "Top (Plan) View-CENTER"))))
			(progn
				(setq ctr 0)
				(while 
					(setq ent(ssname cL ctr))
					(setq ln(car ent))
					(setq lnEnt(entget ln))

					(setq startPoint(cdr(assoc 10 lnEnt)))
					(setq endPoint(cdr(assoc 11 lnEnt)))
					
					(if (=(car(cdr(assoc 10 lnEnt))) (car(cadr(assoc 11 lnEnt))))
						(progn
							(command "_.XLINE" "V" startPoint "")
						)
					)
					(command "_.XLINE" "H" startPoint "")
				)
				(setq ctr(1+ ctr))
			)
		)
	(command "TILEMODE" "0")
	(princ)
)

 

Regards

Ananth

0 Likes
Accepted solutions (3)
1,073 Views
5 Replies
Replies (5)
Message 2 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

This is all you need. Not sure if you put TILEMODE setting on purpose - get it back if so.

 

(defun c:xlines (/ s d i)
  
  (setvar 'cmdecho 0)
  
  (if (setq s (ssget '((0 . "LINE") (8 . "Top (Plan) View-CENTER"))))
    (repeat (setq i (sslength s))
      (setq d (entget (ssname s (setq i (1- i)))))
      (command "_.xline" "_non" (cdr (assoc 10 d)) "_non" (cdr (assoc 11 d)) "")))
  
  (setvar 'cmdecho 1)
  (princ)
  )

 

 

0 Likes
Message 3 of 6

ВeekeeCZ
Consultant
Consultant
Accepted solution

Your code fixed and commented.

Consider using the Reverse Repeat method, see HERE . 

 

(defun c:xlines( / )
  ;; (command "FILEDIA" 0)	don't need this at all.
  (setvar "CMDECHO" 0)	;;Turn off echo
  (command "TILEMODE" "1") 
  
  (if (setq cL (ssget '((0 . "LINE"))));(8 . "Top (Plan) View-CENTER") )))
    (progn
      (setq ctr 0) 
      (while                           ;; I would use REVERSED REPEAT method. It's easier and faster.
	(setq ent (ssname cL ctr))
	;(setq ln (car ent))    ; wrong line, car is used when entity comes from entsel... (setq ent (car (entsel)))
	(setq lnEnt (entget ent))
	
	(setq startPoint(cdr(assoc 10 lnEnt)))
	(setq endPoint(cdr(assoc 11 lnEnt)))
	
	(if (equal
	     ;=                       = when comparing reals, use equal with fuzzy!!!! reals are not precise enougth, these are not identical
	      (car(cdr(assoc 10 lnEnt)))
	      (car(cdr(assoc 11 lnEnt)))  ; cadr was wrong
	      0.001)             ; suitable fuzz
	                              
	  (command "_.XLINE" "V" startPoint "")  ; some parenthesis were wrong !!
	  (command "_.XLINE" "H" startPoint ""))
      (setq ctr(1+ ctr)))))
  (command "TILEMODE" "0")
  (princ)
  )

 

Message 4 of 6

hak_vz
Advisor
Advisor

 

(setq ln(car ent))

 

Elements in selection set are defined different then those created with command entsel. so this is not needed

 

@ВeekeeCZ  posted this as I was typing this

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 5 of 6

cadffm
Consultant
Consultant
Accepted solution

Hi

 

this is not a solution, just comments for learning

 

(defun c:xlines()
(command "FILEDIA" 0) ;;Making command line process This is for standard file selection dialog an in lisp ALWAYS USELESS, specially in programs like this, without a standard file dialog in process
(setvar "CMDECHO" 0) ;;Turn off the SNAP This has nothing to do with SNAP (and SNAP has nothing to do with what you think about '(you mean OSNAPs, i guess) , CMDECHO is the commandline feedback of commands - what you can see, or not, in [F2]
(command "TILEMODE" "1")
(if (setq cL(ssget '((0 . "LINE")(8 . "Top (Plan) View-CENTER"))))
(progn
(setq ctr 0)
(while
;;(setq ent(ssname cL ctr)) ; feedback is an ename like <Objektname: 2e839e64c0>
;;(setq ln(car ent)) ; car is for extraction the first element of a list, but your 'ent' contains an ename and not a list

(setq lnEnt(entget (ssname cL ctr))) ;< this line is enough, no need for  (setq ent / (setq ln

 

(car(cadr(assoc 11 lnEnt)))

means

(assoc 11 lnEnt) = (11 0.0 5.0 0.0)

(cadr(11 7.3 5.0 0.0)) = 7.3

(car 7.3) = ; car is for extraction the first element of a list, 7.3 is not a list

 


(progn
(command "_.XLINE" "V" startPoint "") ; Why _.XLINE and not .XLINE? or better: Why V and not _V ? It's useless to use international commands and options just less then 100% in  code

(command "_.XLINE" "_V" startPoint "")and it works in all language version.


)
) ; <== This is the closing IF-statement bracket, Xline-H will drawn for every line, is this what you want?

 

(command "_.XLINE" "H" startPoint "") ; the same as before with V => better: (command "_.XLINE" "_H" startPoint "")
); <== This is the closing While-statement bracket, (setq ctr is outside of while and it runs in a never ending loop
(setq ctr(1+ ctr))
)
)
(command "TILEMODE" "0") ; better is to save the current setting at start and set it back at the end
(princ)
)

Sebastian

0 Likes
Message 6 of 6

Anonymous
Not applicable

This code is awesome and more simple than mine, i have learnt a new today.

Thanks you for your correct code and your suggestion.

0 Likes