pmxcad Posted May 4, 2018 Posted May 4, 2018 Hello, I found a Lee Mac lisp to activate a viewport. But I want to select in a different way, is this possible? (defun c:vpon ( / d s ) (vl-load-com) (if (setq s (ssget "_+.:S:E:L" '((0 . "VIEWPORT")))) (progn (setq d (vla-get-activedocument (vlax-get-acad-object))) (vla-put-mspace d :vlax-true) (vla-put-activeviewport d (vlax-ename->vla-object (ssname s 0))) ) ) (princ) ) instead of (ssget "_+.:S:E:L" '((0 . "VIEWPORT"))) wanting to use this, (ssget "_X" '((0 . "VIEWPORT") (-4 . ">") (40 . 99) (-4 . "<") (40 . 101))) is this possible?. if i use this it gives a error: ; error: bad argument type: listp Wat is going wrong? thank you in advance, PmxCAD Quote
Jef! Posted May 4, 2018 Posted May 4, 2018 (edited) Hi there. When you use (ssget "_+.:S:E:L" '((0 . "VIEWPORT"))), it is like using (entget), it results in a selection set with a single object being createded. On the other hand, when you use (ssget "_X" it creates a selection set that include all objects that match the ssget criteria. This approach would need more thinking because all it would do is make 1 viewport active and it would arbitrarily be the first one from the selection set with the code from your first example. Edit: UNLESS you have only 1 viewport in the page that meets the criterias (width over 99 units but less than 101, (within all tabs as it is)) this could do the job. (defun c:vpon ( / d s ) (vl-load-com) (if (and (setq s (ssget "_X" '((0 . "VIEWPORT") (-4 . ">") (40 . 99) (-4 . "<") (40 . 101)))) (= 1 (sslength s)) ) (progn (setq d (vla-get-activedocument (vlax-get-acad-object))) (vla-put-mspace d :vlax-true) (vla-put-activeviewport d (vlax-ename->vla-object (ssname s 0))) ) ) (princ) ) Wont work if you have more than one viewport, so up to you to figure which one would be activated and adjust your code accordingly. Won't work if you have viewports of other size, or the viewport is on another tab. It has been a while since i played with vports, and with both version, even if i have 1 vport of the correct size, and it is on the current tab, even if it work i get that message "; error: ActiveX Server returned an error: Le type ne correspond pas". Sure thing I would target the active tab adding (cons 410 (getvar 'ctab)), and would use some more logic rules (other than the width) to ensure that the selection would have lesser chances of not being made correctly. Edited May 4, 2018 by Jef! Quote
Roy_043 Posted May 6, 2018 Posted May 6, 2018 My test (with BricsCAD) shows two issues: 1. The selection set should be limited to the current tab. 2. The function vla-put-activepviewport (with 2 P's) should be used. (defun c:vpon ( / d s ) (vl-load-com) (if (setq s (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'ctab)) '(-4 . ">") '(40 . 99) '(-4 . "<") '(40 . 101)))) (progn (setq d (vla-get-activedocument (vlax-get-acad-object))) (vla-put-mspace d :vlax-true) (vla-put-activepviewport d (vlax-ename->vla-object (ssname s 0))) ) ) (princ) ) Quote
Jef! Posted May 7, 2018 Posted May 7, 2018 1. The selection set should be limited to the current tab.2. The function vla-put-activepviewport (with 2 P's) should be used. I said I would target the active tab adding (cons 410 (getvar 'ctab)) without knowing about vla-put-activepviewport... learning new ways to skin the cat every day! Thanks Roy. From my interpretation of the ActiveX Ref guide for vla-put-activepviewport is that it works for the active paper space, so adding (cons 410 (getvar 'ctab)) in the ssget is redundant/useless if you use vla-put-activepviewport? I still think that arbitrarily activating the first viewport of the selection set make the function totally unpredictable. Even if it textually is what the op asked, it doesn't seem very usefull (unless his workflow guarantees that every tab have a single viewport or a single viewport meeting the criteria, which seems not very likelly) Quote
Roy_043 Posted May 7, 2018 Posted May 7, 2018 I don't think that limiting the selection to the current tab is redundant. At least there is an error in BricsCAD if the (ssname s 0) object is on a different layout. Quote
Jef! Posted May 7, 2018 Posted May 7, 2018 I don't think that limiting the selection to the current tab is redundant. At least there is an error in BricsCAD if the (ssname s 0) object is on a different layout. You are quite right, I had it upside down. (cons 410 (getvar 'ctab)) is required, that is the use of vla-put-activepviewport which doesn't seems to yield any advantages over vla-put-activeviewport. (My bad. Is it friday yet?) So the question would be, if the ssget only grab the viewports on the curent tab only, why would you say that vla-put-activepviewport (with 2 P's) should be used rather than vla-put-activeviewport? Quote
Roy_043 Posted May 7, 2018 Posted May 7, 2018 (edited) This seems to be a (rare) situation where BricsCAD Lisp is not compatible. The ActiveViewport property is always a "VPORT" in BricsCAD. And for the task at hand ("VIEWPORT") you have to use the ActivePViewport property. EDIT: I have sent Bricsys a Support Request regarding this compatibility issue. According to their answer BricCAD is in fact compatible with AutoCAD 2013-2018. So the original c:vpon function should fail with these AutoCAD versions as well. The answer to Jef!'s question: Why use vla-put-activepviewport (with 2 P's)? Would then be: To make the code version independent. Edited May 8, 2018 by Roy_043 Quote
tombu Posted May 8, 2018 Posted May 8, 2018 With Jimmy Bergmark's https://jtbworld.com/autocad-vp-outline-lsp when in modelspace of a viewport it defaults to the active viewport using vla-get-activepviewport. In paperspace it prompts you to select a viewport. Not sure where you're going with this routine, but his example may help. Quote
Lee Mac Posted May 8, 2018 Posted May 8, 2018 I can confirm that activepviewport is required - the code should be amended accordingly. Quote
Jef! Posted May 8, 2018 Posted May 8, 2018 While the viewport activate with both, I get the "; error: ActiveX Server returned an error: Le type ne correspond pas" error message only with vla-put-activeviewport. I had to play with the 2015 Active-x reference guide examples to get a better understanding. I'm not sure how/why the vport gets activated despite the error message when I try with vla-put-activeviewport. There are still things that are not clear in my mind... vla-put-activeviewport obj propval definition: Specifies the active viewport for the drawing. obj: document propval Type: Viewport Viewport definition: A bounded area that displays some portion of a drawing's model space. vla-put-activeviewport obj propval definition: Specifies the active paper space viewport for the drawing. obj: document propval Type: PViewport PViewport definition: Rectangular objects created in paper space that display views. By reading the PViewport definition that makes me understand that the Viewport definition (A bounded area that displays some portion of a drawing's) is *not* a paperspace object. Ok. The confuzing part was/is that when I browse database entities for a given paperspace tab that contain a viewport, there are 2 (0 . "VIEWPORT") objects. The paperSpace itself (69 . 1) and the viewport (69 . 2). If I browse entities when in modelspace, I see the "VIEWPORT" objects from the last activated paperspace. If I split the model in multiple viewports and browse the "View Ports table", I see the (0 . "VPORT") objects. If I understood correctly, a PViewport active-x object is a (0 . "VIEWPORT"), and a Viewport active-x object is a (0 . "VPORT")? Quote
Roy_043 Posted May 9, 2018 Posted May 9, 2018 (edited) @Jef!: I think you understand the difference between vla-put-activeviewport (for MS "VPORT") and vla-put-activepviewport (for PS "VIEWPORT") now. It is indeed a bit confusing (and in your last post you still mix things up a bit). Of course faulty information in the documentation does not help... "The ActiveSpace property (equivalent to the TILEMODE system variable) determines the type of viewport used." http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-2B609059-6B70-4C66-A442-F5917363462A A "VIEWPORT" gets activated despite the error message, because this occurs before the call to vla-put-activeviewport: (vla-put-mspace d :vlax-true) Edited May 9, 2018 by Roy_043 Quote
Jef! Posted May 9, 2018 Posted May 9, 2018 @Jef!:Of course faulty information in the documentation does not help... "The ActiveSpace property (equivalent to the TILEMODE system variable) determines the type of viewport used." http://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-2B609059-6B70-4C66-A442-F5917363462A A "VIEWPORT" gets activated despite the error message, because this occurs before the call to vla-put-activeviewport: (vla-put-mspace d :vlax-true) Ok, I get it now. So I never "controlled" which viewport got activated, I just changed the The ActiveSpace property and happened to have only 1 viewport. Thanks a lot for taking the time to shed light! Faulty information in the documentation indeed does not help... have you seen the following sentence of the one you quoted from the page you linked? "No editing or view changes can be performed unless the viewport is active. To make a viewport active, use the ActiveViewport property on the Document object" (!). If I understood correctly this should be "No editing or view changes can be performed unless the viewport is active. To make a viewport active, use the ActivePViewport property on the Document object"... right? Quote
Roy_043 Posted May 9, 2018 Posted May 9, 2018 .. To make a viewport active, use the ActivePViewport property on the Document object"... right?No. The page is about the Viewport object which is the same as the "VPORT" entity. Viewport object = VPORT entity. PViewport object = VIEWPORT entity. Quote
Recommended Posts
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.