linking multiple statements

linking multiple statements

CSM_MAI
Advocate Advocate
1,193 Views
7 Replies
Message 1 of 8

linking multiple statements

CSM_MAI
Advocate
Advocate

I've written a routine that I cant seem to get to work properly. I think I may need to use a COND statement instead of the way I have it written currently. I want the lisp to deactivate the viewport only if all 3 expressions? are True. If one is false, I don't want anything to happen, but i'm not sure how to link them together. Any tips on this would be appreciated. 

 

(defun c:vptest ()
(if (= (getvar "ctab") "Layout"))        ; check to see if in layout tab (if true)
(ssget "x" (list '(0 . "VIEWPORT"))))) ; check to see if viewport is present (if true)
(= 2 (getvar 'cvport)))                      ; Check to see if MSPACE is active in the Layout Tab (if true, then deactivate viewport)

(progn

(command "._pspace")                     ; Deactivates Viewport if MSPACE is active
(princ "\n Viewport deactivated...")  ; User notification
)
(progn
(princ "\n false")
)
)                                                         ;end if

(princ)
)

0 Likes
Accepted solutions (1)
1,194 Views
7 Replies
Replies (7)
Message 2 of 8

cadffm
Consultant
Consultant
First answer is: You are searching for AND

(if (and T (< 1 2) (wcmatch "abc" "*b*"))(alert "just do it!))

Second answer is:

Your statements are only working for
A Layout with the exacly name "Layout", perhaps you like it that all Layouts are possible? Tilemode check for Model vs Layout Tab
If you are in a Layout Tab current, there is ever a Viewport, so your ssget isn't needed [or you have to edit ssget filterlist with (-4 . ">")(69. 1)]
CVport 2 works sometimes, but if there multiple Viewports or delete one directly before, its possible the Value is 3, 4 or higher. Check (> (getvar "cvport") 1)

Sebastian

0 Likes
Message 3 of 8

CSM_MAI
Advocate
Advocate

Thank you for the response. I will try out tilemode. The thought was if the drawing was opened in model, then there isn't a layout for that drawing. We have a lot of clients that work in model only. Typically we do not use multiple layouts per our standards and other client's standards. Sometimes we have clients that do their electrical drawings all in layout so there wouldn't be a viewport present, that's why the ssget was added to check to see if there was a viewport present. A lot of times I open drawings, and a User has edited the drawing in model space through layout and left it active when they saved and closed the drawing. That's where this whole deal got started. I just want a check for when the User opens the file. Hopefully it'll be something they wont even notice. I appreciate the input.

0 Likes
Message 4 of 8

cadffm
Consultant
Consultant
Accepted solution
I am away from Acad, but is this simple line not enough for your target?
(if (zerop (getvar 'tilemode))(command "_.PSPACE"))

Sebastian

Message 5 of 8

CSM_MAI
Advocate
Advocate

Well that just simplified the whole thing. It works exactly like it should from the looks of it. I've never used "ZEROP" before. Thanks again for looking at this, and for simplifying it. Have a good one. 

0 Likes
Message 6 of 8

CSM_MAI
Advocate
Advocate
Back on the (if (and portion of autolisp, if I wanted to ensure certain statements were true, how would I use that with (progn or (cond? I find myself wanting to ensure certain items during lisp and I'm not sure how to add (and into a statement. Thanks again for any info.
0 Likes
Message 7 of 8

Jonathan.Trostad
Advocate
Advocate

Its pretty simple. You feed AND a bunch of things, could be numbers, variables, text items, etc. AS long as NOTHING in this list is equal to or actually NIL, AND returns a T. if anything in the list is equal to NIL then AND returns NIL.

 

Hope that helps

0 Likes
Message 8 of 8

scot-65
Advisor
Advisor
AND, OR, NOT are pretty versatile. Inform the prosecutor
that you do not want to hear these words while on the
witness stand.

COND can use these as well. Mind that PROGN is not
required inside the COND.

(cond
( (or (test1) (and (not (test2)) (test3)));or
...do stuff here
)
( (and (test1) (not (test2)));and
...do stuff here
)
( (test1) ...do stuff here )
( (not (test2)) ...do stuff here )
(T ...do stuff here )
);cond

Too bad there is not a function "suppose"?

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes