help with making a routine for trim and extend that prompts for an edge

help with making a routine for trim and extend that prompts for an edge

jjcrocco
Enthusiast Enthusiast
912 Views
8 Replies
Message 1 of 9

help with making a routine for trim and extend that prompts for an edge

jjcrocco
Enthusiast
Enthusiast

Hi, I am using Autocad 2022, upgraded from 2018, and noticed the trim and extend native commands have been changed to allow faster operation without having to select an edge or object. However, sometimes a selection is faster.  I want to create a lisp routine that forces it to ask for a selection. I would preload it in my acad.lsp so whenever it is typed, its ready to go.

 

TR = Trim

TT would be the script (LSP) for trim with edge

EX = Extend

EE would be the script to extend with edge

 

Wondering if this has been made already. I was trying to make a script, but could not get it to allow me to select the edge and continue. 

Any help would be appreciated. I am assuming if I can get one to work, the other would be very similar to make.

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Custom commands by John Crocco 2-17-22
;Extend command with forced edge to be selected when prompted
(DEFUN C:EE (/ SS *error*)

;;;;;;;;; Application error handler
(defun *error* (msg)
(command-s "._Undo" "_End") ; end undo group
(cond
((not msg)) ; no error, do nothing
((member (strcase msg t) ; cancel, do undo
'("console break"
"function cancelled"
"quit / exit abort"
)
)
(command-s "._U")
(setvar "cmdecho" cecho)
;UNDO COMMANDS HERE
;
;
;
) ;END OF MEMBER
((princ (strcat "\nError: " msg)))
) ; END OF COND
(princ)
) ; END OF DEFUN ERROR
(vl-load-com)
(setq cecho (getvar "cmdecho"))
(setvar "CmdEcho" 0) ; turn echo off
(command-s "._Undo" "_End") ; close any open group
(command-s "._Undo" "_BEgin") ; start new group
;;;;;;;;;;;;;;;;;;;;;;

(PRINC "SELECT BOUNDERY OBJECTS...\N")
(SETQ SS (SSGET)) ;GENERAL SELECTION SET

(command "extend" "B" SS \ "")

)

 

0 Likes
913 Views
8 Replies
Replies (8)
Message 2 of 9

pendean
Community Legend
Community Legend
Does just turning off TRIMEXTENDMODE variable in R2022 solve your issue, and when you need the 'preselect all' you just tap that <enter> button twice?
You know, like the legacy R2018 behavior?

From HELP https://knowledge.autodesk.com/support/autocad/learn-explore/caas/CloudHelp/cloudhelp/2021/ENU/AutoC...
Message 3 of 9

jjcrocco
Enthusiast
Enthusiast

I wasnt aware of this variable. So that makes it easier.

I can just create a lisp routine that sets the variable to zero then runs the command, then resets it back to 1.

This way I can use the quick version any time, and when I need to use the legacy version i just run the other command.

 

0 Likes
Message 4 of 9

pendean
Community Legend
Community Legend

@jjcrocco wrote:

I wasnt aware of this variable. So that makes it easier.

 

 


There is an easy way to fix that and more right there in the program, start HELP and explore this section

pendean_0-1646757280118.png

 

And the commandline

pendean_0-1646757364997.png

pendean_2-1646757406250.png

 

 

HTH

Message 5 of 9

ВeekeeCZ
Consultant
Consultant

Here are the versions that I use. 

 

