Chamfer 2.0

Chamfer 2.0

SilentStrike24
Enthusiast Enthusiast
1,672 Views
12 Replies
Message 1 of 13

Chamfer 2.0

SilentStrike24
Enthusiast
Enthusiast

Hi guys!

 

Can you please help with a small issue?

 

I'm in need of a chamfer that makes the below shape (green line). Do you know if AutoCAD can do this or is there any free routine for this? Basically, except the chamfer distances there should be an additional question for the user to insert the "X" values.

 

nicolaearhire10_0-1639496338046.png

 

Thanks!

 

@Kent1Cooper

0 Likes
1,673 Views
12 Replies
Replies (12)
Message 2 of 13

Kent1Cooper
Consultant
Consultant

That may be possible, but questions arise:

 

Always between things at right angles as in your image?

 

If not, should the "short legs" be perpendicular to the original edges [left below], or each parallel to the other edge [right]?  Or something else?

Kent1Cooper_0-1639501396926.png

 

Applicable to Lines only, or to adjacent line segments of a Polyline?  Anything else?

Kent Cooper, AIA
0 Likes
Message 3 of 13

SilentStrike24
Enthusiast
Enthusiast

Thanks for the reply @Kent1Cooper!

 

Small green lines are to be always perpendicular on the original lines and this should be applicable only to lines/polylines, not arcs/splines/etc….


Only thing that needs to be “asked” is the length.

 

0 Likes
Message 4 of 13

calderg1000
Mentor
Mentor

Regards @SilentStrike24 

Maybe this code helps something. The lines or polylines must be individual, enter appropriate geometric values ​​within the permissible limits.

