Jump to content

I hope someone can help to combine 2 function Autolisp


Kvlar

Recommended Posts

I have 2 autolisp codes with functions: explode and overkill.

Explode to break objects and overkill to delete duplicate lines.

Can anyone help me to combine these 2 autolisp functions? So I only need to do 1 command by selecting the object 1 time but already running the explode and overkill functions simultaneously.

 

I hope someone can help

Thank you

 

Code for explode:

(defun c:xpl1 (/ sel qaf)
   (setq qaf (getvar "qaflags"))
   (setq sel (ssget))
   (sssetfirst sel sel)
   (setvar "QAFLAGS" 1)
   (command "explode" sel)
   (setvar "QAFLAGS" qaf)
 (princ)
)

 

Code for overkill:

(defun getOrder ( / doc spc dic sort order )
 (vl-load-com)
 (setq doc (vla-get-activeDocument (vlax-get-acad-object))
       spc (if (zerop (vla-get-activespace doc))
             (if (= (vla-get-mspace doc) :vlax-true)
               (vla-get-modelspace doc)
               (vla-get-paperspace doc))
             (vla-get-modelspace doc)
           )
 )
 (if (vl-catch-all-error-p (setq sort (vl-catch-all-apply 'vla-item (list (setq dic (vla-getextensiondictionary spc)) "ACAD_SORTENTS"))))
   (setq sort (vla-addobject dic "ACAD_SORTENTS" "AcDbSortentsTable"))
 )
 (vla-getfulldraworder sort 'order :vlax-false)
 (if (< 0 (vlax-safearray-get-u-bound order 1))
   (vlax-safearray->list order)
 )
)

(defun ssorder ( / s ss )

 (vl-load-com)

 (setq s (ssget "_:L" '((0 . "*POLYLINE,SPLINE,HELIX,LINE,ARC,CIRCLE,ELLIPSE"))))
 (setq ss (ssadd))
 (foreach e (reverse (mapcar (function vlax-vla-object->ename) (getOrder)))
   (if (ssmemb e s)
     (ssadd e ss)
   )
 )
 ss
)

(defun c:ovr1 nil
 (vl-cmdf "_.-OVERKILL" (ssorder) "" "_O" 1e-6 "_I" "_A" "_P" "_Y" "")
 (princ)
)

 

Link to comment
Share on other sites

1 hour ago, Kvlar said:

I have 2 autolisp codes with functions: explode and overkill.

Explode to break objects and overkill to delete duplicate lines.

Can anyone help me to combine these 2 autolisp functions? So I only need to do 1 command by selecting the object 1 time but already running the explode and overkill functions simultaneously.

 

I hope someone can help

Thank you

 

Code for explode:

(defun c:xpl1 (/ sel qaf)
   (setq qaf (getvar "qaflags"))
   (setq sel (ssget))
   (sssetfirst sel sel)
   (setvar "QAFLAGS" 1)
   (command "explode" sel)
   (setvar "QAFLAGS" qaf)
 (princ)
)

 

Code for overkill:

(defun getOrder ( / doc spc dic sort order )
 (vl-load-com)
 (setq doc (vla-get-activeDocument (vlax-get-acad-object))
       spc (if (zerop (vla-get-activespace doc))
             (if (= (vla-get-mspace doc) :vlax-true)
               (vla-get-modelspace doc)
               (vla-get-paperspace doc))
             (vla-get-modelspace doc)
           )
 )
 (if (vl-catch-all-error-p (setq sort (vl-catch-all-apply 'vla-item (list (setq dic (vla-getextensiondictionary spc)) "ACAD_SORTENTS"))))
   (setq sort (vla-addobject dic "ACAD_SORTENTS" "AcDbSortentsTable"))
 )
 (vla-getfulldraworder sort 'order :vlax-false)
 (if (< 0 (vlax-safearray-get-u-bound order 1))
   (vlax-safearray->list order)
 )
)

(defun ssorder ( / s ss )

 (vl-load-com)

 (setq s (ssget "_:L" '((0 . "*POLYLINE,SPLINE,HELIX,LINE,ARC,CIRCLE,ELLIPSE"))))
 (setq ss (ssadd))
 (foreach e (reverse (mapcar (function vlax-vla-object->ename) (getOrder)))
   (if (ssmemb e s)
     (ssadd e ss)
   )
 )
 ss
)

(defun c:ovr1 nil
 (vl-cmdf "_.-OVERKILL" (ssorder) "" "_O" 1e-6 "_I" "_A" "_P" "_Y" "")
 (princ)
)

 

@Kvlar Try this
 

(defun c:foo (/ ssorder getorder qaf sel)
  (defun getorder (/ doc spc dic sort order)
    (vl-load-com)
    (setq doc (vla-get-activedocument (vlax-get-acad-object))
	  spc (if (zerop (vla-get-activespace doc))
		(if (= (vla-get-mspace doc) :vlax-true)
		  (vla-get-modelspace doc)
		  (vla-get-paperspace doc)
		)
		(vla-get-modelspace doc)
	      )
    )
    (if	(vl-catch-all-error-p
	  (setq	sort (vl-catch-all-apply
		       'vla-item
		       (list (setq dic (vla-getextensiondictionary spc)) "ACAD_SORTENTS")
		     )
	  )
	)
      (setq sort (vla-addobject dic "ACAD_SORTENTS" "AcDbSortentsTable"))
    )
    (vla-getfulldraworder sort 'order :vlax-false)
    (if	(< 0 (vlax-safearray-get-u-bound order 1))
      (vlax-safearray->list order)
    )
  )
  (defun ssorder (/ s ss)
    (vl-load-com)
    (setq s (ssget "_:L" '((0 . "*POLYLINE,SPLINE,HELIX,LINE,ARC,CIRCLE,ELLIPSE"))))
    (setq ss (ssadd))
    (foreach e (reverse (mapcar (function vlax-vla-object->ename) (getorder)))
      (if (ssmemb e s)
	(ssadd e ss)
      )
    )
    ss
  )
  (setq qaf (getvar "qaflags"))
  (setq sel (ssget))
  (sssetfirst sel sel)
  (setvar "QAFLAGS" 1)
  (command "explode" sel)
  (setvar "QAFLAGS" qaf)
  (princ)
  (vl-cmdf "_.-OVERKILL" (ssorder) "" "_O" 1e-6 "_I" "_A" "_P" "_Y" "")
  (princ)
)

 

Link to comment
Share on other sites

thanks for the help. but after I tried the code, it didn't work as I needed

 

Link to comment
Share on other sites

38 minutes ago, Kvlar said:

thanks for the help. but after I tried the code, it didn't work as I needed

 

but I think my source code is wrong

 

Link to comment
Share on other sites

9 hours ago, ronjonp said:

@Kvlar Try this
 

(defun c:foo (/ ssorder getorder qaf sel)
  (defun getorder (/ doc spc dic sort order)
    (vl-load-com)
    (setq doc (vla-get-activedocument (vlax-get-acad-object))
	  spc (if (zerop (vla-get-activespace doc))
		(if (= (vla-get-mspace doc) :vlax-true)
		  (vla-get-modelspace doc)
		  (vla-get-paperspace doc)
		)
		(vla-get-modelspace doc)
	      )
    )
    (if	(vl-catch-all-error-p
	  (setq	sort (vl-catch-all-apply
		       'vla-item
		       (list (setq dic (vla-getextensiondictionary spc)) "ACAD_SORTENTS")
		     )
	  )
	)
      (setq sort (vla-addobject dic "ACAD_SORTENTS" "AcDbSortentsTable"))
    )
    (vla-getfulldraworder sort 'order :vlax-false)
    (if	(< 0 (vlax-safearray-get-u-bound order 1))
      (vlax-safearray->list order)
    )
  )
  (defun ssorder (/ s ss)
    (vl-load-com)
    (setq s (ssget "_:L" '((0 . "*POLYLINE,SPLINE,HELIX,LINE,ARC,CIRCLE,ELLIPSE"))))
    (setq ss (ssadd))
    (foreach e (reverse (mapcar (function vlax-vla-object->ename) (getorder)))
      (if (ssmemb e s)
	(ssadd e ss)
      )
    )
    ss
  )
  (setq qaf (getvar "qaflags"))
  (setq sel (ssget))
  (sssetfirst sel sel)
  (setvar "QAFLAGS" 1)
  (command "explode" sel)
  (setvar "QAFLAGS" qaf)
  (princ)
  (vl-cmdf "_.-OVERKILL" (ssorder) "" "_O" 1e-6 "_I" "_A" "_P" "_Y" "")
  (princ)
)

 

This code is almost similar to this:

 

(defun c:test ( / )
        (c:xpl1)
        (c:ovr1)
        (princ)
)

This requires selecting the object twice. what I need is to select the object once with the explode and overkill functions

 

Link to comment
Share on other sites

7 hours ago, Kvlar said:

but I think my source code is wrong

 

I did not check that what you posted actually works.

Link to comment
Share on other sites

5 hours ago, ronjonp said:

I did not check that what you posted actually works.

but, is it possible select the object once with the explode and overkill functions?

Link to comment
Share on other sites

10 minutes ago, Kvlar said:

but, is it possible select the object once with the explode and overkill functions?

 

I use entlast as a place marker then anything created/modified after that you can process using entnext

 

(setq ss (ssadd))  ; Create an empty selection set
(setq LastEnt (entlast))  ;Get the last entity in the drawing 
;explode code
(while (setq LastEnt (entnext LastEnt)) ; Add all entity's created/modified after setting lastent to the selection set
  (ssadd LastEnt ss)  
)

 

 

Link to comment
Share on other sites

18 minutes ago, mhupp said:

 

I use entlast as a place marker then anything created/modified after that you can process using entnext

 

(setq ss (ssadd))  ; Create an empty selection set
(setq LastEnt (entlast))  ;Get the last entity in the drawing 
;explode code
(while (setq LastEnt (entnext LastEnt)) ; Add all entity's created/modified after setting lastent to the selection set
  (ssadd LastEnt ss)  
)

 

 

Is this like doing selection only one time at the beginning, then command 1 will be done, the result will be taken automatically by Lisp and used by Command 2 ?

Link to comment
Share on other sites

I tried to make the code simpler.

this code:

(defun c:subf5a (/ ss i ent obj)
  (setq ss (ssget "_:L" '((0 . "LINE,ARC,LWPOLYLINE,LINE")))) ; Selects lines, arcs, and polylines
  (if ss
    (progn
      (repeat (setq i (sslength ss))
        (setq ent (ssname ss (setq i (1- i))))
        (setq obj (entget ent))
        (if (= (cdr (assoc 0 obj)) "LWPOLYLINE")
          (command "_explode" ent "")
          (command "EXPLODE" ent)
        )
      )
    )
  )
  (command "_.-OVERKILL" "_all" "" "_Done") ; Runs OVERKILL on all objects
  (princ)
)

 

but I have a problem. How do I make the overkill command only apply to the object I selected? 

I think the problem is with the "_all" argument. but I don't know what to change it so that the overkill command only applies to the object I selected.

 

I hope you can help me

Link to comment
Share on other sites

Try this

 

(defun C:Foo (/ ss)
  (if (setq SS (ssget "_:L" '((0 . "LINE,ARC,LWPOLYLINE,LINE")))) ; Selects lines, arcs, and polylines
    (progn
      (setq LastEnt (entlast))  ;Get the last entity in the drawing 
      (command "_explode" SS "")
      (while (setq LastEnt (entnext LastEnt)) ; Add all entity's created/modified after setting lastent to the selection set
        (ssadd LastEnt ss)  
      )
    )
  )
  (command "_.OVERKILL" SS "" "_Done") ; Runs OVERKILL on all objects
  (princ)
)
Link to comment
Share on other sites

Posted (edited)
27 minutes ago, mhupp said:

Try this

 

(defun C:Foo (/ ss)
  (if (setq SS (ssget "_:L" '((0 . "LINE,ARC,LWPOLYLINE,LINE")))) ; Selects lines, arcs, and polylines
    (progn
      (setq LastEnt (entlast))  ;Get the last entity in the drawing 
      (command "_explode" SS "")
      (while (setq LastEnt (entnext LastEnt)) ; Add all entity's created/modified after setting lastent to the selection set
        (ssadd LastEnt ss)  
      )
    )
  )
  (command "_.OVERKILL" SS "" "_Done") ; Runs OVERKILL on all objects
  (princ)
)

This code is good, but I don't want to show this overkill settings popup. I want to set the overkill setting in the autolisp code.

 

example like this (command "_.OVERKILL" SS "" "_O" 1e-6 "_I" "_A" "_P" "_Y" "")

 

but I don't know what argument I should use to set the overkill setting

 

Edited by Kvlar
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...