+ Reply to Thread
Page 1 of 6 1 2 3 ... LastLast
Results 1 to 10 of 52
  1. #1
    Junior Member
    Using
    AutoCAD 2007
    Join Date
    Feb 2011
    Posts
    12

    Default How to create boundary box with spline entity?

    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?

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    4,008

    Default

    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

  3. #3
    Junior Member
    Using
    AutoCAD 2007
    Join Date
    Feb 2011
    Posts
    12

    Default

    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.

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,567

    Default

    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 ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    4,008

    Default

    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

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,567

    Default

    Nice idea Mircea!

    Here is another method (excuse the messy code):

    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
    )
    Test function:
    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 ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  7. #7
    Super Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2014
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    1,297

    Default

    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...

    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)
    )
    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...
    Also check this thread from theswamp...

    M.R.
    Last edited by marko_ribar; 27th Apr 2012 at 04:47 pm.

    Marko Ribar, d.i.a. (graduated engineer of architecture)
    M.R. on YouTube

  8. #8
    Junior Member
    Using
    AutoCAD 2007
    Join Date
    Feb 2011
    Posts
    12

    Default

    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.

  9. #9
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    4,008

    Default

    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

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,567

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by kwwong6 View Post
    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.
    kwwong6,

    As far as I know, the solution that I posted in reply#4 should work in AutoCAD 2007.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Mark Errors boundary not edge match with adjacent boundary
    By chvnprasad in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 28th Mar 2012, 04:02 pm
  2. Create spline
    By hunszab in forum AutoCAD 3D Modelling & Rendering
    Replies: 6
    Last Post: 2nd Aug 2010, 01:04 pm
  3. Create Boundary in lisp from items on layer included nested blocks
    By manddarran in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 20th May 2010, 04:37 pm
  4. Create boundary via vba
    By comcu in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 18th Sep 2008, 06:46 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts