designerstuart Posted October 18, 2011 Posted October 18, 2011 sorry in advance for poor terminology.... i want to have a script which inserts a block to paperspace, but the size of the paper in the layout will determine which block is to be inserted. is there a way to ask in a script, macro, lisp, whatever, for what size the current layout is? thanks all Quote
Tharwat Posted October 18, 2011 Posted October 18, 2011 What do you mean by the size of layout ? is it a block that have got a border of a specific of paper size ? Tharwat Quote
designerstuart Posted October 18, 2011 Author Posted October 18, 2011 hi tharwat no, not a block but the page size of the layout. when i go to file>page setup manager for instance the page size is A1. you know if you have a model drawing with several layouts of different sizes - maybe some drawings have page size A1, some A2, some A3 etc. i was hoping there was some way to extract the size of the page in the current layout so that when i insert a block, it fits the page size that is already made in the layout. i was going to create a block for A1, another for A2 etc. and have a button which did something like this: if papersize=A1 insert block "blockA1" if papersize=A2 insert block "blockA2" thanks for your help Quote
Tharwat Posted October 18, 2011 Posted October 18, 2011 I see . This should get you started .... (setq lay (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object )))) (setq papersize (vla-getpapersize lay 'w 'h)) w h If you need any help , just ask . Tharwat Quote
designerstuart Posted October 18, 2011 Author Posted October 18, 2011 thanks tharwat excuse my ignorance, but how does this work? i have loaded it as a lisp, and it returns 594.0, which is the correct height of the current layout. incidentally, you've pointed out that i do not need both the height and width, as just one measurement will tell me the size of the layout (they are always landscape). so how would i use this to select a different block? i was going to use a simple script like insert "C:/AUTOCAD FILES/blockA1.dwg" 0,0,0 1 but understand the 'if' part makes it more complex. would i combine these two scripts somehow? thanks again for your time Quote
Tharwat Posted October 18, 2011 Posted October 18, 2011 If I understood your needs well , this should help you with it .. Do not forget to change the name of your block according to Paper size and the insertion point of the block . (defun c:TesT (/ papersize Block)(vl-load-com) ;;; Tharwat 18. Oct. 2011 ;;; (cond ((not lay) (setq lay (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)) ) ) ) ) (setq papersize (vla-getpapersize lay 'w 'h)) (cond ((eq w 210.0) (setq Block "C:/AUTOCAD FILES/blockA4.dwg")) ((eq w 297.0) (setq Block "C:/AUTOCAD FILES/blockA3.dwg")) ((eq w 594.0) (setq Block "C:/AUTOCAD FILES/blockA2.dwg")) ((eq w 841.0) (setq Block "C:/AUTOCAD FILES/blockA1.dwg")) ((eq w 1189.0) (setq Block "C:/AUTOCAD FILES/blockA0.dwg")) ) (entmakex (list '(0 . "INSERT") (cons 2 Block) ;; Name of Block [color=red](cons 10 '(0. 0. 0.)) ;; Insertion point for the chosen block[/color] '(41 . 1.) '(42 . 1.) '(43 . 1.) ) ) (princ) ) Tharwat Quote
designerstuart Posted October 19, 2011 Author Posted October 19, 2011 that's great tharwat, thanks. it looks like exactly what i was looking for. i'll play with it and let you know! cheers Quote
Tharwat Posted October 19, 2011 Posted October 19, 2011 that's great tharwat, thanks.it looks like exactly what i was looking for. i'll play with it and let you know! cheers Your welcome buddy . I am really glad to hear that . Tharwat Quote
johmmeke Posted October 19, 2011 Posted October 19, 2011 hey all ... that looks nice what if i whant it the other way ... need to measure my layout for setting pagesetup. we don't use border but block's that come from the client .. how do i measure the outline from then .... greetz john Quote
Tharwat Posted October 19, 2011 Posted October 19, 2011 John , Your explanations are not clear to me at least . Regards. Tharwat Quote
johmmeke Posted October 19, 2011 Posted October 19, 2011 i get drawings with 10 to 50 layout's al size's are scrambled with no pagesetup, now i have to go layout by layout to setup the correct pagesetup... so what i like is a routine that "scans" the layouts and give a list with the size of each layout. so i kan use a pagesetup routine to setup the correst pageup in group. sorry not native enghlis so explanation can be little strange; Quote
Tharwat Posted October 19, 2011 Posted October 19, 2011 i get drawings with 10 to 50 layout's al size's are scrambled with no pagesetup, now i have to go layout by layout to setup the correct pagesetup...so what i like is a routine that "scans" the layouts and give a list with the size of each layout. so i kan use a pagesetup routine to setup the correst pageup in group. sorry not native enghlis so explanation can be little strange; Is this what you mean ... ? (defun c:TesT (/ papersize prnt) (vl-load-com) ;;; Tharwat 19. Oct. 2011 ;;; (foreach x (layoutlist) (cond ((not lay) (setq lay (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)) ) ) ) ) (setq papersize (vla-getpapersize lay 'w 'h)) (setq prnt (cons (strcat "Name of layout :" " " x " " "Paper Size :" " " (rtos w 2 1) " " (rtos h 2 1) ) prnt ) ) ) (foreach lays (reverse prnt) (print lays) ) (textpage) (princ) ) Tharwat Quote
johmmeke Posted October 19, 2011 Posted October 19, 2011 that is totaly what i mean but i always get the same size from your routine 210 297 for every size i test with A4-land A4-portrait A1 and A0 but defently what i look thx Tharwat Quote
Tharwat Posted October 19, 2011 Posted October 19, 2011 that is totaly what i mean but i always get the same size from your routine 210 297 for every size i test with A4-land A4-portrait A1 and A0 but defently what i look thx Tharwat You're right , the size of the paper is always the same . I have no idea why !! Quote
designerstuart Posted October 20, 2011 Author Posted October 20, 2011 Do not forget to change the name of your block according to Paper size and the insertion point of the block (defun c:TesT (/ papersize Block)(vl-load-com) ;;; Tharwat 18. Oct. 2011 ;;; (cond ((not lay) (setq lay (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)) ) ) ) ) (setq papersize (vla-getpapersize lay 'w 'h)) (cond ((eq w 210.0) (setq Block "C:/AUTOCAD FILES/blockA4.dwg")) ((eq w 297.0) (setq Block "C:/AUTOCAD FILES/blockA3.dwg")) ((eq w 594.0) (setq Block "C:/AUTOCAD FILES/blockA2.dwg")) ((eq w 841.0) (setq Block "C:/AUTOCAD FILES/blockA1.dwg")) ((eq w 1189.0) (setq Block "C:/AUTOCAD FILES/blockA0.dwg")) ) (entmakex (list '(0 . "INSERT") (cons 2 Block) ;; Name of Block [color=red](cons 10 '(0. 0. 0.)) ;; Insertion point for the chosen block[/color] '(41 . 1.) '(42 . 1.) '(43 . 1.) ) ) (princ) ) thanks for this tharwat - but i cannot make it work. i get no error message, and no action from autocad. i load the lisp (drag and drop) and then run it (command TEST) the insertion point 0,0,0 is correct and my block names are the same as the names in the lisp have i forgotten anything? should i make a change to this line "(cons 2 Block) ;; Name of Block" ? thanks for all your time Quote
Lee Mac Posted October 20, 2011 Posted October 20, 2011 (edited) You're right , the size of the paper is always the same . I have no idea why !! Because you are always operating on the Active Layout object, which does not change: (foreach x (layoutlist) (cond ((not lay) (setq lay ([color=red]vla-get-activelayout[/color] (vla-get-activedocument (vlax-get-acad-object)) ) ) ) ) Try this instead: (defun c:test ( / width height ) (vlax-for layout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (if (not (eq "MODEL" (strcase (vla-get-name layout)))) (progn (vla-getpapersize layout 'width 'height) (princ (strcat "\n" (vla-get-name layout) ", Paper Size: " (rtos width 2 2) " x " (rtos height 2 2) ) ) ) ) ) (princ) ) (vl-load-com) (princ) Edited October 20, 2011 by Lee Mac Add (vl-load-com) Quote
Lee Mac Posted October 20, 2011 Posted October 20, 2011 (cond ((eq w 210.0) (setq Block [color=red]"C:/AUTOCAD FILES/blockA4.dwg"[/color])) ((eq w 297.0) (setq Block [color=red]"C:/AUTOCAD FILES/blockA3.dwg"[/color])) ((eq w 594.0) (setq Block [color=red]"C:/AUTOCAD FILES/blockA2.dwg"[/color])) ((eq w 841.0) (setq Block [color=red]"C:/AUTOCAD FILES/blockA1.dwg"[/color])) ((eq w 1189.0) (setq Block [color=red]"C:/AUTOCAD FILES/blockA0.dwg")[/color]) ) (entmakex (list '(0 . "INSERT") (cons 2 [color=red]Block[/color]) ;; Name of Block [color=black] [/color][color=black](cons 10 '(0. 0. 0.)) ;; Insertion point for the chosen block[/color] '(41 . 1.) '(42 . 1.) '(43 . 1.) ) ) You cannot entmake the Insert entity if the Block Definition doesn't exist in the drawing. The DXF Group 2 code requires only the Block Name, to reference the entry in the Block Table. Quote
Tharwat Posted October 20, 2011 Posted October 20, 2011 Because you are always operating on the Active Layout object, which does not change: Great , thanks for the correction Lee. You cannot entmake the Insert entity if the Block Definition doesn't exist in the drawing. The DXF Group 2 code requires only the Block Name, to reference the entry in the Block Table. Also one more great info . Highly appreciated . Quote
johmmeke Posted October 21, 2011 Posted October 21, 2011 thx for all the reply ... i know now that i'm looking for something else .. more like the bounding box of all my layouts ... greetz john Quote
Lee Mac Posted October 21, 2011 Posted October 21, 2011 more like the bounding box of all my layouts ... Perhaps take a look at this 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.