entity selection in command extend / trim

Hi, is any possibility in commands extend and trim to select the entity, that is to be modified, by window using two points?Thanks for some tip.

«1

Comments

  • I don't recall a window option but I know there is a fence option. I use it a lot. Once you are being prompted for the entity to trim type F or use the right click context menu to select fence.Not really what you asked for but it may help.

  • Thanks,I know "Fence", I have tried this question, because I think it would be more comfortable to use window seection automtically.

  • Are you saying the command works wrong way around? It always seemed to me the entities to trim or extend should be first part of the process, but compatability with Autocad is the aim even in areas which might have been better designed.

  • I think Vit just wants the objects-to-be-trimmed to be selected in the same way as the cutting objects; i.e., if the point picked in response to "Select entity to trim" doesn't find an object, then that point would be interpreted as the first point of a window or crossing.I've always thought the Trim command should work that way. Typing an option letter is less convenient, and it's hard to see why it shouldn't change automatically, like most selection operations.I've tried to make a command that works that way using Lisp, but it's beyond my ability. Here's what I settled for:

    ;; Trim command that always starts out in Fence mode:(defun c:TF ()(princ "Select cutting objects: ")(setq ss1 (ssget) )(command "Trim" ss1 "" "F" pause));; Trim command that automatically changes to Fence mode;; if the first pick point doesn't find an object.(defun c:TY ()(princ "Select cutting objects: ")(setq ss1 (ssget) )(setq Input1 (entsel) )(if (eq Input1 nil) (command "Trim" ss1 "" "F" pause) (command "Trim" ss1 "" Input1 pause) ))
  • My thanks to Anthony. You have exactly understood, what I wanted to say.But I am not such expirienced in Lisp programming.Thanks a lot.

  • Hmm... If using a rectangular selection method how would you determine the portion of the entity to remove?For example, run the script below, if the magenta rectangle is the selection window created left to right (selecting everything inside only) and the red line is the cutting entity, which portion of the green lines and blue circle should be removed?

    _-color3line3.9457,11.920021.4508,21.3862_line22.5777,19.05723.5701,9.3656_line5.8239,7.637622.8782,16.8034_-color5circle19.7979,11.995122.3523,13.8733_-color1_line32.8704,3.8812-3.4169,27.9225_-color6_rect-3.9428,25.743725.7331,4.8578_-color256_zoom_extents
  • Greg, I didn't think that would be the problem. I figured that the first point you click to form the window or crossing would determine which side of all cutting objects is the part of the trimmed object you want to get rid of. So in the example you gave, the result would be this:http://www.freeimagehosting.net/uploads/b5a2abb130.gif(there's no way to include links on this forum??)But in many cases it would be hard to draw a window or crossing that selects all the objects you want to trim and not any others. The fence line is probably the better way to go.What I wanted to do was something like the second lisp routine I posted, except the first click wouldn't just switch to fence mode; it would also serve as the first point of the fence line. And ideally it would only need a single Enter to end the command, instead of two. But I think that would take a lot of code, and I've never written anything that calculates points on objects or manually removes part of an object.

  • Anthony, for links I have entered the HTML codes and it works: Screen Capture

  • But the code tags didn't protect the HTML... I'll try again

    Screen Capture
  • Well, that failed also... replace the | with angle brackets|a href="http://www.freeimagehosting.net/uploads/b5a2abb130.gif"|Screen Capture|/a|

  • That's another problem with this forum -- you can't preview a post to see whether it works, and you can't delete a post if it doesn't work.But your link did work. The first 3 times you wrote Screen Capture, it's a link, in my browser, and it goes to the image. Only the 4th time failed. Now if I can just figure out how you did it. Testing with a href=".......gif" inside angle brackets, then Screen Capture, then forward-slash a inside angle brackets:Screen Capture

  • That worked, in my browser. Anyone else?

  • Yes, your link worked for me Anthony.

  • For future reference, an easy way to make a link that works here is in Mudcat Forum's Link Maker.

  • Anthony, I think what you want to do should be possible. Build a selection set for the cutting entites as you already are and then build a list of vertices for the fence.Use command as:(command "_TRIM" ss1 "" "_F" pt_list "" "")I thought I would get time to try to write a routine last night but didn't... I will try tonight as it is something I will learn from doing :-)

  • Greg, you're right, with a fence line it might not be so hard. I originally tried to do it with a window or crossing, which wasn't a good idea anyway.But the trimmed parts have to disappear as each fence segment is drawn, not all at once after all the fence segments are drawn. So I think you'd have to execute the built-in TRIM command each time the user selects a vertex:(command "Trim" ss1 "" "F" pt1 pt2 "" "")(setq pt1 pt2)(setq pt2 (getpoint pt1 "next fence vertex: ") );; repeat the loop if a point is picked, or exit if the user presses EnterThe part I can't figure out is how to get the first user input after selecting the cutting edges. That's the most important part. The user has to click somewhere in the drawing window, with the pickbox displayed at the cursor, and that click has to either select an object (if there's one in the pickbox) or else return a point to use as the first vertex of the fence. But GETPOINT doesn't show a pickbox, plus how would you convert the point into an entity selection? And ENTSEL doesn't return the picked point if no object is found.

  • Anthony, I think you should be able to use getpoint followed by ssget with the point... if ssget does not pick an entity then drop into fence point collecting. Here is a start but I will not have a chance to look at it again for several hours.

    (defun C:TEST ( / ss1 pt1 pt2 input kval)    (princ "Select cutting objects: ")    (if (setq ss1 (ssget))        (progn            (initget 1)            (setq pt1 (getpoint "Select object(s) to trim: "))            (if (setq ss2 (ssget pt1))                (command "_TRIM" ss1 "" (list (ssname ss2 0) pt1) "")                (progn                    ;; collect fence points and pass to TRIM command                )            ) ; end if single entity selection        )        (princ "\nNo cutting entites selected...")    ) ; end if - cutting entities    (prin1))
  • Well, here is my attempt at running trim with single entity selection or an automatic fence. This is my first attempt to use grread... I thought I could catch the ESC with it but I must not have that part correct. I guess I should have turned off OSNAPS as they are ignored and just added a local error handler.For me, I am not really interested in the trim but I think pulling the fence creation out into a separate function will come in handy. I am by no means an expert with LISP so feel free to point out things I can do better another way...(I guess I have to post without horizontal whitespace or use &lt pre &gt tags and get the extra vertical whitespace) :-(

    ;;;; Trim command with first pick an entity or start of fence...;;;(defun C:TEST ( / ss1 pt1 pt2 input kval plist)    ;; - Get user to create a selection set of entities to use as the cutting    ;; entities for the trim command.    ;; - Next use getpoint to select a single point and attempt to create    ;; a selection set with that single point.    ;; - If there is an entity selected, call TRIM command for the single     ;; entity    ;; - If no selection set was created stick the point in a list and    ;; enter a loop using grread to get pointsfor a fence, appending the    ;; points to the list as the user selects them.    ;; - Once we get a key value if it is enter or space end the loop    ;; and call TRIM with the fence option and the list of points in the    ;; fence.    ;;    ;; The first point pick should really be done with grread to try for    ;; the full interface of the TRIM command to be implemented.        ;; Prompt user for the cutting entities... may make sense to filter    ;; out some types...    (prompt "Select cutting objects: ")    (if (setq ss1 (ssget))        (progn            ;; Ok, we have a set... carry on            ;; Use initget to prevent null input for the getpoint call            (initget 1)            (setq pt1 (getpoint "Select object(s) to trim: "))            ;; Use the point to try to create a selection set.            (if (setq ss2 (ssget pt1))                ;; Ok, user picked an entity, try to trim it.                (command "_TRIM" ss1 "" (list (ssname ss2 0) pt1) "")                (progn                    ;; So, no entity was picked. Add the pick point to                    ;; a the plist                    ;; Note: this whole progn should be pulled out and                    ;; made a separate function.                    (setq plist (list pt1))                    ;; Initialize pt2 to be the same                    (setq pt2 pt1)                    ;; Loop using grread until we get an enter, space or escape                    ;; (grread flag bits cursor)                    ;; flag == 1 means to track the pointer location                    ;; bits == 11 means we want:                     ;;   1 (dynamic coords) | 2 (keystrokes) | 8 (escape not error)                    (while                         (cond                            ;; 5 indicates pointer movement input... update                            ;; the fence line dynamically                            ((= 5 (car (setq input (grread 1 11 0))))                                (grdraw pt1 pt2 -1 1)                                (setq pt2 (cadr input))                                (grdraw pt1 pt2 -1 1)                                T ;; for the while loop                            )                            ;; type 3 indicates user selected a point                            ((= 3 (car input))                                ;; get the point and append it to the                                ;; list of fence points.                                (setq pt2 (cadr input))                                (setq plist (append plist (list pt2)))                                ;; leap frog pt1 to pt2                                (setq pt1 pt2)                                T ;; resume the while loop                            )                            ;; type 2 indicates a keystroke                            ((= 2 (car input))                                (if (or ;; enter or space key                                        (= 13 (cadr input))                                        (= 32 (cadr input))                                    )                                    (progn                                        ;; Clear the fence                                        (grdraw pt1 pt2 -1 1)                                        (setq i 0)                                        (repeat (1- (length plist))                                                                                (grdraw                                                 (nth i plist)                                                (nth (1+ i) plist) -1 1)                                            (setq i (1+ i))                                        )                                        ;; exit the loop                                        NIL                                    )                                    T ;; continue the while                                )                            )                            ;; input type 11 is from the right mouse button                            ;; ...ignore it for now a 12 will follow                            ((= 11 (car input))                                T                            )                            ;; type 12 seems to be a mouse position following                            ;; a type 11                            ((= 12 (car input))                                ;; Clear the fence lines and exit the loop                                (setq pt2 (cadr input))                                (grdraw pt1 pt2 -1 1)                                (setq i 0)                                (repeat (1- (length plist))                                                                        (grdraw                                         (nth i plist)                                        (nth (1+ i) plist) -1 1)                                    (setq i (1+ i))                                )                                NIL                            )                            ;; Some type of input I am unaware of happened...                            (T                                (princ "\nunexpected input: ")(princ input)                                NIL                            )                        )                    )                    ;; Ok, if plist of not NIL run the TRIM command with a                     ;; fence using the points in plist.                    (if (/= plist NIL)                        (command "_TRIM" ss1 "" "_F" plist "" "")                    )                )            )        )        (princ "\nNo cutting entites selected...")    )    (prin1))
  • Greg, thanks for the tip about feeding a point to SSGET to make it select whatever is in pickbox range of that point. I didn't know about that. But then I remembered the variable LASTPOINT, and I think using that together with ENTSEL is better because it shows the pickbox.Is there any way to make a selection set highlighted but without the grips showing? Like the built-in TRIM command does while you're picking objects to be trimmed? That seems like something you should be able to do in Lisp, one of the most basic things, in fact. But I don't know of any way to do it. According to all the documentation, it should be what you get from (sssetfirst nil ss1), but it isn't. What you actually get from that is what you're supposed to get from (sssetfirst ss1 ss1).Vit, if you're still reading, maybe this is what you wanted?

    ;;; --- TRIM command with automatic Fence(defun c:TR ()(setq SaveCE (getvar "CMDECHO")) ;; save Command Echo setting(princ "Select cutting objects: ")(setq ss1 (ssget)) ;; select cutting edges(sssetfirst nil ss1) ;; highlight cutting edges(setq e1 (entsel "Select object to trim : "))(setq pt1 (getvar "LASTPOINT")) ;; get the pick point(if e1 (progn ;; If an object was found, (setvar "CMDECHO" 1) ;; and turn on Command Echo (command "Trim" ss1 "" pt1) ;; and run Trim in normal mode. (while (> (getvar "cmdactive") 0) (command pause)) ) ;; end Progn for If object found (progn ;; If no object was found, then begin artificial fence mode. (setvar "CMDECHO" 0) ;; suppress command echo (setq pt2 (getpoint pt1 "next fence pt: ")) ;; get 2nd vertex ;; --------Loop to pick next vertex and trim to next fence segment: (while pt2 (command "Trim" ss1 "" "F" pt1 pt2 "" "") ;; trim that segment (setq pt1 pt2) ;; move to next segment (sssetfirst nil ss1) ;; highlight cutting edges (setq pt2 (getpoint pt1 "next fence vertex : ") ) ) ;; ----exit Loop when user presses Enter instead of picking a next point ) ;; end Progn for artificial fence mode (no object found) ) ;; end IF object found(setvar "CMDECHO" SaveCE) ;; restore Command Echo setting if changed) ;------------------------------------------------------------------------------------
  • Anthony, I think sssetfirst in only for selecting and gripping even though the help file says and/or. I have only used it to turn on grips.A search result indicated you should be able to (setvar "GRIPS" 0) before the sssetfirst to have it highlight but not grip... you would want to cave and restore the users original value. I tried this and it did not work for me with my current Bricscad version.You could use (vla-Highlight obj 1) for on and (vla-Highlight obj 0) for off or (redraw ename 3) for on and (redraw ename 4) for off.I made one example using redraw:

    (defun highlight_ss (ss flag / i)    ;; Turns highlight on or off for a selection set of    ;; entities.    ;; flag == 0 or NIL will turn off the highlight    ;; flag == other values will turn it on    ;; variable HIGHLIGHT should be on    (if (and ss (= (type ss) 'PICKSET))        (progn            (if (or (not flag)(zerop flag))                (setq flag 4) ;; turning off highlight                (setq flag 3) ;; turning on highlight            )            (setq i 0)            (repeat (sslength ss)                (redraw (ssname ss i) flag)                (setq i (1+ i))            )        )        (princ "\nERR: highlight_ss: invalid selection set...")    )    (prin1))
  • you would want to save not cave :-)

  • I caved on the attempt to make objects highlighted but not gripped. Too complicated. It was just a cosmetic issue anyway.But here's another custom Trim command. This one automatically changes back and forth between fence mode and standard mode, depending on where you click.Any time you click on an object, you get standard mode, and the object you clicked on gets trimmed if it crosses a cutting object.Any time you don't click on an object, you get fence mode, and the click point is treated as a fence vertex.Hit Enter to exit the command from either mode.How are you getting leading blank spaces in your code posts? This one is supposed to have a two-space indentation after the first line of each If, Progn, or While function. It's easier to read that way.

    ;;; TRIM command with Fence mode automatically turned on and off(defun c:TR ()(princ "Select cutting objects: ")(setq ss1 (ssget)) ;; select cutting edges;------------------------------------------------------(setq pt1 nil pt2 nil NewPt nil) ;; clear fence points(setq LoopFlag 1) ;; set Loop flag;------------------------------ Begin Loop, get user input(while (equal LoopFlag 1) ;; Loop till no point is picked (setq OldLP (getvar "LASTPOINT")) (setq e1 nil) (setq NewPt nil) (sssetfirst nil ss1) ;; highlight cutting edges (if pt1 ;; Is there a fence start point? (progn ;; If so, look for a new fence vertex. (setq NewPt (getpoint pt1 "Next fence point, or object to trim: ")) (if NewPt ;; Did the user actually pick a new point? (progn ;; If so, (if (ssget NewPt) ;; then if there's an object at NewPt, (setq e1 (ssname (ssget NewPt) 0)) ;; make it e1. ) ;; end IF ) ;; end Progn (progn ;; If not (no new point because user hit Enter), (setq pt1 nil) ;; then clear pt1, (setq LoopFlag 0) ;; and prepare to end the loop. ) ;; end Progn ) ;; end IF ) ;; end Progn (progn ;; If not (no fence start point), look for an object to trim (setq e1 (entsel "Object to trim, or start point of fence: ")) (setq NewPt (getvar "LASTPOINT")) (if (equal NewPt OldLP) ;; If the user hit Enter instead of picking, (setq LoopFlag 0) ;; then prepare to end the loop. ) ;; end IF ) ;; end Progn ) ;; end IF;;;-------------------------- Continue Loop, process user input (if e1 ;; Was an object found during user input? (progn ;; If so, (command "Trim" ss1 "" NewPt "") ;; trim the object, (setq pt1 nil pt2 nil) ;; and clear the fence points. ) ;; end Progn for If object found (progn ;; If not (no object found), (if pt1 ;; Is there a fence start point? (progn ;; If so, (setq pt2 NewPt) ;; make the new point the fence end point, (command "Trim" ss1 "" "F" pt1 pt2 "" "") ;; trim to the new fence, (setq pt1 pt2) ;; allow continuation of the fence line, (setq pt2 nil) ;; and get rid of the old end point. ) ;; end Progn (progn ;; If not (no fence start point), (setq pt1 NewPt) ;; make this pt1, (setq pt2 nil) ;; and get rid of the old pt2. ) ;; end Progn ) ;; end IF there's a pt1 ) ;; end Progn for no object found ) ;; end IF object found) ;; end WHILE loop) ;-----------------------------------------------------------
  • To preserve the leading spaces I have been replacing:<div class="code"><code>PASTE CODE HERE</code></div>with:<div class="code"><pre>PASTE CODE HERE</pre></div>but it it then introduces the extra vertical space so there is no good way to post code here. The support team have mentioned they are trying to improve the forums so hopefully it will get better. There is an excellent resource at www.theswamp.org where I have learned a lot.Regarding the highlighting, if you add the highlight_ss function from above you should be able to replace your (sssetfirst nil ss1) with (highlight_ss ss1 1) to turn on the highlight but remember to turn off the highlight before exiting with (highlight_ss ss1 0). If you do not already have a local error function you should create one that will turn off the highlight and restore any variables you touch to the users previous values (in the case the user hits ESC or an actual error is encountered).

  • Thanks for those tips, Greg. I haven't had any problem with the extra vertical space in your code posts. I paste the code into a Lisp file, then open it temporarily in Atlantis word processor and use the Replace command to ReplaceAll ^p^p with ^p (only one pass through the document, to keep the intentional double-spacing).And I guess highlighting isn't so complicated after all. Except that Bricscad said:error : no function definition at [EVAL]But the (vla-Highlight obj 1) that you mentioned before worked, so I made a custom function to apply that to a group. Now I can highlight objects without showing grips.I never understood before that the error function allows you to fix problems that arise from abnormal termination. Many of my custom commands need that. After reading what you said about it, I learned how to use it, and I incorporated it into this cosmetically-enhanced version of Trim with Auto-Fence:

    ;;; sub-routine to highlight a selection set (without grips)(defun hilite (set33 OnOff / N)(setq N 0)(while (< N (sslength set33))  (vla-highlight (vlax-ename->vla-object (ssname set33 N)) OnOff)  (setq N (1+ N))  ) ;; end While) ;-----------------------------------------------------------;; subroutine to handle errors in the custom Trim command(defun IfAbort (emsg)(prompt "\n-- Abnormal termination due to: ")(prompt emsg)(setvar "CMDECHO" SaveCE)         ;; restore command echo status(setvar "OSMODE" SaveOS)          ;; restore Object Snap setting(setq *error* SaveErr)            ;; restore previous error-handling function(hilite ss1 0)                    ;; turn off highlighting) ;-----------------------------------------------------------;;; TRIM command with Fence mode automatically turned on and off(defun c:TR ()(setq SaveCE (getvar "CMDECHO"))  ;; save Command Echo status(setq SaveOS (getvar "OSMODE"))   ;; save Object Snap setting(setq SaveErr *error*)            ;; save current error-handling function(setq *error* IfAbort)            ;; make IfAbort the error-handling function(princ "Select cutting objects: ")(setq ss1 (ssget))                    ;; select cutting edges(sssetfirst nil ss1) (sssetfirst nil) ;; turn off grips of any pre-selected set;------------------------------------------------------(setvar "CMDECHO" 0)              ;; suppress command echo(setvar "OSMODE" 0)               ;; turn off object snap(setq pt1 nil pt2 nil NewPt nil)  ;; clear fence points & pick point(setq LoopFlag 1)                 ;; set Loop flag;------------------------------ Begin Loop, get user input(while (equal LoopFlag 1)         ;; Loop till no point is picked  (setq OldLP (getvar "LASTPOINT"))  (setq e1 nil)  (setq NewPt nil)  (hilite ss1 1)             ;; highlight cutting edges  (if pt1 ;;-------------------1: Is there a fence start point?    (progn                   ;; If so, look for a new fence vertex.      (setq NewPt (getpoint pt1 "Next fence point, or object to trim: "))      (if NewPt ;;---------2: Did the user actually pick a new point?        (progn                                 ;; If so, then          (if (ssget NewPt) ;;---------3: Is there an object at NewPt?            (setq e1 (ssname (ssget NewPt) 0)) ;; If so, make it e1.            ) ;;---end IF-3.          ) ;; end Progn.        (progn               ;; If not (no new point because user hit Enter),          (setq pt1 nil)     ;;   then clear pt1,          (setq LoopFlag 0)  ;;   and prepare to end the loop.          ) ;;end Progn.        ) ;;---end IF-2.      ) ;; end Progn    (progn    ;; If not (no fence start point), look for an object to trim      (setq e1 (entsel "Object to trim, or start point of fence: "))      (setq NewPt (getvar "LASTPOINT"))      (if (equal NewPt OldLP);;-------4: Did the user hit Enter?        (setq LoopFlag 0)          ;;   If so, prepare to end the loop.        ) ;;---end IF-4      ) ;; end Progn    ) ;;---end IF-1;;;-------------------------- Continue Loop, process user input  (if e1 ;;------------------5: Was an object found during user input?    (progn                             ;; If so,      (command "Trim" ss1 "" NewPt "") ;;   trim the object,      (setq pt1 nil pt2 nil)           ;;   and clear the fence points.      ) ;; end Progn    (progn                             ;; If not (no object found),      (if pt1 ;;---------6: Is there a fence start point?         (progn                        ;; If so,           (setq pt2 NewPt)            ;;   make the new point the fence end point,           (command "Trim" ss1 "" "F" pt1 pt2 "" "") ;;   trim to the new fence,           (setq pt1 pt2)              ;;   allow continuation of the fence line,           (setq pt2 nil)              ;;   and get rid of the old end point.           ) ;; end Progn         (progn                        ;; If not (no fence start point),           (setq pt1 NewPt)            ;;   make this pt1,           (setq pt2 nil)              ;;   and get rid of the old pt2.           ) ;; end Progn         ) ;;---end IF-6       ) ;; end Progn    ) ;;---end IF-5) ;; end WHILE loop(setvar "CMDECHO" SaveCE)         ;; restore Command Echo status(setvar "OSMODE" SaveOS)          ;; restore Object Snap setting(setq *error* SaveErr)            ;; restore previous error-handling function(hilite ss1 0)                    ;; turn off highlighting(SelP)) ;-----------------------------------------------------------
  • The error message I tried to include in the previous post was:error : no function definition HIGHLIGHT_SS at [EVAL]with angle brackets around HIGHLIGHT_SSThe forum editor doesn't like angle brackets. But it tolerated the two in the lisp file.

  • Anthony, one other thing I would suggest is to make your variables local. I had edited a previous version of your TR routine when I tested the highlight_ss function. Now I added a local error handler. Note the variables used and the error function are declared in the local scope... after the / in the defun argument list. Oh, the osnap mode is also disabled during the routine.Declaring the names local means they do not live on after the routine has ended. You can confirm the variables still exist after the routine ends right from the command line.... After running both versions enter the command !pt1Have fun!

    (defun highlight_ss (ss flag / i)    ;; Turns highlight on or off for a selection set of    ;; entities.    ;; flag == 0 or NIL will turn off the highlight    ;; flag == other values will turn it on    ;; variable HIGHLIGHT should be on    (if (and ss (= (type ss) 'PICKSET))        (progn            (if (or (not flag)(zerop flag))                (setq flag 4) ;; turning off highlight                (setq flag 3) ;; turning on highlight            )            (setq i 0)            (repeat (sslength ss)                (redraw (ssname ss i) flag)                (setq i (1+ i))            )        )        (princ "\nERR: highlight_ss: invalid selection set...")    )    (prin1));;; --- TRIM command with automatic Fence(defun c:TR ( / *error* SaveCE SaveOSM ss1 el pt1 pt2)    ;; Define a local error handler    (defun *error* (msg)        ;; Print the error message if it is not a user cancelled message        (if (not                (member (strcase msg)                     '("FUNCTION CANCELLED" "CONSOLE BREAK" "QUIT / EXIT ABORT")))            (princ (strcat "\nError: " msg))        )                ;; Turn off the highlight for the cutting entites...        (if (= (type ss1) 'PICKSET)            (highlight_ss ss1 0)        )                ;; Restore system variables...        (and SaveCE (setvar "CMDECHO" SaveCE))        (and SaveOSM (setvar "OSMODE" SaveOSM))    ) ;; end of local error handler        (setq SaveCE (getvar "CMDECHO")) ;; save Command Echo setting    (setq SaveOSM (getvar "OSMODE")) ;; save the OSNAP Mode    (setvar "OSMODE" 0) ;; turn off OSNAPS    (princ "Select cutting objects: ")    (setq ss1 (ssget)) ;; select cutting edges    (highlight_ss ss1 1) ;; highlight cutting edges    (setq e1 (entsel "Select object to trim : "))    (setq pt1 (getvar "LASTPOINT")) ;; get the pick point    (if e1        (progn ;; If an object was found,            (setvar "CMDECHO" 1) ;; and turn on Command Echo            (command "Trim" ss1 "" pt1) ;; and run Trim in normal mode.            (while (> (getvar "cmdactive") 0) (command pause))        ) ;; end Progn for If object found        (progn ;; If no object was found, then begin artificial fence mode.            (setvar "CMDECHO" 0) ;; suppress command echo            (setq pt2 (getpoint pt1 "next fence pt: ")) ;; get 2nd vertex            ;; --------Loop to pick next vertex and trim to next fence segment:            (while pt2                (command "Trim" ss1 "" "F" pt1 pt2 "" "") ;; trim that segment                (highlight_ss ss1 1) ;; highlight cutting edges                (setq pt1 pt2) ;; move to next segment                (setq pt2 (getpoint pt1 "next fence vertex : ") )            ) ;; ----exit Loop when user presses Enter instead of picking a next point            (highlight_ss ss1 0)        ) ;; end Progn for artificial fence mode (no object found)    ) ;; end IF object found    (setvar "CMDECHO" SaveCE) ;; restore Command Echo setting if changed    (setvar "OSMODE" SaveOSM) ;; restore OSNAP Mode setting if changed    (prin1)) ;------------------------------------------------------------------------------------ 
  • Anthony, here is one more suggestion...

  • Hmmm... hit the wrong button and then got sidetracked... :-(You probably should make sure you have a selection set and that the objects in it have the method Highlight. I have not tried the changes below so I hope I got it right!The flow of execution will drop out of the (and ...) if either the object cannot be created from the ename or if the object does not have the Highlight method prior to trying to use it.

    ;;; sub-routine to highlight a selection set (without grips)(defun hilite (set33 OnOff / N obj)    (if (= (type set33) 'PICKSET)        (progn            (setq N 0)            (while (< N (sslength set33))                (and                    (setq obj (vlax-ename->vla-object (ssname set33 N)))                    (vlax-method-applicable-p obj "Highlight")                    (vla-highlight obj OnOff)                )                (setq N (1+ N))            ) ;; end While        )    )) ;-----------------------------------------------------------
  • Oh, before I got sidetracked I was intending to suggest one other change. If you use repeat instead of while you can avoid evaluating the sslength each time through the loop as well as a logical comparison:

                (setq N 0)            (repeat (sslength set33)                ;; do stuff using N as an index                (setq N (1+ N))            ) ;; end Repeat
  • Hi, thank a lot for your Lisps. I tried the Lisp under Number Reply 23 - it's very good for me. Is there any possibility to implement this one?:I select trim edge, and then I want select entities by Fence that has only one start and one end, and then I want to select other entities by Fence that has another one start with another one end. Thanks for your replies!!!v.

This discussion has been closed.