'Erase all but some and move' lisp

'Erase all but some and move' lisp

Anonymous
Not applicable
1,428 Views
6 Replies
Message 1 of 7

'Erase all but some and move' lisp

Anonymous
Not applicable

Hello everyone,

I have not searched for any similar code yet, but am looking for a simple code. This is to aid in generating multi-tab layouts (70+ tabs) and with the tabs set up with all 70+ viewports defined. What I am looking for is this:

 

1) Prompt for a selection of objects to keep

2) Select all objects and deselect any from Step 1

3) Erase remaining objects

4) Initiate Move command

5) Locate left-bottom most point (think of an 8.5 x 11 profile orientation)

6) From Step 5, pick move point [at].35,.319 then move to 0,0,0

7) End script

 

Any help with this will be highly appreciated!

 

~ Thank you! ~

0 Likes
Accepted solutions (1)
1,429 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

So far I've found this: https://autocadtips1.com/2012/02/17/autolisp-delete-outside-of-window/

To erase everything outside of a window.

0 Likes
Message 3 of 7

Kent1Cooper
Consultant
Consultant

A "lisp" [Subject line] is not the same thing as a "script" [end of description], but assuming the former is what you really want....

 

I don't quite get steps 5 and 6 in relation to each other.  Regardless of where the lower left corner of the extent of remaining objects is, if that's what you're after in step 5, moving things from [at].35,.319 to 0,0,0 in step 6 is just moving them that far, so where that all sits in relation to [for example] WCS coordinates doesn't make any difference, and I don't see any point in step 5.  If I'm wrong, can you describe it differently?  Do you perhaps want to move everything remaining so that the lower left corner of their extents goes to .35,.319 in WCS terms?  Or the point [at].35,.319 relative to that lower-left extent goes to WCS 0,0,0?  That would put parts of the objects into negative-XY WCS territory, which is why I'm doubtful, but you may have your reasons.  Or do you want the lower-left extent point to end up at positive .35,.319 in WCS terms?

 

If I'm correct that things will just need to be moved that far, regardless of where they lie, try this:

(defun C:TEST (/ ss)
  (prompt "\nFor those to KEEP,")
  (setq ss (ssget "_:L")); [provides its own Select-objects prompt]
  (command
    "_.erase" "_all" "_remove" ss ""
    "_.move" ss "" "-.35,-.319" "" ; [equivalent to from .35,.319 to 0,0]
  ); command  
); defun

But if you really need to know the lower left corner of the extents of the objects remaining, you can add a REGEN command to reset the EXTMIN and EXTMAX System Variable values, and then get the value of EXTMIN, and use that somehow [depending on what the goal really is] in the Move command.  But be aware that EXTMIN can be a little different from what you expect visually with certain conditions of certain entity types [e,g, Mtext whose "box" is larger than the contents in it, and Splines in some cases].

Kent Cooper, AIA
0 Likes
Message 4 of 7

Anonymous
Not applicable

Hi Kent1Cooper,

I just tested your code, it works fine on erasing and I see it moves the viewport slightly. To elaborate, if relatively the lower left point is (0,0) in relation to the viewport (not WCS), then from that lower left point track +x .35 and +y .319 (so yes it is regardless of WCS, but local to the object). From this, move at this track point to 0,0. So the viewport can be somewhere 100,50,0 for example and still be relocated to 0,0,0,

 

The screenshot may clarify better. The green point in the bottom left would be the tracked point, the one near the center is 0,0,0. So the viewport objects can be anywhere and would be moved by this lower left point to 0,0,0. Even the box on the right, the relative lower left point to be moved to the shown 0,0 point inside the first box (not centroid to itself). I hope this helps more.

0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

All right, I think [but don't guarantee] I understand what you're after -- try this:

 

(defun C:TEST (/ ss)
  (prompt "\nFor those to KEEP,")
  (setq ss (ssget "_:L")); not locked Layer(s) [provides its own Select-objects prompt]
  (command
    "_.erase" "_all" "_remove" ss ""
    "_.regen" ; [to reset what it knows about extents]
    "_.move" ss ""
      "_none" (mapcar '+ (getvar 'extmin) '(0.35 0.319 0.0))
      "_none" '(0.0 0.0 0.0)
  ); command
); defun

 

except that it's going to use the lower left corner of the outer red rectangle, not the inner one as your little diagonal line implies [unless the outer one is not selected to be kept].  If you need to Move both, and need it to use the corner of the inner one, I suspect it would need to ask the User to select that inner one as a separate selection from selecting the collective things to keep, so it can find the lower left corner of just that one object [but that's becoming a little different from your original description].

Kent Cooper, AIA
0 Likes
Message 6 of 7

Anonymous
Not applicable

Thank you! Almost there it looks like 😄

The EXTMIN or EXTMAX do not want to set to the extents of the object and change to some random number when the code is run. No layers are frozen/off/locked and no ghost objects.

 

Update: If the erase command is called first, then a zoom extents on the selected object (prior to invoking Move), it works just right! Tested this by copying to random spots, run your code, then zoom extents and ran it again. It hit 0,0 every time after that. SO Erase, zoom extents, move, zoom extents should fix the extmin/max issue.  Even Zoom Object to the selection works just as good!

0 Likes
Message 7 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

Update: If the erase command is called first, then a zoom extents on the selected object (prior to invoking Move), it works just right! ....


My mistake -- I had thought that REGEN also resets the EXTMIN/EXTMAX System Variables, but Help confirms that it's only Zoom Extents or Zoom All.

Kent Cooper, AIA
0 Likes