PDA

View Full Version : Looping Layers



scottpops
6th Jun 2005, 04:33 pm
Hey all, I recently wrote a post asking about deleting polyline verticies that were too close too each other. I have modified that program to now delete any verticies that are on the same line together (meaning 3 pts). I enter the verticies and their respective attributes into their own separate lists and compare 3 at a time to see if there are extra vertices that are not needed in there. The program works fine :D but now I need to make it go through all the layers in the drawing. I know its probably just a simple loop in the beginning but I am drawing a blank. :? Any help would be appreciated. Thanks!




(defun c:vertdel (/ ent1 ent vertlist
widthlistone widthlisttwo
bulgelist newent idx x
firstvert firstwid1 firstwid2 firstbulge
)

(setq ent1 (entnext))
;set ent1 to next entity

(while (/= ent1 nil)
;as long as there is an entity to grab
(if (= "LWPOLYLINE" (cdr (assoc 0 (entget ent1))))
;if the entity is a lwpolyine

(progn
(command "_.undo" "_be")
(setq ent (entget ent1)
;grab entity list
idx 0
;reset index
newent (list (car ent))
;start new list
ent (cdr ent)
; shorten list by 1
vertlist (list (car ent))
;new list with entity name (will be removed later)
widthlistone (list (car ent))
;new list
widthlisttwo (list (car ent))
;new list
bulgelist (list (car ent))
;new list
)

(while ent
;while we still have items in the entity list

(if (not (= 10 (car (setq x (car ent)))))
;check if attribute is a vertice
(setq newent (cons x newent)
;it's not a vertice, add it to the new list

ent (cdr ent)
;shorten the list
)

(progn
;it is a vertice, save for comparison
; add it and the width & bulge values to
;their own lists

(setq vertlist (cons x vertlist))

(setq ent (cdr ent)
x (car ent)
widthlistone (cons x widthlistone)
ent (cdr ent)
x (car ent)
widthlisttwo (cons x widthlisttwo)
ent (cdr ent)
x (car ent)
bulgelist (cons x bulgelist)
)




)
)
)

(setq vertlist (cdr (reverse vertlist))
;reorder lists and get rid of entity name from beginning
widthlistone (cdr (reverse widthlistone))
widthlisttwo (cdr (reverse widthlisttwo))
bulgelist (cdr (reverse bulgelist))
)

(while vertlist
;while there are still objects in vertlist


(if (and
(/= (caddr vertlist) nil)
;as long as there are 3 points to compare

(setq h (* (distance (cdr (car vertlist))

(cdr (cadr vertlist))
;set h to the distance of pt1 and pt2 times
;the sin of the angle between 1 & 2 and 1 & 3
;(getting the height of the second pt
; above the line from pt1 and pt3)
)
(sin (abs
(- (angle (cdr (car vertlist))
(cdr (cadr vertlist))
)
(angle (cdr (car vertlist))
(cdr (caddr vertlist))
)
)
)
)
)
)
&#40;and &#40;< h 0.001&#41;
&#40;> h -0.001&#41;
;-0.001<h<0.001
&#41;
&#41;
;all conditions are met &#40;point 2 is bad&#41;
&#40;setq firstvert &#40;car vertlist&#41;
;set first object in list to separate variable
vertlist &#40;cddr vertlist&#41;
;remove the first two items
vertlist &#40;cons firstvert vertlist&#41;
;add first object back into the beginning of the list

firstwid1 &#40;car widthlistone&#41;

widthlistone &#40;cddr widthlistone&#41;

widthlistone &#40;cons firstwid1 widthlistone&#41;


firstwid2 &#40;car widthlisttwo&#41;

widthlisttwo &#40;cddr widthlisttwo&#41;

widthlisttwo &#40;cons firstwid2 widthlisttwo&#41;


firstbulge &#40;car bulgelist&#41;

bulgelist &#40;cddr bulgelist&#41;

bulgelist &#40;cons firstbulge bulgelist&#41;
&#41;

&#40;progn ;conditions not met &#40;point 1 is good&#41;
&#40;setq newent &#40;cons &#40;car vertlist&#41; newent&#41;&#41;
;add first object to newent
&#40;setq newent &#40;cons &#40;car widthlistone&#41; newent&#41;&#41;

&#40;setq newent &#40;cons &#40;car widthlisttwo&#41; newent&#41;&#41;

&#40;setq newent &#40;cons &#40;car bulgelist&#41; newent&#41;&#41;

&#40;setq idx &#40;+ idx 1&#41;&#41;
;increment counter, this is so we can set &#40;assoc 90&#41; later

&#40;setq vertlist &#40;cdr vertlist&#41;&#41;
;delete point from list

&#40;setq widthlistone &#40;cdr widthlistone&#41;&#41;

&#40;setq widthlisttwo &#40;cdr widthlisttwo&#41;&#41;

&#40;setq bulgelist &#40;cdr bulgelist&#41;&#41;
&#41;
&#41;
&#41;

&#40;setq newent
&#40;subst &#40;cons 90 idx&#41; &#40;assoc 90 newent&#41; &#40;reverse newent&#41;&#41;
;update the # of vertices
&#41;

&#40;entmod newent&#41;
;modify the pline

&#40;command "_.undo" "_end"&#41;
&#41;
&#41;
&#40;setq ent1 &#40;entnext ent1&#41;&#41;
;goto next entity
&#41;
&#40;princ&#41;
&#41; ;end defun

CarlB
7th Jun 2005, 07:54 am
As near as I can tell, your lisp routine searches through every entity in the drawing - so there is no need to loop through layers.

Instead of checking every entity, you could make a set of all lwpolylines in the drawing and then operate on just those.