Code Red > AutoLISP (Vanilla / Visual)

ascending sorting dynamic blocks ( by diameters and lenght )and rename the block

(1/4) > >>

serge_c:
Need guru's help . I make a lot of movements arrive at the final result, but i am sure it possible to make the shortest way :
if it's possible to select the blocks and automatically the lisp will sort the block by diameter and lenght and after that  if is possible to imput the number which will begin the renumbering !!!
Thanks in advance !!!

BIGAL:
Here is an example of sort on 2 items.


--- Code: ---(setq lst (list '(20 123) '(25 345) '(10 456) '(8 234)))
; sorts on 1st two items
(setq lst (vl-sort lst
'(lambda (a b)
    (cond
      ((< (car a) (car b)))
      ((= (car a) (car b)) (< (cadr a) (cadr b)))
    )
  )
)
)

--- End code ---

serge_c:
BIGAL thanks for this example but I think, I will not succeed by my self.
I make some simple lisp , but this i gonna be to complicated for me , Taht why  I am asking for your level ""GURU's LEVEL""

HOSNEYALAA:
HI
TEST THIS


--- Code: ---

(vl-load-com)

(defun c:test (/ A11 A2 A3 ACDBBLOCKREFERENCE ATTDATA ATTRIBUTES^ ATTS LST PATTERN SS0)

 
 (if  (and
       (progn (initget 7)  (setq pattern(getint  "\nSpecify input NO : ")))
       (setq ss0 (ssget '((0 . "insert") (66 . 1))))
     )
  (progn
   
   
   (foreach ename (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0)))
;;;      (setq ename (mapcar'vlax-ename->vla-object(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss0))))
    (setq AcDbBlockReference (vlax-ename->vla-object ename))
;;;    (setq attributes^ (vlax-invoke AcDbBlockReference 'GetAttributes))
    (progn
           (setq atts (vlax-invoke AcDbBlockReference 'getattributes))
           (foreach att atts
             (cond
                   ((wcmatch (vla-get-tagstring att) "DIAMETRU")
                    (setq a2 (vla-get-textstring att))
                   )
                   ((wcmatch (vla-get-tagstring att) "Lungimea")
                    (setq a3 (vla-get-textstring att))
                   )
             )
                 
           )
           (setq attdata (cons (list (atof a2) (atof a3) AcDbBlockReference) attdata))
         )
     )
;;;(setq attdata nil)
    ; sorts on 1st two items

   ;;BIGAL
      (setq lst (vl-sort attdata
'(lambda (a b)
    (cond
      ((< (car a) (car b)))
      ((= (car a) (car b)) (< (cadr a) (cadr b)))
    )
  )
)
)



   (foreach ename (mapcar 'caddr lst)
;;;      (setq ename (caDr (mapcar 'caddr lst)))
   
   
    (progn
           (setq atts (setq attributes^ (vlax-invoke ename 'GetAttributes)))
           (foreach att atts
;;;      (setq att (car atts))
     
             (cond ((wcmatch (setq a11(vla-get-tagstring att)) "Pozitia")
                     (vla-put-textstring att (RTOS pattern 2 0 ))
                   )
                   
                   
             )
                 
           )
     
           
         )
     (setq pattern (+ 1 pattern))
     )

   









   
  ); progn
 ); if

 (princ)
);




--- End code ---

HOSNEYALAA:
HH

Navigation

[0] Message Index

[#] Next page

Go to full version