Jump to content
fabriciorby

ViewPort Handling

Recommended Posts

fabriciorby

Hello,

I've searched about this issue but I couldn't find anything useful to me.

I'm trying to make something like this:

I have a square inside my Model and a square ViewPort inside my Layout. I need to make the viewport to zoom to a point until the square inside my Model fits the ViewPort.

I have no idea how to work with ViewPorts using lisp :/

I can upload a screenshot if it's too confusing

 

Thank you (:

Share this post


Link to post
Share on other sites
nestly

Zoom > Object will zoom the "square" in model to the largest dimensions that will fit inside the viewport

 

Doh... I overlooked that you're apparently looking for a lisp solution.

Share this post


Link to post
Share on other sites
fabriciorby
Zoom > Object will zoom the "square" in model to the largest dimensions that will fit inside the viewport

How to select the viewport using lisp? Because what I really want to do is, for example, I have 10 squares in the drawing so a copy 10 layouts. For each Layout I need to get one of these squares and zoom.

Share this post


Link to post
Share on other sites
fabriciorby

And if I have 80 squares, for example, I would need to setvar 'ctab every time and it would take a long time. I was thinking about using the Model square points to get the zoom. I tried but I can't understand how VIEWPORT'S DXF works.

 

I was thinking about (ssget "x" '((1 . "MVIEW")(410 . LAYOUTNAME))) and then changing their zoom properties.

Share this post


Link to post
Share on other sites
Tharwat

Is this what you are after ?

 

Don't select too much Closed LWpolylines .

 

(defun c:Test (/ *error* o l i n ss in sn v ln)
 ;;--- Tharwat 15. June. 2013 ---;;
 (setq doc (vla-get-activedocument (setq o (vlax-get-acad-object))))
 (defun *error* (x)
   (vla-put-LayoutCreateViewport
     (vla-get-display (vla-get-preferences o))
     l
   )
   (princ "\n*Cancel*")
 )
 (setq l (vla-get-LayoutCreateViewport
           (vla-get-display (vla-get-preferences o))
         )
       i 1
       n "Square-"
 )
 (if (not l)
   (vla-put-LayoutCreateViewport
     (vla-get-display (vla-get-preferences o))
     :vlax-true
   )
 )
 (if (setq ss (ssget '((0 . "LWPOLYLINE")
                       (-4 . "<AND")
                       (70 . 1)
                       (90 . 4)
                       (-4 . "AND>")
                      )
              )
     )
   (repeat (setq in (sslength ss))
     (setq sn (ssname ss (setq in (1- in))))
     (vla-getboundingbox
       (setq v (vlax-ename->vla-object sn))
       'j
       'k
     )
     (while (member (setq ln (strcat n (itoa i))) (layoutlist))
       (setq ln (strcat n (itoa (setq i (1+ i)))))
     )
     (vla-add (vla-get-layouts (vla-get-activedocument o)) ln)
     (setvar 'ctab ln)
     (vla-put-mspace doc :vlax-true)
     (vla-zoomWindow
       o
       j
       k
     )
     (vla-put-mspace doc :vlax-false)
   )
 )
 (setvar 'ctab "Model")
 (princ)
)
(vl-load-com)

Share this post


Link to post
Share on other sites
BlackBox

From within an activated viewport of the same scale:

(command "._zoom" "window" "_end" pause "_end" pause)

Share this post


Link to post
Share on other sites
fabriciorby
Is this what you are after ?

 

Don't select too much Closed LWpolylines .

 

 

Wow, thank you Tharwat, your code can bring me a lot of ideas. (: (I'm so bad at VisualLisping)

But is there a way of doing this without 'ctab? Only changing DXF values?

You created an layout using VisuaLisp, is there a way to copy an layout with visual lisp? I mean, instead of using (command "layout" "copy")?

You create a new viewport everytime, but, is there a way to select an existing one? If not, is there a way to change the viewport dimension while creating it?

Share this post


Link to post
Share on other sites
fabriciorby
From within an activated viewport of the same scale:

(command "._zoom" "window" "_end" pause "_end" pause)

 

Hm, this can be very helpful. I just need to get the viewport selected, because I'm going to have 2 viewports at the same layout ):

Share this post


Link to post
Share on other sites
BlackBox
Hm, this can be very helpful. I just need to get the viewport selected, because I'm going to have 2 viewports at the same layout ):

 

I use it as a simple routine, so that I manually double click within the desired veiwport, and invoke as if a normal command:

(defun c:ZW ()
    (command "._zoom" "window" "_end" pause "_end" pause)
    (princ)
)

Share this post


Link to post
Share on other sites
Tharwat
Wow, thank you Tharwat, your code can bring me a lot of ideas.

 

You're welcome and happy to hear that .

 

But is there a way of doing this without 'ctab? Only changing DXF values?

 

What's wrong with the 'ctab ? actually we should use it in the code to port at the layout's deck to enter the viewport to zoom for

a specific LWpolyline ( square ) .

 

You created an layout using VisuaLisp, is there a way to copy an layout with visual lisp? I mean, instead of using (command "layout" "copy")?

 

That way is not applicable in this case due to the sequence naming of layouts .

Share this post


Link to post
Share on other sites
fabriciorby

Yes, but I have written a code to make it applicabble (with help from the forum, sometime ago). Let me post it.

[color=RED]([/color][color=BLUE]setq[/color] layouts [color=RED]([/color][color=BLUE]vla-get-layouts[/color] [color=RED]([/color][color=BLUE]vla-get-activedocument[/color] [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED]))))[/color]
[color=#990099];; Temporarily rename layouts to reduce risk of duplication when renumbering[/color]
[color=RED]([/color][color=BLUE]vlax-for[/color] layout layouts
	[color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]/=[/color] [color=#a52a2a]"MODEL"[/color] [color=RED]([/color][color=BLUE]strcase[/color] [color=RED]([/color][color=BLUE]vla-get-name[/color] layout[color=RED])))[/color]
	[color=RED]([/color][color=BLUE]vla-put-name[/color] layout [color=RED]([/color][color=BLUE]vla-get-handle[/color] layout[color=RED]))[/color]
	[color=RED])[/color]
[color=RED])[/color]
[color=RED]([/color][color=BLUE]setq[/color] sfilter [color=RED]([/color][color=BLUE]list[/color][color=RED]([/color][color=BLUE]cons[/color] [color=#009900]8[/color] [color=#a52a2a]"NUM_FOLHA"[/color][color=RED])([/color][color=BLUE]cons[/color] [color=#009900]0[/color] [color=#a52a2a]"TEXT"[/color][color=RED])([/color][color=BLUE]cons[/color] [color=#009900]410[/color] [color=#a52a2a]"MODEL"[/color][color=RED])))[/color]
[color=RED]([/color][color=BLUE]setq[/color] s [color=RED]([/color][color=BLUE]ssget[/color] [color=#a52a2a]"x"[/color] sfilter[color=RED]))[/color][color=#990099];; gets how many square numbering texts it has in the model[/color]
[color=RED]([/color][color=BLUE]vlax-for[/color] layout layouts
	[color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]not[/color] [color=RED]([/color][color=BLUE]=[/color] [color=#a52a2a]"MODEL"[/color] [color=RED]([/color][color=BLUE]strcase[/color] [color=RED]([/color][color=BLUE]vla-get-name[/color] layout[color=RED]))))[/color]
		[color=RED]([/color][color=BLUE]progn[/color]
           [color=RED]([/color][color=BLUE]vla-put-name[/color] layout
			[color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]<[/color] [color=RED]([/color][color=BLUE]setq[/color] order [color=RED]([/color][color=BLUE]vla-get-taborder[/color] layout[color=RED]))[/color] [color=#009900]10[/color][color=RED])[/color]
				[color=RED]([/color][color=BLUE]setq[/color] layname[color=RED]([/color][color=BLUE]strcat[/color] [color=#a52a2a]"0"[/color] [color=RED]([/color][color=BLUE]itoa[/color] order[color=RED])))[/color]
				[color=RED]([/color][color=BLUE]setq[/color] layname[color=RED]([/color][color=BLUE]itoa[/color] order[color=RED]))[/color]
			[color=RED])[/color]
		[color=RED])[/color]
		[color=RED])[/color]
	[color=RED])[/color]
[color=RED])[/color]

 

And, your routine creates a new viewport everytime, but, is there a way to select an existing one? If not, is there a way to change the viewport dimension while creating it?

Edited by fabriciorby
editing code

Share this post


Link to post
Share on other sites
Tharwat
Yes, but I have written a code to make it applicabble (with help from the forum, sometime ago). Let me post it.

 

You are renaming the layouts with their handles' strings and not copying them as you have asked before . ;)

 

And, your routine creates a new viewport everytime, but, is there a way to select an existing one?

 

You can by the use of the 'ctab system variable and with global selection set for the same layout space (cons 410 (getvar 'ctab)) and then you should iterate through the selection set if it holds more than one viewport ans so on .

Share this post


Link to post
Share on other sites
fabriciorby
You are renaming the layouts with their handles' strings and not copying them as you have asked before . ;)

Yes, because I'm copying it manually. The first one is: 01, so the next ones are going to be 01 (2), 01 (3), 01 (4), ... and that's why I rename it, first with it's handles and then with taborder.

 

edit: Oh, I'm sorry, I think I forgot to quote you and we got a misunderstanding here ):

Edited by fabriciorby

Share this post


Link to post
Share on other sites
fabriciorby
I use it as a simple routine, so that I manually double click within the desired veiwport, and invoke as if a normal command:

(defun c:ZW ()
    (command "._zoom" "window" "_end" pause "_end" pause)
    (princ)
)

 

I see, I was thinking about making it automatic, without double clicking. ):

Share this post


Link to post
Share on other sites
Tharwat

As far as I know there is not a function that does that same like the layout command call with the use of copy option as well , but if you are interested in copying the settings of one layout to another , you can use the function vla-copyfrom .

Share this post


Link to post
Share on other sites
fabriciorby
As far as I know there is not a function that does that same like the layout command call with the use of copy option as well , but if you are interested in copying the settings of one layout to another , you can use the function vla-copyfrom .

 

Thank you, Tharwat. I'm going to try this function. (:

I'm going to study your code, maybe I'll need to ressurect this topic soon hehehe

Edited by fabriciorby

Share this post


Link to post
Share on other sites
BlackBox
I see, I was thinking about making it automatic, without double clicking. ):

 

That would potentially require a persistent, per-Document, per-PViewport association storage mechanism that is dependent on an initial setup... Hardly automatic from the big picture, when we're talking about the simple task of picking two points. Just saying.

Share this post


Link to post
Share on other sites
fabriciorby
That would potentially require a persistent, per-Document, per-PViewport association storage mechanism that is dependent on an initial setup... Hardly automatic from the big picture, when we're talking about the simple task of picking two points. Just saying.

 

I don't know if I correctly understood you but, yes I'm going to use this lisp in templates already created (that are dwg and not dwt).

All the squares are going to have a layer with its respective number, this number is gong to have its own layer too. What I'm doing is to get all squares from the layer and then getting their points to (ssget "wp") and get those numbers filtering by layer. Those numbers are going to be the layout name, so it's going to be "01", "02", "03"...

I think it's going to work (:

Share this post


Link to post
Share on other sites
fabriciorby
copy thru layouts ?

 

kruuger

 

Actually, I'm not looking for this haha. Thank you kruuger, it's an interesting lisp by the way (:

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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