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)
2)
Solved! Go to Solution.
Solved by hak_vz. Go to Solution.
Solved by hak_vz. Go to Solution.
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
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 ?
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.
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.
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)?
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
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)
)
Ignore the osnap on need part (png2), I'm confused with other LISP question. Other pictures are still valid.
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.