Jump to content

Auto fit the 3d drawings in the each viewport of each layout


Recommended Posts

Posted

Hi.,

i have nearly 20 drawings done in the 3d space (in model), each drawings are bounded by a 2d rectangle.

i would like to place the each drawings in individual layout. i have inital layout named "1" with all the pagesetup has been applied & viewport settings are set to legacy hidden.

Like to have a script such that each drawings are placed in the layout automatically with the pagesetup and viewport settings predefined.

 

Thanks

Posted

I have this one, which I renamed 'zvprect' - zoom view port rectangle, the original link is in the code below.

 

So go to paperspace, double click in the layout, "ZVPRECT" and select the 2D bounding rectangle required - it should zoom the viewport to that. Works well if the rectangle is not rotated.

 

if you are only doing this task once, or rarely then I am not sure if you need more than this? (considering the time to write, test, check, modify and finish a LISP. a slower LISP might be quicker overall for a small number of drawings)

 

;;https://forums.autodesk.com/t5/autocad-forum/having-trouble-with-the-lisp-that-zooms-a-rectangle-that-fits-in/td-p/9378532
(defun c:zvprect ( / a b e o)
 (if (setq e (car (entsel "\nSelect Rectangle : ")))
   (progn
     (setq o (vlax-ename->vla-object e))
     (vlax-invoke-method o 'GetBoundingBox 'a 'b)
     (setq a (vlax-safearray->list a)
    b (vlax-safearray->list b)
     )
     (vl-cmdf "_.zoom" a b)
     )
   )
 (princ)
)

 

Posted (edited)

If the rectangs are on a layer then can select all etc and make layouts can sort them before making layouts by having a number in the rectangs, StevenP has given the way to fill in each layout. You just need the "Layout" "copy" code.

 

A freebie for you if the layouts have a title block fill in the details in one layout those details are copied to all other layouts. Another is number layouts etc so your task is maybe in reality 2-4 steps. 

 

I went further and asked at start for sheet size and scale so rectangs are correct size when matching in the mview of the layout. I normally work metric this was for a request in imperial.

 

Ok another question you say 3d parts so do the sheets need to imply you want 3d views Front, right etc could be added to the make mview. I do rotation now I guess vpoint could be added.

Edited by BIGAL
Posted

hi @BIGAL @Steven P

 

Thanks for your inputs, here is the sample file attached. i tried the above code provded by steven, but the selected rectangle doesnot fit in the viewport. can you help on this.

6 hours ago, Steven P said:

double click in the layout

which means clicking the view port right?, it enters the model space. but after selecting the rectangle another area has been zoomed, which is away from the drawing. am i doing correct or making mistake somewhere.

 

@BIGAL 

1 hour ago, BIGAL said:

another question you say 3d parts so do the sheets need to imply you want 3d views Front, right etc could be added to the make mview. I do rotation now I guess vpoint could be added.

no, refere the drawing, just as it is i want to display. isometric

Sample.dwg

Posted

MIght do something odd if the viewport is locked

Posted

Ok starting to unravel the request the dwg put me off for a little while, so went back to basics, UCS W PLAN this shows the 3dobjects in plan view, should be able to just pick approx centre of objects, then make a layout, using the point and vpoint, can set the objects to centre of viewport. Need the set scale of viewport based on a 3d view say fill viewport then scale say 0.9  as a nice fit. Yes can get the outer box of the objects, thanks to Lee-mac. There are 4 view directions that is actually the easy part. Vpoint -1,-1,1 gives 3d front view. need to think more have something similar for houses.

 

image.thumb.png.1505035bc04ef17aa4f09b021c0f42b2.png

  • Like 1
Posted (edited)

This is just a start to prove concept lots more to do. Based on supplied dwg.

 

Ok for it to work rename Ph01 to Ph00, unlock viewport, delete all existing layouts as we are going to make new ones.

 

UCS W PLAN so model space is in world

image.png.6af765f59dae189df4b199f951899adc.png

 

Load code it should auto run.

 

Just zoom in and pick a central point on your cabinets, each time you pick it will make a layout with a fixed for moment view angle. next version has choices. Keep picking a point inside objects new layouts will be made. 

 

Yes lots of stuff to still do. I made like 10 layouts as fast as I could pick a point. Need to think about scale factor so looks as a fit in viewport.

 

(defun wow ( )
(setvar 'ctab "Model")
(setq x (- (getint "\Enter start number ")))
(while (setq pt (getpoint "\nSelect a point Enter to exit"))
(setq tabn (strcat "Ph" (rtos (setq x (1+ x)) 2 0)))
(command "layout" "c" "Ph00" tabn)
(setvar 'ctab tabn)
(command "mspace" "vpoint" "-1,-1,1")
(command "zoom" "c" pt 2000)
(setvar 'ctab "Model")
)
)
(wow)

image.png.d0e844662395ab1a7302a58f31241a59.png

Edited by BIGAL
  • Like 1
Posted
18 minutes ago, BIGAL said:

Ok for it to work rename Ph01 to Ph00, unlock viewport, delete all existing layouts as we are going to make new ones.

Yes, you can rename the sheet layout as 1,2,3. .. as this will update to the sheet number in the template block, using ctab variable 

Posted

Did you try it ? This is the only way I could think of to do what you want, I have an idea for auto scale to fit in the viewport. Yes more to be added. Like view direction.

Posted (edited)

Awesome! :), it works. As the name of the program it is "wow". Thank you very much

2 hours ago, BIGAL said:

auto scale to fit in the viewport. Yes more to be added. Like view direction.

yes.

Edited by Sekar
Posted

I have been busy with real work have not forgotten on my TO DO list. need a couple of days.

Posted (edited)

Try this a couple of changes, it asks for a direction Front back left right, I may have the view in wrong directions to what you think change in code. Needs Multi radio buttons to be in a support path so autoloads for the directions. Also big thanks to Lee-mac for solid bounding box.

 

You should be in plan view UCS world Plan, select a group of cabinets using window etc. It will make a new layout. 

 

Rules layout is called Ph00 and viewport unlocked. Use that one to copy. 

image.png.bd69cfee4abea631811eaa9c591d1d50.png

 

It will loop and ask for more till you press Enter. I guess could add other views non 3d, Like front back L Side R Side. Yep did those too.

 

(defun c:wow ( / box ss x ent tabn ans)
(if (not AH:Butts)(load "Multi radio buttons.lsp")) ; loads the program if not loaded already

;; Selection Set Bounding Box  -  Lee Mac
;; Returns a list of the lower-left and upper-right WCS coordinates of a
;; rectangular frame bounding all objects in a supplied selection set.
;; sel - [sel] Selection set for which to return bounding box
(defun LM:bigbox (selobj / obj spc )
    (if
        (setq box (LM:ssboundingbox selobj))
        (progn
            (setq spc
                (vlax-get-property (vla-get-activedocument (vlax-get-acad-object))
                    (if (= 1 (getvar 'cvport))
                        'paperspace
                        'modelspace
                    )
                )
            )
            (if (equal 0.0 (apply '- (mapcar 'caddr box)) 1e-6)
                (progn
                    (setq obj
                        (vlax-invoke spc 'addlightweightpolyline
                            (apply 'append
                                (mapcar '(lambda ( x ) (mapcar '(lambda ( y ) ((eval y) box)) x))
                                   '(
                                        (caar   cadar)
                                        (caadr  cadar)
                                        (caadr cadadr)
                                        (caar  cadadr)
                                    )
                                )
                            )
                        )
                    )
                    (vla-put-closed obj :vlax-true)
                    (vla-put-elevation obj (caddar box))
                )
                (apply 'vlax-invoke 
                    (vl-list* spc 'addbox
                        (apply 'mapcar (cons '(lambda ( a b ) (/ (+ a b) 2.0)) box))
                        (apply 'mapcar (cons '- (reverse box)))
                    )
                )
            )
        )
    )
    (princ)
)