(defun c:TrimAll ()
  (setvar 'edgemode 1)
  (princ "\n")
  (initcommandversion)
  (command "_.trim")
  (while (> (getvar 'cmdactive) 0)
    (command "_c" pause)
    (if (> (getvar 'cmdactive) 0)
      (command pause)))
  (princ)
  )

;----
(defun c:ExtendAll ()
  (setvar 'edgemode 1)
  (princ "\n")
  (initcommandversion)
  (command "_.extend")
  (while (> (getvar 'cmdactive) 0)
    (command "_c" pause)
    (if (> (getvar 'cmdactive) 0)
      (command pause)))
  (princ)
  )

;----
(defun c:TrimSelect ()
  (setvar 'edgemode 0)
  (princ "\n")
  (command-s "_.select")
  (initcommandversion)
  (command "_.trim" "_t" "_p" "")
  (while (> (getvar 'cmdactive) 0)
    (command "_c" pause)
    (if (> (getvar 'cmdactive) 0)
      (command pause)))
  (princ))

;----
(defun c:ExtendSelect ()
  (setvar 'edgemode 0)
  (princ "\n")
  (command-s "_.select")
  (initcommandversion)
  (command "_.extend" "_b" "_p" "")
  (while (> (getvar 'cmdactive) 0)
    (command "_c" pause)
    (if (> (getvar 'cmdactive) 0)
      (command pause)))
  (princ))

 

0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant

@jjcrocco wrote:

....

TT would be the script (LSP) for trim with edge

....

EE would be the script to extend with edge

....

I can just create a lisp routine that sets the variable to zero then runs the command, then resets it back to 1.


Something as simple as these, perhaps?  [I'm on Acad2020, which doesn't yet have the TRIMEXTENDMODE System Variable, so I can't test them.]  There is the difference that they reset it back to whatever it was beforehand, not necessarily always to 1.

 

(defun C:TT (/ tem)
  (setq tem (getvar 'trimextendmode))
  (setvar 'trimextendmode 0)
  (command-s "_.trim")
  (setvar 'trimextendmode tem)
  (princ)
)

(defun C:EE (/ tem)
  (setq tem (getvar 'trimextendmode))
  (setvar 'trimextendmode 0)
  (command-s "_.extend")
  (setvar 'trimextendmode tem)
  (princ)
)

 

They can have *error* handling added to ensure resetting the System Variable if cancelled, but first see whether they do what you intend.

Kent Cooper, AIA
0 Likes
Message 7 of 9

jjcrocco
Enthusiast
Enthusiast

Thank you all.

Its amazing how many ways you can make a routine to do the same thing.

Once I knew abiut the variable, it was simple, and this is what I ended up with.

One things is I get a echo of "1" when it runs. I can deal with it, but coulldnt figure out how to eliminate it.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Custom commands by John Crocco 2-17-22
;TRIM command with forced edge to be selected when prompted
(DEFUN C:TT (/ SS *error*)

;;;;;;;;; Application error handler
(defun *error* (msg)
(command-s "._Undo" "_End") ; end undo group
(cond
((not msg)) ; no error, do nothing
((member (strcase msg t) ; cancel, do undo
'("console break"
"function cancelled"
"quit / exit abort"
)
)
(command-s "._U")
; (setvar "cmdecho" cecho)
(setvar "trimextendmode" 1)
(setvar "cmdecho" cecho) ;UNDO COMMANDS HERE
) ;END OF MEMBER
((princ (strcat "\nError: " msg)))
) ; END OF COND
(princ)
) ; END OF DEFUN ERROR
(vl-load-com)
(setq cecho (getvar "cmdecho"))
(setvar "CmdEcho" 0) ; turn echo off
(command-s "._Undo" "_End") ; close any open group
(command-s "._Undo" "_BEgin") ; start new group
;;;;;;;;;;;;;;;;;;;;;;

(setvar "trimextendmode" 0)
(command "trim" )
(setvar "trimextendmode" 1)
)

0 Likes
Message 8 of 9

ВeekeeCZ
Consultant
Consultant

@Kent1Cooper wrote:

...

 

 

(defun C:TT (/ tem)
  (setq tem (getvar 'trimextendmode))
  (setvar 'trimextendmode 0)
  (command-s "_.trim")
  (setvar 'trimextendmode tem)
  (princ)
)

(defun C:EE (/ tem)
  (setq tem (getvar 'trimextendmode))
  (setvar 'trimextendmode 0)
  (command-s "_.extend")
  (setvar 'trimextendmode tem)
  (princ)
)

 

They can have *error* handling added to ensure resetting the System Variable if cancelled, but first see whether they do what you intend.


 

(command-s) won't let it fall into *error*. ESC will break the EXTEND but keeps evaluating the rest of the routine. So it restores your sysvar in any case.

 

0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant

@jjcrocco wrote:

....

One things is I get a echo of "1" when it runs. I can deal with it, but coulldnt figure out how to eliminate it.

....


A function always returns the result of the last thing in it.  To prevent seeing the result from resetting that System Variable, put in the standard "exit quietly" entry at the end:

  ....

  (setvar "trimextendmode" 1)

  (princ)
)

 

[The description of its use for that purpose is in the Returns portion of the AutoLisp Reference's entry for the (prin1) function, but for some unknown reason "everyone" typically uses (princ) for the purpose -- you'll see it in routines all over this Forum.  It would also work to do it with (print).]

Kent Cooper, AIA
0 Likes