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?
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
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
)
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)?
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)
)
)
)
)
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. :mrgreen:
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)
)
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?]
Re: ssget will not find certain types of viewports
No worries; just ribbing you. :beer:
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. :Oops: :mrgreen:
I've revised the _GetViewports sub-function above.
Cheers
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. =^.^=
Re: ssget will not find certain types of viewports
Quote:
Originally Posted by
lynx_20
Works great!!! Thank you for your help and your patience in working with a self-taught lisp programmer. =^.^=
You're welcome; happy to help. :beer:
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. :mrgreen:
Cheers