Jump to content

Recommended Posts

Posted

I've got two questions/problems with this code:

 

(defun c:cd (/ opt ss1 i ent_i z1 z2 z3 z4)
 (setvar 'cmdecho 0)
 (or lay (setq lay "*TOP*"))
 (or elv (setq elv 29.))
 (while (/= opt "Continue")
   (princ "\nCurrent settings: ")
   (princ (strcat "\nLayer: " (if (= lay "*TOP*") "Any Object with \"TOP\" in the layer name" lay)))
   (princ (strcat "\nElevation: " (rtos elv 2 4)))
   (initget "lAyer Elevation Continue")
   (setq opt (cond
 ((getkword "\nEnter an option to change or press enter to continue [lAyer/Elevation/<Continue>]: "))
 ("Continue")))
   (cond
     ((= opt "lAyer")
      (setq obj (entsel "\nSelect object on desired layer: "))
      (while (not obj) (setq obj (entsel "\nNo object selected, try again: ")))
      (setq lay (cdr (assoc 8 (entget (car obj))))))
     
     ((= opt "Elevation")
      (setq elv (cond
    ((getdist (strcat "\nEnter elevation <" (rtos elv 2 4) ">: ")))
    (elv))))))
 (setq ss1 (ssget "_x" (list (cons 0 "3dface")
        (cons 8 lay)
        (cons 410 "Model"))))
 (setq i -1)
 (while (setq ent_i (ssname ss1 (setq i (1+ i))))
   (setq z1 (caddr (cdr (assoc 10 (entget ent_i)))))
   (setq z2 (caddr (cdr (assoc 11 (entget ent_i)))))
   (setq z3 (caddr (cdr (assoc 12 (entget ent_i)))))
   (setq z4 (caddr (cdr (assoc 13 (entget ent_i)))))
   (if (not (and (eq z1 elv) (eq z2 elv) (eq z3 elv) (eq z4 elv)))
     (entdel ent_i)))
 (setvar 'cmdecho 1)
 (princ))

 

First question is regaring this protion:

(setq i -1)
 (while (setq ent_i (ssname ss1 (setq i (1+ i))))
   (setq z1 (caddr (cdr (assoc 10 (entget ent_i)))))
   (setq z2 (caddr (cdr (assoc 11 (entget ent_i)))))
   (setq z3 (caddr (cdr (assoc 12 (entget ent_i)))))
   (setq z4 (caddr (cdr (assoc 13 (entget ent_i)))))
   (if (not (and (eq z1 elv) (eq z2 elv) (eq z3 elv) (eq z4 elv)))
     (entdel ent_i)))

 

I'm thinking there is a way to simplify this code using the lambda function, but I don't really know how to do it. So my question would be is it possible and if it is, can someone hint how it might be done?

 

 

The problem I'm having is with this part:

 

(and (eq z1 elv) (eq z2 elv) (eq z3 elv) (eq z4 elv))

 

Its stopping on the first "eq" even though the values in the watch list say "z1" is "29." and elv is "29.", and I know dealing with the "=", "eq", and "equal" functions can get tricky, so I'm wondering what I'm doing wrong here.

 

All help would be greatly appriciated.

  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • alanjt

    11

  • KRBeckman

    10

  • BlackBox

    2

  • Lee Mac

    1

Popular Days

Top Posters In This Topic

Posted Images

Posted (edited)

(setq data (entget ent_i))
(apply 'and (mapcar '(lambda (code) (equal elv (cadddr (assoc code data)) 0.0001)) '(10 11 12 13)))

OR

 

(setq data (entget ent_i))
(vl-every '(lambda (code) (equal elv (cadddr (assoc code data)) 0.0001)) '(10 11 12 13))

Edited by alanjt
Posted
(setq data (entget ent_i))
(apply 'and (mapcar (code) (equal elv (cadddr (assoc code data))) '(10 11 12 13)))

 

 

OR

 

(setq data (entget ent_i))
(vl-every '(lambda (code) (equal elv (cadddr (assoc code data)))) '(10 11 12 13))

 

 

So, in this case, "equal" is the correct function to use... I've tried to read previous posts to determine why that is, but I haven't been able to fully understand it. Anyway thanks for the help!!

Posted
So, in this case, "equal" is the correct function to use... I've tried to read previous posts to determine why that is, but I haven't been able to fully understand it. Anyway thanks for the help!!

In this situation, equal would be my choice since it allows for a fuzz factor whereas eq or = will not.

 

Oops, I forgot to include a fuzz factor (update as you see fit) and there was some slop in my code - result of fingers typing faster than my brain can think.

Posted

Give this a try:

 

((lambda (i / ent_i eList)
  (while (setq ent_i (ssname ss1 (setq i (1+ i))))
    (setq z1 (caddr (cdr (assoc 10 (setq eList (entget ent_i))))))
    (setq z2 (caddr (cdr (assoc 11 eList))))
    (setq z3 (caddr (cdr (assoc 12 eList))))
    (setq z4 (caddr (cdr (assoc 13 eList))))
    (if (not (and (= z1 elv) (= z2 elv) (= z3 elv) (= z4 elv)))
      (entdel ent_i))))
 -1)

Posted
Give this a try:

 

((lambda (i / ent_i eList)
  (while (setq ent_i (ssname ss1 (setq i (1+ i))))
    (setq z1 (caddr (cdr (assoc 10 (setq eList (entget ent_i))))))
    (setq z2 (caddr (cdr (assoc 11 eList))))
    (setq z3 (caddr (cdr (assoc 12 eList))))
    (setq z4 (caddr (cdr (assoc 13 eList))))
    (if (not (and (= z1 elv) (= z2 elv) (= z3 elv) (= z4 elv)))
      (entdel ent_i))))
 -1)

If that's all he wanted, I'm going to be severely disappointed.

Posted
(setq data (entget ent_i))
(apply 'and (mapcar '(lambda (code) (equal elv (cadddr (assoc code data)) 0.0001)) '(10 11 12 13)))

OR

 

(setq data (entget ent_i))
(vl-every '(lambda (code) (equal elv (cadddr (assoc code data)) 0.0001)) '(10 11 12 13))

 

I'm having a hard time combining this with the if/then function, how does that work?

Posted
If that's all he wanted, I'm going to be severely disappointed.

 

No, I was looking for something more like alanjt gave me.

Posted
I'm having a hard time combining this with the if/then function, how does that work?

 

(setq i -1)
(while (setq ent_i (ssname ss1 (setq i (1+ i))))
 (setq data (entget ent_i))
 (if (apply 'and
            (mapcar '(lambda (code) (equal elv (cadddr (assoc code data)) 0.0001)) '(10 11 12 13))
     )
   (entdel ent_i)
 )
)

Posted

This is going to sound n00bish, but I don't work in 3d; how do you create a 3dface? I might be able to help you more if I can actually look at the object.

Posted
This is going to sound n00bish, but I don't work in 3d; how do you create a 3dface? I might be able to help you more if I can actually look at the object.

LoL, I guess I should have typed "3dface".embarrassed_smiley.gif

 

I was just curious if there was another way to accomplish the checking portion.

Posted
This is going to sound n00bish, but I don't work in 3d; how do you create a 3dface? I might be able to help you more if I can actually look at the object.

 

I attached an example of when I would use this... basically I want it to delete all the faces on the bottom of this desk top.

SYM-201052-1-A.dwg

Posted
(setq i -1)
(while (setq ent_i (ssname ss1 (setq i (1+ i))))
(setq data (entget ent_i))
(if (apply 'and
(mapcar '(lambda (code) (equal elv (cadddr (assoc code data)) 0.0001)) '(10 11 12 13))
)
(entdel ent_i)
)
)

 

Had to change the code slightly:

 

(while (setq ent_i(ssname ss1 (setq i (1+ i))))
   (setq data (entget ent_i))
   (if (apply 'and
       (mapcar '(lambda (code) (not (equal elv (cadddr (assoc code data)) 0.0001))) '(10 11 12 13))
       )
     (entdel ent_i)
     )
   )

 

So that way it deletes the one's that are NOT at the specified elevation.

 

Also, thanks again for all the help.

Posted
Had to change the code slightly:

 

(while (setq ent_i(ssname ss1 (setq i (1+ i))))
   (setq data (entget ent_i))
   (if (apply 'and
       (mapcar '(lambda (code) (not (equal elv (cadddr (assoc code data)) 0.0001))) '(10 11 12 13))
       )
     (entdel ent_i)
     )
   )

 

So that way it deletes the one's that are NOT at the specified elevation.

 

Also, thanks again for all the help.

 

Oops, didn't realize you wanted to delete it if it didn't match.

 

Try this, it will only check once vs. four times:

(while (setq ent_i (ssname ss1 (setq i (1+ i))))
 (setq data (entget ent_i))
 (if
   (not
     (apply 'and
            (mapcar '(lambda (code) (equal elv (cadddr (assoc code data)) 0.0001)) '(10 11 12 13))
     )
   )
    (entdel ent_i)
 )
)

Posted
Oops, didn't realize you wanted to delete it if it didn't match.

 

Try this, it will only check once vs. four times:

(while (setq ent_i (ssname ss1 (setq i (1+ i))))
(setq data (entget ent_i))
(if
(not
(apply 'and
(mapcar '(lambda (code) (equal elv (cadddr (assoc code data)) 0.0001)) '(10 11 12 13))
)
)
(entdel ent_i)
)
)

 

Good call, rookie mistake :)

Posted
Good call, rookie mistake :)

Ehh, we all make them. Now, the important part is, do you actually understand what's going on in the code snippet?

Posted

I would use this:

 

(while (setq ent_i (ssname ss1 (setq i (1+ i))))
 (setq data (entget ent_i))
 
 (if (vl-some '(lambda ( x ) (not (equal elv (cadddr (assoc x data)) 0.0001))) '(10 11 12 13))
   (entdel ent_i)
 )
)

Posted
Ehh, we all make them. Now, the important part is, do you actually understand what's going on in the code snippet?

 

Not really, I kinda get it, but definatly not 100%. One question I would have would be what's the " 'and " for?

Posted
I would use this:

 

(while (setq ent_i (ssname ss1 (setq i (1+ i))))
 (setq data (entget ent_i))
 
 (if (vl-some '(lambda ( x ) (not (equal elv (cadddr (assoc x data)) 0.0001))) '(10 11 12 13))
   (entdel ent_i)
 )
)

I would too, but since he didn't have any VL functions, I figured it best to leave it all in AL.

Posted
Not really, I kinda get it, but definatly not 100%. One question I would have would be what's the " 'and " for?

The and is applied to a list of T and/or nil. If list contains all T, then and is successful, meaning all values matched; if the list contains at least one nil, and is unsuccessful, meaning a value did not match.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...