Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Copy/Multiply/Cloning Polyline and Connect to Specify Point

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
emreakyazicigsl
1525 Views, 16 Replies

Copy/Multiply/Cloning Polyline and Connect to Specify Point

Hello everyone, I was looking for a LISP that copy or multiply a polyline exactly and then connect to the specified point or pick point of block by creating a new pline. I explained with 2 PNGs, I hope you may help.

1)

Polyline Multiple 2.png

2)

Polyline Multiple.png

Tags (3)
Labels (3)
16 REPLIES 16
Message 2 of 17
hak_vz
in reply to: emreakyazicigsl

Here is solution for Case 1

If direction of newly added polyline is to wrong direction use command REVERSE on base polyline and start again.

I'll leave case 2 to someone else since you didn't provide sufficient details. 

Next time you can try to write down some code and also attach dwg sample for easier work on code. If you attach screenshots it's a plus.

 

(defun c:nps ( / *error* take pointlist2d adoc e eo p1 p2 d1 d2 pts i rev)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(setvar 'cmdecho 1)
		(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)) 
	(setq e (car (entsel "\nSelect polyline >")))
	(cond 
		((and e)
			(setq eo (vlax-ename->vla-object e))
			(cond
				((= (vlax-get eo 'Objectname) "AcDbPolyline")
					(setq p1 (take 2(getpoint "\nSelect point >")))
					(setq p2 (take 2(vlax-curve-getClosestPointTo eo p1)))
					(setvar 'cmdecho 0)
					(setq d1 (vlax-curve-getdistatparam eo (vlax-curve-getParamAtPoint eo p2)))
					(setq pts (pointlist2d (vlax-get eo 'Coordinates)))
					(setq i 0)
					(while (< (vlax-curve-getDistAtPoint eo (nth i pts)) d1) (setq i(1+ i)))
					(setq pts (append (take i pts)(list p2 p1)))
					(entmakex
						(apply 'append
							(cons
							  (list
								'(0 . "LWPOLYLINE")
								'(100 . "AcDbEntity")
								'(100 . "AcDbPolyline")
								'(410 . "Model")
								'(8 . "0")
								'(38 . 0)
								'(62 . 3)
								'(67 . 0)
								'(70 . 0)
								(cons 90 (length pts))
							  )
							  (mapcar 'list (mapcar '(lambda (a) (cons 10 a)) pts))
							) 
						)
					)
					(setvar 'cmdecho 1)
				)
			)
		)
	)
	(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 3 of 17
Sea-Haven
in reply to: emreakyazicigsl

Is this an extra to https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/break-amp-fillet-amp-join-a-polyline...

 

I have something but a bit buggy so did not post but creates 2 plines.

 

It would have been better to have asked at your other post for some more options. In saying that how many more combinations do you want ?

 

 

Message 4 of 17
Sea-Haven
in reply to: hak_vz

Hak_vz need to pick pline near end this gives direction then can get angle of that segment, know angle can draw a line towards the pline use fillet to join. 

 

In other post asks for radius but in this post not requested the other post has a rad value so could be user input to zero.

Message 5 of 17
Sea-Haven
in reply to: emreakyazicigsl

Case 1 but with a radius needs slight adjust to break for a zero radius use same pt twice.

 

;  https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/break-amp-fillet-amp-join-a-polyline-line/td-p/10707334

(defun c:dbl5 ( / rad oldsnap pt pt2 ent1 ent2 ent3 ent4 ent5 obj obj2)
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq rad 5.0)

(setq pt (getpoint "\nPick point"))

(setq ent1 (entsel "Pick p/Line "))

(setq obj (vlax-ename->vla-object (car ent1 )))

(if (= (vla-get-objectname obj) "AcDbline")
(progn
   (command "Pedit" ent1 "Y" "" )
   (setq ent1 (entlast))
  (setq obj (vlax-ename->vla-object ent1))
  )
)

(setq pt2 (vlax-curve-getclosestpointto obj pt))
(command "circle" pt2 rad)
(setq ent2 (entlast))
(setq obj2 (vlax-ename->vla-object ent2))
(setq pts (vlax-invoke obj 'intersectWith obj2 acExtendnone))

(entdel (entlast))

(setq pt2 (polar pt (angle pt pt2 )(- (distance pt pt2) rad)))

(command "Break" (list (nth 0 pts)(nth 1 pts))(list (nth 3 pts)(nth 4 pts)))
(setq ent5 (entlast))

(command "LINE" pt pt2 "")
(setq ent3 (entlast))

(command "LINE" pt pt2 "")
(setq ent4 (entlast))

(setvar 'filletrad rad)

(command "fillet" ent1 ent3)
(command "fillet" ent5 ent4)

(setvar 'osmode oldsnap)
(princ)
)
(c:dbl5)

 As requested in other post. 

Message 6 of 17
emreakyazicigsl
in reply to: hak_vz

Thank you so much. That's so good but I was wondering if new pline may take all their properties from source pline?

								'(8 . "0")
								'(38 . 0)
								'(62 . 3)
								'(67 . 0)
								'(70 . 0)

 

Also, can I use osnap on while I'm selecting my pick point? That would be important for me while merging blocks and plines. Plus, while merging further point, can we use x,y coordinates and 90 degrees instead of hypotenuse as you can see in PNG (alternative section, in bottom)?

emreakyazicigsl_0-1635067857803.png

 

Message 7 of 17
emreakyazicigsl
in reply to: Sea-Haven

Since they were different cases, I thought different question posts should be more propriate. In your reply and dbl5 command, there is no 'cloning pline' as same as source pline, only break fillet new segments of pline and join. I thought they were different.
Message 8 of 17
hak_vz
in reply to: emreakyazicigsl

@emreakyazicigsl 

Here is updated code for case 1

 

(defun c:nps ( / *error* take pointlist2d adoc e eo fo p1 p2 d1 d2 pts i rev)
	(defun *error* ( msg )
		(if (not (member msg '("Function cancelled" "quit / exit abort")))
			(princ)
		)
		(setvar 'cmdecho 1)
		(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)) 
	(setq e (car (entsel "\nSelect polyline >")))
	(cond 
		((and e)
			(setq eo (vlax-ename->vla-object e))
			(cond
				((= (vlax-get eo 'Objectname) "AcDbPolyline")
					(setvar 'cmdecho 0)
					(command "_.copy" e  "" "_none" '(0 0 0) "_none" '(0 0 0))
					(setq fo (vlax-ename->vla-object (entlast)))
					(setq p1 (take 2(getpoint "\nSelect point >")))
					(setq p2 (take 2(vlax-curve-getClosestPointTo eo p1)))
					(setq d1 (vlax-curve-getdistatparam eo (vlax-curve-getParamAtPoint eo p2)))
					(setq pts (pointlist2d (vlax-get eo 'Coordinates)))
					(setq i 0)
					(while (< (vlax-curve-getDistAtPoint eo (nth i pts)) d1) (setq i(1+ i)))
					(setq pts (append (take i pts)(list p2 p1)))
					(vlax-put fo 'Coordinates (apply 'append pts))
					(setvar 'cmdecho 1)
				)
			)
		)
	)
	(princ "\nDone1")
	(princ)
)

 

 

Problem is not as simple as it looks, since drawing direction of base polyline affects how code works. For case 1 this can be solved by reverting polyline. For case 2 this won't work. Also I suppose you are not working only along x axis.

If I find some time to work on this I'll try to make some code that joins case 1 and 2.

 

 

 

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 9 of 17
emreakyazicigsl
in reply to: hak_vz

Thank you so so much. If you can join both, I'll be here ofc. But right now, it's also amazing. I really thank you.
Message 10 of 17
Sea-Haven
in reply to: emreakyazicigsl

Have a look at your other post.

SeaHaven_0-1635133067018.png

 

Message 11 of 17
Sea-Haven
in reply to: emreakyazicigsl

Try this for Case 2 

 

; sq to point and extend pline
; By AlanH Oct 2021

(defun c:sq2pt ( / pt pt1 pt2 pt3 ent ent2 obj obj1 xyz co-ordsxy d1 d2 ang
(setq pt (getpoint "\nPick point"))
(setq ent (entsel "\nPick pline near end "))

(setq pt3 (cadr ent))
(setq obj (vlax-ename->vla-object (car ent)))

(setq xyz (vlax-get Obj 'Coordinates))

(setq I 0 co-ordsxy '())
(repeat (/ (length xyz) 2)
(setq xy (list (nth i xyz)(nth (+ I 1) xyz) ))
(setq co-ordsxy (cons xy co-ordsxy))
(setq I (+ I 2))
)

(setq pt1 (nth 0 co-ordsxy))
(setq pt2 (last co-ordsxy))
(setq d1 (distance pt1 pt3))
(setq d2 (distance pt2 pt3))
(if (> d1 d2)
(setq co-ordsxy (reverse co-ordsxy))
)

(setq pt1 (nth 0 co-ordsxy))
(setq pt2 (nth 1 co-ordsxy))
(setq ang (angle pt2 pt1))

(command "xline" pt1 pt2 "")
(setq obj1 (vlax-ename->vla-object (entlast)))

(setq pt3 (vlax-curve-getclosestpointto obj1 pt))
(command "line" pt pt3 "")
(setq ent2 (entlast))
(vla-delete obj1)

(princ) 

)
Message 12 of 17
emreakyazicigsl
in reply to: Sea-Haven

It's amazing, for case 2, this was what I was looking for. Only, if we can copy/multiple/clone original pline, then fillet and join the new pline created, that would be exactly what I seek.
Message 13 of 17
Sea-Haven
in reply to: emreakyazicigsl

Need more detail, image etc.

Message 14 of 17
emreakyazicigsl
in reply to: Sea-Haven

Oh, sorry. Here you are.

emreakyazicigsl_2-1635258160920.png

 

 

 

Message 15 of 17

Ignore the osnap on need part (png2), I'm confused with other LISP question. Other pictures are still valid.

Message 16 of 17
VUHOACH
in reply to: hak_vz

CAN YOU WRITE WITH LISP BUT CAN WORK WITH CURVES LIKE THE PICTURE BELOW?

 

 

 

VUHOACH_1-1667494237563.png

VUHOACH_2-1667494305681.png

 

Message 17 of 17
Sea-Haven
in reply to: emreakyazicigsl

Did something for sewer & drainage connections offset pline then drag over house lot boundary and get result you want.

 

Trying to find it. 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report