programming challenge: how to draw outlines ?

programming challenge: how to draw outlines ?

ivanovsky
Enthusiast Enthusiast
1,964 Views
18 Replies
Message 1 of 19

programming challenge: how to draw outlines ?

ivanovsky
Enthusiast
Enthusiast

hi,every one.

here is the problem,

i have several lines (the colorful lines in 2nd pic) which are supposed to be offsetted both sides and chamfered,

how can i solve this prolem ?

is there any algrithm to solve this kind of problems ? 

thank you.

微信截图_20221228111029.png

微信截图_20221228121508.png

0 Likes
1,965 Views
18 Replies
Replies (18)
Message 2 of 19

Sea-Haven
Mentor
Mentor

Could be done there is lots of chamfer / fillet stuff out there. Before jumping in with code need a couple of questions to be answered, do you start with the c/l as per image and offset them ? The tricky part is where you have multiple crossing intersections that need to be done in one go. 

 

A sample dwg would help.

 

0 Likes
Message 3 of 19

ivanovsky
Enthusiast
Enthusiast

i start with lines which are in one single dwg.

0 Likes
Message 4 of 19

Sea-Haven
Mentor
Mentor

Post a sample dwg please.

0 Likes
Message 5 of 19

ivanovsky
Enthusiast
Enthusiast
ok.
i've add a pic and a dwg.
thanks.
0 Likes
Message 6 of 19

Sea-Haven
Mentor
Mentor

Will have a look at it.

0 Likes
Message 7 of 19

ivanovsky
Enthusiast
Enthusiast

hello,everyone, i need your help. 

any thought is good.

0 Likes
Message 8 of 19

john.uhden
Mentor
Mentor

@ivanovsky 

If you can stomach using the BOUNDARY (BPOLY) command to make one pick inside each of the triangular/multilateral cells, then the rest (offset & chamfer & cleanup) can be programmed.

John F. Uhden

0 Likes
Message 9 of 19

devitg
Advisor
Advisor

@ivanovsky , so this is the before 

 

devitg_0-1672255295299.png

Shall it be the inside lines the same color or any one . ?

 

 

 

0 Likes
Message 10 of 19

Sea-Haven
Mentor
Mentor

Like the idea Bpoly maybe allow for a square or polygon shape.

 

Pick pick pick is pretty fast around 0.5 second per pick not sure answer is that fast but even 1 second that is like 35 seconds.

0 Likes
Message 11 of 19

Sea-Haven
Mentor
Mentor

Give this a try

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/programming-challenge-how-to-draw-outlines/td-p/11644442

