Gather lines drawn in while loop and join into polyline??

Gather lines drawn in while loop and join into polyline??

DC-MWA
Collaborator Collaborator
1,057 Views
7 Replies
Message 1 of 8

Gather lines drawn in while loop and join into polyline??

DC-MWA
Collaborator
Collaborator

Hi all,

Working on a little routine to draw cabinets in plan. The routine draws multiple lines and fillets them as you go. 

I'm trying to join all the lines together as a polyline at the end.

I've been playing with ssadd but it gets only part of the lines at  the end.

Here is what I tried:

 

(setq lastEnt (entlast));;get first

<routine draws multiple lines here>

(setq ss1 (ssadd))
(if (setq en (entnext LastEnt)) ;Check if there's a new entity created sinse the last one
(while en ;Step through all new entities
(ssadd en ss1) ;Add it to the selection set
(setq en (entnext en)) ;Get the next entity
);w
);i

(setvar "PEDITACCEPT" 1)

(command ".pedit" lastEnt "j" ss1 "" "")

 

I've attached the lisp (removed my failed attempt).

Thank you in advance for any input.

-dc

 

 

 

0 Likes
1,058 Views
7 Replies
Replies (7)
Message 2 of 8

ВeekeeCZ
Consultant
Consultant

It looks like the issue is somewhere else.

It's this line:

(command "line" end1 pt4 "")

It tends to create a zero length line because the osnaps are set to 1 at the moment.

 

About the joining - I would probably prefer to use the JOIN command...

  (setq enl (entlast))
....
  (setq ss (ssadd))
  (while (setq enl (entnext enl))
    (ssadd enl ss))
  (initcommandversion)
  (command "_.join" ss "")

But the solution for sure would be to draw a polyline right away. 

0 Likes
Message 3 of 8

Sea-Haven
Mentor
Mentor

Of the top of my head

(Repeat  ;; draws multiple lines

<routine draws a line here>

(setq ss1 (ssadd entlast))

)

 

I did something similar will try to find where it added sections together.

 

Remeber now you can start a pline command then use a while to keep going working out all your new points.

 

(command "_pline")
(command (setq pt (getpoint "Pick start point - Enter or C to finish")))
(while (= (getvar "cmdactive") 1 ) 
(repeat do your thing here with working out next point polar etc
(command pt)
)
(command "close"))

 

0 Likes
Message 4 of 8

DC-MWA
Collaborator
Collaborator

Hello,

Thank you for your response and input.

1st:  (command "line" end1 pt4 "") this draws the last closing line. It only draws a zero length line of the user is zoomed way out. We are working on floor plans so this is not an issue.

 

2nd: Figuring out the points to use a polyline is way over my head.

 

Ok...

So I got this thing to work, but I have draw this dummy line and then erase it quickly before the routine starts. This does not seem to affect anything but it sure seems "hokey" at best.

So it now draws the lines, fillets them cleanly and joins them at the end. Drawing the little temporary line seems lame... Any ideas?

 

0 Likes
Message 5 of 8

ВeekeeCZ
Consultant
Consultant

@DC-MWA wrote:

Hello,

Thank you for your response and input.

1st:  (command "line" end1 pt4 "") this draws the last closing line. It only draws a zero length line of the user is zoomed way out. We are working on floor plans so this is not an issue.

 


 

Rule number one: Always turn off OSNAPS while you're working with points within the command function. Period. 

I know what it does because I constantly got a zero len line. Jesus, what sort of excuse that is... when screen is zoom-in well enough it works, but if you zoom out just a little bit over the edge, then is not?

 

Anyway, I guess that drawing the offset polyline would only require usage of (inters) function, which should not be too complicated.

 

 

I have no idea what dummy line you're talking about.

0 Likes
Message 6 of 8

DC-MWA
Collaborator
Collaborator

I will look into the "(inters) function"

Thanks for your time,

Have a great day.

-dc

0 Likes
Message 7 of 8

hencoop
Advisor
Advisor

At the start of your program you should store the current OSMODE value:

(SETQ curr_osmode (GETVAR "OSMODE"))

 

Before you begin drawing anything you should initialize your empty selection set ss1.

Move (SETQ ss1 (SSADD)) above the entity creation stuff in your code before your WHILE loop.

 

Then, every time you create a new entity, execute this code:
(SSADD (ENTLAST) ss1)

When you are done your selection set will have everything necessary for your PEDIT command:

(COMMAND ".PEDIT" "M" ss1 "" "Yes" "Join" 0.0)

 

As others have suggested, you should disable snaps in your programs whenever you are not manually picking the points.  Even if you are manually picking points in your program it is better to set the OSMODE to exactly what is needed just prior to manually picking any point.  You can use the command line overrides within your command call (e.g., "non", "end", "tan", "qua", "int" or multiples, "end,qua,int" etc.) or (SETVAR "OSMODE" ###) to do this before using the COMMAND function.   (Look at OSMODE help to find the numbers you need or just set it via the dialog and use (GETVAR "OSMODE") to see the number for those settings.)  Then, use (SETVAR "OSMODE" ###) just before points are acquired (manually picked) or used in your COMMAND call to set it to whatever is needed.  DO NOT put the point selection inside your command call!

 

Use

(SETQ pnt# (GETPOINT)); or,

(SETQ pnt# (POLAR <pt> <angle> <distance>)); or,

(SETQ pnt# (INTERS <line-a pt1><line-a pt2><line-b pt1><line-b pt2> <nil or T>)); nil = lines treated as infinite length when checking if intersection is on both line segments.

 

Store each of the points as a separate symbol (variable name) and then put those in your command call.

(COMMAND ".LINE" pnt1 pnt2 "")

 

When you exit your program use (SETVAR "OSMODE" curr_osmode) to restore the osmode to what it was when you started.  (Put this in your program's error function too if you have one.)

 

HTH

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 8 of 8

DC-MWA
Collaborator
Collaborator

I have corrected the osmode issue.

I will playing with it more this evening.

Thank you for the input.

-dc

0 Likes