Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

having issues with filtering in ssget

4 REPLIES 4
Reply
Message 1 of 5
AR12
466 Views, 4 Replies

having issues with filtering in ssget

Ok so what I'm trying to do is, get a MTEXT that is at a specific point. Here is what I am trying to do:(UCS is a variable set

earlier in the code):

 

(setq WCS UCS)
(setq WCSX (car WCS))
(setq WCSY (cadr WCS))
(setq WCSZ (caddr WCS))
(setq WCSX1 (+ WCSX 5.3164))
(setq WCSY1 (+ WCSY 5.6625))
(setq WCSZ1 (+ WCSZ 0.0000))
(setq WCS1 (list WCSX1 WCSY1 WCSZ1))
(setq ListFilter (list (cons 0 "MTEXT") (cons 10 WCS1)))
(setq BKFTHICKNESS (ssget "X" ListFilter))
(setq listlength (sslength BKFTHICKNESS))

 

In my example, UCS is currently set to (0.0 0.0 0.0). I have the UCS set to this point, which the WCS would be (7.5 9.025 0.0). The MTEXT that I'm trying to locate on my example is 0.500\", if I use (cons 1 "0.500\"") instead of (cons 10 WCS1) it is able to find it. I have pasted below what I get if I do a ssget on the text I am looking for.

 

((-1 . <Entity name: 7ffffb2c220>) (0 . "MTEXT") (330 . <Entity name: 7ffffb289b0>) (5 . "AF2") (100 . "AcDbEntity") (67 . 1) (410 . "Drawing") (8 . "Main") (390 . <Entity name: 7ffffb28a80>) (100 . "AcDbMText") (10 13.5 14.6875 0.0) (40 . 0.125) (41 . 0.88) (46 . 0.0) (71 . 9) (72 . 5) (1 . "0.500\"") (7 . "Valmont") (210 0.0 0.0 1.0) (11 1.0 0.0 0.0) (42 . 0.678385) (43 . 0.139323) (50 . 0.0) (73 . 1) (44 . 0.9))


In the case of my example, WCS1 is set to (10 13.5 14.6875 0.0) .

Thanks,
Adam Richardson

If needed: AutoCAD 2017 User using Visual LISP for editing LISP and DCL files
4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: AR12


@AR12 wrote:

Ok so what I'm trying to do is, get a MTEXT that is at a specific point. .... 

(setq WCS UCS)
(setq WCSX (car WCS))
(setq WCSY (cadr WCS))
(setq WCSZ (caddr WCS))
(setq WCSX1 (+ WCSX 5.3164))
(setq WCSY1 (+ WCSY 5.6625))
(setq WCSZ1 (+ WCSZ 0.0000))
(setq WCS1 (list WCSX1 WCSY1 WCSZ1))
(setq ListFilter (list (cons 0 "MTEXT") (cons 10 WCS1)))
(setq BKFTHICKNESS (ssget "X" ListFilter))
(setq listlength (sslength BKFTHICKNESS))

 

In my example, UCS is currently set to (0.0 0.0 0.0). I have the UCS set to this point, which the WCS would be (7.5 9.025 0.0). .... I have pasted below what I get if I do a ssget on the text I am looking for.

 

(... (10 13.5 14.6875 0.0) ...)

In the case of my example, WCS1 is set to (10 13.5 14.6875 0.0) .


As an aside, there's a much slicker way to add XYZ values to a point list, which can spare you the need for the WCS variable entirely.  And you can combine multiple (setq)'s into one function.  You can do all of that this way:

 

(setq

  WCS1 (mapcar '+ UCS '(5.3164 5.6625 0.0))
  ListFilter (list (cons 0 "MTEXT") (cons 10 WCS1))
  BKFTHICKNESS (ssget "X" ListFilter)
  listlength (sslength BKFTHICKNESS)

); setq

 

And you could consolidate even further:

 

