• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

custom command to edit a polylinea

  • Thread starter Thread starter BCgeppoIT
  • Start date Start date

BCgeppoIT

Guest
Good morning to all, I often find myself using the edit polylinea command, I wanted to ask if you can create a custom command to avoid all the steps that autocad of practice asks, my command is always used in this sequence:
-edit polylinea
- select an object
- to the question "you want to turn it into polylinea" the answer is always
-to the request "type an option" the answer is always combined so that the polyline is completely closed.
I hope I explained.
hello good day
 
Code:
Polylinejoin.lsp [command name: PJ];; viable joins objects [Lines/Arcs/LWPolylines/not-splined-or-fitted 2DPolylines]
;;    into connected lwpolylines.
;;  rejects splined/fitted 2dpolylines, [joining them to other objects removes their
;;    spline/fit curvature] and 3dpolylines [can't be joined].
;;  if one viable object is selected, joins all other possible objects [contiguous at ends to
;;    it and to each other] to it, into one lwpolyline.
;;  if multiple viable objects are selected, joins them into as many lwpolylines as
;;    appropriate, not including anything contiguous at ends that was not selected.
;;  leaves selected lines/arcs that are not contiguous to anything else as lines/arcs,
;;    not converted into one-segment polylines.
;;  concept from c:pljoin by beaufordt on autocad customization discussion group
;;  streamlined by kent cooper, june 2011; expanded capabilities july 2012
;;  last edited 16 july 2012

(defun c:pj ; = polyline join
  (/ *error* pjss cmde peac nextent pjinit inc edata pjent)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "function cancelled,quit / exit abort,console break"))
      (princ (strcat "\nerror: " errmsg))
    ); if
    (setvar 'peditaccept peac)
    (command "_.undo" "_end")
    (setvar 'cmdecho cmde)
    (princ)
  ); defun - *error*

  (princ "\nto join objects into polyline(s) [pick 1 to join all possible to it],")
  (setq
    pjss (ssget '((0 . "line,arc,*polyline")))
    cmde (getvar 'cmdecho)
    peac (getvar 'peditaccept)
    nextent (entlast); starting point for checking new entities
  ); setq
  (repeat (setq pjinit (sslength pjss) inc pjinit); pj initial-selection quantity & incrementer
    (if
      (and
        (=
          (cdr (assoc 0 (setq edata (entget (setq pjent (ssname pjss (setq inc (1- inc))))))))
          "polyline" ; 2d "heavy" or 3d polyline
        ); =
        (or
          (= (cdr (assoc 100 (reverse edata))) "acdb3dpolyline"); 3d
          (member (boole 1 6 (cdr (assoc 70 edata))) '(2 4)); splined or fitted 2d
        ); or
      ); and
      (ssdel pjent pjss); remove 3d, splined/fitted 2d from set
    ); if
  ); repeat
  (setvar 'cmdecho 0)
  (command "_.undo" "_begin")
  (setvar 'peditaccept 1)
  (setvar 'plinetype 2); [just in case; assumes no desire to save and set back if different]
  (if pjss ; selected qualifying object(s)
    (cond ; then
      ( (= pjinit (sslength pjss) 1); selected only one, and it qualifies
        (command "_.pedit" pjss "_join" "_all" "" ""); join everything possible to it
      ); single-selection condition
      ( (> (sslength pjss) 1); more than one qualifying object
        (command "_.pedit" "_multiple" pjss "" "_join" "0.0" "")
      ); multiple qualifying condition
      ((prompt "\nsingle object not viable, or <= 1 of multiple selection viable."))
    ); cond
    (prompt "\nnothing viable selected.")
  ); outer if
  (while (setq nextent (entnext nextent)); start with first newly-created pline, if any
    (if ; revert any un-joined lines/arcs back from pline conversion
      (and ; newly-created single-segment pline from unconnected line/arc
        (= (cdr (assoc 90 (entget nextent))) 2)
        (not (vlax-curve-isclosed nextent))
      ); and
      (command "_.explode" nextent)
    ); if
  ); while
  (setvar 'peditaccept peac)
  (command "_.undo" "_end")
  (setvar 'cmdecho cmde)
  (princ)
); defun

(prompt "\ntype pj for polyline-join command.")
this lisp combines polyline lines and adjacent arches, if selected only one element or only the selected ones, if the selection is multiple.
select the text in the window and save it in the file: polylinejoin.lsp
drag the file into the autocad work area or type (load "<disco: percorso=""></disco:>polylinejoin.lsp"), and type the command: p.
 
Thanks endlessly, thinking the time I lost until now I live to cry, incredible what you could do knowing I'm playing. Thanks again
greetings to the whole forum
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top