TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: mohan on May 17, 2022, 06:40:57 AM

Title: Convert line & arc to Polyline
Post by: mohan 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.
Title: Re: Convert line & arc to Polyline
Post by: mhupp 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.
Title: Re: Convert line & arc to Polyline
Post by: dexus 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. )
Title: Re: Convert line & arc to Polyline
Post by: mohan 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.  :-)