(setq

  WCS1 (mapcar '+ UCS '(5.3164 5.6625 0.0))
  BKFTHICKNESS (ssget "X" (list (cons 0 "MTEXT") (cons 10 WCS1)))
  listlength (sslength BKFTHICKNESS)

); setq

 

My first question would be:  Are those decimal values in WCS1 and the (assoc 10) entry precise, or are they the result of object-snapping or some kind of calculation?  If they're precisely accurate values, then it ought to find that item, but if they're rounded in any way, and have more decimal places that it's not showing, it won't.  You might overcome that by adding point values that you get from some source other than explicitly spelling out their XYZ values, e.g.

(setq WCS1 (mapcar '+ UCS (getvar 'ucsorg)))

But it's not clear to me whether that's the appropriate System Variable -- it depends on where your adjustment values are coming from.

 

I also wonder about using (trans) on something, but if what (entget) returns for the (assoc 10) entry is the same as what (cons 10 WCS1) returns, that shouldn't be the issue.

Kent Cooper, AIA
Message 3 of 5
Hallex
in reply to: AR12

You might be want to use fuzz toselect at point

;; some point specified mtext position

(setq pt '(-333.122  15.8563 0.0);|<-- your point coordinates|;
      fuzz 0.01);; small double increment, set to suit
(if
  (setq sset
(ssget "_X"
       (list (cons 0 "mtext")
	     (cons -4 "<or")
	     (cons -4 ">,*,*")
	     (cons 10 (list (- (car pt) fuzz) (cadr pt) (caddr pt)))
	     (cons -4 "<,*,*")
	     (cons 10 (list (+ (car pt) fuzz) (cadr pt) (caddr pt)))
	     (cons -4 "or>")
	     (cons 410 (getvar 'ctab)))))
(alert (cdr (assoc 1 (entget (setq mtx (ssname sset 0)))))))

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 4 of 5
AR12
in reply to: Kent1Cooper

Kent,

I'm aware of being able to consolidate, but I usually try to get it working as seperate lines before combining so that if there's an issue with a single line I can adjust and test without having to run the whole string of code.

 

As for your first question:


@Kent1Cooper wrote:

My first question would be:  Are those decimal values in WCS1 and the (assoc 10) entry precise, or are they the result of object-snapping or some kind of calculation?  If they're precisely accurate values, then it ought to find that item, but if they're rounded in any way, and have more decimal places that it's not showing, it won't.  You might overcome that by adding point values that you get from some source other than explicitly spelling out their XYZ values, e.g.

(setq WCS1 (mapcar '+ UCS (getvar 'ucsorg)))



The point UCS is determined via a user pick, which for my example I use the End Point Osnap and select the bottom left corner of a box. The MTEXT is at (6.0000 5.6625 0.0) when I view it in properties after setting the UCS Origin to the point UCS. My paste was actually from when I was trying to explode it into regular TEXT and see if it could find it, so my numbers were off, which of course that hadn't worked either.

 

Hallex,

I'm not sure about fuzz, I've never used fuzz before in lisp coding, and the only thing I can find in the AutoCAD 2013 Development help about fuzz is in (equal).

Thanks,
Adam Richardson

If needed: AutoCAD 2017 User using Visual LISP for editing LISP and DCL files
Message 5 of 5
AR12
in reply to: AR12

Ok so I switched my code around a little bit and discovered the following. If I find the MTEXT that I need with the (ssget) function when I compare the WCS1 variable to a variable I created using (cdr (assoc 10 (entget (ssname (ssget functions, I get the following by using fuzz that if I have a fuzz of 0.00000001 it does not come out as true, but if I use less of a Fuzz it comes out as true. This tells me that although visually they are equal, my locations are not truely equal. Any ideas how I can get around this? the WCS1 variable is calculated based on a user pick location.

Thanks,
Adam Richardson

If needed: AutoCAD 2017 User using Visual LISP for editing LISP and DCL files

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost