MikeP Posted September 22, 2011 Share Posted September 22, 2011 can someone help me with this lisp. i got it a while ago and its never worked right since day one, but ive learned how to deal with it. WHAT IT IS SUPPOSED TO DO: select a set of objects. creates a bounding box around the greatest extents and offsets that by 2" WHAT IT IS DOING: it creates an odd shaped bounding box that does not have square corners. HOW I GET BY: If you start the command, select all the objects you want, then zoom way way in and hit enter. zoom back out and the bounding box is drawn correctly. It only works if you are zoomed in a lot. (defun c:f6 (/ ll ur lr ul vlst ss clyr) ;; do a polar offset of the corners ;; ofs is a real of the offset value ;; returns a new point list (defun offsetpts (ll lr ur ul ofs / ang) (setq ang (angle ll lr)) ; base angle (setq ll (polar ll (- ang (* pi 0.75)) (sqrt (* (* ofs ofs) 2))) lr (polar lr (- ang (/ pi 4)) (sqrt (* (* ofs ofs) 2))) ur (polar ur (+ ang (/ pi 4)) (sqrt (* (* ofs ofs) 2))) ul (polar ul (+ ang (* pi 0.75)) (sqrt (* (* ofs ofs) 2))) ) (if ll (list ll lr ur ul) ) ) ; end defun ;; CAB 10/17/2006 ;; returns a point list ((lower left)(upper right)) (defun ssboundingbox (ss / i ent lst ptlst mnpt mxpt) (setq i -1) (while (setq ent (ssname ss (setq i (1+ i)))) (setq lst (cons (vlax-ename->vla-object ent) lst)) ) (mapcar '(lambda (x) (vla-getboundingbox x 'mnpt 'mxpt) (setq ptlst (cons (vlax-safearray->list mnpt) ptlst)) (setq ptlst (cons (vlax-safearray->list mxpt) ptlst)) ) lst ) ;;following by Tony Tanzillo (list (apply 'mapcar (cons 'min ptlst)) (apply 'mapcar (cons 'max ptlst)) ) ) ;;===================================================== (setq clyr (getvar "clayer")) (prompt "\nSelect objects to frame.") (if (setq ss (ssget)) (progn (setq llur (ssboundingbox ss)) (setq LL (car llur) UR (cadr llur) LR (list (car UR) (cadr LL)) UL (list (car LL) (cadr UR)) ) (setq vlst (offsetpts LL LR UR UL 2.0)) (command "-layer" "m" "Face 6" "c" "red" "" "lt" "Dashed" "Face 6" "") (command "_.pline") (mapcar 'command vlst) (command "_c") ) ) (setvar "clayer" clyr) loop (princ) ) Quote Link to comment Share on other sites More sharing options...
pBe Posted September 23, 2011 Share Posted September 23, 2011 one reason it wont work well if UCS is not WORLD so... (defun trns (pt) (trans pt 0 1)) (setq ll [color=blue](trns[/color] (polar ll (- ang (* pi 0.75)) (sqrt (* (* ofs ofs) 2)))[color=blue])[/color] lr [color=blue](trns[/color] (polar lr (- ang (/ pi 4)) (sqrt (* (* ofs ofs) 2)))[color=blue])[/color] ur [color=blue](trns[/color] (polar ur (+ ang (/ pi 4)) (sqrt (* (* ofs ofs) 2)))[color=blue])[/color] ul [color=blue](trns[/color] (polar ul (+ ang (* pi 0.75)) (sqrt (* (* ofs ofs) 2)))[color=blue])[/color] ) I'm not saying that it IS the problem but its just one of many. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 23, 2011 Share Posted September 23, 2011 Try something like this: (defun c:f6 ( / _offsetoutside _corners->list ss ) ;; © Lee Mac 2011 (defun _offsetoutside ( a b ) (mapcar (function (lambda ( b c ) (mapcar (function (lambda ( b c ) ((eval b) c a)) ) b c ) ) ) '((- -) (+ -) (+ +) (- +)) b ) ) (defun _corners->list ( a b ) (mapcar (function (lambda ( a b ) (list (car a) (cadr b))) ) (list a b b a) (list a a b b) ) ) (if (setq ss (ssget '((0 . "~VIEWPORT")))) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 8 "Face 6") (cons 90 4) (cons 70 1) ) (mapcar (function (lambda ( x ) (cons 10 x)) ) (_offsetoutside 2.0 (apply '_corners->list (LM:SSBoundingBox ss)) ) ) ) ) ) (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)) ) (vl-load-com) (princ) Using SelectionSet Bounding Box from here. Quote Link to comment Share on other sites More sharing options...
MikeP Posted September 26, 2011 Author Share Posted September 26, 2011 its working great. though its not putting the box on my current line type scale "12". how do i do this. I changed a few things so that it puts it on a different layer. (defun c:f6 ( / _offsetoutside _corners->list ss ) ;; © Lee Mac 2011 (defun _offsetoutside ( a b ) (mapcar (function (lambda ( b c ) (mapcar (function (lambda ( b c ) ((eval b) c a)) ) b c ) ) ) '((- -) (+ -) (+ +) (- +)) b ) ) (defun _corners->list ( a b ) (mapcar (function (lambda ( a b ) (list (car a) (cadr b))) ) (list a b b a) (list a a b b) ) ) (setq clyr (getvar "clayer")) (command "-layer" "m" "Face 6" "c" "red" "" "lt" "Dashed" "Face 6" "") (if (setq ss (ssget '((0 . "~VIEWPORT")))) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 8 "Face 6") (cons 90 4) (cons 70 1) ) (mapcar (function (lambda ( x ) (cons 10 x)) ) (_offsetoutside 2.0 (apply '_corners->list (LM:SSBoundingBox ss)) ) ) ) ) ) (princ) (setvar "clayer" clyr) ) ;;--------------=={ 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)) ) (vl-load-com) (princ) Quote Link to comment Share on other sites More sharing options...
MikeP Posted September 27, 2011 Author Share Posted September 27, 2011 need help with the above ^^^^^ Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 27, 2011 Share Posted September 27, 2011 Try this: (defun c:f6 ( / _offsetoutside _corners->list lay ss ) ;; © Lee Mac 2011 (setq lay "Face 6") (defun _offsetoutside ( a b ) (mapcar (function (lambda ( b c ) (mapcar (function (lambda ( b c ) ((eval b) c a)) ) b c ) ) ) '((- -) (+ -) (+ +) (- +)) b ) ) (defun _corners->list ( a b ) (mapcar (function (lambda ( a b ) (list (car a) (cadr b))) ) (list a b b a) (list a a b b) ) ) (if (setq ss (ssget '((0 . "~VIEWPORT")))) (progn (if (not (tblsearch "LAYER" lay)) (entmake (list (cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord") (cons 2 lay) (cons 62 1) (cons 6 (if (tblsearch "LTYPE" "Dashed") "Dashed" "Continuous")) (cons 70 0) ) ) ) (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 8 lay) (cons 90 4) (cons 70 1) (cons 48 (getvar 'LTSCALE)) ) (mapcar (function (lambda ( x ) (cons 10 x)) ) (_offsetoutside 2.0 (apply '_corners->list (LM:SSBoundingBox ss)) ) ) ) ) ) ) (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)) ) (vl-load-com) (princ) Also, when modifying code written by others it is good etiquette to mark your modifications. Quote Link to comment Share on other sites More sharing options...
MikeP Posted September 27, 2011 Author Share Posted September 27, 2011 its returning a scale of .4. how come? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 27, 2011 Share Posted September 27, 2011 its returning a scale of .4. how come? You tell me... It uses your setting of LTSCALE. Quote Link to comment Share on other sites More sharing options...
MikeP Posted September 27, 2011 Author Share Posted September 27, 2011 is ltscale the only thing that determines the spacing of a dashed linetype? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 27, 2011 Share Posted September 27, 2011 is ltscale the only thing that determines the spacing of a dashed linetype? No, that is also dependent on the linetype definition itself. Quote Link to comment Share on other sites More sharing options...
MikeP Posted September 27, 2011 Author Share Posted September 27, 2011 im really confused.... is the "linetype scale" in the properties the same as the "LTSCALE". because when I have no objects selects it says my scale is 12. but when I enter "LTSCALE" it says .4 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted September 27, 2011 Share Posted September 27, 2011 Maybe check the setting of PSLTSCALE too. Quote Link to comment Share on other sites More sharing options...
MikeP Posted September 27, 2011 Author Share Posted September 27, 2011 my global scale is .4 but my current line type scale is 12. not exactly sure the difference. but i need this lisp to use the current linetype scale of 12 instead Quote Link to comment Share on other sites More sharing options...
MikeP Posted September 27, 2011 Author Share Posted September 27, 2011 ok everything works now. thanks Lee Quote Link to comment Share on other sites More sharing options...
MikeP Posted September 27, 2011 Author Share Posted September 27, 2011 i had to use the celtscale instead of ltscale 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.