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

0 Members and 1 Guest are viewing this topic.

mohan

  • Newt
  • Posts: 98
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: 250
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.     (progn
  5.       (command "_.pedit" "_m" arc "" "_Y" "")
  6.       (setq a (itoa (sslength arc)))
  7.     )
  8.     (princ (strcat "\nMohan there were no arc Object(s) found ... "))
  9.   )
  10.   (if (setq line (ssget "_X" '((0 . "LINE") (410 . "Model"))))
  11.     (progn
  12.       (command "_.pedit" "_m" line "" "_Y" "")
  13.       (setq l (itoa (sslength line)))
  14.     )
  15.     (princ (strcat "\nMohan there were no line Object(s) found ... "))
  16.   )
  17.   (princ (strcat "\nMohan total of " a " Arc Object(s) & " l " Line Object(s) were converted to Polylines ... "))
  18.   (princ)
  19. )

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: 197
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: 98
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.
 :smitten:

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"

mohan

  • Newt
  • Posts: 98
Re: Convert line & arc to Polyline
« Reply #4 on: October 29, 2023, 05:10:18 AM »
---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 was modifying to work through all layouts & model, still there is minor error !
Code - Auto/Visual Lisp: [Select]
  1. (defun c:convert_arc_line (/ arc a line l)
  2.   (setq a "0" l "0")
  3. (setvar 'ctab tab)
  4.   (if (setq arc (ssget "_X" '((0 . "ARC") (410 . (getvar 'ctab)))))
  5.     (progn
  6.       (command "_.pedit" "_m" arc "" "_Y" "")
  7.       (setq a (itoa (sslength arc)))
  8.     );progn
  9.     (princ (strcat "\nMohan there were no arc Object(s) found ... "))
  10.   );if
  11.   (if (setq line (ssget "_X" '((0 . "LINE") (410 . (getvar 'ctab)))))
  12.     (progn
  13.       (command "_.pedit" "_m" line "" "_Y" "")
  14.       (setq l (itoa (sslength line)))
  15.     );progn
  16.     (princ (strcat "\nMohan there were no line Object(s) found ... "))
  17.   );if
  18. );foreach
  19.   (princ (strcat "\nMohan total of " a " Arc Object(s) & " l " Line Object(s) were converted to Polylines ... "))
  20.   (princ)
  21. );defun

Added thses lines
(foreach tab (layoutlist)
(setvar 'ctab tab)
......................................(410 . (getvar 'ctab))

......................................(410 . (getvar 'ctab))
)

Editing completed !
« Last Edit: October 29, 2023, 05:25:39 AM by mohan »
"Save Energy"

mohan

  • Newt
  • Posts: 98
Re: Convert line & arc to Polyline
« Reply #5 on: October 29, 2023, 08:24:55 AM »
Sorry guys, I found the error on my code
This line should replace with
Code - Auto/Visual Lisp: [Select]
  1. (if (setq arc (ssget "_X" '((0 . "ARC") (410 . (getvar 'ctab)))))
this one
Code - Auto/Visual Lisp: [Select]
  1. (if (setq arc (ssget "_X" (list '(0 . "ARC") (cons 410 (getvar 'ctab)))))
"Save Energy"