if and conditional help to compare (apply 'max of a list to a (car pt of inters

if and conditional help to compare (apply 'max of a list to a (car pt of inters

Anonymous
Not applicable
2,425 Views
24 Replies
Message 1 of 25

if and conditional help to compare (apply 'max of a list to a (car pt of inters

Anonymous
Not applicable

Hello, 

    I'm trying to compare the results of

        a minimum or maximum apply

with

        the fisrt position of a list that is the (car of a coordinate given by inters command)

 

the values are the same but the results are always nil for both expressions

      (if (= xMax1 (car pts1234)) (progn (setq x1(/ (+ xMin1 (car pts1234)) 2.00)) ))
      (if (= xMin1 (car pts1234)) (progn (setq x1(/ (+ xMax1 (car pts1234)) 2.00)) ))

 

what is wrong?

 

the important part of the code and the results

_$ (setq pt1 (cdr (assoc 10 (entget ocd_line)))) ; 1

(-184.619 265.883 0.0)


_$ (setq pt2 (cdr (assoc 11 (entget ocd_line))))

(-145.645 265.883 0.0)


_$ (setq xl1 (list (car pt1) (car pt2)))

(-184.619 -145.645)


_$ (setq xMax1 (apply 'max xl1))

-145.645


_$ (setq xMin1 (apply 'min xl1))

-184.619


_$ (setq yl1 (list (cadr pt1) (cadr pt2)))

(265.883 265.883)


_$ (setq yMax1 (apply 'max yl1))

265.883


_$ (setq yMin1 (apply 'min yl1))

265.883


_$ (setq pt3 (cdr (assoc 10 (entget obc_line))))

(-184.619 294.473 0.0)


_$ (setq pt4 (cdr (assoc 11 (entget obc_line))))

(-184.619 265.883 0.0)


_$ (setq xl2 (list (car pt3) (car pt4)))

(-184.619 -184.619)


_$ (setq xMax2 (apply 'max xl2))

-184.619


_$ (setq xMin2 (apply 'min xl2))

-184.619


_$ (setq yl2 (list (cadr pt3) (cadr pt4)))

(294.473 265.883)


_$ (setq yMax2 (apply 'max yl2))

294.473


_$ (setq yMin2 (apply 'min yl2))

265.883


_$ (setq pts1234 (inters pt1 pt2 pt3 pt4))

(-184.619 265.883 0.0)


_$ (if (= xMax1 (car pts1234)) (progn (setq x1(/ (+ xMin1 (car pts1234)) 2.00)) ))

nil


_$ (if (= xMin1 (car pts1234)) (progn (setq x1(/ (+ xMax1 (car pts1234)) 2.00)) ))

nil

 

xMin1 and (car pts1234) has the same value as follow

 

_$ (car pts1234)
-184.619

 

_$ xMin1
-184.619

  

should be something like that: (if (= -184.619 -184.619) (progn (setq x1(/ (+ xMax1 (car pts1234)) 2.00)) ))

 

 

Why is not returning TRUE to the sentence to execute the x1 calculation??? (if (= xMin1 (car pts1234)) (progn

 

Because the x1 remains ZERO as set before

_$ x1
0

 

Thanks in advance,

Luis

0 Likes
Accepted solutions (2)
2,426 Views
24 Replies
Replies (24)
Message 2 of 25

ВeekeeCZ
Consultant
Consultant

Don't compare those values in full precision. Use the equal function.

 

(equal x y 1e-4)

0 Likes
Message 3 of 25

Anonymous
Not applicable

Equal is not working either

 

(if (equal xMin1 (car pts1234)) (progn (setq x4 7) ))

result NIL as well

 

0 Likes
Message 4 of 25

Ranjit_Singh
Advisor
Advisor
Accepted solution

you are missing the fuzz factor in your equal function

(if (equal xMin1 (car pts1234) 1e-3) (progn (setq x4 7) ))
Message 5 of 25

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Equal is not working either

 

(if (equal xMin1 (car pts1234)) (progn (setq x4 7) ))

result NIL as well

 


You need a fuzz factor [the 1e-4 in @ВeekeeCZ's suggestion].  Read more about (equal) in Help.

 

And by the way, in this situation you don't need those (progn) "wrappers" at all.  That's only needed if what needs to be done for the 'then' or 'else' expression in an (if) function involves more than one function, so that they need to be wrapped into single expressions.

Kent Cooper, AIA
0 Likes
Message 6 of 25

Anonymous
Not applicable

Thanks Kent, fuzz factor works on the IF command...

 

my new problem now is in the fillet command (same problem but different command)

now the x1, y1, x2, y2 are ok and creating mpt1 and mpt2 fine

but the fillet between mpt1 and mpt2 is not working... should be again a precision problem


_$ (setq x1(/ (+ xMin1 (car pts1234)) 2.00))
_$ (if (equal xMin1 (car pt1) 1e-4) (progn (setq y1(/ (+ (cadr pt1) (cadr pts1234)) 2.00)) ))
_$ (if (equal xMin1 (car pt2) 1e-4) (progn (setq y1(/ (+ (cadr pt2) (cadr pts1234)) 2.00)) ))
_$ (setq x2(/ (+ xMax2 (car pts1234)) 2.00))
_$ (if (equal xMax2 (car pt3) 1e-4) (progn (setq y2(/ (+ (cadr pt3) (cadr pts1234)) 2.00)) ))
_$ (if (equal xMax2 (car pt4) 1e-4) (progn (setq y2(/ (+ (cadr pt4) (cadr pts1234)) 2.00)) ))
_$ (setq mPt1(list x1 y1))
_$ (setq mPt2(list x2 y2))
_$ (command "._fillet" mPt1 mPt2)  ; sometimes works depending on the value that changes in every loop

 

_$ mpt1
(-157.329 229.418)
_$ mpt2
(-156.949 229.453)
_$ (command "._fillet" mPt1 mPt2)
nil

 

Is there a way to use fuzz factor on the FILLET command as well??

 

The complete code that is not working is attached.

 

Regards,

Luis

 

 

0 Likes
Message 7 of 25

stevor
Collaborator
Collaborator

Fuzz for fillet: not that I know.

You probably will use the more 'inters,

with the 5th argument, to get actual intersections,

instead of fillets, because the fillet can produce

different results for inputs that appear the same.

 

If you post an image of the desired result,

it would help.

S
0 Likes
Message 8 of 25

stevor
Collaborator
Collaborator

Trying to send a zip, abandoned. Some amended code:

[code]


 (DeFun Mid_P (a b / c d) (mapcar '(Lambda (c d)
    (* 0.5 (+ c d))) a b) )
    
 ; unknown purpose shape , reworded a bit
 (Defun C:qqq ()   (setq os (getvar 'osmode))
  (setvar 'osmode 0) (setvar "filletrad" 0) (setvar "cmdecho" 0)
  ; --- ROTINA - MONTA LOTE  --- 8,14,1
  (setq a '(-155.397 219.383 0)   ax -155.397   ay 219.383   
        b '(-151.948 230.953 0)   bx -151.948   by 230.953)
  (command "Line" a b "")
  (setq ab_line (entlast))
  (setq c '(-158.829 230.953 0)   cx -158.829   cy 230.953)
  (command "Line" b c "")
  (setq bc_line (entlast))
  (setq d '(-158.829 229.383 0)   dx -158.829   dy 229.383)
  (command "Line" c d "")
  (setq cd_line (entlast))
  (setq e '(-216.119 229.383 0)   ex -216.119   ey 229.383)
  (command "Line" d e "")
  (setq de_line (entlast)   f '(-216.119 219.383 0)   
        fx -216.119   fy 219.383)
  (command "Line" e f "")   (setq ef_line (entlast))
  (command "Line" f a "")   (setq fa_line (entlast))
 ; --- ROTINA - MÁXIMO / MÍNIMO  ---
  (setq x (list ax bx cx dx ex fx )   
        xMax (apply 'max x)   xMin (apply 'min x))
  (setq y (list ay by cy dy ey fy )   
        yMax (apply 'max y)   yMin (apply 'min y))
 ; --- ROTINA - OSNAP / OFFSET / FILLET  --- ab - ofa
  (setq offP (osnap e "NEA"))
  (command "offset" 4.00 ab_line offP "") ; RF - F
  (setq oab_line (entlast))
 ; --- ROTINA - OSNAP / OFFSET / FILLET  --- bc - oab
  (setq offP (osnap a "NEA"))
  (command "offset" 1.50 bc_line offP "") ; RDL - L
  (setq obc_line (entlast)   flag 1)
  (setq P1 (cdr (assoc 10 (entget obc_line))))
  (setq P2 (cdr (assoc 11 (entget obc_line))))
  (setq P3 (cdr (assoc 10 (entget oab_line))))
  (setq P4 (cdr (assoc 11 (entget oab_line))))
  (setq I4P (inters P1 P2 P3 P4 )) ; *
  (if (= I4P nil) (progn (setq flag 0)))
  ;
  (if (= I4P nil) (progn (princ" Fillet-1 ")
    (command "._fillet" obc_line oab_line)) ) ; 3
  ;  
  (setq P1 (cdr (assoc 10 (entget obc_line))))
  (setq P2 (cdr (assoc 11 (entget obc_line))))
  (setq xl1 (list (car P1) (car P2)))
  (setq xMax1 (apply 'max xl1)   xMin1 (apply 'min xl1))
  (setq yl1 (list (cadr P1) (cadr P2)))
  (setq yMax1 (apply 'max yl1)   yMin1 (apply 'min yl1))
  (setq P3 (cdr (assoc 10 (entget oab_line))))
  (setq P4 (cdr (assoc 11 (entget oab_line))))
  (setq xl2 (list (car P3) (car P4)))
  (setq xMax2 (apply 'max xl2)   xMin2 (apply 'min xl2))
  (setq yl2 (list (cadr P3) (cadr P4)))
  (setq yMax2 (apply 'max yl2)   yMin2 (apply 'min yl2))
  (setq I4P (inters P1 P2 P3 P4 )) ;
  (setq x1 nil   y1 nil   x2 nil   y2 nil   M1 nil   M2 nil)
  (setq x1 (/ (+ xMin1 (car I4P)) 2.))
  (if (equal xMin1 (car P1) 1e-3) (progn
     (setq y1 (/ (+ (cadr P1) (cadr I4P)) 2.)) ))
  (if (equal xMin1 (car P2) 1e-3) (progn
     (setq y1 (/ (+ (cadr P2) (cadr I4P)) 2.)) ))
  (setq y2 (/ (+ yMin2 (cadr I4P)) 2.))
  (if (equal yMin2 (cadr P3) 1e-3) (progn
     (setq x2 (/ (+ (car P3) (car I4P)) 2.)) ))
  (if (equal yMin2 (cadr P4) 1e-3) (progn
     (setq x2 (/ (+ (car P4) (car I4P)) 2.)) ))
  (if (= flag 1) (progn (setq M1 (list x1 y1)) ))
  (if (= flag 1) (progn (setq M2 (list x2 y2)) ))
  (if (= flag 1) (progn (princ" Fillet-2 ")
     (command "._fillet" M1 M2) ))
  ; ROTINA - OSNAP / OFFSET / FILLET   cd - obc
  (setq offP (osnap b "NEA"))
  (command "offset" 1.50 cd_line offP "") ; RDL - L
  (setq ocd_line (entlast)   flag 1)
  (setq P1 (cdr (assoc 10 (entget ocd_line))))
  (setq P2 (cdr (assoc 11 (entget ocd_line))))
  (setq P3 (cdr (assoc 10 (entget obc_line))))
  (setq P4 (cdr (assoc 11 (entget obc_line))))
  (setq I4P (inters P1 P2 P3 P4 )) ;
  (if (= I4P nil) (progn (setq flag 0)))
  ;
  (if (= I4P nil) (progn (princ" Fillet-3 ")
     (command "._fillet" ocd_line obc_line)) ) ; 2
  (setq P1 (cdr (assoc 10 (entget ocd_line))))
  (setq P2 (cdr (assoc 11 (entget ocd_line))))
  (setq xl1 (list (car P1) (car P2)))
  (setq xMax1 (apply 'max xl1)   xMin1 (apply 'min xl1))
  (setq yl1 (list (cadr P1) (cadr P2)))
  (setq yMax1 (apply 'max yl1)   yMin1 (apply 'min yl1))
  (setq P3 (cdr (assoc 10 (entget obc_line))))
  (setq P4 (cdr (assoc 11 (entget obc_line))))
  (setq xl2 (list (car P3) (car P4)))
  (setq xMax2 (apply 'max xl2)   xMin2 (apply 'min xl2))
  (setq yl2 (list (cadr P3) (cadr P4)))
  (setq yMax2 (apply 'max yl2)   yMin2 (apply 'min yl2))
  (setq I4P (inters P1 P2 P3 P4 )) ;
  (setq x1 nil  y1 nil  x2 nil  y2 nil  M1 nil  M2 nil)
  (setq x1 (/ (+ xMin1 (car I4P)) 2.))
  (if (equal xMin1 (car P1) 1e-4) (progn
     (setq y1 (/ (+ (cadr P1) (cadr I4P)) 2.)) ))
  (if (equal xMin1 (car P2) 1e-4) (progn
     (setq y1 (/ (+ (cadr P2) (cadr I4P)) 2.)) ))
  (setq x2 (/ (+ xMax2 (car I4P)) 2.))
  (if (equal xMax2 (car P3) 1e-4) (progn
     (setq y2 (/ (+ (cadr P3) (cadr I4P)) 2.)) ))
  (if (equal xMax2 (car P4) 1e-4) (progn
     (setq y2 (/ (+ (cadr P4) (cadr I4P)) 2.)) ))
  ;(if (= flag 1) (progn (setq M1 (list x1 y1)) ))
  (if (= flag 1) (progn (setq M1 (Mid_P P1 P2 )) ))
  (if (= flag 1) (progn (setq M2 (list x2 y2)) ))
  ;
  (if (= flag 1) (progn (princ" Fillet-4 ")
    ;;; (command "._fillet" M1 M2)  unstable
     (command "._fillet" (osnap M1 'nea) (osnap M2'nea)) ))
  (setvar 'osmode os)
 (princ " Endo " ) (princ) )
      
      (C:qqq)

 

[code]

S
0 Likes
Message 9 of 25

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

_$ (command "._fillet" mPt1 mPt2)
nil

 

....

Without a sample drawing or image, I'm having a hard time imagining the exact situation.  It would help if you can provide one, with notes indicating the various locations of resulting variables.  From an illustration like that of what you are trying to do, it may be apparent that there's a different [read "easier"] way to do whatever it is.

 

Fillet doesn't require that kind of precision -- if the point variables are within pickbox range of appropriate objects, it should work [it does for me in quick experimentation, in Acad2017].  But are you sure there are always objects there?

 

This may not be the issue if you're getting mPt1 and mPt2 results, but....  Since you're not specifying nil as an 'onseg' argument to the (inters) function, your Lines must actually cross for it to return a point-location result.  If they ever don't cross [or at least meet], (inters) will return nil.

Kent Cooper, AIA
0 Likes
Message 10 of 25

Anonymous
Not applicable

Hi Kent,

Of course. 

shapes.jpg

The problem is on the last fillet that is unstable like Stevor said.

 

I'm trying the fillet suggested by Stevor but it´s returning an error message

 

(command "._fillet" (osnap mPt1 "nea") (osnap mPt2 "nea"))
; error: Function cancelled

 

Thanks a lot

0 Likes
Message 11 of 25

Anonymous
Not applicable

Kent,

 

This little part of the LISP code was generated by a VBS MACRO routine inside a QLIKVIEW dashboard application. There I choose some parameters that will be used to created many irregular shapes. After the basic shapes are created (one by one) the programm does OFFSET with different distances always to the inside part of the shape and to finish the draw FILLETs will correct the inside shape to a single polygon.

 

I'm also trying the use of nil in the INSTERS command

 

Regards

0 Likes
Message 12 of 25

Kent1Cooper
Consultant
Consultant

I'd still like to see indications of where the variable locations are [such as a leader pointing to a point with a note identifying that point as (for example) mPt1, etc.].

 

Some stuff I notice in perusing the code, without digging too deeply:

You can skip all those individual-coordinate variables [ax, ay, bx, by, etc., etc.], as well as the x and y compiled lists of those, and any time after all the points a through f have been established, do this:

; ----------------- ROTINA - MÁXIMO / MÍNIMO -----------------

(setq

  LL (mapcar 'min a b c d e f); = Lower Left

  UR (mapcar 'max a b c d e f); = Upper Right

  xMin (car LL)

  xMax (car UR)

  yMin (cadr LL)

  yMax (cadr UR)

)

 

Likewise, later, this part:

 (setq xl1 (list (car pt1) (car pt2)))
 (setq xMax1 (apply 'max xl1))
 (setq xMin1 (apply 'min xl1))
 (setq yl1 (list (cadr pt1) (cadr pt2)))
 (setq yMax1 (apply 'max yl1))

 (setq yMin1 (apply 'min yl1))

 

can be done without pulling individual coordinates out of each point:

(setq

  LL (mapcar 'min pt1 pt2)

  UR (mapcar 'max pt1 pt2)

  xMax1 (car UR)

  xMin1 (car LL)

  yMax1 (cadr UR)

  yMin1 (cadr LL)

)

 

which admittedly doesn't save quite as much with only two points as that approach does with six points earlier.  Likewise for the similar situation about pt3 and pt4.

 

(osnap e "NEA") can't help [under these circumstances] but be just e -- no need for a separate offpt variable, and I think likewise for a and b later.

 

Regarding this line:

  (if (= pts1234 nil) (progn (setq flag 0)))

It's never necessary to check whether a variable is "equal to" nil -- if so, it simply doesn't exist.  The (not) function can determine that.  And I repeat, that (progn) wrapper is doing nothing for you, when it encloses only a single function.  That line can be:
  (if (not pts1234) (setq flag 0))

and similarly elsewhere.  Another way some people like to do that is:

  (or pts1234 (setq flag 0))

 

EDIT: Come to think of it, you could handle the flagging business in a simpler way, using T vs. nil about the pts1234 variable, without the flag variable at all.  Eliminate everything that sets any value to flag, and then wherever you have a check on whether it's 1:

 

(if (= flag 1) ....

 

just check whether pts1234 exists instead:

 

(if pts1234 ....

 

Kent Cooper, AIA
0 Likes
Message 13 of 25

Anonymous
Not applicable

Hi Kent,

 

Thanks for the tips in codification I'll do that after solving the main problem.

 

I've changed a little bit the code with the suggestions you and Stevor did but still without success. The last fillet is unstable, sometimes does sometimes not.

 

_$ (setq flag 1)
_$ (setq pt1 (cdr (assoc 10 (entget ocd_line))))
_$ (setq pt2 (cdr (assoc 11 (entget ocd_line))))
_$ (setq pt3 (cdr (assoc 10 (entget obc_line))))
_$ (setq pt4 (cdr (assoc 11 (entget obc_line))))
_$ (setq pts1234 (inters pt1 pt2 pt3 pt4))
_$ (if (= pts1234 nil) (progn (setq flag 0)))
_$ (if (= pts1234 nil) (progn (command "._fillet" ocd_line obc_line)) ) ; 2
_$ (setq pt1 (cdr (assoc 10 (entget ocd_line))))
_$ (setq pt2 (cdr (assoc 11 (entget ocd_line))))
_$ (setq xl1 (list (car pt1) (car pt2)))
_$ (setq xMax1 (apply 'max xl1))
_$ (setq xMin1 (apply 'min xl1))
_$ (setq yl1 (list (cadr pt1) (cadr pt2)))
_$ (setq yMax1 (apply 'max yl1))
_$ (setq yMin1 (apply 'min yl1))
_$ (setq pt3 (cdr (assoc 10 (entget obc_line))))
_$ (setq pt4 (cdr (assoc 11 (entget obc_line))))
_$ (setq xl2 (list (car pt3) (car pt4)))
_$ (setq xMax2 (apply 'max xl2))
_$ (setq xMin2 (apply 'min xl2))
_$ (setq yl2 (list (cadr pt3) (cadr pt4)))
_$ (setq yMax2 (apply 'max yl2))
_$ (setq yMin2 (apply 'min yl2))
_$ (setq pts1234 (inters pt1 pt2 pt3 pt4 nil))
_$ (setq x1 nil)
_$ (setq y1 nil)
_$ (setq x2 nil)
_$ (setq y2 nil)
_$ (setq mpt12 nil)
_$ (setq mpt34 nil)
_$ (setq x1(/ (+ xMin1 (car pts1234)) 2.00))
_$ (if (equal xMin1 (car pt1) 1e-3) (progn (setq y1(/ (+ (cadr pt1) (cadr pts1234)) 2.00)) ))
_$ (if (equal xMin1 (car pt2) 1e-3) (progn (setq y1(/ (+ (cadr pt2) (cadr pts1234)) 2.00)) ))
_$ (setq x2(/ (+ xMax2 (car pts1234)) 2.00))
_$ (if (equal xMax2 (car pt3) 1e-3) (progn (setq y2(/ (+ (cadr pt3) (cadr pts1234)) 2.00)) ))
_$ (if (equal xMax2 (car pt4) 1e-3) (progn (setq y2(/ (+ (cadr pt4) (cadr pts1234)) 2.00)) ))
_$ (if (= flag 1) (progn (setq mPt12(list x1 y1)) )) ; ocd_line
_$ (if (= flag 1) (progn (setq mPt34(list x2 y2)) )) ; obc_line
_$ (if (= flag 1) (progn (setq i4pts12 (inters pt1 pt2 mpt12 mpt34 nil)) ))
_$ (if (= flag 1) (progn (setq i4pts34 (inters pt3 pt4 mpt12 mpt34 nil)) ))
_$ (if (= flag 1) (progn (command "._fillet" (osnap mPt12 "nea") (osnap mPt34 "nea") ) ))
_$ (if (= flag 1) (progn (command "._fillet" (osnap i4pts12 "nea") (osnap i4pts34 "nea") ) ))

 

I've even try to duplicate the FILLET using new coordinates found by INTERS command but is not working as well. Somehow the FILLET is returning NIL even if the coordinates are "supposing" hitting the lines. I'll probably direct the solution for a new logical approach.

 

New ideas please let me know.

Thanks a lot

0 Likes
Message 14 of 25

Ranjit_Singh
Advisor
Advisor

Post a drawing which is giving you error. Help us replicate the problem at our end.

0 Likes
Message 15 of 25

Anonymous
Not applicable

Sure, I'll prepare a simple version focus on the problem and post it here soon.

0 Likes
Message 16 of 25

Anonymous
Not applicable

The drawing is created by the following code

 

(vl-load-com)
(setq os (getvar 'osmode))
(setvar 'osmode 0)
(setvar "filletrad" 0)
(setq a ' (-155.397 219.383 0))
(setq ax (car a))
(setq ay (cadr a))
(setq b ' (-151.948 230.953 0))
(setq bx (car b))
(setq by (cadr b))
(command "Line" a b "")
(setq ab_line (entlast))
(setq c ' (-158.829 230.953 0))
(setq cx (car c))
(setq cy (cadr c))
(command "Line" b c "")
(setq bc_line (entlast))
(setq d ' (-158.829 229.383 0))
(setq dx (car d))
(setq dy (cadr d))
(command "Line" c d "")
_$ (setq cd_line (entlast))
_$ (setq e ' (-216.119 229.383 0))
(setq ex (car e))
(setq ey (cadr e))
(command "Line" d e "")
_$ (setq de_line (entlast))
_$ (setq f ' (-216.119 219.383 0))
(setq fx (car f))
(setq fy (cadr f))
(command "Line" e f "")
_$ (setq ef_line (entlast))
_$ (command "Line" f a "")
_$ (setq fa_line (entlast))
; ----------------- ROTINA - MÁXIMO / MÍNIMO -----------------
_$ (setq x (list ax bx cx dx ex fx ))
_$ (setq xMax (apply 'max x))
_$ (setq xMin (apply 'min x))
_$ (setq y (list ay by cy dy ey fy ))
_$ (setq yMax (apply 'max y))
_$ (setq yMin (apply 'min y))
; ----------------- ROTINA - OSNAP / OFFSET / FILLET ----------------- ab - ofa
_$ (setq offpt (osnap e "NEA"))
_$ (command "offset" 4.00 ab_line offpt "") ; RF - F
_$ (setq oab_line (entlast))
; ----------------- ROTINA - OSNAP / OFFSET / FILLET ----------------- bc - oab
_$ (setq offpt (osnap a "NEA"))
_$ (command "offset" 1.50 bc_line offpt "") ; RDL - L
_$ (setq obc_line (entlast))
_$ (setq flag 1)
_$ (setq pt1 (cdr (assoc 10 (entget obc_line))))
_$ (setq pt2 (cdr (assoc 11 (entget obc_line))))
_$ (setq pt3 (cdr (assoc 10 (entget oab_line))))
_$ (setq pt4 (cdr (assoc 11 (entget oab_line))))
_$ (setq pts1234 (inters pt1 pt2 pt3 pt4))
_$ (if (= pts1234 nil) (progn (setq flag 0)))
_$ (if (= pts1234 nil) (progn (command "._fillet" obc_line oab_line)) ) ; 3
_$ (setq pt1 (cdr (assoc 10 (entget obc_line))))
_$ (setq pt2 (cdr (assoc 11 (entget obc_line))))
_$ (setq xl1 (list (car pt1) (car pt2)))
_$ (setq xMax1 (apply 'max xl1))
_$ (setq xMin1 (apply 'min xl1))
_$ (setq yl1 (list (cadr pt1) (cadr pt2)))
_$ (setq yMax1 (apply 'max yl1))
_$ (setq yMin1 (apply 'min yl1))
_$ (setq pt3 (cdr (assoc 10 (entget oab_line))))
_$ (setq pt4 (cdr (assoc 11 (entget oab_line))))
_$ (setq xl2 (list (car pt3) (car pt4)))
_$ (setq xMax2 (apply 'max xl2))
_$ (setq xMin2 (apply 'min xl2))
_$ (setq yl2 (list (cadr pt3) (cadr pt4)))
_$ (setq yMax2 (apply 'max yl2))
_$ (setq yMin2 (apply 'min yl2))
_$ (setq pts1234 (inters pt1 pt2 pt3 pt4 nil))
_$ (setq x1 nil)
_$ (setq y1 nil)
_$ (setq x2 nil)
_$ (setq y2 nil)
_$ (setq mpt12 nil)
_$ (setq mpt34 nil)
_$ (setq x1(/ (+ xMin1 (car pts1234)) 2.00))
_$ (if (equal xMin1 (car pt1) 1e-3) (progn (setq y1(/ (+ (cadr pt1) (cadr pts1234)) 2.00)) ))
_$ (if (equal xMin1 (car pt2) 1e-3) (progn (setq y1(/ (+ (cadr pt2) (cadr pts1234)) 2.00)) ))
_$ (setq y2(/ (+ yMin2 (cadr pts1234)) 2.00))
_$ (if (equal yMin2 (cadr pt3) 1e-3) (progn (setq x2(/ (+ (car pt3) (car pts1234)) 2.00)) ))
_$ (if (equal yMin2 (cadr pt4) 1e-3) (progn (setq x2(/ (+ (car pt4) (car pts1234)) 2.00)) ))
_$ (if (= flag 1) (progn (setq mPt12(list x1 y1)) )) ; obc_line
_$ (if (= flag 1) (progn (setq mPt34(list x2 y2)) )) ; oab_line
_$ (if (= flag 1) (progn (setq i4pts12 (inters pt1 pt2 mpt12 mpt34 nil)) ))
_$ (if (= flag 1) (progn (setq i4pts34 (inters pt3 pt4 mpt12 mpt34 nil)) ))
_$ (if (= flag 1) (progn (command "._fillet" (osnap mPt12 "nea") (osnap mPt34 "nea") ) ))
_$ (if (= flag 1) (progn (command "._fillet" (osnap i4pts12 "nea") (osnap i4pts34 "nea") ) ))
; ----------------- ROTINA - OSNAP / OFFSET / FILLET ----------------- cd - obc
_$ (setq offpt (osnap b "NEA"))
_$ (command "offset" 1.50 cd_line offpt "") ; RDL - L
_$ (setq ocd_line (entlast))
_$ (setq flag 1)
_$ (setq pt1 (cdr (assoc 10 (entget ocd_line))))
_$ (setq pt2 (cdr (assoc 11 (entget ocd_line))))
_$ (setq pt3 (cdr (assoc 10 (entget obc_line))))
_$ (setq pt4 (cdr (assoc 11 (entget obc_line))))
_$ (setq pts1234 (inters pt1 pt2 pt3 pt4))
_$ (if (= pts1234 nil) (progn (setq flag 0)))
_$ (if (= pts1234 nil) (progn (command "._fillet" ocd_line obc_line)) ) ; 2
_$ (setq pt1 (cdr (assoc 10 (entget ocd_line))))
_$ (setq pt2 (cdr (assoc 11 (entget ocd_line))))
_$ (setq xl1 (list (car pt1) (car pt2)))
_$ (setq xMax1 (apply 'max xl1))
_$ (setq xMin1 (apply 'min xl1))
_$ (setq yl1 (list (cadr pt1) (cadr pt2)))
_$ (setq yMax1 (apply 'max yl1))
_$ (setq yMin1 (apply 'min yl1))
_$ (setq pt3 (cdr (assoc 10 (entget obc_line))))
_$ (setq pt4 (cdr (assoc 11 (entget obc_line))))
_$ (setq xl2 (list (car pt3) (car pt4)))
_$ (setq xMax2 (apply 'max xl2))
_$ (setq xMin2 (apply 'min xl2))
_$ (setq yl2 (list (cadr pt3) (cadr pt4)))
_$ (setq yMax2 (apply 'max yl2))
_$ (setq yMin2 (apply 'min yl2))
_$ (setq pts1234 (inters pt1 pt2 pt3 pt4 nil))
_$ (setq x1 nil)
_$ (setq y1 nil)
_$ (setq x2 nil)
_$ (setq y2 nil)
_$ (setq mpt12 nil)
_$ (setq mpt34 nil)
_$ (setq x1(/ (+ xMin1 (car pts1234)) 2.00))
_$ (if (equal xMin1 (car pt1) 1e-3) (progn (setq y1(/ (+ (cadr pt1) (cadr pts1234)) 2.00)) ))
_$ (if (equal xMin1 (car pt2) 1e-3) (progn (setq y1(/ (+ (cadr pt2) (cadr pts1234)) 2.00)) ))
_$ (setq x2(/ (+ xMax2 (car pts1234)) 2.00))
_$ (if (equal xMax2 (car pt3) 1e-3) (progn (setq y2(/ (+ (cadr pt3) (cadr pts1234)) 2.00)) ))
_$ (if (equal xMax2 (car pt4) 1e-3) (progn (setq y2(/ (+ (cadr pt4) (cadr pts1234)) 2.00)) ))
_$ (if (= flag 1) (progn (setq mPt12(list x1 y1)) )) ; ocd_line
_$ (if (= flag 1) (progn (setq mPt34(list x2 y2)) )) ; obc_line
_$ (if (= flag 1) (progn (setq i4pts12 (inters pt1 pt2 mpt12 mpt34 nil)) ))
_$ (if (= flag 1) (progn (setq i4pts34 (inters pt3 pt4 mpt12 mpt34 nil)) ))
_$ (if (= flag 1) (progn (command "._fillet" (osnap mPt12 "nea") (osnap mPt34 "nea") ) ))
_$ (if (= flag 1) (progn (command "._fillet" (osnap i4pts12 "nea") (osnap i4pts34 "nea") ) ))
; ----------------- ROTINA - OSNAP / OFFSET / FILLET ----------------- de - ocd
_$ (setq offpt (osnap a "NEA"))
_$ (command "offset" 1.50 de_line offpt "") ; RDL - L
_$ (setq ode_line (entlast))
_$ (setq flag 1)
_$ (setq pt1 (cdr (assoc 10 (entget ode_line))))
_$ (setq pt2 (cdr (assoc 11 (entget ode_line))))
_$ (setq pt3 (cdr (assoc 10 (entget ocd_line))))
_$ (setq pt4 (cdr (assoc 11 (entget ocd_line))))
_$ (setq pts1234 (inters pt1 pt2 pt3 pt4))
_$ (if (= pts1234 nil) (progn (setq flag 0)))
_$ (if (= pts1234 nil) (progn (command "._fillet" ode_line ocd_line)) ) ; 3
_$ (setq pt1 (cdr (assoc 10 (entget ode_line))))
_$ (setq pt2 (cdr (assoc 11 (entget ode_line))))
_$ (setq xl1 (list (car pt1) (car pt2)))
_$ (setq xMax1 (apply 'max xl1))
_$ (setq xMin1 (apply 'min xl1))
_$ (setq yl1 (list (cadr pt1) (cadr pt2)))
_$ (setq yMax1 (apply 'max yl1))
_$ (setq yMin1 (apply 'min yl1))
_$ (setq pt3 (cdr (assoc 10 (entget ocd_line))))
_$ (setq pt4 (cdr (assoc 11 (entget ocd_line))))
_$ (setq xl2 (list (car pt3) (car pt4)))
_$ (setq xMax2 (apply 'max xl2))
_$ (setq xMin2 (apply 'min xl2))
_$ (setq yl2 (list (cadr pt3) (cadr pt4)))
_$ (setq yMax2 (apply 'max yl2))
_$ (setq yMin2 (apply 'min yl2))
_$ (setq pts1234 (inters pt1 pt2 pt3 pt4 nil))
_$ (setq x1 nil)
_$ (setq y1 nil)
_$ (setq x2 nil)
_$ (setq y2 nil)
_$ (setq mpt12 nil)
_$ (setq mpt34 nil)
_$ (setq x1(/ (+ xMin1 (car pts1234)) 2.00))
_$ (if (equal xMin1 (car pt1) 1e-3) (progn (setq y1(/ (+ (cadr pt1) (cadr pts1234)) 2.00)) ))
_$ (if (equal xMin1 (car pt2) 1e-3) (progn (setq y1(/ (+ (cadr pt2) (cadr pts1234)) 2.00)) ))
_$ (setq y2(/ (+ yMin2 (cadr pts1234)) 2.00))
_$ (if (equal yMin2 (cadr pt3) 1e-3) (progn (setq x2(/ (+ (car pt3) (car pts1234)) 2.00)) ))
_$ (if (equal yMin2 (cadr pt4) 1e-3) (progn (setq x2(/ (+ (car pt4) (car pts1234)) 2.00)) ))
_$ (if (= flag 1) (progn (setq mPt12(list x1 y1)) )) ; ode_line
_$ (if (= flag 1) (progn (setq mPt34(list x2 y2)) )) ; ocd_line
_$ (if (= flag 1) (progn (setq i4pts12 (inters pt1 pt2 mpt12 mpt34 nil)) ))
_$ (if (= flag 1) (progn (setq i4pts34 (inters pt3 pt4 mpt12 mpt34 nil)) ))
_$ (if (= flag 1) (progn (command "._fillet" (osnap mPt12 "nea") (osnap mPt34 "nea") ) ))
_$ (if (= flag 1) (progn (command "._fillet" (osnap i4pts12 "nea") (osnap i4pts34 "nea") ) ))

_$ (setvar 'osmode os)

 

The code is creating the wrong drawing below, because the last FILLET lines are returning NIL in most of the times I execute it. That is the problem.

 

shapes.jpg

 

The code is created by a vbs macro routine inside a Qlikview application. There is no much more to say.  Please let me know if I forgot to give some info.

To reproduce the problem just open a new drawing in AUTOCAD and put the code inside a VLIDE editor (ENTER). 

 

Thanks in advance,

Luis

0 Likes
Message 17 of 25

Anonymous
Not applicable

So, I was investigating this odd behavior and I notice something funny.

 

After the code that does not do the last fillet's commands I wrote.

(command "line" mpt12 b "" "")

(command "line" mpt34 a "" "")

 

So, I repeat the FILLET command

(if (= flag 1) (progn (command "._fillet" (osnap mPt12 "nea") (osnap mPt34 "nea") ) ))

 

And It does a fillet between a wrong line segments... but, does not returns NIL (it's some kind of progress I believe)

 

After that on the AUTOCAD I choose to undo the three last commands, that put the drawing back in the previous condition.

Finally I repeat the same FILLET command again

(if (= flag 1) (progn (command "._fillet" (osnap mPt12 "nea") (osnap mPt34 "nea") ) ))

 

And it works fine but does not solve my problem, because I can't do that in my routine.

 

This problem is driving me crazy.

Any additional help will be appreciated.

 

Regards,

Luis

 

 

0 Likes
Message 18 of 25

Kent1Cooper
Consultant
Consultant

Could it be that the Zoom level affects it, because of the size of the PICKBOX setting in relation to the Lines involved and the surrounding geometry?  What if you put in a Zoom Object to one of those Lines before the FILLET command?  That should remove any ambiguity about which Line is being picked at the points in Fillet.

 

Another possibility, if it's "seeing" something other than the Lines you want it to, is to take advantage of the fact that (entdel) removes an entity, but if you do it again with the same entity name, it brings it back in!  That means you could do:

 

(entdel oab_line)

(entdel obc_line)

.... etc.

 

with all the Lines that are not supposed to be involved in the Fillet, then do the Fillet without those Lines around to be mistakenly "seen," then do these again:

 

(entdel oab_line)

(entdel obc_line)

.... etc.

 

and they'll all be restored.

Kent Cooper, AIA
Message 19 of 25

Anonymous
Not applicable

About ZOOM the object how can I do it? I'm still a newbie in LISP commands.

 

I'll try the (entdel) approach meanwhile. I'll keep you posted.

 

Thanks

0 Likes
Message 20 of 25

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

About ZOOM the object how can I do it? I'm still a newbie in LISP commands.

 

...

There's an Object option in the Zoom command:

 

(command "_.zoom" "_object" YourLineVariableName)

Kent Cooper, AIA