(defun c:chd (/ s s1 s2 pins cc pc1 pc1b pc2 pc2b pc1v pc2v x)
  (setq
    spm (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
  )
  (setq dc (getreal "\nEnter Chamfer distance value: ")
        x  (getreal "\nEnter distance X: ")
  )
  (setq s (ssget '((0 . "*line"))))
  (setq s1 (vlax-ename->vla-object (ssname s 0))
        s2 (vlax-ename->vla-object (ssname s 1))
  )
  (setq pins (vla-intersectwith s1 s2 acextendnone))
  (setq cc (vla-addcircle spm
                          pins
                          dc
           )
  )
  (setq pc1  (vla-intersectwith cc s1 acextendnone)
        pc1b (vlax-safearray->list (vlax-variant-value pc1))
  )
  (setq pc2  (vla-intersectwith cc s2 acextendnone)
        pc2b (vlax-safearray->list (vlax-variant-value pc2))
  )
  (vla-erase cc)
  (setq l1(vla-addline spm pc1 (setq pc1v (vlax-3d-point (polar pc1b pi x))))
   l2(vla-addline spm
               pc2
               (setq pc2v (vlax-3d-point (polar pc2b (/ (* 3 pi) 2) x)))
  )
 l3(vla-addline spm pc1v pc2v))
  (Foreach x (list l1 l2 l3)
(vla-put-color x 3))
)

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 5 of 13

SilentStrike24
Enthusiast
Enthusiast

Thanks for replying @calderg1000!

 

Code looks ok, it "asks" the right questions, but there's an error as per below screenshot:

 

"error: no function definition: VLAX-ENAME->VLA-OBJECT"

 

nicolaearhire10_0-1639551583950.png

0 Likes
Message 6 of 13

ВeekeeCZ
Consultant
Consultant

Add this as the very first line.

(vl-load-com)

Message 7 of 13

jaimuthu
Advocate
Advocate

its possible for corner trim with chamfer d1 d2 are same value

0 Likes
Message 8 of 13

Kent1Cooper
Consultant
Consultant

Are you saying that CHAMFER doesn't trim the corners, and you are trying to make a routine that does?

 

If that's the issue, you probably just have the TRIMMODE System Variable set to 0, when it should be set to 1.  Then ordinary CHAMFER will trim the corners.

 

If that's not the issue, explain in more detail.  The code is hard to test, because it needs a lot of fixing [is it an AI effort?  ChatGPT, for example, is notoriously bad at AutoLisp, so far].  But I notice a couple of things to start with:

 

The Chamfer distances should not be in a list.  Do this instead:

(command "_.chamfer" "_distance" dc dc)

which in an AutoLisp (command) function concludes the command, so you need to start it again:

(command
  "_.chamfer" "_distance" dc dc
  "_.chamfer" s1 s2
)

But s1 and s2 there require just entity names, not VLA objects, and the same is true for some later usages.  So you may need to store them in both forms under different variable names.

 

The TRIM commands near the end should be using 'line' as the first selection [cutting boundary] and 's1'/'s2' as the second, but that's going to need to be a location, not just the object, so it knows which part to Trim off.  And they could be in one TRIM command, and they need to conclude it -- all signs of ChatGPT's ignorance of the details.

 

But all that may be irrelevant, if the only issue is the TRIMMODE setting.

Kent Cooper, AIA
0 Likes
Message 9 of 13

john.uhden
Mentor
Mentor

IGNORE THIS POST

 

 

John F. Uhden

0 Likes
Message 10 of 13

jaimuthu
Advocate
Advocate

Application ERROR: Invalid
type sent as command input

0 Likes
Message 11 of 13

john.uhden
Mentor
Mentor

@SilentStrike24 ,

Try this on for size.  It deals with only lines for now, but maybe that's good enough.

Note that it has no error or undo control (easy to add).

It can give you screwy results if the chamfer distance is longer than the hypotenuse (or something like that).

(defun c:ch3 ( / d e1 e2 e3 @midp e2o p1 p2 p3)
  (defun @midp (e / ent)
    (setq ent (entget e))
    (mapcar '* '(0.5 0.5)(mapcar '+ (setq p1 (cdr (assoc 10 ent)))(setq p2 (cdr (assoc 11 ent)))))
  )
  (setq e2o vlax-ename->vla-object)
  (and
    (setq e1 (car (entsel "\nSelect chamfer leg: ")))
    (setq e2 (car (entsel "\nSelect chamfer hypotenuse: ")))
    (not (initget 7))
    (setq d (getdist "\nEnter length of chamfer (perpendicular to leg): "))
    (vl-cmdf "_.offset" d e1 (@midp e2) "")
    (setq e3 (entlast))
    (entmakex
      (list '(0 . "LINE")
        (cons 10 (setq p3 (vlax-invoke (e2o e2) 'intersectwith (e2o e3) 3)))
        (cons 11 (vlax-curve-getclosestpointto e1 p3))
      )
    )
    (if (< (distance p3 p1)(distance p3 p2))
      (entmod (subst (cons 10 p3)(cons 10 p1)(entget e2)))
      (entmod (subst (cons 11 p3)(cons 11 p2)(entget e2)))
    )
    (entdel e3)
  )
  (princ)
)

 

John F. Uhden

0 Likes
Message 12 of 13

marko_ribar
Advisor
Advisor

Based on @john.uhden code...

I tested and it works as desired...

 

(defun c:ch3 ( / *error* @midp e2o cmde pea lwf ss d dd ee1 ee2 e11 e12 e2 e3 p1 p2 p3 p4 p11 p22 )

  (or (not (vl-catch-all-error-p (vl-catch-all-apply (function vlax-get-acad-object) nil))) (vl-load-com))

  (defun *error* ( m )
    (if (= 8 (logand 8 (getvar (quote undoctl))))
      (if command-s
        (command-s "_.undo" "_e")
        (vl-cmdf "_.undo" "_e")
      )
    )
    (if cmde
      (setvar (quote cmdecho) cmde)
    )
    (if pea
      (setvar (quote peditaccept) pea)
    )
    (if m
      (prompt m)
    )
    (princ)
  )

  (defun @midp ( elin / ent )
    (setq ent (entget elin))
    (mapcar (function *) (list 0.5 0.5) (mapcar (function +) (setq p1 (cdr (assoc 10 ent))) (setq p2 (cdr (assoc 11 ent)))))
  )

  (setq e2o vlax-ename->vla-object)

  (setq cmde (getvar (quote cmdecho)))
  (setq pea (getvar (quote peditaccept)))
  (setvar (quote cmdecho) 0)
  (if (= 8 (logand 8 (getvar (quote undoctl))))
    (vl-cmdf "_.undo" "_e")
  )
  (vl-cmdf "_.undo" "_be")
  (and
    (setq e11 (entsel "\nPick first chamfer leg : "))
    (setq e12 (entsel "\nPick second chamfer leg : "))
    (not (initget 7))
    (setq dd (getdist "\nPick or specify chamfer distance : "))
    (if (= (cdr (assoc 0 (entget (car e11)))) "LWPOLYLINE")
      (progn
        (vl-cmdf "_.explode" (car e11))
        (setq ss (ssget "_p"))
        (setq e11 (nentselp (cadr e11)))
        (setq e12 (nentselp (cadr e12)))
        (ssdel (car e11) ss)
        (ssdel (car e12) ss)
        (vl-cmdf "_.chamfer" "_d" dd dd (car e11) (car e12))
        (setq lwf t)
      )
      (vl-cmdf "_.chamfer" "_d" dd dd (car e11) (car e12))
    )
    (setq e2 (car (entsel "\nSelect chamfer hypotenuse : ")))
    (not (initget 7))
    (setq d (getdist "\nEnter length of chamfer (perpendicular to leg) : "))
    (vl-cmdf "_.offset" d (car e11) (@midp e2) "")
    (setq p11 p1 p22 p2)
    (setq e3 (entlast))
    (setq p3 (mapcar (function +) (list 0.0 0.0 0.0) (vlax-invoke (e2o e2) (quote intersectwith) (e2o e3) 3)))
    (if (< (distance p3 p1) (distance p3 p2))
      (entmod (subst (cons 10 p3) (cons 10 p1) (entget e2)))
      (entmod (subst (cons 11 p3) (cons 11 p2) (entget e2)))
    )
    (if (and e3 (not (vlax-erased-p e3)))
      (progn
        (entdel e3)
        t
      )
    )
    (setq p4 (vlax-curve-getclosestpointto (car e11) p3 t))
    (setq ee1
      (entmakex
        (list (cons 0 "LINE")
          (cons 10 p3)
          (cons 11 p4)
        )
      )
    )
    (if (< (distance p4 (cdr (assoc 10 (entget (car e11))))) (distance p4 (cdr (assoc 11 (entget (car e11))))))
      (entupd (cdr (assoc -1 (entmod (subst (cons 10 p4) (assoc 10 (entget (car e11))) (entget (car e11)))))))
      (entupd (cdr (assoc -1 (entmod (subst (cons 11 p4) (assoc 11 (entget (car e11))) (entget (car e11)))))))
    )
    (vl-cmdf "_.offset" d (car e12) (@midp e2) "")
    (setq e3 (entlast))
    (setq p3 (mapcar (function +) (list 0.0 0.0 0.0) (vlax-invoke (e2o e2) (quote intersectwith) (e2o e3) 3)))
    (if (< (distance p3 p11) (distance p3 p22))
      (entmod (subst (cons 10 p3) (cons 10 p1) (entget e2)))
      (entmod (subst (cons 11 p3) (cons 11 p2) (entget e2)))
    )
    (if (and e3 (not (vlax-erased-p e3)))
      (progn
        (entdel e3)
        t
      )
    )
    (setq p4 (vlax-curve-getclosestpointto (car e12) p3 t))
    (setq ee2
      (entmakex
        (list (cons 0 "LINE")
          (cons 10 p3)
          (cons 11 p4)
        )
      )
    )
    (if (< (distance p4 (cdr (assoc 10 (entget (car e12))))) (distance p4 (cdr (assoc 11 (entget (car e12))))))
      (entupd (cdr (assoc -1 (entmod (subst (cons 10 p4) (assoc 10 (entget (car e12))) (entget (car e12)))))))
      (entupd (cdr (assoc -1 (entmod (subst (cons 11 p4) (assoc 11 (entget (car e12))) (entget (car e12)))))))
    )
    (if lwf
      (progn
        (setvar (quote peditaccept) 1)
        (ssadd (car e11) ss)
        (ssadd ee1 ss)
        (ssadd e2 ss)
        (ssadd ee2 ss)
        (ssadd (car e12) ss)
        (vl-cmdf "_.pedit" "_m" ss "" "_j")
        (while (< 0 (getvar (quote cmdactive)))
          (vl-cmdf "")
        )
      )
    )
  )
  (*error* nil)
)

 

HTH.

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 13 of 13

john.uhden
Mentor
Mentor

@marko_ribar ,

I admire your improvement.

John F. Uhden

0 Likes