Jump to content

lisp to zoom to newly imported points (or to a selection set)


Recommended Posts

Posted

Hi all,

 

I am using one of lee mac's lisp (pointsin-v1.0.13) to import point from a text file, and i add some modification to be able to export points from excel.

 

I wonder if there is a lisp to zoom to newly inserted points. I currently use zoom extent at the end of lisp but if i import the points to my existing drawing it would instead zoom to the whole drawing not just to the newly inserted points. :)

Posted

Hi,

 

As it is clear from the Lisp file, the author name is this: [ Copyright 2015 Thomas Gail Haws ].

 

Search for the name of the function and replace it with the following:

(DEFUN PI:INSERT3DPOINTS (POINTSLIST POINTFORMAT / NODELAYERFORMAT POINTLIST th:entlast th:newobj th:lst a b)
 (SETQ NODELAYERFORMAT (PI:GETNODELAYERFORMAT POINTFORMAT))
 (setq th:entlast (entlast))
 (COMMAND "._undo" "_group")
 (FOREACH POINTLIST POINTSLIST
   (PI:MAKELAYER NODELAYERFORMAT POINTLIST POINTFORMAT)
   (COMMAND "._point" (CAR POINTLIST))
   (if (and (not (eq (setq th:newobj (entlast)) th:entlast))
            (eq (cdr (assoc 0 (entget th:newobj))) "POINT")
         )
     (setq th:lst (cons (cdr (assoc 10 (entget th:newobj))) th:lst))
     )
 )
 (if th:lst
   (progn
     (setq a (car th:lst)
       b a
       )
     (mapcar '(lambda (pt)
                (and (< (car pt)  (car a))
                  (< (cadr pt) (cadr a))
                  (setq a pt)
                  )
                (and (> (car pt)  (car b))
                  (> (cadr pt) (cadr b))
                  (setq a pt)
                  ))
       th:lst)
     (command "_.zoom" "_non" a "_non" b)
     )
   )
 (COMMAND "._undo" "_end")
)

Posted

I'm sorry, my mistake :o

I downloaded the lisp a long time ago, and as i remembered it it is lee mac's..

my bad :oops:

 

Thanks for the reply,man

I'll try it!

Posted

I just wanted to be fair with the author. :)

 

Waiting for your test.

Posted

Syukron akhi,

 

Shoutout to Thomas! :D

 

I did test with a selection set of 5 coordinates(same coordinates but different sequence), to check the a and b value, it works great if the smallest coordinate is in the first list and the biggest coordinates is in the last list, however, the a and b didn't get quite right when the order are not in order:

 

Test 1 :

coord 1 = 10,10

coord 2 = 20,20

coord 3 = 30,30

coord 4 = 40,40

 

The result will be a = (40.0 40.0 0.0) and b = (10.0 10.0 0.0)

 

Test 2 :

coord 1 = 40,40

coord 2 = 30,30

coord 3 = 20,20

coord 4 = 10,10

 

The result will be a = (10.0 10.0 0.0) and b = (40.0 40.0 0.0)

 

Test 3 :

coord 1 = 30,30

coord 2 = 40,40

coord 3 = 10,10

coord 4 = 20,20

 

The result will be a = (10.0 10.0 0.0) and b = (30.0 30.0 0.0)

 

Test 4 :

coord 1 = 20,20

coord 2 = 30,30

coord 3 = 10,10

coord 4 = 40,40

 

The result will be a = (40.0 40.0 0.0) and b = (20.0 20.0 0.0)

 

Test 5 :

coord 1 = 30,30

coord 2 = 10,10

coord 3 = 20,20

coord 4 = 40,40

 

The result will be a = (40.0 40.0 0.0) and b = (30.0 30.0 0.0)

Posted

You want to zoom the newly created points or analyse the coordinates?

Posted (edited)

Maybe my wording is wrong.

I want it to zoom extent from the bottom left coordinate to the top right coordinate of the newly inputted points.

Edited by elimgo
Posted

Soo.. looking at (command "_.zoom" "_non" a "_non" b) in your code, i figured out that a is the smallest coordinate and b is the biggest coordinate.

 

And i did some searching and found this : http://www.cadtutor.net/forum/showthread.php?93410-Point-Min-Max-x-coordinate

 

So i revised my lisp and after some testing i realized that to zoom extent to the selection the a is not the smallest coordinate but the bottom left coordinate and b is the top right coordinate in the drawing.

 

How does the autocad zoom extent work? Is there the code for it? Can i modify it so that it will only zoom extent to a set selection?

Posted

Hi..

 

After done some more searching, i found that i can set the current layer to the imported point, freeze all another layer, zoom extent, and then unfreeze the layer.

 

I use this from http://www.cadtutor.net/forum/showthread.php?76896-Freeze-all-layers-except-current-and-restore-previous-state

(defun c:frz ( / d n )
   (while (setq d (tblnext "LAYER" (null d)))
       (if
           (and
               (zerop (logand 1 (cdr (assoc 70 d))))
               (not (member (setq n (cdr (assoc 2 d))) *thaw-list*))
           )
           (setq *thaw-list* (cons n *thaw-list*))
       )
   )
   (command "_.-layer" "_F" "*" "")
   (princ)
)

(defun c:unfrz ( )
   (if *thaw-list*
       (command "_.-layer" "_T"
           (apply 'strcat (mapcar '(lambda ( x ) (strcat "," x)) *thaw-list*))
           ""
       )
   )
   (setq *thaw-list* nil)
   (princ)
)

 

that works for me.

 

Thank you :)

Posted

Look at the zoom options Extents All Window Centre. Tharwat has posted the answer using the Zoom Window option of two points, the "W" is optional, likewise the order of the two points does not matter.

 

Extents zooms to limits of objects

All zooms to two preset lower left and upper right "Limits" type that "Limits".

Centre asks for a point and a scale, you could use this method also.

Posted

Thank you Roy.

 

Yes to go with bounding box should be a bit better than just the insert point of each block although I think it is enough for the OP with the codes that I provided.

Posted

I haven't seen the original code, but if I've understood the request, I believe the function could be written:

(DEFUN PI:INSERT3DPOINTS (POINTSLIST POINTFORMAT / NODELAYERFORMAT POINTLIST mip map)
   (SETQ NODELAYERFORMAT (PI:GETNODELAYERFORMAT POINTFORMAT))
   (setq mip (caar POINTSLIST)
         map (caar POINTSLIST)
   )
   (COMMAND "._undo" "_group")
   (FOREACH POINTLIST POINTSLIST
       (PI:MAKELAYER NODELAYERFORMAT POINTLIST POINTFORMAT)
       (COMMAND "._point" (CAR POINTLIST))
       (setq mip (mapcar 'min mip (CAR POINTLIST))
             map (mapcar 'max map (CAR POINTLIST))
       )
   )
   (command "_.zoom" "_w" "_non" mip "_non" map)
   (COMMAND "._undo" "_end")
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...