highflybird Posted April 16, 2014 Share Posted April 16, 2014 (DEFUN C:SPL2CIR () (SETVAR "CMDECHO" 0) (SETQ OLDOS (GETVAR"OSMODE")) (SETVAR "OSMODE" 0) (IF (SETQ SS (SSGET '((0 . "SPLINE") (73 . 16)))) (PROGN (COMMAND ".UNDO" "BE") (SETQ I -1) (REPEAT (SSLENGTH SS) (SETQ EN (SSNAME SS (SETQ I (1+ I))) ENT (ENTGET EN) PL (MEMBER (ASSOC 10 ENT) ENT)) (IF PL (PROGN (SETQ P1 (CDR (CAR PL)) P2 (CDR (NTH 4 PL)) P3 (CDR (NTH 8 PL)) P4 (CDR (NTH 12 PL)) PC (INTERS P1 P3 P2 P4 T) R (DISTANCE PC P1)) (COMMAND "CIRCLE" PC R "ERASE" EN "") )) ) (COMMAND ".UNDO" "E") )) (SETVAR "OSMODE" OLDOS) (SETVAR "CMDECHO" 1) (PRINC) ) Hi,all why this code can not change spline to circle ? test.dwg Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 16, 2014 Share Posted April 16, 2014 The posted tool is designed to work only on splines with exact 16 control points; the example you posted have 66. (SSGET '((0 . "SPLINE") (73 . [color=blue]16[/color]))) If you attempt to adjust it, please pay attention that circle's center is located by an algorithm based on opposite points retrived by their indexes. (SETQ P1 (CDR (CAR PL)) P2 (CDR (NTH [color=blue]4[/color] PL)) P3 (CDR (NTH [color=blue]8[/color] PL)) P4 (CDR (NTH [color=blue]12[/color] PL)) ... Really not sure what to suggest as change for that algorithm to work for any number of points, especialy odd ones. Quote Link to comment Share on other sites More sharing options...
highflybird Posted April 17, 2014 Author Share Posted April 17, 2014 The posted tool is designed to work only on splines with exact 16 control points; the example you posted have 66.(SSGET '((0 . "SPLINE") (73 . [color=blue]16[/color]))) If you attempt to adjust it, please pay attention that circle's center is located by an algorithm based on opposite points retrived by their indexes. (SETQ P1 (CDR (CAR PL)) P2 (CDR (NTH [color=blue]4[/color] PL)) P3 (CDR (NTH [color=blue]8[/color] PL)) P4 (CDR (NTH [color=blue]12[/color] PL)) ... Really not sure what to suggest as change for that algorithm to work for any number of points, especialy odd ones. Thank you very much.MSasu. Obviously, this code is not perfect, I change it (SSGET '((0 . "SPLINE") (73 . 66))) The center and diameter all changed. Who has the perfect code? Quote Link to comment Share on other sites More sharing options...
highflybird Posted April 17, 2014 Author Share Posted April 17, 2014 Control point is uncertain. Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 17, 2014 Share Posted April 17, 2014 The above center identification algorithm is based on identification of diametrically opposed control points (0 with 8, respectively 4 with 12). At a quick inspection your spline doesn't have its control points equally spaced and even worse, these don't seem to be diametrically opposed. Quote Link to comment Share on other sites More sharing options...
lucas3 Posted April 17, 2014 Share Posted April 17, 2014 (defun c:tt (/ ss lst) (if (setq ss (ssget '((0 . "spline")))) (progn (setq lst (mapcar '(lambda (x) (setq pts (xdrx_getsamplept x) p (apply 'xdrx_points_centroid pts) d (mapcar '(lambda (a) (distance a p)) pts) ) (list p (/ (apply '+ d) (length pts)) x) ) (xdrx_pickset->ents ss) ) ) (mapcar '(lambda (x) (xdrx_circle_make (car x) (cadr x)) ) lst ) (xdrx_entity_delete ss) ) ) (princ) ) must use XDRX_API download:http://bbs.xdcad.org/thread-668896-1-1.html Quote Link to comment Share on other sites More sharing options...
lucas3 Posted April 17, 2014 Share Posted April 17, 2014 (defun c:tt () (if (setq ss (ssget)) (progn (repeat (setq n (sslength ss)) (vla-GetBoundingBox (setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n))))) 'll 'ur ) (setq ll (vlax-safearray->list ll) ur (vlax-safearray->list ur) ) (setq wh (mapcar '- ur ll)) (if (equal (car wh) (cadr wh) 1e-3) ; (progn (entmake (list (cons 0 "circle") (cons 10 (mapcar '* '(0.5 0.5 0.5) (mapcar '+ ll ur))) (cons 40 (* 0.25 (+ (car wh) (cadr wh)))) (cons 62 2) ) ) (vla-delete obj) ) ) ) ) ) ) Quote Link to comment Share on other sites More sharing options...
highflybird Posted April 17, 2014 Author Share Posted April 17, 2014 Thanks ,lucas But some one still not ok. test2.dwg Quote Link to comment Share on other sites More sharing options...
fixo Posted April 18, 2014 Share Posted April 18, 2014 (edited) Try this one, for A2010 and higher (defun C:SAC ( / *error* dis found i objs pts rad sset) ;; fixo 2014;; ;;;Convert connected splines to circle (defun *error* (msg) (and msg (not (wcmatch (strcase msg) "*CANCEL*,*QUIT*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (vla-endundomark adoc) (setvar 'cmdecho 1) (princ) ) (defun mid-point (p q) (mapcar '(lambda (a b) (/ (+ a b) 2.)) p q) ) (defun group-by-num (lst num / ls ret) (if (= (rem (length lst) num ) 0) (progn (setq ls nil) (repeat (/ (length lst) num) (repeat num (setq ls (cons (car lst) ls) lst (cdr lst))) (setq ret (append ret (list (reverse ls))) ls nil))) ) ret ) (vl-load-com) (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ) (vla-startundomark adoc) (setvar 'plineconvertmode 1) ;_ 0 - streight segments ;_ 1 - line and arcs (if (< (atoi (substr (getvar 'acadver) 1 2)) 18);;>= Acad 2010 (alert "Requires 2010 or higher release") (progn (setq sset nil sset (ssget (list (cons 0 "spline")))) (setq i -1) (setvar 'cmdecho 0) (repeat (sslength sset) (command "_splinedit"(ssname sset (setq i (1+ i))) "_p" "2") (setq objs (cons (vlax-ename->vla-object (entlast))objs)) ) ;;; ) (foreach plobj objs (setq pts (append (group-by-num (vlax-safearray->list (vlax-variant-value (vla-get-coordinates plobj)))3) pts ) ) ) (setq dis 0.) (foreach p pts (foreach q (cdr (reverse pts)) (if (> (setq dis (distance p q)) rad) (setq rad dis)) )) (setq found nil) (foreach p pts (foreach q (cdr (reverse pts)) (if (equal (setq dis (distance p q)) rad 1e-9) (setq found (mid-point p q)) ))) (if found (progn (command "_circle" "_non" (trans found 0 1 T)(/ rad 2.) ) (command "_erase" sset "") (foreach p objs (vla-delete p)))))) (*error* nil) (princ) ) (princ "\nType SAC in command line") (princ) Edited April 18, 2014 by SLW210 Code Tags! Quote Link to comment Share on other sites More sharing options...
highflybird Posted April 18, 2014 Author Share Posted April 18, 2014 (edited) Try this one, for A2010 and higher Thanks fixo, This is change spline to pline,not circle. I think if spline closed change it to circle. if not closed, change it to circle or arc. Edited April 18, 2014 by highflybird Quote Link to comment Share on other sites More sharing options...
fixo Posted April 18, 2014 Share Posted April 18, 2014 So expand this code to your needs Quote Link to comment Share on other sites More sharing options...
highflybird Posted April 18, 2014 Author Share Posted April 18, 2014 So expand this code to your needs Thanks fixo, run "SAC" test.dwg is change spline to pline, test2.dwg is change to circle, why? test.dwg test2.dwg Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.