Author Topic: Filter by Z-Value  (Read 6848 times)

0 Members and 1 Guest are viewing this topic.

Rooster

  • Guest
Filter by Z-Value
« on: January 14, 2009, 09:38:32 AM »
I'm trying to use a LISP that I've edited to select all objects with a z-value of -999, but when I run it AutoCAD doesn't pick anything up. Can anyone see where I'm going wrong?

(defun c:fz999(/ cSet)

  (setq cSet(ssget
      '((10 . *, *, -999))
      ); end ssget
  ); end setq

(if cSet
  (progn
     (princ(strcat "\n" (itoa(sslength cSet)) " found."))
     (sssetfirst nil cSet)
  ); end progn
  (princ "\nNothing found. ")
); end if
(princ)
); end of c:fz999

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Filter by Z-Value
« Reply #1 on: January 14, 2009, 10:09:42 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Rooster

  • Guest
Re: Filter by Z-Value
« Reply #2 on: January 14, 2009, 10:14:36 AM »
Ah - thankyou. That looks promising......

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Filter by Z-Value
« Reply #3 on: January 14, 2009, 10:16:17 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Filter by Z-Value
« Reply #4 on: January 14, 2009, 10:18:07 AM »
Let us know if you still have trouble with it.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Rooster

  • Guest
Re: Filter by Z-Value
« Reply #5 on: January 14, 2009, 10:32:14 AM »
Let us know if you still have trouble with it.

Thanks - I used your first example to get this....

;FILTERS ALL OBJECTS WITH Z-VALUE OF -999
(defun c:fz9(/ cSet)

  (setq cSet(ssget "X"
               '((-4 . "*,*,=") (10 . 0.0 0.0 -999.0))
             ); end ssget
   ); end setq
 
  (if cSet
    (progn
      (princ(strcat "\n" (itoa(sslength cSet)) " found."))
      (sssetfirst nil cSet)
      ); end progn
     (princ "\nNothing found. ")
    ); end if
  (princ)
  ); end of c:fz9

....and that worked for me once, but now when I try to run my LISP again I get an 'Unknown Command' error upon entering fz9, which is really puzzling me. I've made sure of all the obvious things like no typos, LISP loaded into drawing, etc.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Filter by Z-Value
« Reply #6 on: January 14, 2009, 10:40:26 AM »
Try this one:

Code: [Select]
;;FILTERS ALL OBJECTS WITH Z-VALUE OF -999
(defun c:fz9 (/ cSet)
  (if (setq cSet (ssget "X"
'((-4 . "*,*,=") (10 0.0 0.0 -999.0))
)
      )
    (progn
      (princ (strcat "\n" (itoa (sslength cSet)) " found."))
      (sssetfirst nil cSet)
    )
    ;; end progn
    (princ "\nNothing found. ")
  )
  ;; end if
  (princ)
)
;; end of c:fz9

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Filter by Z-Value
« Reply #7 on: January 14, 2009, 10:41:50 AM »
You had a dot that didn't belong.
Use this
Code: [Select]
(10 0.0 0.0 -999.0)
Urg, Ron's just too fast. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dustinthiesse

  • Guest
Re: Filter by Z-Value
« Reply #8 on: January 14, 2009, 10:44:36 AM »
Take a look here: 8-)
http://www.theswamp.org/index.php?topic=1333.msg16766#msg16766

Nice.  I had never seen that done before.  I was testing it out on some drawings that we received from some other company where they had things on all kinds of different Z levels.  I used

Code: [Select]
(setq sset(ssget "X" '((-4 . "*,*,/=")(10 0.0 0.0 0.0))))

to grab everything not on Z=0 and then set them all to zero.

It worked on most of the entities, but it doesn't seem to find the Mtext and Leaders.  None of those object types changed value, and the above statement returns nil even though there are objects set to other various Z values.

I even inspected a couple of the entities to make sure that the group 10 DXF code did have a value other than 0.0 for the Z position which turned out to be true.  Any ideas?

Rooster

  • Guest
Re: Filter by Z-Value
« Reply #9 on: January 14, 2009, 10:46:49 AM »
You had a dot that didn't belong.

Ah - so simple. Thanks :)

Rooster

  • Guest
Re: Filter by Z-Value
« Reply #10 on: January 14, 2009, 10:53:19 AM »
Ok, now my problem is that on my function for filtering all objects with a z-value of 0 I'm getting 3D polylines selected, even though their z-values are not 0 - being polylines, they have multiple z-values. How do I get around this?

;FILTERS ALL OBJECTS WITH Z-VALUE OF 0
(defun c:fz0(/ cSet)

  (setq cSet(ssget
               '((-4 . "*,*,=") (10 0.0 0.0 0.0))
             ); end ssget
   ); end setq
 
  (if cSet
    (progn
      (princ(strcat "\n" (itoa(sslength cSet)) " found."))
      (sssetfirst nil cSet)
      ); end progn
     (princ "\nNothing found. ")
    ); end if
  (princ)
  ); end of c:fz0

EDIT: looking at the DXF codes of the 3D polylines, their group 10 value is 0.0, so obviously it's another group code that I need to work with, but I can't work out which one.....
« Last Edit: January 14, 2009, 10:59:48 AM by Rooster »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Filter by Z-Value
« Reply #11 on: January 14, 2009, 11:06:59 AM »
You could mess around with this filter....not sure if it will work for you since it disregards 3dpoly's.

Code: [Select]
(setq cSet (ssget "X"
'((-4 . "<OR")
  (-4 . "*,*,=")
  (10 0.0 0.0 -999.000)
  (38 . -999.0);;polyline elevation
  (-4 . "<NOT")
  (100 . "AcDb3dPolyline");;not 3d poly's
  (-4 . "NOT>")
  (-4 . "OR>")
)
)
      )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Rooster

  • Guest
