
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm trying to modify a routine created by "CAB" that works for one polyline to another one that works for all polylines of a layer. But, something goes wrong if the drawing has more than one polyline. Works for the first polyline but, to the others the polyline are mixing up with the first one.
Here is the code:
;;;=======================[ PSimple.lsp ]=======================
;;; Author: Charles Alan Butler
;;; Version: 1.1 Nov. 09, 2007
;;; Purpose: To remove un needed vertex from a pline
;;;=============================================================
(vl-load-com)
(defun c:PSimple (/ doc ent elst vlst idx dir keep result hlst len
group_on)
;; CAB 11/03/07
;; group on the elements of a flat list
;; (group_on '(A B C D E F G) 3)
;; Result ((A B C) (D E F) (G nil nil)...)
(defun group_on (inplst gp# / outlst idx subLst)
(setq outlst nil)
(setq subLst nil)
(while inplst
(setq idx -1
subLst nil
)
(while (< (setq idx (1+ idx)) gp#)
(setq subLst (cons (nth idx inplst) subLst))
)
(setq outlst (cons (reverse subLst) outlst))
(repeat gp#
(setq inplst (cdr inplst))
)
)
(reverse outlst)
)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq entlayer (car (entsel "\nSelect Object on Layer to Search and Report: ")))
(setq layer (cdr (assoc 8 (entget entlayer))))
(setq SelSet (ssget "_X" (list (cons 0 "*POLYLINE,LWPOLYLINE" )(cons 8 layer ))) Index 0 ) ; (automatic selection polyline from layer variable)
(setq i 0)
(setq n_ent (sslength SelSet)) ; Sets n to the length of the variable a. Ie. the number of entities selected by the user.
(repeat n_ent ; Starts SelSet loop that repeats n times.
(vla-StartUndoMark doc)
(setq na (ssname SelSet i)) ; Sets na to the entityname. Changes for each time i increase.
(setq elst (entget na))
(setq idx 0)
(repeat (fix (vlax-curve-getendparam na)) ; loop dentro de cada polyline (na)
(cond
((null keep)
(setq keep '(1)
dir (angle '(0 0) (vlax-curve-getFirstDeriv na 0.0))
))
((or (null(vlax-curve-getFirstDeriv na idx))
(equal dir (setq dir (angle '(0 0)
(vlax-curve-getFirstDeriv na idx))) 0.000001))
(setq keep (cons 0 keep))
)
((setq keep (cons 1 keep)))
)
(setq idx (1+ idx))
)
(setq vlst nil)
(setq vlst (vl-remove-if-not
'(lambda (x) (vl-position (car x) '(40 41 42 10))) elst)) ; elst
(setq vlst (group_on vlst 4))
(setq idx -1
len (1- (length vlst))
keep (reverse (cons 1 keep))
)
(while (<= (setq idx (1+ idx)) len)
(cond
((not (zerop (cdr(cadddr (nth idx vlst))))) ; keep arcs
(setq result (cons (nth idx vlst) result))
)
((not (zerop (nth idx keep)))
(setq result (cons (nth idx vlst) result))
)
)
)
(setq hlst nil)
(setq hlst (vl-remove-if
'(lambda (x) (vl-position (car x) '(40 41 42 10))) elst))
(mapcar '(lambda(x) (setq hlst (append hlst x))) (reverse result))
(setq hlst (subst (cons 90 (length result)) (assoc 90 hlst) hlst))
(entmod hlst)
(setq i (+ i 1))
(vla-EndUndoMark doc)
)
(princ)
)
(prompt "\nPline Simplify loaded, PSimple to run.")
(princ)
---
Sorry, I'm newbie at LISP.
Thanks in advance + regards,
lzucco
Solved! Go to Solution.