(defun LM:ssboundingbox (sel / idx llp ls1 ls2 obj urp)
    (repeat (setq idx (sslength sel))
        (setq obj (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))))
        (if (and (vlax-method-applicable-p obj 'getboundingbox)
                 (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-getboundingbox (list obj 'llp 'urp))))
            )
            (setq ls1 (mapcar 'min (vlax-safearray->list llp) (cond (ls1) ((vlax-safearray->list llp))))
                  ls2 (mapcar 'max (vlax-safearray->list urp) (cond (ls2) ((vlax-safearray->list urp))))
            )
        )
    )
    (if (and ls1 ls2) (list ls1 ls2))
)


(setvar 'ctab "Model")
(setq x (- (getint "\Enter start number ") 1))

(prompt "select a group of cupboards")
(while (setq ss (ssget))
  (LM:bigbox ss)
  (setq ent (entlast))
  (setq tabn (strcat "Ph" (rtos (setq x (1+ x)) 2 0)))
  (command "layout" "c" "Ph00" tabn)
  (setvar 'ctab tabn)
  (setq ans (ah:butts 1 "V"   '("Chhose 3d direction " "3d Front" "3d Back" "3d Left" "3d Right" "Front" "BacK" "Left" "Right"))) 	; ans holds the button picked value as a string
  (command "Mspace")
  (cond
   ((= ans "3d Front")(command "vpoint" "-1,-1,1"))
   ((= ans "3d Back")(command  "vpoint" "1,1,1"))
   ((= ans "3d Left")(command  "vpoint" "1,1,1"))
   ((= ans "3d Right")(command  "vpoint" "1,-1,1"))
   ((= ans "Front")(command  "vpoint" "0,-1,0"))
   ((= ans "Back")(command  "vpoint" "0,1,0"))
   ((= ans "Left")(command  "vpoint" "-1,0,0"))
   ((= ans "Right")(command  "vpoint" "1,0,0"))
  )

  (setq pt1 (car box) pt2 (cadr box))
  (setq mp (mapcar '* (mapcar '+ pt1 pt2)'(0.5 0.5 0.5)))
  (command "zoom" "c" mp 2000)
  (command "zoom" "OB" ent "")
  (command "erase" ent "")
  (command "pspace")
  (setvar 'ctab "Model")
  (prompt "select a group of cupboards Enter to exit ")
)

; sort tabs by CAB
;; 07/14/2005  CAB 

(setq cnt 1
    doc (vla-get-activedocument (vlax-get-acad-object))
)
(foreach lay (acad_strlsort (vl-remove "Model" (layoutlist)))
   (vla-put-taborder (vla-item (vla-get-layouts doc) lay) cnt)
   (setq cnt (1+ cnt))
)
(princ)
)
(c:wow)

 

lastly change the name to something you will remember. 

Multi radio buttons.lsp

Edited by BIGAL
Posted

hi @BIGAL

Thanks for your great help. works fine as required. I have to work on the views.  one last thing. how to reorder the layouts in ascending order

 

image.png.f7e3a251c669b4da4b7e6deff66a92ab.png

Posted (edited)

There is a difference between Acad and my Bricscad which I forgot about they do the layout copy in reverse of each other so Bricscad is 1 2 3 and auto cad 8 7 6 and so on. When you know how many to make can do in reverse order. Anyway can add re-sort layouts by name it is out there, I will try to find else will add a renumber to end.

 

Reload the code above edited a reorder tabs thanks to CAB.

 

Edited by BIGAL
  • Like 1
Posted

Thanks @BIGAL

 

Is it possible to add text in the each layout from the model space , which was requested in another post.

Posted (edited)

Yes if you put the text in a layer and inside a cupboard can find that text and put it in the layout. You can put in a no plot layer.

 

Post a dwg.

Edited by BIGAL
Posted (edited)

hi @BIGAL

 

The code works charm. Attached herewith the drawing. i put the text in the HEADING layer. and turned off the plot in the modelspace layer properties. How to print the text, while converting pdf along with the drawing.

 

Sample.dwg

Edited by Sekar
Posted (edited)

Text needs to be like this and say on a no plot layer. Must be inside an outline of objects. 

image.png.2adc19d63612d951120fb56a41855def.png

Watch this space.

Edited by BIGAL

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