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

Join polylines, arcs, lines that are on the same layers

21 REPLIES 21
SOLVED
Reply
Message 1 of 22
kameron1967
5529 Views, 21 Replies

Join polylines, arcs, lines that are on the same layers

Hi guys,

 

I've seen variations of pline join, but I need one that join lines/plines/arcs only if they are on the same layer.  Thanks in advance. If you want to use this one by Lee Mac as an example and just add the entities on the same layer portion, I'd much appreciate it.  🙂

 

(defun c:pj ( / pe ss )
  (setq pe (getvar 'PEDITACCEPT))
  (setvar 'PEDITACCEPT 1)
  (if (setq ss (ssget "_:L" '((0 . "ARC,LINE,LWPOLYLINE"))))
    (command "_.pedit" "_M" ss "" "_J" "" "")
  )
  (setvar 'PEDITACCEPT pe)
  (princ)
)

21 REPLIES 21
Message 2 of 22
hmsilva
in reply to: kameron1967

Something like this, perhaps

 

(defun c:pj ( / pe s ss )
  (setq pe (getvar 'PEDITACCEPT))
  (setvar 'PEDITACCEPT 1)
  (princ "\nPick one object to join: ")
  (if (and (setq s (ssget "_+.:E:S:L" '((0 . "ARC,LINE,LWPOLYLINE"))))
	   (princ "\nSelect the remaining objects to join: ")
	   (setq ss (ssget (list '(0 . "ARC,LINE,LWPOLYLINE") (assoc 8 (entget (ssname s 0))))))
	   )
    (command "_.pedit" "_M" ss "" "_J" "" "")
  )
  (setvar 'PEDITACCEPT pe)
  (princ)
)

 

HTH

Henrique

EESignature

Message 3 of 22
Shneuph
in reply to: kameron1967

Henrique beat me to it.. here's an alternate..

(defun c:pj ( / pe ss n indss cssname sslist)
  (setq pe (getvar 'PEDITACCEPT)
	n 1);setq
  (setvar 'PEDITACCEPT 1)
  (if (setq ss (ssget "_:L" '((0 . "ARC,LINE,LWPOLYLINE"))))
    (progn
      (while (> (sslength ss) 0)
	(setq clay (cdr (assoc 8 (entget (ssname ss 0)))))
	(setq cssname (strcat "ss-" clay))
	(if (not (eval (read cssname)))
	  (set (read cssname) (ssadd))
	  );if
	(ssadd (ssname ss 0) (eval (read cssname)))
	(ssdel (ssname ss 0) ss)
	(if (not (member cssname sslist))
	  (setq sslist (cons cssname sslist))
	  );if
	);while
      (foreach indss sslist
	(command "_.pedit" "_M" (eval (read indss)) "" "_J" "" "")
	(set (read indss) nil)
	);foreach
      );progn
    )
  (setvar 'PEDITACCEPT pe)
  (princ)
  )

 

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 4 of 22
Lee_Mac
in reply to: kameron1967

Another perhaps:

 

(defun c:pjl ( / ent idx itm lay lst sel val var )
    (setq var '(peditaccept cmdecho)
          val  (mapcar 'getvar var)
    )
    (mapcar '(lambda ( a b c ) (if a (setvar b c))) val var '(1 0))
    (if (setq sel (ssget "_:L" '((0 . "ARC,LINE,LWPOLYLINE"))))
        (progn
            (repeat (setq idx (sslength sel))
                (setq ent (ssname sel (setq idx (1- idx)))
                      lay (cdr (assoc 8 (entget ent)))
                )
                (if (setq itm (assoc lay lst))
                    (setq lst (subst (vl-list* lay ent (cdr itm)) itm lst))
                    (setq lst (cons  (list lay ent) lst))
                )
            )
            (foreach grp lst
                (apply 'command (append '("_.pedit" "_m") (cdr grp) '("" "_j" "" "")))
            )
        )
    )
    (mapcar '(lambda ( a b ) (if b (setvar a b))) var val)
    (princ)
)

 

Message 5 of 22
kameron1967
in reply to: Lee_Mac

Thanks for getting back to me so quickly guys. First of all, Henrique - your routine requires me to choose one entity and one layer at a time. But I appreciate the effort. Shneuph's routine does address what I need, and that is to work with all entities on all layers, joining only lines that are on the same layer - so perfect. Lee's routine does what it's supposed to (and as always - look great), however, I could use a typical feed back that tells you how many lines were added resulting in however polylines or whether it added 0 polylines because it was done - the way the original routine displayed. All in all, great job everyone! I love all your efforts! 🙂

 

Feedback on Lee's routine:  I tried it on busy drawing and got an alert that keeps popping up even though I clicked yes (5-6 times) until I clicked 'no' on the drawing order, before it will start executing the routine.  This was a busy drawing, so not sure what the difference is..Lee?  Thanks.

Message 6 of 22
Shneuph
in reply to: Lee_Mac

Lee-

I like the way you save variables and thier values to lists:

(setq var '(peditaccept cmdecho)
      val  (mapcar 'getvar var))

 and then reset them at the end:

(mapcar '(lambda ( a b ) (if b (setvar a b))) var val)

 but does the routine ever change these vars?

 

 

EDIT:

oh I see...

(mapcar '(lambda ( a b c ) (if a (setvar b c))) val var '(1 0))

 got it.Smiley Wink

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 7 of 22
hmsilva
in reply to: kameron1967


@kameron1967 wrote:

... Henrique - your routine requires me to choose one entity and one layer at a time. ...


Sorry Kameron,

I understood (diagonal reading) that your goal was to pedit in one layer only... Smiley Embarassed

 

@Lee_Mac and @Shneuph nice codes.

 

Henrique

EESignature

Message 8 of 22
kameron1967
in reply to: hmsilva

No worries, Henrique. 🙂
Message 9 of 22
Lee_Mac
in reply to: kameron1967

kameron1967 wrote:

Lee's routine does what it's supposed to (and as always - look great), however, I could use a typical feed back that tells you how many lines were added resulting in however polylines or whether it added 0 polylines because it was done - the way the original routine displayed.

 

Thank you kameron -

 

I suppressed the command echo for the PEDIT command by setting the CMDECHO system variable to zero in the program - you can enable this command-line output by changing this '(1 0) to '(1 1).

 

kameron1967 wrote:

Feedback on Lee's routine:  I tried it on busy drawing and got an alert that keeps popping up even though I clicked yes (5-6 times) until I clicked 'no' on the drawing order, before it will start executing the routine.  This was a busy drawing, so not sure what the difference is..Lee?  Thanks.

 

The alert requesting whether to disregard draw-order for processor-intensive operations is standard AutoCAD behaviour when the number of entities exceeds a certain limit - you are receiving this alert multiple times because my program is calling the PEDIT command multiple times (once for each layer).

 

You can disable the alert by setting the DRAWORDERCTL system variable to 0.

Message 10 of 22
Lee_Mac
in reply to: Shneuph

Shneuph wrote:

Lee-

I like the way you save variables and thier values to lists:

(setq var '(peditaccept cmdecho)
      val  (mapcar 'getvar var))

 and then reset them at the end:

(mapcar '(lambda ( a b ) (if b (setvar a b))) var val)

 but does the routine ever change these vars?

 

 

EDIT:

oh I see...

(mapcar '(lambda ( a b c ) (if a (setvar b c))) val var '(1 0))

 got it.Smiley Wink

 

hmsilva wrote:

@Lee_Mac and @Shneuph nice codes.

 

Thank you both for the compliments!

Message 11 of 22
kameron1967
in reply to: Lee_Mac

Great. You're awesome, Lee! Cheers! 🙂
Message 12 of 22
kameron1967
in reply to: kameron1967

Lee/Shneuph - if I wanted to specify the fuzz distance - where do I change that? Thanks.
Message 13 of 22
Lee_Mac
in reply to: kameron1967

kameron1967 wrote:
Lee/Shneuph - if I wanted to specify the fuzz distance - where do I change that? Thanks.
The prompt after the "_J" in the PEDIT command.
Message 14 of 22
kameron1967
in reply to: Lee_Mac

Thanks, Lee. I noticed that fuzz distance set to 0 works better than if it was set to 0.05, so I left it at 0. 🙂
Message 15 of 22
zeitarbeit
in reply to: Lee_Mac

@Lee_Mac:

Thanks for your work.

In my nooby understanding the I am trying to tackle is slightly different to your solution provided, in the sense that entities may consist of arcs, lines etc and do not snap to adjacent endpoints. I have tried in vain:

(apply 'command (append '("_.pedit" "_m") (cdr grp) '("" "_j" "0.05" "")))

Could you kindly pinpoint me into the direction how to alter your initial solution in order to snap endpoints before/while joining?

Kind regards

Sebastian

 

Message 16 of 22
Peter_MElad
in reply to: Lee_Mac

is there any solution to make this,and for specific layers

 

123.PNG

1234.png

  

  

Message 17 of 22
Sea-Haven
in reply to: kameron1967

The 1st suggestion is a defun F0 which is for fillet with a zero radius. Auto load it on start up.

(defun c:f0 () (setvar 'filletrad 0.0)(command "fillet"))

 

For multiple press enter or space bar will pop it up again.

 

Gap is it a pline or lines ? Makes a difference for the selection method.

 

Internal corner need some rules like pick 1st controls the square off start point. Yes No ?

Message 18 of 22
Peter_MElad
in reply to: Sea-Haven

for the left shape is there any way to do it

Message 19 of 22
Kent1Cooper
in reply to: Peter_MElad


@Peter_MElad wrote:

for the left shape is there any way to do it


Same question as in the longer paragraph >here<.

Kent1Cooper_0-1686745458882.png

In addition, what if the two white pieces are not orthogonal?  Should the connector be horizontal in any case [or vertical if that's closer], or perpendicular to them?  What if they're not parallel?  Etc., etc., etc.

Kent Cooper, AIA
Message 20 of 22
Peter_MElad
in reply to: Kent1Cooper

only parallel connect as you made to achieve  (be as far as possible from the lines)  ........ if not parallel connect with two points only. and finally close polyline (close Area)

I don't have the ability to make lisp

 

 

Capture.PNG

 

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

Post to forums  

Autodesk Design & Make Report

”Boost