Jump to content

Recommended Posts

Posted

Hi all, I am attempting to get a viewport from blocks in modelspace to paperspace with a layout template. I would like this automated by selecting all the blocks in numerical order and placing them on the correct numbered layout. I have found plenty of lisp out there, but nothing that seems to work 100%.  

 

I know there are programs out there, but I want to try to learn autolisp with this project. 

 

I think I was able to get close with these two: 

Draw bounding box on object-from Blackbox

 

Create multiple viewport from multiple rectangle in model space-from hmsilva


The main difference I want to change below is to select all of my objects, instead of being prompted to select a single object,

(defun c:BNDBX (/ eName mn mx)
 (vl-load-com)
 (if (setq eName (car (entsel "\n  >>  Select Object  >> ")))
   (progn
     (vla-getboundingbox (vlax-ename->vla-object eName) 'mn 'mx)
     (vl-cmdf "._rectang" (vlax-safearray->list mn) (vlax-safearray->list mx))))
 (princ)
)
)

I have tried inserting (if  (setq eName (ssget "_x" '((0 . "INSERT") (2 . "PageView")))) on the 3rd line with no success. 

 

Eventually I would like to have the second code produce layouts in order. But I figured I would get this chunk sorted first. 

Posted

I am working on something at moment for some one else,  to clarify you want a new layout to match 1 block at a time at a scale ? Or multiple blocks screen area into 1 layout again at scale re Lee's suggestion.

 

I do this now as 2 steps make the rectangs then make the layouts. 

 

 

Posted

Thanks all, yes I should have clarified, I basically have individual "Pageview" blocks in modelspace that I would like viewports created on a layout tab for each one. 

 

I wanted it to select all pageview blocks and draw rectangles around them and then use a version of this code from hmsilva 

(defun c:demo (/ ctb i layout llpt ll llpt ss ur urpt)
   (if (= 1 (getvar "tilemode"))
      (if (= (length (layoutlist)) 1)
         (if (= (car (layoutlist)) "Layout1")
            (if (setq ss (ssget '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
               (progn
                  (setq ctb (getvar 'CTAB))
                  (setvar 'CTAB "Layout1")
                  (if (= 1 (getvar "cvport"))
                     (command "_.MSPACE")
                  )
                  (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- (sslength ss))))) 'll 'ur)
                  (setq llpt (vlax-safearray->list ll)
                        urpt (vlax-safearray->list ur)
                        layt 1
                  )
                  (command "_.zoom" llpt urpt)
                  (command "_.PSPACE")
                  (repeat i
                     (command "_.-layout"
                              "_C"
                              (getvar 'CTAB)
                              (setq layout (strcat "Layout" (itoa (setq layt (1+ layt)))))
                     )
                     (setvar 'CTAB layout)
                     (vla-getboundingbox (vlax-ename->vla-object (ssname ss (setq i (1- i)))) 'll 'ur)
                     (setq llpt (vlax-safearray->list ll)
                           urpt (vlax-safearray->list ur)
                     )
                     (command "_.MSPACE")
                     (command "_.zoom" llpt urpt)
                     (command "_.PSPACE")
                  )
                  (setvar 'CTAB ctb)
               )
               (princ "\n** You didn't select closed LwPolylines **")
            )
            (princ "\n** Command only allowed with one Layout Tab named \"Layout1\" **")
         )
         (princ "\n** Command only allowed with one Layout Tab **")
      )
      (princ "\n** Command not allowed in Layout Tab **")
   )
   (princ)
)

 

Another issue I thought of yesterday is that the Pageview blocks are numbered and in a numerical order, but they don't follow a pline or anything like that. By using the code above, the rectangles wouldn't be associated with those numbers in the blocks. 

 

In the code it seems as though the last rectangle drawn becomes the first layout view, so maybe there would be a way to 

-prompt the user for the number of pages

-use a while loop to create a box around the last numbered block

-then create for n-1, and repeat? 

 

I am new to autolisp, so I have these ideas in my head but putting them into action is a different story. 

Posted (edited)

The order is as I answered some one privately today, the selection is in creation order generally, not in what you label them but what you can do is male a list ((order entity)(order entity).....

 

Then you sort list on order then loop through using entity so make layouts in correct order. 

 

I don't recognise pageview ? Is it pline outlines or a block ?

 

An image would help a dwg even better.

 

 

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