TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Rooster on January 14, 2009, 09:38:32 AM

Title: Filter by Z-Value
Post by: Rooster 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
Title: Re: Filter by Z-Value
Post by: CAB on January 14, 2009, 10:09:42 AM
Take a look here: 8-)
http://www.theswamp.org/index.php?topic=1333.msg16766#msg16766
Title: Re: Filter by Z-Value
Post by: Rooster on January 14, 2009, 10:14:36 AM
Ah - thankyou. That looks promising......
Title: Re: Filter by Z-Value
Post by: CAB on January 14, 2009, 10:16:17 AM
Another example:
http://www.theswamp.org/index.php?topic=12490.msg153883#msg153883
Title: Re: Filter by Z-Value
Post by: CAB on January 14, 2009, 10:18:07 AM
Let us know if you still have trouble with it.
Title: Re: Filter by Z-Value
Post by: Rooster 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.
Title: Re: Filter by Z-Value
Post by: ronjonp 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
Title: Re: Filter by Z-Value
Post by: CAB 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. :-)
Title: Re: Filter by Z-Value
Post by: dustinthiesse 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?
Title: Re: Filter by Z-Value
Post by: Rooster on January 14, 2009, 10:46:49 AM
You had a dot that didn't belong.

Ah - so simple. Thanks :)
Title: Re: Filter by Z-Value
Post by: Rooster 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.....
Title: Re: Filter by Z-Value
Post by: ronjonp 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>")
)
)
      )
Title: Re: Filter by Z-Value
Post by: Rooster 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.....
Title: Re: Filter by Z-Value
Post by: CAB on January 14, 2009, 11:20:21 AM
d-unit
could you post a sample DWG for testing?
Title: Re: Filter by Z-Value
Post by: dustinthiesse 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.)
Title: Re: Filter by Z-Value
Post by: ronjonp 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
Title: Re: Filter by Z-Value
Post by: Rooster 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....
Title: Re: Filter by Z-Value
Post by: ronjonp 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>")
   )
   )
)
Title: Re: Filter by Z-Value
Post by: CAB 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.
Title: Re: Filter by Z-Value
Post by: dustinthiesse 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-)
Title: Re: Filter by Z-Value
Post by: Rooster on January 15, 2009, 04:08:48 AM
This seems to work:

Thanks ronjonp :)
Title: Re: Filter by Z-Value
Post by: ronjonp on January 15, 2009, 05:13:00 PM
You're welcome :)