Dinesh Palatty/Trim a block using following LISP

Dinesh Palatty/Trim a block using following LISP

d_palatty
Explorer Explorer
355 Views
3 Replies
Message 1 of 4

Dinesh Palatty/Trim a block using following LISP

d_palatty
Explorer
Explorer

I would like to trim a block using following LISP

(defun c:TrimRef ()

(if (ssget "_I" '((0 . "INSERT")))
(command "_.-REFEDIT" "_Ok" "_All" "_No")
(command "_.-REFEDIT" pause "_Ok" "_All" "_No"))
(initcommandversion)
(command-s "_.TRIM")
(command "_.REFCLOSE" "_Save")
(princ)
)

 

But LISP isnt working can anybody fix the error?

 

@d_palatty - moderation team has adjusted title for better clarity.

 

0 Likes
356 Views
3 Replies
Replies (3)
Message 2 of 4

Moshe-A
Mentor
Mentor

@d_palatty hi,

 

it looks like -refedit at it's first argument does not accept autolisp variable only picking from mouse

check this one 

 

Moshe

 

 

(defun c:trimref ()
 (command "-refedit" pause "_OK" "_All" "_No")
 (initcommandversion)
 (command-s "._trim")
 (command "._refclose" "_Save")
 (princ)
)

 

 

 

0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant

@d_palatty wrote:

....

(if (ssget "_I" '((0 . "INSERT")))

....


There is also the possibility that the selection there could contain more than one Block, which REFEDIT will not like.

Kent Cooper, AIA
0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

@d_palatty wrote:

.... LISP isnt working can anybody fix the error?


But with a single Block pre-selected [or none], I find this approach works for me:

 

(defun c:TrimRef (/ ss)
  (if
    (and
      (setq ss (ssget "_I" '((0 . "INSERT"))))
      (= (sslength ss) 1); single Block only
    ); and
    (progn ; then
      (sssetfirst nil ss) ; make it single-object selection, not selection set
      (command "_.-REFEDIT" "_Ok" "_All" "_No")
    )
    (command "_.-REFEDIT" pause "_Ok" "_All" "_No"); else
  )
  (initcommandversion)
  (command-s "_.TRIM")
  (command "_.REFCLOSE" "_Save")
  (princ)
)

 

EDIT:  Added a check on whether only one Block is pre-selected [lines 3-6], and lines 7, 8 & 10 to change the selection set into a single-object selection that REFEDIT can work with.  If there's a pre-selection of more than one Block, it abandons that and asks you to select one, just as if there is no pre-selection.

Kent Cooper, AIA
0 Likes