Jump to content
MrCocopuffz

Join lines on same layer

Recommended Posts

MrCocopuffz

Hello everyone. I'm trying to put together a lisp to be able to select a line, which will cause all the lines on that layer to be selected, then using the join command will make any lines connected at the endpoints to become a poly lines. I'm using some code from other lisps and trying to make this work. If I enter each line in on the command line it seems to work but when I use the new command "JLL" nothing really happens. It goes through the process of selecting everything but does not join.

 

(defun C:JLL ()
(setq targetEnt (car (entsel "\nSelect object on layer to select: ")))
(setq targetLayer (assoc 8 (entget targetEnt)))
(sssetfirst nil (ssget "_X" (list targetLayer)))
(command "join" "")
(princ)
)

Share this post


Link to post
Share on other sites
rkmcswain

In AutoCAD, try running it with QAFLAGS = 1

 

Interestingly, it works fine in BricsCAD with QAFLAGS = 0 (the default)

Share this post


Link to post
Share on other sites
MrCocopuffz

It works!!! Thank you so much.:D

Share this post


Link to post
Share on other sites
rkmcswain

I would suggest setting that sysvar in the routine, and returning it to a value of 0 when you're done.

QAFLAGS at a non-zero value can cause other oddities

Share this post


Link to post
Share on other sites
MrCocopuffz

Good to know, thanks for the help.

Share this post


Link to post
Share on other sites
MrCocopuffz

Would I place (setvar "qaflags" 1) right above the (command "join" "") or under (defun C:JLL ()? Or does it matter?

Share this post


Link to post
Share on other sites
MrCocopuffz

So I'm watching the text window as it executes and it looks like this:

 

Command: jll

Select object on layer to select: join 1340 found

 

5 objects converted to 1 polyline, 1333 objects discarded from the operation

Command: JLL

Unknown command "JLL". Press F1 for help.

 

Why is it giving me an additionall "JLL" and "Unknown command" at the end?

Share this post


Link to post
Share on other sites
tombu

This works using initcommandversion without qaflags:

(defun C:JLL ()
(setq targetEnt (car (entsel "\nSelect object on layer to select: ")))
(setq targetLayer (assoc 8 (entget targetEnt)))
(sssetfirst nil (ssget "_X" (list targetLayer)))
(initcommandversion 2)
(command-s "join" "")
(princ)
)

Share this post


Link to post
Share on other sites
MrCocopuffz
This works using initcommandversion without qaflags:
(defun C:JLL ()
(setq targetEnt (car (entsel "\nSelect object on layer to select: ")))
(setq targetLayer (assoc 8 (entget targetEnt)))
(sssetfirst nil (ssget "_X" (list targetLayer)))
(initcommandversion 2)
(command-s "join" "")
(princ)
)

 

For some reason, this version doesn't work for me. It asks for the selection but then nothing after.

Share this post


Link to post
Share on other sites
tombu

Odd, for me the Command or Text window displays:

Command: JLL

 

Select object on layer to select: join 3 found

 

3 objects converted to 1 polyline

Command:

 

after selecting one line it joined it with 2 other lines that shared endpoints.

 

What did your Command or Text window display after you selected a line?

Share this post


Link to post
Share on other sites
MrCocopuffz
Odd, for me the Command or Text window displays:

Command: JLL

 

Select object on layer to select: join 3 found

 

3 objects converted to 1 polyline

Command:

 

after selecting one line it joined it with 2 other lines that shared endpoints.

 

What did your Command or Text window display after you selected a line?

 

This is a copy/paste from the text window:

 

Command: JLL

 

Select object on layer to select: _.join 5 found

 

5 objects converted to 1 polyline

Command: JLL

Unknown command "JLL". Press F1 for help.

 

It's executing the command correctly, joining the lines, then it simply adds a "JLL" at the command line adding "unknown command" after. Looking around at other code is there something like CMDECHO or something I need?

Share this post


Link to post
Share on other sites
tombu

That's even stranger, the JLL command works then is an unknown command when JLL is relaunched for some unknown reason?

JLL couldn't have worked if JLL was an unknown command.

 

While it's still defined in the drawing run JLL and select connecting lines on another layer to see if it returns the same.

Share this post


Link to post
Share on other sites
MrCocopuffz

Yes, it works perfectly. I type JLL and select a line and all the lines connected on that layer are connected. Then I can simply hit spacebar and continue again for a line on a different layer.

Here's the replay:

 

Command: JLL

Select object on layer to select: _.join 1340 found

 

5 objects converted to 1 polyline, 1333 objects discarded from the operation

Command: JLL

Unknown command "JLL". Press F1 for help.

 

Command:

Command: JLL

 

Select object on layer to select: _.join 7 found

 

7 objects converted to 1 polyline

Command: JLL

Unknown command "JLL". Press F1 for help.

 

I tried changing the command to _.join to see if there was any difference.

Share this post


Link to post
Share on other sites
tombu

Glad it worked out.

Share this post


Link to post
Share on other sites
BIGAL

Joining lines can be done form the command line no code its part of the pedit command, Ellen Finklestein has an article on how to do it over at cadalyst. Will try to find.

Share this post


Link to post
Share on other sites
tombu

For joining lines on the same layer I'd use GETSEL to select all lines on a selected layer and the JOIN command to join them.

Good starter lisp routine though. I try to avoid modifying Dimension and Expert Variables that affect other things when I can, but as long as you include a local *error* function to make sure they're reset you should be fine.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×