Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Cycle through selections

  1. #1
    Member
    Join Date
    2009-06
    Location
    Florida
    Posts
    27
    Login to Give a bone
    0

    Default Cycle through selections

    I have a lisp routine that I constructed from other lisps that I found around the forums. This lisp selects only the objects in Modelspace that can be seen in the selected viewport and moves them to Paperspace. What I would like for it to do is run on all viewports in a single tab with no user input.

    Any help in helping me understand would be greatly appreciated.
    Code:
    ;;; ChangeSpace.lsp moves objects from MSpace to Pspace 
    ;;; Based on VPLIM.lsp written by Rebecca L. Johnson, June 1, 2007
    (defun c:CS (/ vp ht wd vn ctr ctrx ctry vs xp iw bl br tr tl items)
    
      (command "pspace")					
      (setq vp (entget 					
    	       (car (entsel "\nSelect Viewport to move Item from Modelspace to Paperspace.... "))
    	   );entget
      );setq
      (setq ht (cdr (assoc 41 vp)))				; Get Viewport height
      (setq wd (cdr (assoc 40 vp)))				; Get Viewport width
      (setq vn (cdr (assoc 69 vp)))				; Get Viewport CVPort variable
      (command "mspace")					
      (setvar "cvport" vn)					; Set correct viewport
      (command ".ucs" "v")					; Set UCS to View
      (setq ctr (getvar "viewctr"))				; Get VIEWCTR
      (setq ctrx (car ctr))					; Get X of CTR
      (setq ctry (cadr ctr))				; Get Y of CTR
      (setq vs (getvar "viewsize"))				; Get inside Viewport height
      (setq xp (/ ht vs))					; Get XP Factor with height 
    							
      (setq iw (* (/ vs ht) wd))				; Get inside width of Viewport
      (setq bl (list (- ctrx (/ iw 2)) (- ctry (/ vs 2))))
    							; Find four corners of Viewport
      (setq br (list (+ ctrx (/ iw 2)) (- ctry (/ vs 2))))
      (setq tr (list (+ ctrx (/ iw 2)) (+ ctry (/ vs 2))))
      (setq tl (list (- ctrx (/ iw 2)) (+ ctry (/ vs 2))))
    
      (Setq items (ssget "w" bl tr))  			;Makes a selection set of all objects in selected vport
      (command "chspace" items "" "")				
      (command "pspace"))				
      (princ)						
    );defun
    Last edited by bbDmn0; 2011-06-23 at 03:38 PM.

  2. #2
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Cycle through selections

    Objects selected this way, change space from active mspace viewport and their location is maintained according to this viewport...

    Although I don't know why you need this, this is the code you are looking for...

    Code:
    (defun c:CSALL (/ cspace ssvps i entvp vp ht wd vn ctr ctrx ctry vs xp iw bl br tr tl items)
      (command "pspace")
      (setq cspace (getvar "CTAB"))					
      (setq ssvps (ssget "_X" (list (cons 0 "VIEWPORT") (cons 410 cspace)) ))
      (setq i (- (sslength ssvps) 1))
      (repeat (- (sslength ssvps) 1)
      (setq i (1- i))
      (command "mspace")
      (setq entvp (ssname ssvps i))
      (setq vp (entget entvp)) 					
      (setq ht (cdr (assoc 41 vp)))				; Get Viewport height
      (setq wd (cdr (assoc 40 vp)))				; Get Viewport width
      (setq vn (cdr (assoc 69 vp)))				; Get Viewport CVPort variable
      (command "mspace")					
      (setvar "cvport" vn)					; Set correct viewport
      (command ".ucs" "v")					; Set UCS to View
      (setq ctr (getvar "viewctr"))				; Get VIEWCTR
      (setq ctrx (car ctr))					; Get X of CTR
      (setq ctry (cadr ctr))				; Get Y of CTR
      (setq vs (getvar "viewsize"))				; Get inside Viewport height
      (setq xp (/ ht vs))					; Get XP Factor with height 
    							
      (setq iw (* (/ vs ht) wd))				; Get inside width of Viewport
      (setq bl (list (- ctrx (/ iw 2)) (- ctry (/ vs 2))))
    							; Find four corners of Viewport
      (setq br (list (+ ctrx (/ iw 2)) (- ctry (/ vs 2))))
      (setq tr (list (+ ctrx (/ iw 2)) (+ ctry (/ vs 2))))
      (setq tl (list (- ctrx (/ iw 2)) (+ ctry (/ vs 2))))
    
      (Setq items (ssget "w" bl tr))  			;Makes a selection set of all objects in selected vport
      (command "chspace" items "" "")				
      (command "pspace")
      )				
      (princ)						
    );defun

    M.R.
    Last edited by marko_ribar; 2011-06-24 at 04:11 PM. Reason: code changed - now change space is within all viewports limits

  3. #3
    Member
    Join Date
    2009-06
    Location
    Florida
    Posts
    27
    Login to Give a bone
    0

    Default Re: Cycle through selections

    The end result of this will be to include in my batch plot script for WMFs. From what you wrote it would work if there was one Viewport. I need it to run through multiple viewports individually running though one then starting over with another viewport.

  4. #4
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Cycle through selections

    But this code was intended to do job with multiple viewports placed in paperspace Layout... It just doesn't change space of objects that already changed space within lastly created viewport, for selected objects doesn't exist any more in model space after change space once took place... For plotting, I think it will work (just set plot window of viewport lower-left point and upper-right point per viewport)... Note that when erased vports and again created and you are in same session CVPORT variable will search for newer bigger number values, so if this happened I suggest you save or qsave dwg and open it again to reset CVPORT values...

    P.S. I don't know if you can use window for selection of area for plotting, but you can still plot active mspace viewport in its viewsize value... Keep in mind that you plot every viewport separately per one paper. If you want to plot all viewports together you don't need this code for doing job (set separately visual style per viewport and plot them all - all Layout)

    M.R.
    Last edited by marko_ribar; 2011-06-23 at 08:55 PM.

  5. #5
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Cycle through selections

    Notification that the code was changed...

    If you want to change order of plotting (from firstly created viewport to lastly one), just change variables in lines :

    Code:
      (setvar "CVPORT" (+ k 2))
      (setq entvp (ssname ssvps i))
    If you want to plot from lastly created viewport to firstly, you do not change anything in above posted code...
    No need for this as I just until now see that you already have variable vn for setting "CVPORT"

    M.R.
    Last edited by marko_ribar; 2011-06-24 at 04:14 PM. Reason: No need for this as I just until now see that you already have variable vn for setting "CVPORT"

  6. #6
    I could stop if I wanted to
    Join Date
    2009-03
    Location
    London, England
    Posts
    304
    Login to Give a bone
    0

    Default Re: Cycle through selections

    I see you are having fun with the colour coding Marko!

  7. #7
    All AUGI, all the time
    Join Date
    2015-10
    Location
    Belgrade, Serbia, Europe
    Posts
    564
    Login to Give a bone
    0

    Default Re: Cycle through selections

    Yes, Lee Mac, thanks to you...

    To plot all viewports with Default Windows System Printer use this code :

    Code:
    (defun c:PLOTALLVPS (/ cspace ssvps i entvp vp ht wd vn ctr ctrx ctry vs xp iw bl br tr tl items)
      (command "pspace")
      (setq cspace (getvar "CTAB"))					
      (setq ssvps (ssget "_X" (list (cons 0 "VIEWPORT") (cons 410 cspace)) ))
      (setq i (- (sslength ssvps) 1))
      (repeat (- (sslength ssvps) 1)
      (setq i (1- i))
      (command "mspace")
      (setq entvp (ssname ssvps i))
      (setq vp (entget entvp)) 					
      (setq ht (cdr (assoc 41 vp)))				; Get Viewport height
      (setq wd (cdr (assoc 40 vp)))				; Get Viewport width
      (setq vn (cdr (assoc 69 vp)))				; Get Viewport CVPort variable
      (command "mspace")					
      (setvar "cvport" vn)					; Set correct viewport
      (command ".ucs" "v")					; Set UCS to View
      (setq ctr (getvar "viewctr"))				; Get VIEWCTR
      (setq ctrx (car ctr))					; Get X of CTR
      (setq ctry (cadr ctr))				; Get Y of CTR
      (setq vs (getvar "viewsize"))				; Get inside Viewport height
      (setq xp (/ ht vs))					; Get XP Factor with height 
    							
      (setq iw (* (/ vs ht) wd))				; Get inside width of Viewport
      (setq bl (list (- ctrx (/ iw 2)) (- ctry (/ vs 2))))
    							; Find four corners of Viewport
      (setq br (list (+ ctrx (/ iw 2)) (- ctry (/ vs 2))))
      (setq tr (list (+ ctrx (/ iw 2)) (+ ctry (/ vs 2))))
      (setq tl (list (- ctrx (/ iw 2)) (+ ctry (/ vs 2))))
      (setvar "TILEMODE" 1)
      (command "zoom" "w" bl tr)
      (command "-plot" "Y" "" "Default Windows System Printer.pc3" "" "" "L" "N" "W" bl tr "F" "C" "N" "" "Y" "" "N" "Y" "Y")
      (setvar "TILEMODE" 0)
      (command "pspace")
      )				
      (princ)						
    );defun
    M.R.
    Last edited by marko_ribar; 2011-06-24 at 04:16 PM. Reason: code changed as vn variable for "CVPORT" already used

  8. #8
    Member
    Join Date
    2009-06
    Location
    Florida
    Posts
    27
    Login to Give a bone
    0

    Default Re: Cycle through selections

    Marko I understand what you wrote but I don't think it will help me. To create a WMF you need to select all the objects to be included in the print. In paperspace if you select the viewport it will only print the viewport not the objects in it.

    To create a WMF with the WMFOUT command I will either need to move everything to Modelspace or Paperspace.

    I need the code below ran on each viewport individually. Selecting a viewport and cycling to the next one is where I need the help.

    Code:
    (defun changespace (/ ht wd vn ctr ctrx ctry vs xp iw bl br tr tl items)
      (setq ht (cdr (assoc 41 vp)))			; Get Viewport height
      (setq wd (cdr (assoc 40 vp)))			; Get Viewport width
      (setq vn (cdr (assoc 69 vp)))			; Get Viewport CVPort variable
      (command "mspace")					
      (setvar "cvport" vn)				; Set correct viewport
      (command ".ucs" "v")			; Set UCS to View
      (setq ctr (getvar "viewctr"))			; Get VIEWCTR
      (setq ctrx (car ctr))				; Get X of CTR
      (setq ctry (cadr ctr))				; Get Y of CTR
      (setq vs (getvar "viewsize"))			; Get inside Viewport height
      (setq xp (/ ht vs))				; Get XP Factor with height 
    							
      (setq iw (* (/ vs ht) wd))			; Get inside width of Viewport
      (setq bl (list (- ctrx (/ iw 2)) (- ctry (/ vs 2)))
    					; Find four corners of Viewport
      (setq br (list (+ ctrx (/ iw 2)) (- ctry (/ vs 2))))
      (setq tr (list (+ ctrx (/ iw 2)) (+ ctry (/ vs 2))))
      (setq tl (list (- ctrx (/ iw 2)) (+ ctry (/ vs 2))))
    
      (Setq items (ssget "w" bl tr))  		;Makes a selection set of all objects in selected vport
      (command "chspace" items "" "")				
      (command "pspace")				
      (princ)
    )

  9. #9
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,096
    Login to Give a bone
    0

    Default Re: Cycle through selections

    What AutoCAD version are you using? If you have 2009 or newer, you could try the ExportLayout command.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  10. #10
    100 Club
    Join Date
    2000-11
    Location
    Ontario, Canada
    Posts
    116
    Login to Give a bone
    0

    Default Re: Cycle through selections

    Quote Originally Posted by bbDmn0 View Post
    ...To create a WMF with the WMFOUT command I will either need to move everything to Modelspace or Paperspace.
    Actually, you just need to activate the paperspace viewport using the mspace command, and you can use wmfout on the modelspace objects it displays. Just select "All" when prompted for selection; it will only export what is displayed in the viewport.

    (edit) On further review, it occurs to me you want more than a single viewport in your exported wmf. In that case, this is not so helpful...
    Last edited by GHarvey; 2011-06-24 at 03:33 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Selections
    By jbervel in forum Robot Structural Analysis
    Replies: 1
    Last Post: 2010-05-06, 04:20 PM
  2. API Selections
    By justsagar in forum NavisWorks - General
    Replies: 8
    Last Post: 2010-01-25, 07:02 AM
  3. Sheet Selections
    By Opie in forum AutoCAD Sheet Set Manager
    Replies: 3
    Last Post: 2005-10-31, 12:42 PM
  4. Multi selections
    By G.Smith in forum Revit Architecture - Wish List
    Replies: 3
    Last Post: 2005-06-29, 07:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •