Jump to content

Recommended Posts

Posted

Im trying to automate the process of creating layouts. Also i need a lisp function to use to create a viewport. I basically need to make a viewport in a certain layer (non printable of course) with fit option (it takes the hole printing area of paper space) and then set the scale for this viewport. Scale can be found within an attribute of a block already inserted in drawing. If someone has some ideas please can you share it with me. Thanks in advance.

Posted

Change the name of the name according to the one you need as noticed in the routine .:)

 

(defun c:Test (/ p1 p2 e)(vl-load-com)
 ;; Tharwat 10. 07. 2011
 (if (eq (vla-get-activespace
           (vla-get-activedocument (vlax-get-acad-object))
         )
         0
     )
   (if (and
         (setq p1 (getpoint "\n First corner fo Viewport :"))
         (setq p2 (getcorner p1 "\n Second corner fo Viewport :"))
       )
     (progn
       (command "_.mview" "_non" p1 "_non" p2)
       (vla-put-customscale
         (setq e (vlax-ename->vla-object (entlast)))
         acVpScaleToFit
       )
       (vla-put-layer e [color=red][b]"0"[/b][/color])[color=red]; <<-- Change the "0" to your favourite layer[/color]
     )
     (princ)
   )
   (princ "\n you must be in paper space world !!")
 )
 (princ)
)

Tharwat

  • Like 1
Posted

First of all thanks a lot.

Ive managed to test it, but i didn't understood the scale part. It offers me to draw viewport. This part is ok, but pulling attribute value from a block and use it for scale i cant resolve.

Guest kruuger
Posted

(defun c:TEST (/ P W H)
 (if
   (and
     (setq P (getpoint "\nSelect center point of VIEPORT: "))
     (setq W (getreal "\nSelect width of VIEPORT: "))
     (setq H (getreal "\nSelect height of VIEPORT: "))
   )
   (progn
     (vla-Display 
       (vla-AddPViewport
         (vla-Get-PaperSpace
           (vla-Get-ActiveDocument
             (vlax-Get-Acad-Object)
           )
         )
         (vlax-3D-Point P) W H
       )
       :vlax-true
     )
   )
   (princ "\n** Invalid input **")
 )
 (princ)
)

vla viewport

k.

Posted

kruuger . just read this :)

 

but pulling attribute value from a block and use it for scale i cant resolve.

 

Regards.

Posted

Nice coding Kruuger :thumbsup: I tweaked it a little for a more intuitive input:

 

