See the top rated post in this thread. Click here

Results 1 to 10 of 10

Thread: ssget will not find certain types of viewports

  1. #1
    Member
    Join Date
    2016-01
    Posts
    34
    Login to Give a bone
    0

    Default ssget will not find certain types of viewports

    Hi:

    This command -

    Code:
    (setq ents (ssget "_c" '(0 0) '(23.6 17.6) '((0 . "VIEWPORT"))))
    will find viewports all day long but only if it was created with mview & the 'Fit' option. If the viewport was created with 'Object' or 'Polyline' option nothing is found on that sheet.

    Any idea what I am missing?

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: ssget will not find certain types of viewports

    Viewports created by Object aren't the same, as they have pointers to the dependent entity, which is why Properties shows both as being selected.

    In a quick test, this seems to work:

    Code:
    (vl-load-com)
    
    (defun c:FOO (/ ss)  
      (if (ssget "_c" '(0 0) '(23.6 17.6))
        (progn
          (vlax-for x
                      (setq ss
                             (vla-get-activeselectionset
                               (vla-get-activedocument (vlax-get-acad-object))
                             )
                      )
            (if (= "AcDbViewport" (vla-get-objectname x))
              (vla-put-color x acred)                                       ;<-- do something useful
            )
          )
          (vla-delete ss)
        )
      )
      (princ)
    )
    ** Error handling not provided
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2016-01
    Posts
    34
    Login to Give a bone
    0

    Default Re: ssget will not find certain types of viewports

    Your code detects the view ports!! Sorry for the delay in replying but this has been a side project & I was hit with a few things that will earn us some money.

    I am still learning vla & vlax 'stuff' and am uncertain how to handle x. I end up using fragments found online or forum assistance and Frankenstein it in with my code. Below is what happens after I define ents. What I need help with is how to replace using ents with your method of seeing if there is only one viewport or more than one viewport.

    Code:
    (if ents
        (progn
          (setq numVP 0)			;for some reason have to define if no viewport on drawing's first sheet before next line
          (setq numVP (sslength ents))
          (cond ((> numVP 1)        ;More than 1 VP this sheet
             (setq vpScale "AS NOTED")
            )
            ((= numVP 1)        ;calulate VP scale
             (setq ent (ssname ents 0))
             (vpsc)            ;do the math
             (cond ((= vpMult 0.5) (setq vpScale "DOUBLE SIZE"))
               ((= vpMult 1) (setq vpScale "FULL SIZE"))
               ((= vpMult 2) (setq vpScale "HALF SIZE"))
               ((= vpMult 4) (setq vpScale "3"=1'-0""))
               ((= vpMult 8) (setq vpScale "1-1/2"=1'-0""))
               ((= vpMult 12) (setq vpScale "1"=1'-0""))
               ((= vpMult 16) (setq vpScale "3/4"=1'-0""))
               ((= vpMult 24) (setq vpScale "1/2"=1'-0""))
               ((= vpMult 32) (setq vpScale "3/8"=1'-0""))
               ((= vpMult 48) (setq vpScale "1/4"=1'-0""))
               ((= vpMult 64) (setq vpScale "3/16"=1'-0""))
               ((= vpMult 96) (setq vpScale "1/8"=1'-0""))
               (T (setq vpScale "AS NOTED"))
             )
            )
          )
        )
        (setq vpScale "NONE")        ;zero VP this sheet
      )

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: ssget will not find certain types of viewports

    Hard to assist with partial code that calls methods that aren't included; please save both of us some time and explain what you're trying to do in entirety.

    It looks like you're attempting to populate a title block attribute with the respective Viewport's scale value (for single Viewport, etc)?
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  5. #5
    Member
    Join Date
    2016-01
    Posts
    34
    Login to Give a bone
    0

    Default Re: ssget will not find certain types of viewports

    As requested, here is the full segment of code. This is for our manufacturing title block that was only using 'B' size sheets with the main viewport created with fit. Recently we have had to add a 'C' size sheet viewport created with polyline. Because I currently am the only using the 'C' size sheet, I have created a beta version where I trap the sheet size to run the current code on the 'B' size sheets. For the 'C' size sheets I put 'EDIT' into the scale attribute to remind me to manually correct later.

    Any help in converting from using ssget would be great. I have a rough idea what is happening when you setq ss but after that I'm lost.

    Code:
    (defun getVPscale (/ ent ents data numVP cvhgt cvsize vpMult) ;get the scale of the viewport
      (cond
        ((= shtSize "B")
         (setq ents (ssget "_c" '(0 0) '(16.3762 10.25) '((0 . "VIEWPORT"))))
        )
        ((= shtSize "C")
         (if (ssget "_c" '(0 0) '(23.6 17.6))
           (progn
    	 (vlax-for x
    		     (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
    	   (if (= "AcDbViewport" (vla-get-objectname x))
    	     (setq vpScale "EDIT")
    	   )
    	 )
    	 (vla-delete ss)
           )
         )
        )
      )
      (if ents
        (progn
          (setq numVP 0)
          (setq numVP (sslength ents))
          (cond ((> numVP 1)		;More than 1 VP this sheet
    	     (setq vpScale "AS NOTED")
    	    )
    	    ((= numVP 1)		;calulate VP scale
    	     (setq ent (ssname ents 0))
    	     (vpsc)			;do the math
    	     (cond ((= vpMult 0.5) (setq vpScale "DOUBLE SIZE"))
    		   ((= vpMult 1) (setq vpScale "FULL SIZE"))
    		   ((= vpMult 2) (setq vpScale "HALF SIZE"))
    		   ((= vpMult 4) (setq vpScale "3\"=1'-0\""))
    		   ((= vpMult 8) (setq vpScale "1-1/2\"=1'-0\""))
    		   ((= vpMult 12) (setq vpScale "1\"=1'-0\""))
    		   ((= vpMult 16) (setq vpScale "3/4\"=1'-0\""))
    		   ((= vpMult 24) (setq vpScale "1/2\"=1'-0\""))
    		   ((= vpMult 32) (setq vpScale "3/8\"=1'-0\""))
    		   ((= vpMult 48) (setq vpScale "1/4\"=1'-0\""))
    		   ((= vpMult 64) (setq vpScale "3/16\"=1'-0\""))
    		   ((= vpMult 96) (setq vpScale "1/8\"=1'-0\""))
    		   (T (setq vpScale "AS NOTED"))
    	     )
    	    )
    	    (T (setq vpScale "NONE"))		;zero VP this sheet
          )
        )
      )
    )
    
    (defun vpsc (/ entData vpScale_act ash ash1 ash2)
      (if ent
        (progn
          (setq entData (entget ent))
          (cond ((= (cdr (assoc 0 entData)) "VIEWPORT")
    	     T
    	    )
    	    ((and (= (cdr (assoc 0 entData)) "LWPOLYLINE") (assoc 330 entData))
    	     (setq entData (entget (cdr (assoc 330 entData))))
    	    )
    	    (T
    	     (setq entData nil)
    	    )
          )
          (if entData
    	(setq vpScale_act (/ (cdr (assoc 45 entData)) (cdr (assoc 41 entData))))
          )
        )
      )
      (if vpScale_act
        (progn
          (setq ash (LM:roundto vpScale_act 4))
          (cond ((>= ash 1)
    	     (setq vpMult (fix vpScale_act)
    		   ash1	  (/ ash vpMult)
    		   ash2	  (LM:roundto ash1 2)
    	     )
    	    )
    	    ((= ash 0.5)
    	     (setq vpMult ash
    		   ash2	1
    	     )
    	    )
    	    ((< ash 1) (setq vpMult 0))
          )
          (if (/= ash2 1)
    	(setq vpMult 0)
          )
        )
      )
    )

  6. #6
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: ssget will not find certain types of viewports

    Again, incomplete code; multiple variables are set outside of this scope & sub-functions are not included.

    That said, you just need a selection set of Viewport entities, right?

    If so, change this:
    Code:
    (defun getVPscale (/ ent ents data numVP cvhgt cvsize vpMult) ;get the scale of the viewport
      (cond
        ((= shtSize "B")
         (setq ents (ssget "_c" '(0 0) '(16.3762 10.25) '((0 . "VIEWPORT"))))
        )
        ((= shtSize "C")
         (if (ssget "_c" '(0 0) '(23.6 17.6))
           (progn
    	 (vlax-for x
    		     (setq ss (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
    	   (if (= "AcDbViewport" (vla-get-objectname x))
    	     (setq vpScale "EDIT")
    	   )
    	 )
    	 (vla-delete ss)
           )
         )
        )
      )
    
    ;; <snip>
    To this:
    Code:
    (defun getVPscale (/ ent ents data numVP cvhgt cvsize vpMult) ;get the scale of the viewport
      (cond
        ((= shtSize "B")
         (setq ents (_GetViewports '(0 0) '(16.3762 10.25)))
        )
        ((= shtSize "C")
         (setq ents (_GetViewports '(0 0) '(23.6 17.6)))
        )
      )
    
    ;; <snip>
    Here's the _GetViewports sub-function:
    Code:
    (vl-load-com)
    
    (defun _GetViewports (pt1 pt2 / *error* ss vps ents)
      ;; Example: 
      ;; (_GetViewports '(0 0) '(23.6 17.6))
    
      (defun *error* (msg)
        (if ss (vla-delete ss))
        (cond ((not msg))                                                   ; Normal exit
              ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
              ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
        )
        ents
      )
    
      (if (ssget "_c" pt1 pt2)
        (progn
          (vlax-for x (setq ss
                             (vla-get-activeselectionset
                               (vla-get-activedocument (vlax-get-acad-object))
                             )
                      )
            (if (= "AcDbViewport" (vla-get-objectname x))
              (setq vps (cons (vlax-vla-object->ename x) vps))
            )
          )
          (if vps
            (progn
              (setq ents (ssadd))
              (foreach vp vps
                (setq ents (ssadd vp ents))
              )
            )
          )
        )
      )
    
      (*error* nil)
    )
    Last edited by BlackBox; 2019-09-04 at 08:13 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  7. #7
    Member
    Join Date
    2016-01
    Posts
    34
    Login to Give a bone
    0

    Default Re: ssget will not find certain types of viewports

    Thank you. Your solution is working great no matter the type of viewport on the sheet.

    The only issue is where I check if there is more than one viewport on a sheet in the getVPscale function:

    Code:
    ;; snip
    (if ents
        (progn
          (setq numVP 0) ;; hack if 1st sheet has 0 viewports
          (setq numVP (sslength ents))
    ;; snip

    If there are one or more viewports on the sheet it sets numVP to 1 and not the quantity of viewports. Should I be using something other than sslength?

    And sorry for not including my call to Lee Mac's round function. That was my hack that I was planning on cutting while updating for the 'C' size title block. We had a couple guys who insisted on just zoom object to the model space border rather than setting one of the preset zooms in the template drawing - "Close enough". [Know why they are no longer here?]

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    1

    Default Re: ssget will not find certain types of viewports

    No worries; just ribbing you.

    Looks like I neglected to include the SS to which the valid Viewports were to be added, which is why you were getting 1 as the SSLENGTH count.

    I've revised the _GetViewports sub-function above.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  9. #9
    Member
    Join Date
    2016-01
    Posts
    34
    Login to Give a bone
    0

    Default Re: ssget will not find certain types of viewports

    Works great!!! Thank you for your help and your patience in working with a self-taught lisp programmer. =^.^=

  10. #10
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: ssget will not find certain types of viewports

    Quote Originally Posted by lynx_20 View Post
    Works great!!! Thank you for your help and your patience in working with a self-taught lisp programmer. =^.^=
    You're welcome; happy to help.

    Everyone is self-taught (really); if we're lucky, we choose to learn by taking what we like from those willing to share knowledge, otherwise failure will teach us a lot.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. Replies: 9
    Last Post: 2015-11-24, 05:38 PM
  2. ssget "X" vs ssget "_X" - what's the difference
    By mark_hartman in forum AutoLISP
    Replies: 11
    Last Post: 2008-02-27, 04:50 AM
  3. SSGET returns error - bad SSGET list
    By tany0070 in forum AutoLISP
    Replies: 2
    Last Post: 2007-03-09, 07:26 AM
  4. Assign certain Object types to certain Layers
    By mckishen in forum AutoCAD General
    Replies: 8
    Last Post: 2006-02-27, 11:22 PM
  5. Replies: 20
    Last Post: 2006-02-15, 08:31 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
  •