Paste to Original Coordinates and Zoom to Pasted Objects Area

Paste to Original Coordinates and Zoom to Pasted Objects Area

GeryKnee
Advocate Advocate
1,742 Views
10 Replies
Message 1 of 11

Paste to Original Coordinates and Zoom to Pasted Objects Area

GeryKnee
Advocate
Advocate

I need to complete this code :

 


(defun c:PasteclipToOrigin()

            ;;;; Store all entities of ModelSpace to a Collection "ObjectsBefore"

                 ......................................

(command "PASTEORIG")

           ;;;; FN2 Define which of the entities existing in ModelSpace now (after PASTEORIG)

           ;;;;; are not items of  stored in ObjectsBefore.

           ;;;;;; those entities  added by PASTEORIG

           ;;;;;;; Let  "ObjectsAdded" be the Added entities collection.

                 ......................................

           ;;;;;;; Get the Bounding Box Of Objects in ObjectsAdded

                 ......................................

           ;;;;;;; ZoomWidow (BoundingBox)

)

Thanks,

Gery.

0 Likes
Accepted solutions (1)
1,743 Views
10 Replies
Replies (10)
Message 2 of 11

Kent1Cooper
Consultant
Consultant

It's not necessary to store an ObjectsBefore collection of all entities.  The typical way to do this kind of thing would be to store the one entity returned by (entlast) into a variable -- let's say 'ent' -- before the Pasting, and then after it:

  (while (setq ent (entnext ent)) ....

[which steps through everything added by the Pasting] put each new 'ent' into a selection set.

 

But a perhaps simpler approach would be to use PASTEBLOCK instead, then EXPLODE the Block, and its pieces will become the Previous selection.  That eliminates the saving of a last entity beforehand, and the stepping through of new ones.

 

However you make that selection, there are various routines out there to draw the collective bounding box around multiple objects, such as mine called DrawBoundingBoxMult.lsp, >here<.

Kent Cooper, AIA
Message 3 of 11

GeryKnee
Advocate
Advocate

Hello Kent,

Sure, that's the solution.

Your opinion to store just the laste created object, is absolutelly clever.

But i don't know if Creation Order Changes using the BrinkToFront or SendToBack procedures.

If Creation Order doesn't change , that's very fast and safe.

i'll be happy , If you have the time to complete the code as you know very good to do it.

You know, i'm a very old man to learn Lisp.

Because I use from long time ago Delphi, witch has an extremly different logic.

It;s too late for me to learn lisp at my 67th year.

If tomorrow i'll be alive, i'll look here.

Thank you very match for your help,

Gery.

0 Likes
Message 4 of 11

Sea-Haven
Mentor
Mentor

Agree Kent your method a slight change in the order Pasteblock, get bounding box, then explode. This will allow simple mid point of last block.

0 Likes
Message 5 of 11

GeryKnee
Advocate
Advocate

In addition to my previouw post, I need objects to be passed to the original UCS coordinates and pasteblock cannot do it.

0 Likes
Message 6 of 11

GeryKnee
Advocate
Advocate

Hello sea.heaven,

pasteblock asks user to define insertion point. But i want paste objects from clipboard to UCS origin postition and this is the reason i try for this code. i want pasted object to be located to their origin position and be zoomed on screen after paste done.

0 Likes
Message 7 of 11

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

In addition to my previouw post, I need objects to be passed to the original UCS coordinates and pasteblock cannot do it.


Then I think the store-(entlast) / PASTEORIG / step-through-newer-objects approach is the way to go.  I can't work that out now, but may think about it later, if someone else doesn't jump in.  [The routine linked at the end of Message 2 would be altered to use the collective bounding box corners for a ZOOM window, rather than to draw the box in a RECTANG command.]

Kent Cooper, AIA
0 Likes
Message 8 of 11

GeryKnee
Advocate
Advocate

Yes,

Exactly this.

Thank you,

Gery.

0 Likes
Message 9 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

.... steps through everything added .... put each new 'ent' into a selection set. ....


Actually, it wouldn't be necessary to put them into a selection set.  It could simply figure out the collective extents of all the new objects as it steps through them.

 

Here's a quickie:

 

(defun C:POZE ; = PasteOrig & Zoom to Extents of pasted object(s)
  (/ ent eLL eUR LL UR)
  (setq ent (entlast)); [nil if used in new drawing]
  (command "_.pasteorig")
  (while (setq ent (if ent (entnext ent) (entnext))); next, or first if used in new drawing
    (vla-getboundingbox (vlax-ename->vla-object ent) 'minpt 'maxpt)
    (setq
      eLL (vlax-safearray->list minpt)
      eUR (vlax-safearray->list maxpt)
      LL (if LL (mapcar 'min eLL LL) eLL); least of X's & Y's
      UR (if UR (mapcar 'max eUR UR) eUR); greatest of X's & Y's
    ); setq
  ); while
  (command "_.zoom" "_non" (trans LL 0 1) "_non" (trans UR 0 1))
  (princ)
); defun

Consider whether to add something like this at the end:

  (command "_.zoom" "0.95x")

to back off a little, so pasted elements are not quite hard up against the edges of the view area.

 

Kent Cooper, AIA
Message 10 of 11

GeryKnee
Advocate
Advocate

Yes, Kent.

Thank you very match.

That's a great code.

the  (command "_.zoom" "0.95x")  is necessary of course

Regards,

Gery

0 Likes
Message 11 of 11

Sea-Haven
Mentor
Mentor

Just an idea if using select window 1st dwg ie pick 2 diag points, then save mid point using vl-bb-set, go to other dwg pasteorig then can use vl-bb-ref to return the midpoint. Zoom c Pt scale etc all done no bounding box etc 

0 Likes