(defun From1to4 ( / vertices entselOut PickPoint dist StartIndex)
(vl-load-com)
(setq entselOut (entsel "Pick a polyline near to the startpoint")
PickPoint (cadr entselOut)
vertices (mapcar
'cdr
(vl-remove-if-not
'(lambda (a / )
(= (car a) 10)
)
(entget (car entselOut))
)
)
StartIndex (vl-position
(apply
'min
(setq dist
(mapcar
'(lambda (a / )
(distance PickPoint a)
)
vertices
)
)
)
dist
)
)
(repeat StartIndex (setq vertices (reverse (cons (car vertices) (reverse (cdr vertices))))))
)
1. Select Polyline
2. Pick the Point
3. Get the Vertices of the Polyline
4. Sort them, so that the vertices nearest to the Point in 2. is the first.
5. reverse or not the list from step 4. to be clockwise
6. insert BlockReference on each vertex
7. change Attribute value
(setq num_seq
(getint
(strcat "\nStarting number <"
(itoa num_seq)">: ")))
(car (nentsel "\n--- SELECT ATTRIBUTE ---- ")))
(if (and curText ;
(setq curData (entget curText))
(= (cdr (assoc 0 curData)) "ATTRIB")
)
(progn
(vla-put-TextString
(vlax-ename->vla-object curText)curStr)
(setq num_seq(1+ num_seq))
)
(princ "\n--- THIS IS NOT AN ATTRIBUTE ---- ")
is it possible to increase the value of attribute block along a polyline clockwise automaticaly. and how?
is it possible to increase the value of attribute block along a polyline clockwise automaticaly. and how?
Perhaps a bit of searching will lead you in the right direction
http://goo.gl/M9O64C (http://goo.gl/M9O64C)
http://goo.gl/GhIaYY (http://goo.gl/GhIaYY)
(defun c:pblinclw ( / ListClockwise-p osm ss lw vl pt n pr k v bl att )
(defun ListClockwise-p ( lst / z vlst )
(vl-catch-all-apply 'minusp
(list
(if
(not
(equal 0.0
(setq z
(apply '+
(mapcar
(function
(lambda (u v)
(- (* (car u) (cadr v)) (* (car v) (cadr u)))
)
)
(setq vlst
(mapcar
(function
(lambda (a b) (mapcar '- b a))
)
(mapcar (function (lambda (x) (car lst))) lst)
(cdr (reverse (cons (car lst) (reverse lst))))
)
)
(cdr (reverse (cons (car vlst) (reverse vlst))))
)
)
) 1e-6
)
)
z
(progn
(prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list")
nil
)
)
)
)
)
(setq osm (getvar 'osmode))
(setvar 'osmode 8)
(prompt "\nPick 2D LWPOLYLINE that has blocks with attributes to increment at its vertices...")
(setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
(setq lw (ssname ss 0))
(setq vl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget lw))))
(if (not (ListClockwise-p vl)) (setq vl (reverse vl)))
(setq pt (getpoint "\nPick starting point : "))
(setq n (length vl))
(setq pr (getstring "\nSpecify prefix : "))
(setq vl (vl-member-if '(lambda (x) (equal (list (car pt) (cadr pt)) x 1e-6)) (reverse (cdr (vl-member-if '(lambda (x) (equal (list (car pt) (cadr pt)) x 1e-6)) (reverse (append vl vl)))))))
(setq k 0)
(repeat n
(setq k (1+ k))
(setq v (car vl))
(setq bl (ssname (ssget v '((0 . "INSERT") (66 . 1))) 0))
(setq att (entnext bl))
(entmod (subst (cons 1 (strcat pr (itoa k))) (assoc 1 (entget att)) (entget att)))
(entupd att)
(setq vl (cdr vl))
)
(setvar 'osmode osm)
(princ)
)
hi ribarm. Same times gives me this error message and the lisp stop
; error: bad argument type: lselsetp nil
Why ?
Look the test file . Why in this file the code didn't work?
The code works without failure with test dwg.
Moritz
You have to make sure that you don't miss your selection the way the code is written. Generally an if statement is included to verify that all items needed exist before actually executing the code.
(setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
(setq bl (ssname (ssget v '((0 . "INSERT") (66 . 1))) 0))
1.(command "_.zoom" "_extents")
(command "_.draworder" (ssget "_X" '((0 . "~Insert"))) "" "_back")
(setq bl (ssname (ssget v '((0 . "INSERT") (66 . 1))) 0))
With:(setq bl
(ssname
(ssget
"_X"
(list
'(0 . "INSERT")
'(66 . 1)
'(-4 . "<,<,*")
(list 10 (+ (car v) 1e-6) (+ (cadr v) 1e-6) 0.0)
'(-4 . ">,>,*")
(list 10 (- (car v) 1e-6) (- (cadr v) 1e-6) 0.0)
)
)
0
)
)
May solve all issues I have mentioned. But the program will probably be slower.(defun c:pblinclw ( / ListClockwise-p osm ss lw vl pt n pr k v bl att )
(defun ListClockwise-p ( lst / z vlst )
(vl-catch-all-apply 'minusp
(list
(if
(not
(equal 0.0
(setq z
(apply '+
(mapcar
(function
(lambda (u v)
(- (* (car u) (cadr v)) (* (car v) (cadr u)))
)
)
(setq vlst
(mapcar
(function
(lambda (a b) (mapcar '- b a))
)
(mapcar (function (lambda (x) (car lst))) lst)
(cdr (reverse (cons (car lst) (reverse lst))))
)
)
(cdr (reverse (cons (car vlst) (reverse vlst))))
)
)
) 1e-6
)
)
z
(progn
(prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list")
nil
)
)
)
)
)
(setq osm (getvar 'osmode))
(setvar 'osmode 8)
(prompt "\nPick 2D LWPOLYLINE that has blocks with attributes to increment at its vertices...")
(setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
(setq lw (ssname ss 0))
(setq vl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget lw))))
(if (not (ListClockwise-p vl)) (setq vl (reverse vl)))
(setq pt (getpoint "\nPick starting point : "))
(setq n (length vl))
(command "_.zoom" "_extents")
(command "_.draworder" (ssget "_X" '((0 . "~Insert"))) "" "_back")
(setq pr (getstring "\nSpecify prefix : "))
(setq vl (vl-member-if '(lambda (x) (equal (list (car pt) (cadr pt)) x 1e-6)) (reverse (cdr (vl-member-if '(lambda (x) (equal (list (car pt) (cadr pt)) x 1e-6)) (reverse (append vl vl)))))))
(setq k 0)
(repeat n
(setq k (1+ k))
(setq v (car vl))
(setq bl (ssname (ssget v '((0 . "INSERT") (66 . 1))) 0))
(setq att (entnext bl))
(entmod (subst (cons 1 (strcat pr (itoa k))) (assoc 1 (entget att)) (entget att)))
(entupd att)
(setq vl (cdr vl))
)
(setvar 'osmode osm)
(princ)
)
(defun c:pblinclw ( / ListClockwise-p osm ss lw vl pt n pr k v bl att )
(defun ListClockwise-p ( lst / z vlst )
(vl-catch-all-apply 'minusp
(list
(if
(not
(equal 0.0
(setq z
(apply '+
(mapcar
(function
(lambda (u v)
(- (* (car u) (cadr v)) (* (car v) (cadr u)))
)
)
(setq vlst
(mapcar
(function
(lambda (a b) (mapcar '- b a))
)
(mapcar (function (lambda (x) (car lst))) lst)
(cdr (reverse (cons (car lst) (reverse lst))))
)
)
(cdr (reverse (cons (car vlst) (reverse vlst))))
)
)
) 1e-6
)
)
z
(progn
(prompt "\n\nChecked vectors are colinear - unable to determine clockwise-p of list")
nil
)
)
)
)
)
(setq osm (getvar 'osmode))
(setvar 'osmode 8)
(prompt "\nPick 2D LWPOLYLINE that has blocks with attributes to increment at its vertices...")
(setq ss (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
(setq lw (ssname ss 0))
(setq vl (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget lw))))
(if (not (ListClockwise-p vl)) (setq vl (reverse vl)))
(setq pt (getpoint "\nPick starting point : "))
(setq n (length vl))
(setq pr (getstring "\nSpecify prefix : "))
(setq vl (vl-member-if '(lambda (x) (equal (list (car pt) (cadr pt)) x 1e-6)) (reverse (cdr (vl-member-if '(lambda (x) (equal (list (car pt) (cadr pt)) x 1e-6)) (reverse (append vl vl)))))))
(setq k 0)
(repeat n
(setq k (1+ k))
(setq v (car vl))
(setq bl
(ssname
(ssget
"_X"
(list
'(0 . "INSERT")
'(66 . 1)
'(-4 . "<,<,*")
(list 10 (+ (car v) 1e-6) (+ (cadr v) 1e-6) 0.0)
'(-4 . ">,>,*")
(list 10 (- (car v) 1e-6) (- (cadr v) 1e-6) 0.0)
)
)
0
)
)
(setq att (entnext bl))
(entmod (subst (cons 1 (strcat pr (itoa k))) (assoc 1 (entget att)) (entget att)))
(entupd att)
(setq vl (cdr vl))
)
(setvar 'osmode osm)
(princ)
)