Callout dimension of a chamfer by select 2 edges!

Callout dimension of a chamfer by select 2 edges!

Anonymous
Not applicable
2,754 Views
23 Replies
Message 1 of 24

Callout dimension of a chamfer by select 2 edges!

Anonymous
Not applicable

Chamfer.png

 

--------------------------------------------

Instead of callout the dimension 10x10, Can we choose 2 edges to callout a C10 as ficture above in Autocad or have a lisp to do that ?

0 Likes
Accepted solutions (2)
2,755 Views
23 Replies
Replies (23)
Message 2 of 24

hak_vz
Advisor
Advisor

Try this

 

(defun c:cld ( / p1 p2 txt mp oldorto)
(setq p1 (getpoint "\nSelect first point >"))
(setq p2 (getpoint "\nSelect second point >"))
(setq oldorto (getvar 'orthomode))
(setvar 'orthomode 0)
(setq txt (strcat "C" (rtos(abs(car(mapcar '- p1 p2))) 2 0)))
(setq mp (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5)))
(command "_.leader" mp pause "" txt "")
(setvar 'orthomode oldorto)
(princ)
)

Miljenko Hatlak

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 3 of 24

Kent1Cooper
Consultant
Consultant

Choosing only at B should be enough if it's a Chamfer at equal setbacks of two orthogonal, perpendicular Lines [or Polyline segments].  Is that always the condition?  Do you want to choose at A because they may not always be orthogonal?  If they are not always perpendicular, or not always orthogonal, but if the Chamfer setbacks are always equal, then choosing the two Lines or segments on either side of the corner, not the corner piece, would be more useful.

Kent Cooper, AIA
0 Likes
Message 4 of 24

hak_vz
Advisor
Advisor

Here is another version that takes into account system variable chamfera to get chamfer distance.

As in first example you just have to take edge points  of chamfer line (not your A and B).

This two points are selected so that leader arrow is set at the middle of chamfered edge.

 

(defun c:cld ( / p1 p2 txt mp oldorto)
(setq oldorto (getvar 'orthomode))
(setvar 'orthomode 0)
(setq p1 (getpoint "\nSelect first point >"))
(setq p2 (getpoint "\nSelect second point >"))
(setq mp (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5)))
(setq txt (strcat "C" (rtos (getvar 'chamfera) 2 0)))
(command "_.leader" mp pause "" txt "")
(setvar 'orthomode oldorto)
(princ)
)

 

 

Miljenko Hatlak

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 24

Kent1Cooper
Consultant
Consultant

@hak_vz wrote:

.... takes into account system variable chamfera to get chamfer distance.

....


That assumes that the Chamfer was done under the current CHAMFERA setting [and that CHAMFERB is equal], which would be fine if labeled immediately after doing the Chamfer.  @Anonymous , is this something you want to be able to do later, so that the current CHAMFERA setting may not be what was used to make the Chamfer you select?

Kent Cooper, AIA
0 Likes
Message 6 of 24

Kent1Cooper
Consultant
Consultant

@hak_vz wrote:
....
(setq txt (strcat "C" (rtos(abs(car(mapcar '- p1 p2))) 2 0)))
....

@Anonymous , here is why my questions matter, just in the case where the Chamfered lines are perpendicular, and with equal Chamfer distances, but if they may not always be orthogonal.  The left one is as in your image [but at Chamfer distances of 5], and correct, but note the values in the others, rotated versions of the same thing:

ChamferLabel.PNG

[I had to change the 0 in the code line above to 2 to get the second & fourth values not rounded off.  Would you always want it rounded to the nearest whole-number value?]

 

And if they may not always be perpendicular, and/or may not always be equal distances, it's an entirely different animal.

Kent Cooper, AIA
0 Likes
Message 7 of 24

hak_vz
Advisor
Advisor

@Kent1Cooper wrote:

Choosing only at B should be enough if it's a Chamfer at equal setbacks of two orthogonal, perpendicular Lines [or Polyline segments].  Is that always the condition?  Do you want to choose at A because they may not always be orthogonal?  If they are not always perpendicular, or not always orthogonal, but if the Chamfer setbacks are always equal, then choosing the two Lines or segments on either side of the corner, not the corner piece, would be more useful.


I have created my code assuming what you described, since if this conditions are not fulfilled, then using leader instead dim lines is technically incorrect, and requires different dimensioning. I prefer first version, but under conditions you have elaborated in both of your posts, second version can be used.

 

Miljenko Hatlak

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 8 of 24

Kent1Cooper
Consultant
Consultant

@hak_vz wrote:
.... under conditions you have elaborated in both of your posts, second version can be used.

... if the Chamfer in question was made under the current CHAMFERA setting, and if it was made with equal CHAMFERA and CHAMFERB settings.  I still want to hear from @Anonymous whether or not those conditions can be assumed.

Kent Cooper, AIA
0 Likes
Message 9 of 24

ВeekeeCZ
Consultant
Consultant

One more version.

 

(defun c:ChL (/ s e m d c)
  
  (and (setq s (cadr (entsel "\nSelect a chamfer: ")))
       (setq e (osnap s "_end"))
       (setq m (osnap s "_mid"))
       (setq d (* 2 (distance e m)))
       (setq c (strcat "C" (rtos (sqrt (/ (* d d) 2)) 2 0)))
       (command "_.mleader" "_mid" m pause c ""))
  (princ)
  )

 

0 Likes
Message 10 of 24

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:

One more version.....


... if the Chamfered things are perpendicular, and the Chamfer distances are equal.  @Anonymous , will that always be the case?

Kent Cooper, AIA
0 Likes
Message 11 of 24

CodeDing
Advisor
Advisor

@Kent1Cooper ,

 

Maybe we can work with something like this? Is not dependent on any system variables. Determines Chamfer on the fly and direction MLeader should go.

 

Any thoughts?

 

(Can't upload images at the moment to show final result)

 

(defun c:TEST ( / e fivePoints chamferData c1 c2 dist angRad midPt)
  (if (and (setq e (entsel "\nSelect Chamfered Segment: "))
           (eq "LWPOLYLINE" (cdr (assoc 0 (entget (car e)))))
           (setq fivePoints (Get5P e))
           (setq chamferData (GetChamferData fivePoints))
      );and
    (progn
      (setq c1 (cadr chamferData)                 ;; chamfer distance 1
            c2 (caddr chamferData)                ;; chamfer distance 2
            dist (max c1 c2)                      ;; distance out from chamfer (for leader)
            angRad (GetRad fivePoints chamferData);; angle out from chamfer (in radians)
            midPt (caddr fivePoints)              ;; mid point on chamfer
      );setq
      (command "_.MLEADER" "non" midPt "non" (polar midPt angRad dist)
               (strcat "C1-" (rtos c1 2 2) " / C2-" (rtos c2 2 2)))
      (prompt "\nComplete.")
    );progn
  );if
  (princ)
);defun

(defun GetRad (fp cd / p2 p4)
  ;returns angle (radian) of direction perpendicular outward from chamfer
  (setq p2 (cadr fp) p4 (cadddr fp))
  (angtof
    (angtos
      (if (> (SideOf p2 p4 (car cd)) 0)
        (+ (angle p2 p4) (* 0.5 pi))
        (- (angle p2 p4) (* 0.5 pi))
      );if
      0
      14
    );angtos
    0
  );angtof
);defun

(defun GetChamferData (fp / iPt)
  ;returns ([intersection point] [chamfer distance 1] [chamfer distance 2])
  (list
    (setq iPt (inters (car fp) (car (cdr fp)) (car (cdddr fp)) (car (cddddr fp)) nil))
    (distance (cadr fp) iPt)
    (distance (cadddr fp) iPt)
  );list
);defun

(defun Get5P (e / MultiAssoc pList p1 p2 p3 p4 p5)
  ;returns 5 points as list
  ;...first 2 are points before chamfer
  ;...3rd is midpoint of chamfer
  ;...last 2 are points after chamfer
  (setq MultiAssoc (lambda (k l / i) (if (setq i (assoc k l)) (cons (cdr i) (MultiAssoc k (cdr (member i l)))))))
  (setq pList (MultiAssoc 10 (entget (car e))))
  (setq p3 (osnap (cadr e) "_nea"))
  (while (and (not (and p1 p2 p4 p5))
              pList)
    (cond
      (p4 (setq p5 (car pList))) 
      (p2 (setq p4 (car pList)))
      (p1 (setq p2 (car pList)))
      (t  (setq p1 (car pList)))
    );cond
    (setq pList (cdr pList))
  );while
  (while (and (not (LM:Collinear-p p2 p3 p4))
              pList)
    (setq p1 p2 p2 p4 p4 p5 p5 (car pList) pList (cdr pList))
  );while
  (if (and (LM:Collinear-p p2 p3 p4)
           (not (LM:Collinear-p p1 p3 p5))
      );and
    (list p1 p2 (polar p2 (angle p2 p4) (* 0.5 (distance p2 p4))) p4 p5)
  );if
);defun

;; Collinear-p  -  Lee Mac
;; Returns T if p1,p2,p3 are collinear
(defun LM:Collinear-p ( p1 p2 p3 )
    (
        (lambda ( a b c )
            (or
                (equal (+ a b) c 1e-8)
                (equal (+ b c) a 1e-8)
                (equal (+ c a) b 1e-8)
            )
        )
        (distance p1 p2) (distance p2 p3) (distance p1 p3)
    )
)

;;D. C. Broad, Jr.
;;(sideof [ray-origin] [another-point-on-ray] [point-to-be-tested])
;;return values
;;negative = point is to the right side of the ray
;;0 = point is on the ray
;;otherwise point is on the left side of the ray.
;;P1 should not equal P2 for meaningful results.
(defun SideOf (p1 p2 p / r)
  (setq r (cond
            ((equal p1 p 1e-10) 0)
            (t (sin (- (angle p1 p) (angle p1 p2))))
          )
  )
  (if (equal r 0 1e-10) 0 r)
)

 

Best,

~DD

0 Likes
Message 12 of 24

Kent1Cooper
Consultant
Consultant

@CodeDing wrote:

.... Any thoughts? ....


Another thing we need to know from @Anonymous is what kind of object(s) they're working with.  It looks like your suggestion depends on it being a Chamfered corner of a LWPolyline, but it could just as well be three Lines.

Kent Cooper, AIA
Message 13 of 24

CodeDing
Advisor
Advisor

What kind of barbarian chamfers LINES?! Lol jk. Good insight.

0 Likes
Message 14 of 24

Anonymous
Not applicable

Cham1.png

Thank you very much for your support! It meet as my expecting but can you improve your code as Figure above?

And It can choose only one edges instead of choose 2 points as yourcode? if it can not I am still happy^^

0 Likes
Message 15 of 24

Anonymous
Not applicable

Many thanks for your reply, but I want to improve somethings as fig. below!

Cham1.png

0 Likes
Message 16 of 24

hak_vz
Advisor
Advisor

@AnonymousEverything is possible but please attach sample drawing so we can figure out what objecs you use, and how to show data when cut is not 45°

Miljenko Hatlak

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 17 of 24

Anonymous
Not applicable

Thank you very much for your help! But your lisp only support for LWPOLYLINE? It can choose the lines?

0 Likes
Message 18 of 24

Anonymous
Not applicable

The attached file is my sample drawing!

0 Likes
Message 19 of 24

hak_vz
Advisor
Advisor
Accepted solution

Try this modified version

 

(defun c:cld ( / e ent p1 p2 txt mp oldorto vec dx dy ent)
	(cond
		((setq e (car (entsel "\nSelect chamfer line edge>")))
			(cond
				((and  (setq ent (entget e))(= (cdr (assoc 0 ent)) "LINE"))
					(setq oldorto (getvar 'orthomode))
					(setvar 'orthomode 0)
					(setq
						p1 (cdr(assoc 10 ent))
						p2 (cdr(assoc 11 ent))
						vec (mapcar 'abs (mapcar '- p1 p2))
						dx (car vec)
						dy (cadr vec)
						mp (mapcar '* (mapcar '+ p1 p2) '(0.5 0.5))
					)
					(if(= dx dy)
						(command "_.mleader" "_mid" mp pause (strcat "C" (rtos dx 2 0)) "")
						(command "_.mleader" "_mid" mp pause "Error" "")
					)
					(setvar 'orthomode oldorto)
				)
				(T (princ "\nEntity is not a line!"))
			)	
		)
		(T (princ "\nNothing selected!"))
	)
(princ)
)

Miljenko Hatlak

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.
Message 20 of 24

Anonymous
Not applicable

Thank you very much! It is perfect!