Not sure what you mean by "boundary box" - if is about "bounding box", then please check this routine written by Lee Mac.
Registered forum members do not see this ad.
Hi pro guru.
Anybody can help me how to write a lisp can create a boundary box with spline entity?![]()
Not sure what you mean by "boundary box" - if is about "bounding box", then please check this routine written by Lee Mac.
Regards,
Mircea
AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3
Yes I mean like the routine written by Lee Mac. But this Lisp cannot correctly make the bounding box for the spline. I need is really close to the spline ==> "mean no gap".
Thanks in advance.
Indeed, the BoundingBox method is inaccurate for Splines.
An alternative approach might be to approximate the Spline using an appropriate point list, then calculate the bounds of such point list; though, this algorithm will undoubtedly be slower than the BoundingBox method.
Here is an example to demonstrate this method (you will need to download my Entity to Point List function):
Code:(defun BoundingBox ( ent / l ) (if (setq l (LM:Entity->PointList ent)) (mapcar '(lambda ( a ) (apply 'mapcar (cons a l))) '(min max)) ) )
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
Alternatively may create a copy in place of the spline, apply FLATTEN command on it and use Lee’s routine for bounding box; remove helper polyline just after.
Regards,
Mircea
AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3
Nice idea Mircea!
Here is another method (excuse the messy code):
Test function:Code:(defun SplineBoundingBox ( ent / pt1 pt2 res var ) (if (setq ent (entmakex (entget ent))) (progn (setq var (mapcar 'getvar '(peditaccept cmdecho))) (mapcar 'setvar '(peditaccept cmdecho) '(1 0)) (command "_.pedit" ent 10 "") (mapcar 'setvar '(peditaccept cmdecho) var) (if (not (equal ent (setq ent (entlast)))) (progn (vla-getboundingbox (vlax-ename->vla-object ent) 'pt1 'pt2) (setq res (mapcar 'vlax-safearray->list (list pt1 pt2))) ) ) (entdel ent) ) ) res )
Code:(defun c:test ( / bb en ) (princ "\nSelect a Spline: ") (if (setq en (ssget "_+.:E:S:L" '((0 . "SPLINE")))) (if (setq bb (SplineBoundingBox (ssname en 0))) (entmakex (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 4) (cons 70 1) (list 10 (caar bb) (cadar bb)) (list 10 (caadr bb) (cadar bb)) (list 10 (caadr bb) (cadadr bb)) (list 10 (caar bb) (cadadr bb)) ) ) (princ "\nUnable to retrieve Bounding Box.") ) ) (princ) ) (vl-load-com) (princ)
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
I think that Lee's code won't be correct for earlier versions of ACAD... If you don't need exactly but approx result, try this...
If you want exact results, consider converting SPLINE to POLYLINE like Mircea suggested or if you have A2010 or above (not sure for A2009) A2008 doesn't support - try SPLINEDIT -> Convert to polyline and obtain Bounding Box from pline - after remove dummy pline... If you have A2010 or above, then try also Lee's code - just checked on my A2012 and it worked...Code:(defun SplineBoundingBox ( ent / xmin xmax ymin ymax res cmde ) (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0) (vl-cmdf "_.ucs" "w") (vl-cmdf "_.plan" "") (vl-cmdf "_.zoom" "o" ent "") (setq ymin (- (cadr (getvar 'viewctr)) (/ (getvar 'viewsize) 2.0)) ymax (+ (cadr (getvar 'viewctr)) (/ (getvar 'viewsize) 2.0))) (vl-cmdf "_.ucs" "z" 90) (vl-cmdf "_.plan" "") (vl-cmdf "_.zoom" "o" ent "") (setq xmax (- (car (trans (getvar 'viewctr) 1 0)) (/ (getvar 'viewsize) 2.0)) xmin (+ (car (trans (getvar 'viewctr) 1 0)) (/ (getvar 'viewsize) 2.0))) (vl-cmdf "_.zoom" "p") (vl-cmdf "_.zoom" "p") (vl-cmdf "_.zoom" "p") (vl-cmdf "_.zoom" "p") (vl-cmdf "_.zoom" "p") (vl-cmdf "_.ucs" "p") (vl-cmdf "_.ucs" "p") (setvar 'cmdecho cmde) (setq res (list (list xmin ymin 0.0) (list xmax ymax 0.0))) res ) (defun c:test ( / bb en ) (princ "\nSelect a Spline: ") (if (setq en (ssget "_+.:E:S:L" '((0 . "SPLINE")))) (if (setq bb (SplineBoundingBox (ssname en 0))) (entmakex (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 4) (cons 70 1) (list 10 (caar bb) (cadar bb)) (list 10 (caadr bb) (cadar bb)) (list 10 (caadr bb) (cadadr bb)) (list 10 (caar bb) (cadadr bb)) ) ) (princ "\nUnable to retrieve Bounding Box.") ) ) (princ) )
Also check this thread from theswamp...
M.R.
Last edited by marko_ribar; 27th Apr 2012 at 04:47 pm.
Thank for Lee Mac and Marko Ribar Lisp. After try on my AutoCAD 2007, still cannot work well. Maybe my AutoCAD are version are too old. Both of your code cannot support. Anyway thank you both of you. I still need to find out how to break though it.
Please check this solution to convert the said spline to a polyline using your AutoCAD version.
Regards,
Mircea
AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3
Registered forum members do not see this ad.
kwwong6,
As far as I know, the solution that I posted in reply#4 should work in AutoCAD 2007.
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
Bookmarks