luctifo Posted September 17, 2012 Posted September 17, 2012 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! Quote
Lee Mac Posted September 17, 2012 Posted September 17, 2012 Welcome to CADTutor luctifo. Consider the following function: http://lee-mac.com/ssboundingbox.html Quote
luctifo Posted September 18, 2012 Author Posted September 18, 2012 (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 September 18, 2012 by luctifo Added credentials Quote
Lee Mac Posted September 18, 2012 Posted September 18, 2012 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)) ) Quote
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.