PDA

View Full Version : ActivePViewport Mystery


lance.81922
2005-05-30, 05:52 PM
I have been trying to use VLISP functions to activate a PViewport with ACAD 2006, and have been having some problems. Assume in the following that PVIEWPORTS is a VLISP selection set of PViewports, and that PVIEWPORT is a Pviewport (duh).
(vlax-for pviewport pviewports
;;;ACTIVATE VIEWPORT
(vla-put-ActiveSpace doc acPaperSpace)
(vla-put-MSpace doc acFalse)
(vl-catch-all-apply 'vlax-invoke-method (list pviewport 'Display acTrue))
(vla-put-MSpace doc acTrue)
(vla-put-ActivePViewport doc pviewport)
(setvar "UCSVP" 0)
)
The vl-catch-all apply was added because sometimes (but not always) I would get a "Not in paperspace" error when trying to invoke the Display method on my pviewport.

The big error seems to be in the vla-put-ActivePViewport line, where I invariably see "Error setting current viewport". The main defect I see when inspecting the PVIEWPORT object is the new property "LabelBlockID" is undefined. Other than that it looks like a valid PViewport.

I have successfully done this kind of coding with "old-style" AutoLISP, but figured I needed to learn my way around the ActiveX functions. I have not yet found much in the way of helpful example code for setting a PViewport active other than one example from Autodesk. Can somebody help?

lance.81922
2005-05-30, 06:20 PM
Oh, yeah, and I just figured out that vlax-for is for collections and not for selection sets. Replaced it with code to iterate through the set:
(setq ctr -1)
(repeat(- (vla-get-count pviewports)1)
(setq pviewport(vla-item pviewports (setq ctr(1+ ctr))))
Why the heck is Viewports a collection and PViewports is not?

miff
2005-05-30, 07:22 PM
Oh, yeah, and I just figured out that vlax-for is for collections and not for selection sets.
Why the heck is Viewports a collection and PViewports is not?Well, if you use (ssget) to create your ss it is different than if you use the ActiveX method of obtaining a selection set (which IS a collection and you CAN use (vlax-for) with).

What is your code for setting PViewports?

lance.81922
2005-05-30, 07:46 PM
the ActiveX method of obtaining a selection set (which IS a collection and you CAN use (vlax-for)
Thanks, miff! I didn't get an error but was wondering why. Guess I've been concentrating on the other errors I mentioned. The whole thing is:
(defun lg:allvports
(/ doc origspace layout layouts pviewport pviewports ssvp)
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
layouts (vla-get-Layouts doc)
)
(if (= (vla-get-ActiveSpace doc) 1) ; In Model space
(progn
(setq origspace 1)
(vla-put-ActiveSpace doc acPaperSpace)
)
)
(vlax-for layout layouts
(setq ssvp (ssget "X"
(list '(-4 . "<AND")
'(-4 . "<AND")
'(0 . "VIEWPORT")
(cons 410 (vla-get-Name layout))
'(-4 . "AND>")
'(-4 . "<NOT")
'(69 . 1)
'(-4 . "NOT>")
'(-4 . "AND>")
)
)
)
(setq pviewports (pickset->vla-SelectionSet ssvp "SS1"))
;(vlax-for pviewport pviewports
(setq ctr -1)
(repeat(- (vla-get-count pviewports)1)
(setq pviewport(vla-item pviewports (setq ctr(1+ ctr))))

;;;ACTIVATE VIEWPORT
(vla-put-ActiveSpace doc acPaperSpace)
(vla-put-MSpace doc acFalse)
;(vlax-invoke-method pviewport 'Display acTrue)
(vl-catch-all-apply 'vlax-invoke-method (list pviewport 'Display acTrue))
(vla-put-MSpace doc acTrue)
(vla-put-ActivePViewport doc pviewport)
(setvar "UCSVP" 0)
)
)
(princ)
)
;; From CadVault
(defun PickSet->vla-SelectionSet
(ss SelSetName / i EntList EntArray ColSelSets SelSet)
(setq i -1)
;;;* Create list from pickset (autolisp selection set: ss)
(repeat (sslength ss)
(setq EntList (cons (ssname ss (setq i (1+ i))) EntList))
)
(setq EntList (reverse EntList))
;;;* Create array from created list
(setq EntArray
(vlax-safearray-fill
(vlax-make-safearray
vlax-vbObject
(cons 0 (1- (length EntList)))
)
(mapcar 'vlax-ename->vla-object EntList)
)
)
;;;* Create selection set object from created array
(if (not SelSetName)
(setq SelSetName (strcat "SelSet " (rtos (getvar "cdate") 2 8)))
)
(setq ColSelSets
(vla-get-selectionsets
(vla-get-activedocument (vlax-get-acad-object))
)
)
;;;* Delete the selection set object exists
(vl-catch-all-apply
'vla-delete
(list
(vl-catch-all-apply 'vla-item (list ColSelSets SelSetName))
)
)
;;;* Create the selection set object
(setq SelSet (vla-add ColSelSets SelSetName))
(vla-additems SelSet EntArray)
SelSet
)
The code to create the ActiveX SelectionSet from an (ssget) set is pretty cool and seems to work OK. The part where I try to activate the PViewport is what's got me stumped. I'm just doing the (setvar "UCSVP" 0) part as an example, since my intent is to create a toolbox routine for any time I need to activate all PViewports before doing something to them.

lance.81922
2005-05-30, 09:31 PM
Found it -- I was trying to make a PViewport active on a layout that was not active. Doh!

miff
2005-05-31, 12:06 AM
Thanks, miff!
I'm just doing the (setvar "UCSVP" 0) part as an example, since my intent is to create a toolbox routine for any time I need to activate all PViewports before doing something to them.
You're welcome! I'm glad you found the problem with the code. Now I just have to inquire what it is you would need to do that requires each VP to be active.....the ONLY things I can think of relate to layers, zooming and/or views. Most anything else can be done via ActiveX methods & properties without being made active.

Jeff

lance.81922
2005-05-31, 01:00 AM
Jeff,

The example I posed [(setvar "UCSVP" 0)] is one that needs to be done to each viewport, and I think you have to activate the port to set it. It may well be that there's an ActiveX way to set that sysvar in each viewport without activating it, but I don't know off the top of my head how you'd do that. Certainly if you activate the PViewport you can do it. I'm not sure how many other sysvars are unique to each viewport, but that one is. As I said, though, this was mostly an exercise in how to activate a PViewport, how to deal with an ActiveX SelectionSet (thanks again! Where is "SelectionSet=Collection" documented?), switching layouts, and how to switch back and forth between MSpace and PSpace. I've done all this many times in AutoLISP but there are a number of coding differences, of course. Some people get their kicks in funny ways.......:Oops:

miff
2005-05-31, 04:29 AM
Lance, while it's true that a VP must be active to use with (setvar), it's also true that most objects, including VP's, that have a SysVar specific to that object will have a property that can be set. To use the UCSVP scenario, since you already have the vla-object of the VP in pviewport you would do this:
(vla-put-ucsperviewport pviewport :vlax-false)

I suggest making the function (vlax-dump-object) your friend. It will help you to see what properties are available for each object.

The documentation for Selection Sets is in the ActiveX & VBA Developer's Guide. An SS is a collection in ActiveX, just as are Blocks, Layers, TextStyles, DimStyles, etc. And to go a bit further, where you have the Blocks Collection, which contains all of the defined blocks in the drawing, each one of those Block Defs is a collection of entities........