### Author Topic: Convert line & arc to Polyline  (Read 781 times)

0 Members and 2 Guests are viewing this topic.

#### mohan

• Newt
• Posts: 87
##### Convert line & arc to Polyline
« on: May 17, 2022, 06:40:57 AM »
Code: [Select]
(defun c:convert_arc_line ( / arc line)
(if (setq arc (ssget "_X" '((0 . "ARC")))) (command "_.pedit" "_m" arc "" "_Y" "") (princ (strcat "\nMohan there were no arc Object(s) found ... ")))
(if (setq line (ssget "_X" '((0 . "LINE")))) (command "_.pedit" "_m" line "" "_Y" "") (princ (strcat "\nMohan there were no line Object(s) found ... ")))
(princ (strcat "\nMohan total of " (itoa (sslength arc)) " Arc Object(s) & " (itoa (sslength line)) " Line Object(s) were converted to Polylines ... " ))
(princ))
Command: CONVERT_ARC_LINE
_.pedit
Select polyline or [Multiple]: _m
Select objects:   1 found

Select objects:
Convert Lines, Arcs and Splines to polylines [Yes/No]? <Y> _Y
Enter an option [Close/Open/Join/Width/Fit/Spline/Decurve/Ltype gen/Reverse/Undo]:
Command: _.pedit
Select polyline or [Multiple]: _m
Select objects:   2 found

Select objects:
Convert Lines, Arcs and Splines to polylines [Yes/No]? <Y> _Y
Enter an option [Close/Open/Join/Width/Fit/Spline/Decurve/Ltype gen/Reverse/Undo]:
Command:
Mohan total of 1 Arc Object(s) & 2 Line Object(s) were converted to Polylines ...

Command: CONVERT_ARC_LINE

Mohan there were no arc Object(s) found ...
Mohan there were no line Object(s) found ... ; error: bad argument type: lselsetp nil

Note: If there were no objects of (line or arc) why this error shows "error: bad argument..............
Please anyone help to fix it.
« Last Edit: May 17, 2022, 06:56:58 AM by mohan »
"Save Energy"

#### mhupp

• Bull Frog
• Posts: 243
##### Re: Convert line & arc to Polyline
« Reply #1 on: May 17, 2022, 08:11:14 AM »
when nothing is selected with ssget for arc and line they are still nil. You can't use sslength on a nil selection set.

Code - Auto/Visual Lisp: [Select]
1. (defun c:convert_arc_line (/ arc a line l)
2.   (setq a "0" l "0")
3.   (if (setq arc (ssget "_X" '((0 . "ARC") (410 . "Model"))))
4.       (command "_.pedit" "_m" arc "" "_Y" "")
5.       (setq a (itoa (sslength arc)))
6.     )
7.     (princ (strcat "\nMohan there were no arc Object(s) found ... "))
8.   )
9.   (if (setq line (ssget "_X" '((0 . "LINE") (410 . "Model"))))
10.       (command "_.pedit" "_m" line "" "_Y" "")
11.       (setq l (itoa (sslength line)))
12.     )
13.     (princ (strcat "\nMohan there were no line Object(s) found ... "))
14.   )
15.   (princ (strcat "\nMohan total of " a " Arc Object(s) & " l " Line Object(s) were converted to Polylines ... "))
16.   (princ)
17. )

This will default to: Mohan total of 0 Arc Object(s) & 0 Line Object(s) were converted to Polylines ...
if any arc or lines are converted it will update the 0 to that number.

---Edit
Might also want to limit your selection to model space or ctab (current tab). "_X" picks up any line or arc in the drawing even on other tabs but the command line pedit will only modify lines and arcs on current tab.
« Last Edit: May 17, 2022, 01:00:59 PM by mhupp »

#### dexus

• Newt
• Posts: 143
##### Re: Convert line & arc to Polyline
« Reply #2 on: May 17, 2022, 08:15:29 AM »
I change the PEDITACCEPT variable so you don't have to add "_Y".
That way it also works if it already is set to 1.

Code - Auto/Visual Lisp: [Select]
1. (defun c:convert_arc_line (/ ss internalcounter ~CMD ~PEDITACCEPT *error*)
2.   (defun *error* (msg)
3.     (setvar "CMDECHO" ~CMD)
4.     (setvar "PEDITACCEPT" ~PEDITACCEPT)
5.     (princ msg)
6.     (princ)
7.   )
8.   (setq ~CMD (getvar "CMDECHO"))
9.   (setvar "CMDECHO" 0)
10.   (setq ~PEDITACCEPT (getvar "PEDITACCEPT"))
11.   (setvar "PEDITACCEPT" 1) ; Temperaraly set PEDITACCEPT to 1 so it doesn't ask to confirm the conversion to Polyline
12.
13.   (if (setq ss (ssget "X" '((0 . "LINE,ARC"))))
14.     (progn ; Make selection and continue if anything is found
15.       (setq internalcounter (sslength ss))
16.       (princ (strcat (itoa internalcounter) " object(s) found."))
17.       (repeat internalcounter
18.         (vl-cmdf "_pedit" (ssname ss (setq internalcounter (1- internalcounter))) "") ; Preform pedit to convert
19.       )
20.     )
21.     (princ "No Line or Arc objects found.")
22.   )
23.
24.   (setvar "CMDECHO" ~CMD)
25.   (setvar "PEDITACCEPT" ~PEDITACCEPT)
26.   (princ)
27. )

#### mohan

• Newt
• Posts: 87
##### Re: Convert line & arc to Polyline
« Reply #3 on: May 18, 2022, 01:41:58 AM »
when nothing is selected with ssget for arc and line they are still nil. You can't use sslength on a nil selection set.

This will default to: Mohan total of 0 Arc Object(s) & 0 Line Object(s) were converted to Polylines ...
if any arc or lines are converted it will update the 0 to that number.

---Edit
Might also want to limit your selection to model space or ctab (current tab). "_X" picks up any line or arc in the drawing even on other tabs but the command line pedit will only modify lines and arcs on current tab.

I got it, thank you so much.

I change the PEDITACCEPT variable so you don't have to add "_Y".
That way it also works if it already is set to 1

Thanks for the Another way.
« Last Edit: May 18, 2022, 01:48:32 AM by mohan »
"Save Energy"