Re: Filter by Z-Value
« Reply #12 on: January 14, 2009, 11:12:39 AM »
You could mess around with this filter....not sure if it will work for you since it disregards 3dpoly's

Thanks ronjonp, but that's still picking up my 3D polylines that I want it to leave well alone.....

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Filter by Z-Value
« Reply #13 on: January 14, 2009, 11:20:21 AM »
d-unit
could you post a sample DWG for testing?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dustinthiesse

  • Guest
Re: Filter by Z-Value
« Reply #14 on: January 14, 2009, 11:30:12 AM »
d-unit
could you post a sample DWG for testing?

There are 4 Mtext and 3 leader objects that are at Z=2700 that will not go to Z=0 using the attached code.
Thanks in advance CAB.

(Also, it looks like there is a block that has an attribute on a different Z value as well.  I haven't looked into that one yet.)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Filter by Z-Value
« Reply #15 on: January 14, 2009, 11:35:22 AM »
Sounds like you need to use Joe Burke's superflatten routine.

http://www.theswamp.org/index.php?topic=18153.0

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Rooster

  • Guest
Re: Filter by Z-Value
« Reply #16 on: January 14, 2009, 11:40:56 AM »
seems like there are two threads in one here, lol  :lol:

So anyway, I think I have my LISP doing what I want with this:

Code: [Select]
(defun c:fz0(/ cSet)

(setq cSet (ssget
'((-4 . "*,*,=")
  (10 0.0 0.0 0.000)
  (-4 . "<NOT")
  (0 . "LWPOLYLINE,POLYLINE");;not polylines
  (-4 . "NOT>")
)
)
      )
 
  (if cSet
    (progn
      (princ(strcat "\n" (itoa(sslength cSet)) " found."))
      (sssetfirst nil cSet)
      ); end progn
     (princ "\nNothing found. ")
    ); end if
  (princ)
  ); end of c:fz0

So my last question is how do I now edit this so that it selects objects with z of either 0.0 or -999.0
I did try experimenting with (-4 . "<XOR") but it didn't seem to work....

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Filter by Z-Value
« Reply #17 on: January 14, 2009, 11:55:52 AM »
This seems to work:

Code: [Select]
(setq cset (ssget "x"
  '((-4 . "<OR")
    (-4 . "*,*,=")
    (10 0.0 0.0 0.000)
    (-4 . "*,*,=")
    (10 0.0 0.0 -999.0)
    (-4 . "OR>")
    (-4 . "<NOT")
    (0 . "LWPOLYLINE,POLYLINE")
    ;;not polylines
    (-4 . "NOT>")
   )
   )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Filter by Z-Value
« Reply #18 on: January 14, 2009, 12:30:20 PM »
d-unit
could you post a sample DWG for testing?

There are 4 Mtext and 3 leader objects that are at Z=2700 that will not go to Z=0 using the attached code.
Thanks in advance CAB.

(Also, it looks like there is a block that has an attribute on a different Z value as well.  I haven't looked into that one yet.)

See link in Ron's post or the old Flatten worked too.
Maybe because it has a dictionary attached, not sure but don't have time to investigate at the moment.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dustinthiesse

  • Guest
Re: Filter by Z-Value
« Reply #19 on: January 14, 2009, 01:08:42 PM »
d-unit
could you post a sample DWG for testing?

There are 4 Mtext and 3 leader objects that are at Z=2700 that will not go to Z=0 using the attached code.
Thanks in advance CAB.

(Also, it looks like there is a block that has an attribute on a different Z value as well.  I haven't looked into that one yet.)

See link in Ron's post or the old Flatten worked too.
Maybe because it has a dictionary attached, not sure but don't have time to investigate at the moment.

Thanks for the link Ron!  Worked like a charm.  I tried the express tools flatten, but it converted leaders into Plines and Mtext into Text (and got rid of my fields!).  Superflatten keeps the objects the same...one of these days I'll have to dissect that program so I can learn from it.  8-)

Rooster

  • Guest
Re: Filter by Z-Value
« Reply #20 on: January 15, 2009, 04:08:48 AM »

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Filter by Z-Value
« Reply #21 on: January 15, 2009, 05:13:00 PM »
You're welcome :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC