Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HELP : Adjust all Lines direction

3 REPLIES 3
Reply
Message 1 of 4
Tohami
294 Views, 3 Replies

HELP : Adjust all Lines direction

Could any one help me to create a code that let me adjust all lines direction to be in +X & +Y & +Z directions.

That mean all lines should have Start X & Y & Z equal or smaller than corresponding End X & Y & Z.

Here you are the concept and i wish any one can write code for it :

 

for any line in the model;

if Start X bigger than corresponding End X then; flip line, else; do nothing

if Start Y bigger than corresponding End Y then; flip line, else; do nothing

if Start Z bigger than corresponding End Z then; flip line, else; do nothing

 

Thanks in advance

3 REPLIES 3
Message 2 of 4
effeltour
in reply to: Tohami

 

 

(defun c:LineadjustXYZ ( / ss  cnt  1e  Spt  Ept )     ;  Command is adjustable.
  (setq ss (ssget '((0 . "LINE"))))
  (setq cnt 0)
  (repeat (sslength ss)
    (setq 1e (ssname ss cnt)
   Spt (cdr (assoc 10 (entget 1e)))
   Ept (cdr (assoc 11 (entget 1e)))
    )

    (if (or (> (car Spt) (car Ept))
     (> (cadr Spt) (cadr Ept))
     (> (caddr Spt) (caddr Ept))
 )
      (progn
        (entmod (subst (cons 10 Ept) (assoc 10 (entget 1e)) (entget 1e)))
        (entmod (subst (cons 11 Spt) (assoc 11 (entget 1e)) (entget 1e)))
      )
    )
    (setq cnt (1+ cnt))
  )
  (princ)
)

Message 3 of 4
phanaem
in reply to: Tohami

Hi Tohami


You have to decide when you want to flip a line, because is not clear...

Those 3 conditions can meet all three together, any two at once, or just one of them....

And, except for the fist case, if you flip a line, then according to your rule, you must flip it again...

If you decide  when to flip, you can use this code:

(defun flip_line (ent / p1 p2) ; ent is ENAME type
      (setq ent (vlax-ename->vla-object ent)
        p1 (vlax-get ent 'StartPoint)
        p2 (vlax-get ent 'EndPoint))
      (vlax-put ent 'StartPoint p2)
      (vlax-put ent 'EndPoint p1)
      )

Message 4 of 4
JustoAg
in reply to: Tohami

I think you then need all these lines with no negative deltas in X, Y & Z, right?. I have this routine that put the lines in the first quadrant direction.

(defun f2 ()

	(setq ss (ssget '((0 . "LINE") )))
	(if (not ss) (exit))
	
	(setq oldos (getvar "OSMODE"))
	(setvar "OSMODE" 0)
	
	(if ss (setq i (sslength ss)))

	(while (not (minusp (setq i (1- i))))
		
		(setq 	1e (ssname ss i)
   				Spt (cdr (assoc 10 (entget 1e)))
   				Ept (cdr (assoc 11 (entget 1e)))
				ang (angle Spt Ept)
		)

		(cond 	((and (> ang (/ pi 2.0)) (<= ang pi))
			   		(command "._Mirror" 1e "" spt (polar spt (/ pi 2.0) 1.0) "_Y")(setq 1e (entlast))); 2nd Quad
				 
		  		((and (> ang pi) (< ang (/ (* 3.0 pi) 2.0)))
		   			(command "._Mirror" 1e "" spt (polar spt (/ (* pi 3.0) 4.0) 1.0) "_Y")(setq 1e (entlast))); 3rd Quad
		   		
		  		((and (>= ang (/ (* 3.0 pi) 2.0)) (< ang (* pi 2.0)))
		   			(command "._Mirror" 1e "" spt (polar spt 0.0 1.0) "_Y")(setq 1e (entlast))); 4th Quad
		   		
		  		(T nil)
		)

		;; Now for Z values
		(setq oLine (vlax-ename->vla-object 1e))
		(setq deltas (vlax-safearray->list (vlax-variant-value (vlax-get-property oLine 'Delta))))

		(if (minusp (last deltas))
			(progn
				(setq p1 (vlax-get oLine 'StartPoint)
        			  p2 (vlax-get oLine 'EndPoint))
      			(vlax-put oLine 'StartPoint p2)
      			(vlax-put oLine 'EndPoint p1)
			)		
		)
	)

	(setvar "OSMODE" oldos)
	(princ)
)

 

Hope this is what you need.

 

---

Justo Aguiar

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost