Message 1 of 2
troubleshooting autolisp routine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone, i have lots of drawings that each of them has hundreds of polylines, some of these polylines have vertices that share the same exact coordinate witch is fine but some of them were supposed to do that but because drawing imperfections there is a slight gap between them (basically two different polylines were supposed to touch at one or more vertices but they didn't snap together perfectly)
I wrote a basic autolisp script that was supposed to take the polylines and look for vortices that are very close and snaps them together but it seems it doesn't work and i belive the snapvertex subroutine is not working, i really appreciate if someone could help me troubleshoot it
thank you
(defun c:SnapVerts ( / ss fuzz i j ent1 ent2 vlist1 vlist2 v1 v2 d)
;Get list of vertices from polyline
(defun getvertices (ent / elist n vlist)
(setq elist (entget ent)
n (cdr (assoc 90 elist)) ; number of vertices
vlist '()
)
(repeat n
(setq vlist (cons (cdr (assoc 10 elist)) vlist))
(setq elist (cdr (member (assoc 10 elist) elist)))
)
(reverse vlist)
)
;Reposition a vertex in polyline
(defun setvertex (ent old new / edata)
(setq edata (entget ent))
(setq edata
(mapcar
(function
(lambda (x)
(if (and (= (car x) 10) (= (cdr x) old))
(cons 10 new)
x
)
)
)
edata
)
)
(entmod edata)
(entupd ent)
)
(setq fuzz 0.1) ; fuzz distance
(prompt "\nSelect polylines to process: ")
(setq ss (ssget '((0 . "LWPOLYLINE"))))
(if ss
(progn
(repeat (setq i 0)
(setq ent1 (ssname ss i))
(setq vlist1 (getvertices ent1))
(setq j (+ i 1))
(while (< j (sslength ss))
(setq ent2 (ssname ss j))
(setq vlist2 (getvertices ent2))
(foreach v1 vlist1
(foreach v2 vlist2
(setq d (distance v1 v2))
(if (< d fuzz)
(progn
(setvertex ent2 v2 v1)
)
)
)
)
(setq j (1+ j))
)
(setq i (1+ i))
)
(princ "\nVertices snapped based on proximity.")
)
(prompt "\nNo polylines selected.")
)
(princ)
)