Hello, I would like to adapt the code below to work with these new blocks. The goal is to add functionality to split and join polylines. I would also like to make it bulletproof, as I've noticed that the current code doesn't work correctly at certain angles.
;;ВeekeeCZ
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/efficient-techniques-for-enlarging-polylines-adding-length/m-p/12468169#M459583
(defun c:ins35 ( / p e)
(command "_.-insert" "20M" "_s" 1 pause pause
"_.explode" "_l"
"_.draworder" "_l" "" "_b")
(setq e (entlast)
p (car (nentselp (getvar 'lastpoint))))
(command "_.break" p
"_non" (trans (vlax-curve-getendpoint e) 0 1)
"_non" (trans (vlax-curve-getstartpoint e) 0 1))
(initcommandversion)
(command "_.join" p e "_l" "")
(princ)
)
Solved! Go to Solution.
Solved by Moshe-A. Go to Solution.
Solved by Kent1Cooper. Go to Solution.
@adaptacad wrote:
.... the current code doesn't work correctly at certain angles. ....
That's never enough information. What is incorrect about whatever it does? Can you post a drawing file containing something on which it does whatever it does wrong?
Also, it appears that the code is assuming that the coil part will always be what amounts to the "Last" object after Exploding the Block. Can you be certain that "Last" will never be the Text instead? [Was the original routine written for Blocks containing only one object, like a Polyline or Arc or something?]
The goal is to add length to a polyline.
@adaptacad hi,
@adaptacad wrote:The goal is to add length to a polyline.
- Insert the block: Click on the polyline, and it will break.
- Add the block at the desired interval to increase the length by 20, 30, 40, 50, etc.
- Then, join the polyline back together.
i am sorry, for better understanding give us more specific details
post a dwg with before and after state
why break the pline and than join it?
Moshe
@adaptacad wrote:
The goal is ....
I understand that much. [@Moshe-A , note that the Polylines in the Blocks are coils that go around different numbers of times, 10 units per loop adjusted for the little straight ends, so their total lengths are according to the Text, and they will add that amount to the total Polyline length once Joined.] But it doesn't answer my questions in Message 2.
Thanks! The problem is actually that the last object that was exploding was a text, removed and worked on.
@adaptacad wrote:
Since this is a loop, is it possible to add it without needing the block? specifying only the size?
If you want to be able to select the longer Polyline and get a total length including the loops, then I expect it will be necessary to have them joined, with the difference of the actual length of what's in each kind. But you could -Insert the Blocks pre-exploded, and save a step. Prefix the command name with a hyphen - and prefix the Block name with an asterisk *. [Maybe redefine the Blocks without the Text?] Note that it will ask for only one scale factor, and you won't see it drag into position or rotation, but you can still give it an insertion point and rotation Osnapped to the longer Polyline.
@adaptacad hi,
check this PUSHIN command.
the following declaration are constant but you can change them to meet other requirements
(setq ENTER_LEG 0.5) ; const
(setq CIRC_RAD 1.5) ; const
the first is the 0.5 segment starting the arc
the second is minimum arc radius to check
selecting polyarc is rejected. if you pick too close to endpoint this is also rejected
it works in a big loop so you can pick plines again to push more coils.
oh yes...no need for block it is done with polyline as whole 😀
enjoy
Moshe
(vl-load-com) ; load ActiveX support
(defun c:pushin (/ isStraightSegment calcRad askdist ; local functions
ENTER_LEG CIRC_RAD pick0 pick1 ename0 ename1 elist0 ;| p0 p1 p2|; plen prm rad r)
(defun isStraightSegment (edata t1)
(vl-some
(function
(lambda (t2 blg)
(and
(equal (distance t1 t2) 0.0 1e-3)
(= blg 0.0)
)
); lambda
); function
(setq l1 (mapcar 'cdr (vl-remove-if-not (function (lambda (itm) (= (car itm) 10))) edata))) ; points
(setq l2 (mapcar 'cdr (vl-remove-if-not (function (lambda (itm) (= (car itm) 42))) edata))) ; bulges
); vl-some
); isStraightSegment
; calculate circle radius
; Qr is quote int
(defun calcRad (len Qr / i)
(setq i 1)
(while (> (/ (1- len) i pi 2) CIRC_RAD)
(setq i (1+ i))
)
(set Qr (1- i)) ; indirect set
(/ (1- len) (1- i) pi 2)
); calcRad
(defun askdist (msg def / ask)
(initget (+ 2 4))
(if (not (setq ask (getdist (strcat "\n" msg " <" (rtos def 2) ">: "))))
(setq ask def)
(setq def ask)
)
); askdist
(setvar "cmdecho" 0)
(command "._undo" "_begin")
(setq ENTER_LEG 0.5) ; const
(setq CIRC_RAD 1.5) ; const
(if (= (getvar "userr5") 0.0)
(setvar "userr5" 20.0)
)
(while (and
(setq pick0 (entsel "\nPick pline: "))
(setq ename0 (car pick0))
(setq elist0 (entget ename0))
(= (cdr (assoc '0 elist0)) "LWPOLYLINE")
(setq p0 (cadr pick0))
)
(setq p0 (vlax-curve-getClosestPointToProjection ename0 p0 '(0.0 0.0 1.0)))
(setq prm (vlax-curve-getParamAtpoint ename0 p0))
(setq p1 (vlax-curve-getPointAtParam ename0 (fix prm)))
(setq p2 (vlax-curve-getPointAtParam ename0 (1+ (fix prm))))
(cond
((not (isStraightSegment elist0 p1))
(vlr-beep-reaction)
(princ "\nPick straight polyline segment.")
); case
((or
(< (distance p0 p1) ENTER_LEG)
(< (distance p0 p2) ENTER_LEG)
)
(vlr-beep-reaction)
(princ "\nMove away from vertex.")
); case
((setvar "userr5" (setq plen (askdist "Total length to pushin" (getvar "userr5"))))
(command "._break" ename0 "_None" (polar p0 (angle p2 p1) ENTER_LEG) "_None" (polar p0 (angle p1 p2) ENTER_LEG))
(setq ename1 (entlast))
(setq rad (calcRad plen 'r))
(command "._pline" "_None" (polar p0 (angle p2 p1) ENTER_LEG) "_width" 0 0 "_None" p0 "_Arc")
(repeat r
(command "_None" (polar p0 (- (angle p1 p2) (/ pi 2)) (* rad 2)) "_None" p0)
)
(command "_Line" "_None" (polar p0 (angle p1 p2) ENTER_LEG) "")
(command "._join" ename0 (entlast) ename1 "")
(command "._text" "_Middle" (polar p0 (- (angle p1 p2) (/ pi 2)) rad) ENTER_LEG 0 (rtos plen 2 0))
); case
); cond
); while
(command "._undo" "_end")
(setvar "cmdecho" 1)
(princ)
)
Can't find what you're looking for? Ask the community or share your knowledge.