(defun c:test ( / p1 p2 )
 ;; Kruuger's code, tweaked by Lee Mac 
 (if
   (and
     (setq p1 (getpoint "\nSpecify First Corner of Viewport: "))
     (setq p2 (getcorner "\nSpecify Opposite Corner of Viewport: " p1))
   )
   (progn
     (setq p1 (trans p1 1 0)
           p2 (trans p2 1 0)
     )
     (vla-Display 
       (vla-AddPViewport
         (vla-Get-PaperSpace (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
         (vlax-3D-Point (mapcar '(lambda ( a b ) (/ (+ a b) 2.)) p1 p2))
         (abs (- (car  p1) (car  p2)))
         (abs (- (cadr p1) (cadr p2)))
       )
       :vlax-true
     )
   )
 )
 (princ)
)

  • Like 1
Posted
What kind of attributes you have in a block ?

Its just the number for custom setting of the viewport scale. For example i have a titleblock and in it i defined my scale 1:100, so i need to make a viewport with a scale 0.01. It would be nice to lock it inside the lisp while doing all this stuff.

Posted

Perhaps these will help you read your attribute.

 

Set the VP Scale using vla-put-customscale

 

Lock the VP using vla-put-displaylocked

Posted

Thank you Lee Mac and Kruuger! Unfortunately i cant see the attribute extraction from block to use as a scale in the code. Sorry if i am a bit annoying, but i want to understand a code and not just copy paste it. As for the viewport making, I dont want to pick points. Just like type in the command (-vports), and select fit as an option and that's it.

Posted
Perhaps these will help you read your attribute.

 

Set the VP Scale using vla-put-customscale

 

Lock the VP using vla-put-displaylocked

Thanks a lot Lee. This will be useful allright.

Guest kruuger
Posted
Nice coding Kruuger :thumbsup: I tweaked it a little for a more intuitive input:

 

(defun c:test ( / p1 p2 )
 ;; Kruuger's code, tweaked by Lee Mac 
 (if
   (and
     (setq p1 (getpoint "\nSpecify First Corner of Viewport: "))
     (setq p2 (getcorner "\nSpecify Opposite Corner of Viewport: " p1))
   )
   (progn
     (setq p1 (trans p1 1 0)
           p2 (trans p2 1 0)
     )
     (vla-Display 
       (vla-AddPViewport
         (vla-Get-PaperSpace (vla-Get-ActiveDocument (vlax-Get-Acad-Object)))
         (vlax-3D-Point (mapcar '(lambda ( a b ) (/ (+ a b) 2.)) p1 p2))
         (abs (- (car  p1) (car  p2)))
         (abs (- (cadr p1) (cadr p2)))
       )
       :vlax-true
     )
   )
 )
 (princ)
)

thanks Lee. Tweaked code saved :)

 

sakinen probalby you want something like this ? see attached. type MVP and select border.

it get scale from attribute border and create viewport in paper scale. also create hyperlink between viewport and boarder (only WCS)

i try to create something to speed up making viewport. we draw boarder in model (it is faster then work in paper space with many vport) and then automatically create vport with scale, description etc (all with vla).

kruuger

v0.03.dwg

Make Viewport v0.03.lsp

Posted

Tried it. Didn't work for me. Good idea thou. Its probably something wrong i am doing.

Guest kruuger
Posted
Tried it. Didn't work for me. Good idea thou. Its probably something wrong i am doing.

any error ? what is wrong ?

Posted
Tried it. Didn't work for me. Good idea thou. Its probably something wrong i am doing.

 

Could you bring a copy of your block in dwg format ?

  • 4 years later...
Posted

How to modify the code to return to paper?

(defun c:vtest ( / p1 p2 d)
 ;; Kruuger's code, tweaked by Lee Mac 
 (if
   (and
     (setq p1 (getpoint "\nSpecify First Corner of Viewport: "))
     (setq p2 (getcorner "\nSpecify Opposite Corner of Viewport: " p1))
   )
   (progn
     (setq p1 (trans p1 1 0)
           p2 (trans p2 1 0)
     )
     (vla-Display 
       (vla-AddPViewport
         (vla-Get-PaperSpace (setq d (vla-Get-ActiveDocument (vlax-Get-Acad-Object))))
         (vlax-3D-Point (mapcar '(lambda ( a b ) (/ (+ a b) 2.)) p1 p2))
         (abs (- (car  p1) (car  p2)))
         (abs (- (cadr p1) (cadr p2)))
       )
       :vlax-true
     )
     [color="red"](vla-put-mspace d :vlax-true)
     (command "_.Zoom" "_E")
     (command "_.Zoom" "_W")
     (?)[/color]
   )
   )
 (princ)
)

 

Did not work.

(vla-put-mspace d :vlax-false)

and

(command "_.pspace")

Posted

This works for me:

(defun c:vtest ( / app doc pt1 pt2 )
   ;; Kruuger's code, tweaked by Lee Mac 
   (if
       (and
           (setq pt1 (getpoint "\nSpecify first corner of viewport: "))
           (setq pt2 (getcorner "\nSpecify opposite corner of viewport: " pt1))
       )
       (progn
           (setq app (vlax-get-acad-object)
                 doc (vla-get-activedocument app)
                 pt1 (trans pt1 1 0)
                 pt2 (trans pt2 1 0)
           )
           (vla-display
               (vla-addpviewport (vla-get-paperspace doc)
                   (vlax-3D-point (mapcar '(lambda ( a b ) (/ (+ a b) 2.)) pt1 pt2))
                   (abs (- (car  pt1) (car  pt2)))
                   (abs (- (cadr pt1) (cadr pt2)))
               )
               :vlax-true
           )
           (vla-put-mspace doc :vlax-true)
           (vla-zoomextents app)
           (vla-put-mspace doc :vlax-false)
       )
   )
   (princ)
)
(vl-load-com) (princ)

  • 4 years later...
Posted

hello everyone...i need lispo file which automatically pick the scale of viewport and give it to me in desire units so i can easily put it in my title block...i dont know i am asking the right thing or not but someone pls guide me...

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