Changing the new chamfer command!

Changing the new chamfer command!

boyds86
Enthusiast Enthusiast
1,069 Views
12 Replies
Message 1 of 13

Changing the new chamfer command!

boyds86
Enthusiast
Enthusiast

Hello,

 

I want to change the current chamfer command by using autolisp below. But i am facing with a problem.

When I join the lines, If lines are separeted, it only chamfers the last object as command below.

 

After joining objects, It can create 1 or 2 or 3.......polylines. And the last polyline wil be chamfered only. There any way to chamfer all polyline objects that created after "Join" command?  and explode all polyline objects After chamfered?

 

Thank you!

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun C:CHÀ ()

(setq A (ssget "_:L" '((-4 . "<and") (0 . "*LINE")(-4 . "and>"))))
(command "join" A "")
(setq B (entlast))
(command "chamfer" "P" "d" pause pause B "")
(setq C (entlast))
(command "explode" C "")
(princ)
)

;;;;;;;;

HEHEH.png

0 Likes
Accepted solutions (1)
1,070 Views
12 Replies
Replies (12)
Message 2 of 13

Sea-Haven
Mentor
Mentor

Step 1 join all lines

Step2 is ssget all new plines that have been joined.

Step3 loop through the selection set doing Chamfer for each pline in the selection, hint ssname.

Step 4 go get a coffee as all done.

0 Likes
Message 3 of 13

boyds86
Enthusiast
Enthusiast
Thank you for yoursupport but is there a way to combine Step1&step2? I mean I want to choose onetime only!
0 Likes
Message 4 of 13

ВeekeeCZ
Consultant
Consultant
Accepted solution

Should work with both pls and lines. 

 

(defun c:CHA ( / s e i)
  
  (and (setq s (ssget "_:L" '((0 . "LINE,LWPOLYLINE"))))
       (setq e (entlast))
       (initcommandversion)
       (not (command "_.join" s ""))
       (or (if (> (getvar 'cmdactive) 0) (command))
	   T)
       (setq s (cond ((ssget "_P" '((0 . "LWPOLYLINE") (-4 . ">") (90 . 2))))
		     ((ssadd))))
       (or (while (setq e (entnext e))
	     (if (and (= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
		      (< 2 (cdr (assoc 90 (entget e)))))
	       (ssadd e s)))
	   T)
       (not (command "_.chamfer" "_d" pause pause))
       (repeat (setq i (sslength s))
	 (vl-cmdf "_.chamfer" "_p" (ssname s (setq i (1- i)))))
       (initcommandversion)
       (command "_explode" s "")
       )
  (princ)
  )

 

Message 5 of 13

hak_vz
Advisor
Advisor

Function to chamfer multiple lines lwpolylines at contacts. Works with lines, lwpolylines and multi-segments lwpolyline.

 

 

(defun c:mycha ( / *error* adoc unique take pointlist2d count ss i pts  res )
	;CREATED:Monday, October 31, 2022
	;Author:  hak_vz 
	;https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5530556
	;Posted at
	;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/changing-the-new-chamfer-command/td-p/11519219
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(setvar 'cmdecho 1)
		(princ)
	)
	(defun unique (lst)
		(cond 
			((null lst) lst)
			((member (car lst) (cdr lst))(unique (cdr lst)))
			(T (cons (car lst) (unique (cdr lst))))
		)
	)
	(defun take (amount lst / ret)(repeat amount (setq ret (cons (car lst) (take (1- amount) (cdr lst))))))
	(defun pointlist2d (lst / ret) (while lst (setq	ret (cons (take 2 lst) ret) lst (cddr lst))) (reverse ret))
	(defun count (x lst)
		(cond
			((null lst) 0)
			((equal x (car lst)) (+ 1 (count x (cdr lst))))
			(t (count x (cdr lst)))
		)
	)
	(setq adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	(setq ss (ssget '((0 . "LINE,LWPOLYLINE"))))
	(cond 
		((and ss)
			(setq i -1 pts (list))
			(while (< (setq i (1+ i)) (sslength ss))
				(setq eo (vlax-ename->vla-object (ssname ss i)))
				(cond 
					((vlax-property-available-p eo 'coordinates)
						(setq lpts (pointlist2d (vlax-get eo 'coordinates)))
						(if (> (length lpts) 2)
							(vl-cmdf "_.chamfer" "p" (ssname ss i))
							(setq pts (append pts lpts))
						)						
					)
					((vlax-property-available-p eo 'startpoint)
						(setq pts (append pts (list(take 2 (vlax-get eo 'startpoint)))))
						(setq pts (append pts (list(take 2 (vlax-get eo 'endpoint)))))
					)
						
				)
			)
			(setvar 'cmdecho 0)
			(foreach pt pts
				(if (> (count pt pts) 1) (setq res (cons pt res)))
			)
			(foreach pt (unique res)
					(setq ss (ssget "c" pt pt))
					(vl-cmdf "_.chamfer" (ssname ss 0) (ssname ss 1))
			)
			(setvar 'cmdecho 1)
			(vla-endundomark adoc)
			(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 6 of 13

boyds86
Enthusiast
Enthusiast

Thank you for yourconcern but It does not works for me! It only join the objects and stop!

0 Likes
Message 7 of 13

boyds86
Enthusiast
Enthusiast
Thank you for your time but It only chamfer the polyline and it does not has a step to input the value of chamfer (Depend on the previous value)?
0 Likes
Message 8 of 13

hak_vz
Advisor
Advisor
Modify chamfer expression in provided code according to your need, or create separate function that will define chamfer distance. Sorry but you didn't provided enough info for us to create function according to your exact needs

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 9 of 13

ВeekeeCZ
Consultant
Consultant

Try the updated version.

0 Likes
Message 10 of 13

boyds86
Enthusiast
Enthusiast

Thank you very much, It is good now but one more thing I need that all objects are exploded, Yourversion show that one object is exploded only. If all objects are exploded after chamfered, It will be great!

0 Likes
Message 11 of 13

boyds86
Enthusiast
Enthusiast
Thank you very much, I will try to test and modify it as I need!
0 Likes
Message 12 of 13

ВeekeeCZ
Consultant
Consultant

@boyds86 wrote:

Thank you very much, It is good now but one more thing I need that all objects are exploded, Yourversion show that one object is exploded only. If all objects are exploded after chamfered, It will be great!


 

Unless I am missing something it works that way already, at least on my end.

0 Likes
Message 13 of 13

boyds86
Enthusiast
Enthusiast
..................
.................
(repeat (setq i (sslength s))
(vl-cmdf "_.chamfer" "_p" (ssname s (setq i (1- i))))
(initcommandversion)
(command "_explode" s "")) <---Bracket should be here for all objects will be exploded!
------------------------------------
Thank you so much for yourtime! I really appreciate it!
0 Likes