TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Nibster on March 28, 2011, 03:23:47 PM
-
I'm having trouble here finding what I need in lisp (i think i found it in vba or vlisp, but i'm not entirely sure), and if i search any more on my own I fear i'll upset the 'ignorance is bliss' mentality.
It's a simple layer setup routine for a simple drafter who does some funny and not so simple things, like use clipped viewports that are perfectly rectangular. :?
Anyway, is there a way to modify this code so it doesn't bomb out when it is forced to pick a clipped viewport?
;; start of FPM-DH function
(defun c:FPM-DH (/ ss Vpid)
(setvar "cmdecho" 0)
(command "_.pspace")
(setq ss (car (entsel "\nselect viewport: ")))
(setq Vpid (cdr (assoc 69 (entget ss))))
(command "_.mspace")
(setvar "cvport" Vpid)
(command "vplayer" "f" "*|M*,*LS|*,*|P*" "" "t" "*|E*" "" "")
(command "_.regenall")
(command "_.pspace")
(command "_.zoom" "E")
(princ)
(alert "Door Holders tab \nsetup is complete!")
)
;; end of FPM-DH function
or, if there's another way to transparently go around the issue (like unclip the vport using lisp) that would be fine by me too!
-
seem to have found my answer HERE (http://www.theswamp.org/index.php?topic=1274.0). i think.... now to see how to blend that in as neatly as possible...
-
Use a filtered selection set. Here's the command line entry showing what happens when I select in the same place:
Command: (entget (car (entsel)))
Select object: ((-1 . <Entity name: -1f00d0>) (0 . "LWPOLYLINE") (5 . "10996")
(102 . "{ACAD_REACTORS") (330 . <Entity name: -1d1c70>) (102 . "}") (330 .
<Entity name: -1d92c0>) (100 . "AcDbEntity") (67 . 1) (410 . "Layout1") (8 .
"C-TOPO-TEXT") (100 . "AcDbPolyline") (90 . 5) (70 . 129) (43 . 0.0) (38 . 0.0)
(39 . 0.0) (10 12.9127 11.024) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10
13.2893 7.59882) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 21.0855 8.05049)
(40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 20.8971 11.4756) (40 . 0.0) (41 .
0.0) (42 . 0.0) (91 . 0) (10 15.0971 14.2985) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(91 . 0) (210 0.0 0.0 1.0))
Command: (setq ss (ssget ":S" '((0 . "Viewport"))))
Select objects:
<Selection set: 9c2>
Command: (setq ent (entget (ssname ss 0)))
((-1 . <Entity name: -1d1c70>) (0 . "VIEWPORT") (330 . <Entity name: -1d92c0>)
(5 . "886A") (100 . "AcDbEntity") (67 . 1) (410 . "Layout1") (8 . "VP") (100 .
"AcDbViewport") (10 16.9991 10.9487 0.0) (40 . 8.17273) (41 . 6.69973) (68 . 2)
(69 . 2) (12 -2424.01 -544.43 0.0) (13 0.0 0.0 0.0) (14 0.5 0.5 0.0) (15 0.5
0.5 0.0) (16 0.0 0.0 1997.26) (17 1.78181e+006 290121.0 0.0) (42 . 50.0) (43 .
0.0) (44 . 0.0) (45 . 267.989) (50 . 0.0) (51 . 0.0) (72 . 10000) (90 . 901120)
(340 . <Entity name: -1f00d0>) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0)
(111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5)
(348 . <Entity name: -1f5560>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63
. 250) (421 . 3355443))
-
Heh, or the way shown in that other thread :-)
-
Use a filtered selection set. Here's the command line entry showing what happens when I select in the same place:
Command: (entget (car (entsel)))
Select object: ((-1 . <Entity name: -1f00d0>) (0 . "LWPOLYLINE") ... )
Command: (setq ss (ssget ":S" '((0 . "Viewport"))))
Select objects:
<Selection set: 9c2>
Command: (setq ent (entget (ssname ss 0)))
((-1 . <Entity name: -1d1c70>) (0 . "VIEWPORT") ... )
Ooo! Didn't know you could do that - Thanks Jeff - that'll certainly save a lot of legwork in the future.
-
Use a filtered selection set. Here's the command line entry showing what happens when I select in the same place:
Command: (entget (car (entsel)))
Select object: ((-1 . <Entity name: -1f00d0>) (0 . "LWPOLYLINE") (5 . "10996")
(102 . "{ACAD_REACTORS") (330 . <Entity name: -1d1c70>) (102 . "}") (330 .
<Entity name: -1d92c0>) (100 . "AcDbEntity") (67 . 1) (410 . "Layout1") (8 .
"C-TOPO-TEXT") (100 . "AcDbPolyline") (90 . 5) (70 . 129) (43 . 0.0) (38 . 0.0)
(39 . 0.0) (10 12.9127 11.024) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10
13.2893 7.59882) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 21.0855 8.05049)
(40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 20.8971 11.4756) (40 . 0.0) (41 .
0.0) (42 . 0.0) (91 . 0) (10 15.0971 14.2985) (40 . 0.0) (41 . 0.0) (42 . 0.0)
(91 . 0) (210 0.0 0.0 1.0))
Command: (setq ss (ssget ":S" '((0 . "Viewport"))))
Select objects:
<Selection set: 9c2>
Command: (setq ent (entget (ssname ss 0)))
((-1 . <Entity name: -1d1c70>) (0 . "VIEWPORT") (330 . <Entity name: -1d92c0>)
(5 . "886A") (100 . "AcDbEntity") (67 . 1) (410 . "Layout1") (8 . "VP") (100 .
"AcDbViewport") (10 16.9991 10.9487 0.0) (40 . 8.17273) (41 . 6.69973) (68 . 2)
(69 . 2) (12 -2424.01 -544.43 0.0) (13 0.0 0.0 0.0) (14 0.5 0.5 0.0) (15 0.5
0.5 0.0) (16 0.0 0.0 1997.26) (17 1.78181e+006 290121.0 0.0) (42 . 50.0) (43 .
0.0) (44 . 0.0) (45 . 267.989) (50 . 0.0) (51 . 0.0) (72 . 10000) (90 . 901120)
(340 . <Entity name: -1f00d0>) (281 . 0) (71 . 1) (74 . 0) (110 0.0 0.0 0.0)
(111 1.0 0.0 0.0) (112 0.0 1.0 0.0) (79 . 0) (146 . 0.0) (170 . 0) (61 . 5)
(348 . <Entity name: -1f5560>) (292 . 1) (282 . 1) (141 . 0.0) (142 . 0.0) (63
. 250) (421 . 3355443))
yeah... that's WAY over my head.
I replaced lines 3,4,&5 in my original post with CAB's input found in the link in my second post. I am still new at this game, but at least I could follow along better that way too.
Thanks guys!
-
yeah... that's WAY over my head.
Don't worry, its not as scary as it looks :-)
This was Jeff's intention:
(defun c:FPM-DH ( / cm ss vpid )
(setq cm (getvar 'CMDECHO))
(setvar 'CMDECHO 0)
(if (setq ss (ssget "_+.:S:E" '((0 . "VIEWPORT"))))
(progn
(setq vpid (cdr (assoc 69 (entget (ssname ss 0)))))
(command "_.mspace")
(setvar 'CVPORT vpid)
(command "_.vplayer" "_f" "*|M*,*LS|*,*|P*" "" "t" "*|E*" "" "")
(command "_.regenall" "_.pspace" "_.zoom" "E")
)
)
(alert "Door Holders tab \nsetup is complete!")
(setvar 'CMDECHO cm)
(princ)
)
Also, since you are changing system variables (I know, its only CMDECHO), consider adding an error handler (http://lee-mac.com/errorhandling.html).
Lee
-
oh yeah, i keep forgetting about 'resets'. I see in the link that you provided that i also need to look at the osnaps, which can sometimes be a pain.
would you also be so kind and explain line 4 in the code you provided? I want very much to understand how you got done in 1 line what needed more than 4 in previous searches.
Thanks!!
-
yeah, how did you do this Lee? I just discovered that I don't have to pick the viewport frame, I can pick inside frame and the dang thing and it works! (I was testing if your version had a "nothing selected, try again" feature)
OR not need to be in pspace?!? wow....
:not_worthy:
-
anyway, this is what I've settled on. since there's more than one vport in the file and they each need their own layer settings, I made Lee's contribution a subroutine (i think that's what it's called, please correct my terminology as required) and this is the format i created:
;start of VPORT selection function
(defun c:vpselect (/ ss vpid)
(if (setq ss (ssget "_+.:S:E" '((0 . "VIEWPORT"))))
(progn
(setq vpid (cdr (assoc 69 (entget (ssname ss 0)))))
(command "_.mspace")
(setvar 'CVPORT vpid)
) ;end progn
) ;end if
) ;end defun
;
;end of VPORT selection function
;---------------------------------------------------------------------------------------
;; start of FPM-SD function
(defun c:FPM-SD (/ cm)
(setq cm (getvar 'CMDECHO))
(setvar "cmdecho" 0)
(c:vpselect)
(command "vplayer" "f" "*|E*,*|M*,*LS|*,*|P*,*|A-FLOR-RMNA" "" "t" "*|E*FIRE*SMDT*SURV*" "" "")
(command "_.regenall" "_.pspace" "_.zoom" "E")
(alert "Smoke Detector tab \nsetup is complete!")
(setvar 'CMDECHO cm)
(princ)
)
;; end of FPM-SD function
Thanks again to all who chimed in
-
oh yeah, i keep forgetting about 'resets'. I see in the link that you provided that i also need to look at the osnaps, which can sometimes be a pain.
Just keep in mind that before changing System Variables, store their original values and reset them afterwards; and, if there is a point at which the user could press Esc (like at a selection prompt) or there is some code that could error, include an error handler (*error* function) to reset the System Variables should either of these scenarios arise.
would you also be so kind and explain line 4 in the code you provided? I want very much to understand how you got done in 1 line what needed more than 4 in previous searches.
This was utilising the idea that Jeff demonstrated in his earlier post: that Viewports and Clipped Viewports may be selected using a filtered ssget call.
The '+.' forces point mode only (similar to setting PICKAUTO = 0), the ':S' forces a single selection, the ':E' selects everything in the pickbox aperture. So with these options enabled we are effectively replicating the behaviour of entsel.
-
Thanks for the explanation Lee.
I'm still confused on how it seems to work properly when nothing is picked and the vport is active.
edit: ok, it doesn't work when you don't pick the viewport frame. I need to add something in there to loop until an object is selected.... hmmm.
-
edit: ok, it doesn't work when you don't pick the viewport frame. I need to add something in there to loop until an object is selected.... hmmm.
Perhaps change it to something along these lines:
(defun vpselect ( / ss vpid )
(while (not (setq ss (ssget "_+.:S:E" '((0 . "VIEWPORT")))))
(princ "\n** Please Select a Viewport **")
)
(setq vpid (cdr (assoc 69 (entget (ssname ss 0)))))
(command "_.mspace")
(setvar 'CVPORT vpid)
(princ)
)
(defun c:FPM-SD ( / cm )
(setq cm (getvar 'CMDECHO))
(setvar 'CMDECHO 0)
(vpselect)
(command "_.vplayer" "_f" "*|E*,*|M*,*LS|*,*|P*,*|A-FLOR-RMNA" "" "_t" "*|E*FIRE*SMDT*SURV*" "" "")
(command "_.regenall" "_.pspace" "_.zoom" "_E")
(alert "Smoke Detector tab \nsetup is complete!")
(setvar 'CMDECHO cm)
(princ)
)
-
~sigh~
i hope i can get it to click soon where i look at this stuff and I can just see how all the pieces fall together.
Thanks a ton (imperial) Lee. That's quite a bit cleaner than what I was attempting!
-
~sigh~
i hope i can get it to click soon where i look at this stuff and I can just see how all the pieces fall together.
Don't worry, one day you'll look back on this thread and be amazed at how far you will have progressed :-)
Thanks a ton (imperial) Lee. That's quite a bit cleaner than what I was attempting!
You're welcome :-)
I'm not overly keen on my solution however, since, should the user wish to exit the selection prompt, he/she must hit Esc, else be trapped in the while loop 'til the heat death of the universe...
-
<snip>
I'm not overly keen on my solution however, since, should the user wish to exit the selection prompt, he/she must hit Esc, else be trapped in the while loop 'til the heat death of the universe...
(setvar 'ErrNo 0)
(while (and (not (equal (getvar 'ErrNo) 52)) (not flag))
(if (setq ss (ssget "_+.:S:E" '((0 . "VIEWPORT"))))
(setq flag t)
(princ "\n** Please Select a Viewport **")
)
)
-
Nice one Tim - I thought that only worked with entsel - happily mistaken 8-)