Jump to content

Help: Find longest lines then set LIMMIN & LIMMAX


Recommended Posts

Posted

Hello,

I need some help setting up the limits (LIMMIN, LIMMAX) for a bunch of drawings.

Limits are to be set to the title block frame which was exploded:( and sometime moved! I tried mashing-up some lisp without success. Here what I think should be the simplest way to do it:

 

- Find longest lines on layer "_TB" [should find 2 lines (top & bottom) on title block layer].

- Find bottom left corner, find top right corner from coordinates of lines found.

- Assign LIMMIN and LIMMAX accordingly.

 

Optional: delete everything outside of LIMMIN and LIMMAX.

 

This lisp by "Lee Mac" and "alanjt" got me started:

http://www.cadtutor.net/forum/archive/index.php/t-51523.html

 

 

Thanks!

Posted (edited)

Thanks for helping!

 

 
(defun c:TBLimits (/ ss i l1 l2 ll ur bb)
; With help from function "SelectionSet BoundingBox" by Lee Mac
(setq ss (ssget "X" '((0 . "LINE") (8 . "_TB"))))
(repeat (setq i (sslength ss))
(vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'll 'ur)
(setq l1 (cons (vlax-safearray->list ll) l1)
l2 (cons (vlax-safearray->list ur) l2)
)
)
(setq bb (mapcar '(lambda (a b) (apply 'mapcar (cons a b))) '(min max) (list l1 l2)))

(setvar "LIMMIN" (list (car (car bb)) (cadr (car bb)) ))
(setvar "LIMMAX" (list (car (cadr bb)) (cadr (cadr bb)) ))

(princ)
)
(vl-load-com)

Edited by luctifo
Added credentials
Posted

Hi luctifo,

 

Please read my Terms of Use applicable to all code on my site and retain my code headers where my code is used.

 

For your program, you simply need to call my function as follows:

 

(defun c:tblimits ( / box sel )
   (if (setq sel (ssget "_X" '((0 . "LINE") (8 . "_TB"))))
       (progn
           (setq box (LM:SSBoundingBox sel))
           (setvar 'limmin (mapcar '+ (car  box) '(0 0)))
           (setvar 'limmax (mapcar '+ (cadr box) '(0 0)))
       )
   )
   (princ)
)
(vl-load-com) (princ)

;;--------------=={ SelectionSet BoundingBox }==--------------;;
;;                                                            ;;
;;  Returns the lower-left and upper-right points of a        ;;
;;  rectangle bounding all objects in a supplied SelectionSet ;;
;;------------------------------------------------------------;;
;;  Author: Lee Mac, Copyright © 2011 - www.lee-mac.com       ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  ss - SelectionSet for which to return the BoundingBox     ;;
;;------------------------------------------------------------;;
;;  Returns:  Point List decribing BoundingBox (in WCS)       ;;
;;------------------------------------------------------------;;

(defun LM:SSBoundingBox ( ss / i l1 l2 ll ur )
   (repeat (setq i (sslength ss))
       (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'll 'ur)
       (setq l1 (cons (vlax-safearray->list ll) l1)
             l2 (cons (vlax-safearray->list ur) l2)
       )
   )
   (mapcar '(lambda ( a b ) (apply 'mapcar (cons a b))) '(min max) (list l1 l2))
)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...