Jump to content

Recommended Posts

Posted

This is a chunck of a larger code I have been working on for some time now. I see there is a mistake and instead of changing everything I want to try and add 0.9325 to pLL and subtract 0.9325 from pUR only in the x value. The y and z value are fine. pLR and pUL should follow since they are based off of pLL and pUR.

 

 
(defun C:BP47
      ;; = Box Plate with 47-degree end-flap angles
      (/ *error*)
 (vl-load-com)
 (defun *error* (errmsg)
   (if (not (wcmatch errmsg "Function cancelled,quit / exit abort")
)
     (princ (strcat "\nError: " errmsg))
   )     ; end if
   (BPReset)
 )     ; end defun - *error*
 (defun BPReset ()
   (setvar 'plinewid plw)
   (setvar 'osmode osm)
   (setvar 'blipmode blipm)
   (setvar 'clayer curlay)
   (command "_.undo" "_end")
   (setvar 'cmdecho cmde)
 )     ; end defun
 (setq cmde (getvar 'cmdecho))
 (setvar 'cmdecho 0)
 (command "_.undo" "_begin")
 (setq osm (getvar 'osmode))
 (setvar 'osmode 0)
 (setq blipm (getvar 'blipmode))
 (setq
   curlay (getvar 'clayer)
   plw    (getvar 'plinewid)
   p1    (getpoint "\nSpecify First Corner: ")
   p2    (getcorner p1 "\nSpecify Opposite Corner: ")
   fl    (getdist p1 "\nSpecify Depth: ")
   flr    (/ fl (sin (* (/ 47.0 180) pi)))
[b][i]    pLL    (mapcar 'min p1 p2)  ; Lower Left corner
   pUR    (mapcar 'max p1 p2)  ; Upper Right[/i][/b]
   pLR    (list (car pUR) (cadr pLL) 0) ; Lower Right
   pUL    (list (car pLL) (cadr pUR) 0) ; Upper Left
   FS    (* (/ 47.0 180) pi)  ; Forty-Seven degrees
 )     ; end setq
)

 

Any help it appreciated.

Kenter

Posted

So like this?? Or did I miss the mark completely?

 

pLL (apply 'mapcar (cons 'min (+ p1 0.9325) p2) ; Lower Left corner

pUR (apply 'mapcar (cons 'min (- p1 0.9325) p2) ; Upper Right

Posted

'cons' requires either a list, or another single element...

 

Also, think about what you are constructing in order to use the syntax I posted :)

Posted

Try this code instead

 
(setq pLL
  (list (apply 'min (mapcar 'car (list p1 p2)))
 (apply 'min (mapcar 'cadr (list p1 p2)))
 0)
     pLL (mapcar '+ pLL (list -0.9325 -0.9325 0))
     pUR
  (list (apply 'max (mapcar 'car (list p1 p2)))
 (apply 'max (mapcar 'cadr (list p1 p2)))
 0)
     pUR (mapcar '+ pUR (list 0.9325 0.9325 0))
     )

 

~'J'~

Posted
Try this code instead

 
(setq pLL
  (list (apply 'min (mapcar 'car (list p1 p2)))
 (apply 'min (mapcar 'cadr (list p1 p2)))
 0)
     pLL (mapcar '+ pLL (list -0.9325 -0.9325 0))
     pUR
  (list (apply 'max (mapcar 'car (list p1 p2)))
 (apply 'max (mapcar 'cadr (list p1 p2)))
 0)
     pUR (mapcar '+ pUR (list 0.9325 0.9325 0))
     )

 

~'J'~

 

That worked flawlessly, I just tweaked it a little to suit my needs and voiala. Thank you.

 

Kenter

Posted

OK, I realise you aren't going to bother to pursue my line of thought, but here goes:

 

(setq pt1 '(1 2 3) pt2 '(4 5 6))

(cons 'min (list pt1 pt2))

==> (min pt1 pt2)

(apply 'mapcar (cons 'min (list pt1 pt2)))

==> (apply 'mapcar (min pt1 pt2))
==> ((min 1 4) (min 2 5) (min 3 6))

 

Oh well.

Posted

No, I wasn't following what you meant. I still don't see it to tell the honest truth. I am still quit new to all this stuff, and I do appreciate all you have helped me with.

Posted

Don't worry about it mate, I was just a little disappointed that you gave up with it is all.

Posted

Ouch, the 'disappointed' word comes out. lol. I wouldn't mind an explination of what you were trying to do in the code though. I like to learn.

Posted (edited)
Ouch, the 'disappointed' word comes out. lol.

 

Well, what can I say lol - you did dive in for the easy option when Fixo posted it...

 

I wouldn't mind an explination of what you were trying to do in the code though. I like to learn.

 

I demonstrated the procedure in post #7, the way to get your head around it is to realise that the 'apply' function requires a function and a list of arguments for that function and serves no other purpose other than to apply the function to the list of args.

 

From there, just look at the list of arguments you are supplying to the mapcar function and read it as one line without the apply function being there.

Edited by Lee Mac
Posted

I don't alway's search for command's I do not know

But when I do,

I search cadtutor. :P

Posted

LMAO, that is sweet. Love Dos Equis commercials

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...