; off 500 chamfer 500
(defun c:wow (/ oldsnap oldlay off cham ent1 ent2 co-ord x pt plst)
  (setq oldsnap (getvar 'osmode))
  (setvar 'osmode 0)
  (setq oldlay (getvar 'clayer))
  (setq off (getdist "\nEnter offset "))
  (setq cham (getdist "\nEnter chamfer distance "))
  (setvar 'clayer "BSC_R_EDGE")
  (setvar 'chamferA cham)
  (setvar 'chamferB cham)
  (while (setq pt (getpoint "\nPick point inside Enter to exit "))
    (command "bpoly" pt "")
    (setq ent1 (entlast))
    (command "offset" off ent1 pt "")
    (setq ent2 (entlast))
    (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget ent2))))
    (setq co-ord (cons (last co-ord) co-ord))
    (command "erase" ent1 "")
    (setq x 0)
    (setq plst '())
    (repeat (- (length co-ord) 1)
      (setq plst (cons (mapcar '* (mapcar '+ (nth X co-ord) (nth (setq x (1+ x)) co-ord)) '(0.5 0.5)) plst))
    )
    (setq plst (cons (last plst) plst))
    (setq x 0)
    (repeat (- (length plst) 1)
      (command "Chamfer" (nth x plst) (nth (1+ x) plst))
      (setq x (1+ x))
    )
    (setvar 'osmode oldsnap)
  )
  (princ)
)
(c:wow)
Message 12 of 19

hak_vz
Advisor
Advisor

@ivanovsky 

Here is my solution to your request!

(defun c:pips ( / *error* take pointlist2dm mappend mklist flatten adoc od cd de do coords i p newcoords)
	;posted at
	;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/programming-challenge-how-to-draw-outlines/td-p/11644442
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(if (and adoc) (vla-endundomark adoc))
		(setvar 'cmdecho 1)
		(princ "\nDone!")
		(princ)
	)
	(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 mappend (fn lst)(apply 'append (mapcar fn lst)))
	(defun mklist (x) (if (listp x) x (list x)))
	(defun flatten (exp)(mappend 'mklist exp))
	(setq adoc (vla-get-activedocument (vlax-get-acad-object))) 
	(setvar 'cmdecho 0)
	(vla-endundomark adoc)
	(vla-startundomark adoc)
	(setq od (getreal "\nEnter offset distance >"))
	(setq cd (getreal "\nEnter chamfer distance >"))
		(while (setq pt (getpoint "\nPick internal point >"))
			
			
			(command "-boundary" pt "")
			(setq de (entlast))
			(vla-offset (vlax-ename->vla-object de)(* -1 od))
			(entdel de)
			(setq do (vlax-ename->vla-object (entlast)))
			(setq coords (pointlist2d(vlax-get do 'coordinates)))
			(setq coords (append coords (list (car coords))))
			(setq coords (append coords (list (cadr coords))))
			(setq i 0 p (1- (length coords)) newcoords (list))
				(while (< (setq i (1+ i)) p)
					(setq newcoords (append newcoords (list (polar (nth i coords) (angle (nth i coords) (nth (1- i) coords)) cd))))
					(setq newcoords (append newcoords (list (polar (nth i coords) (angle (nth i coords) (nth (1+ i) coords)) cd))))
				)
			(vlax-put do 'Coordinates (flatten newcoords))
		)
	(vla-endundomark adoc)
	(setvar 'cmdecho 1)
	(princ "\nDone!")
	(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 13 of 19

Sea-Haven
Mentor
Mentor

Hak_vz thought about doing a work out new points for the chamfer, just went down the lazy way. Nice job. The vlax-put is very fast.

 

Jut need Ivannovski to reply now.

0 Likes
Message 14 of 19

ivanovsky
Enthusiast
Enthusiast

thanks, i like your code. it works, but there is a little bug, some edge has wrong shape._20230109144138.png

0 Likes
Message 15 of 19

ivanovsky
Enthusiast
Enthusiast

they can have any color.

0 Likes
Message 16 of 19

ivanovsky
Enthusiast
Enthusiast
thanks for your code, it works properly.
i wonder a routine which could generate the outlines automaticly,
i wanna know related algrithms,
would you give me any advice?
0 Likes
Message 17 of 19

john.uhden
Mentor
Mentor

@hak_vz 

Did you notice that the large, um, polygon has a vertex pointing internally that doesn't want to get chamfered?

I haven't tried out your code or studied it enough to see if it handles that.  Does it?  If not then the challenge gets more complicated as each vertex will have to be analyzed to see if it's internal or external as only the external vertices should be chamfered.

At least I think I've found that an AutoCAD BOUNDARY (BPOLY) command always creates a CCW polyline (in the positive angular direction).  That can save a lot of coding.  I think you did because you multiplied the offset distance by -1 (to the left) which would be to the inside of a CCW polyline.  Good thinking!!

John F. Uhden

0 Likes
Message 18 of 19

ivanovsky
Enthusiast
Enthusiast
thank you for your advice.
i need a solution which could generate outlines automaticly, so i need some suggestion about algorithms.
0 Likes
Message 19 of 19

Sea-Haven
Mentor
Mentor

My advice is to fully automate task may takes hours of a programmers time versus the 30 seconds to do like 30 objects. Given your hourly rate of pay is 30 seconds to long v's say 4+ hours at my charge out rate. Or maybe it will be like 2 days. $0.0275 per 30.

0 Likes