TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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
-
Take a look here: 8-)
http://www.theswamp.org/index.php?topic=1333.msg16766#msg16766
-
Ah - thankyou. That looks promising......
-
Another example:
http://www.theswamp.org/index.php?topic=12490.msg153883#msg153883
-
Let us know if you still have trouble with it.
-
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.
-
Try this one:
;;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
-
You had a dot that didn't belong.
Use this
(10 0.0 0.0 -999.0)
Urg, Ron's just too fast. :-)
-
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
(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?
-
You had a dot that didn't belong.
Ah - so simple. Thanks :)
-
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.....
-
You could mess around with this filter....not sure if it will work for you since it disregards 3dpoly's.
(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>")
)
)
)
-
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.....
-
d-unit
could you post a sample DWG for testing?
-
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.)
-
Sounds like you need to use Joe Burke's superflatten routine.
http://www.theswamp.org/index.php?topic=18153.0
-
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:
(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....
-
This seems to work:
(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>")
)
)
)
-
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.
-
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-)
-
This seems to work:
Thanks ronjonp :)
-
You're welcome :)