Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Zoom into a set of coordinates depending depending on selection

49 REPLIES 49
SOLVED
Reply
Message 1 of 50
kameron1967
1704 Views, 49 Replies

Zoom into a set of coordinates depending depending on selection

Hi guys,

 

I wonder if anyone can do a routine that zooms into a coordinate, based on input.  So for 1A, it would zoom into the coordinate for 1A.

 

1A = 1,1

1B = 1,2

1C = 1,3

1D = 1,4

 

I will try to attempt one shortly and will post it within 1 hour.  Thanks in advance.

49 REPLIES 49
Message 21 of 50
kameron1967
in reply to: Kent1Cooper

In response to your comment, Kent - I had to populate quite a few points (200+).  I used excel to perform the task for me to concatenate the information so that at the end I just do a simple cut/paste onto the list section.  I basically obtained all the points of A-Z and all the points of 1-10 and used excel to finish the job for me.

Message 22 of 50
Kent1Cooper
in reply to: kameron1967


@kameron1967 wrote:

....  I wonder though if we can specify the xy coordinate where the grid begins.  The coordinate is based on the origin at present, but to apply it to real situation, we'd want to set the starting point (1A) at let's say 100, 200 and have it go negative direction.  So for X or -X direction, A would be at 90, B woud be at 80 and so on.  As for the Y direction, 1 would be at the 190 and 2 would be at 180 and so on.

 

If we can account for the gap distances for both X or Y direction between each grid lines as well as specify the original grid starting point - your routine would be more applicable.

 

Sorry - I don't mind working the long way with the ones that were provided, but if you think it's a doable task, I'd love to see it. 


Yes, as it is, it's limited to the situation in the original post.  All of what you suggest is certainly doable, with some constant multipliers and/or addition/subtraction functions.  Suppose something that asks the User for the location for position 1A, which corner that's in, and the spacing between columns and rows -- would those be all the variable elements you would need?  A version could be made to offer defaults if you have a most-common arrangement.

Kent Cooper, AIA
Message 23 of 50
alanjt_
in reply to: Kent1Cooper

Ok, you're right, 2600 would be too much, but in this situation, I *assumed* it would be a nominal amount. I mean, how many points is someone going to have stored to zoom to at a given time?

Message 24 of 50
alanjt_
in reply to: alanjt_

Just noticed the 200 points post. If that regard, I'd either choose the points from a list box OR you could make individual commands for each one...

 

(foreach zoom '(("1A" 1. 1. 0.) ("1B" 1. 2. 0.) ("1C" 1. 3. 0.) ("1D" 1. 4. 0.))
  (eval (list 'defun
              (read (strcat "c:" (car zoom)))
              nil
              (list 'vla-zoomcenter
                    '(vlax-get-acad-object)
                    (vlax-3d-point (cdr zoom))
                    '(* (getvar "VIEWSIZE") 0.02)
              )
              '(princ)
        )
  )
)

 

Message 25 of 50
Kent1Cooper
in reply to: alanjt_


@alanjt_ wrote:

Ok, you're right, 2600 would be too much, but in this situation, I *assumed* it would be a nominal amount. I mean, how many points is someone going to have stored to zoom to at a given time?


As we learn from kameron1967, at least 200+ is possible.  The resulting code must be impressive, with 200+ lines in the zoomlist part alone....  I think the same could be handled far more efficiently with [assuming that, as in the OP, numbers are for the X element and letters for the Y element] one list of 10 X-coordinate values, one list of 26 Y-coordinate values, and two (nth) functions to get the right ones from the entered position designations.  With a separate list for each location, in that situation there will be 26 lists that contain the same X coordinate, for each X coordinate that's used, and 10 lists that contain the same Y coordinate, for each Y coordinate that's used, not to mention that every one of those lists has to contain the 0 Z coordinate individually -- that's a lot of duplication.

Kent Cooper, AIA
Message 26 of 50
alanjt_
in reply to: Kent1Cooper

@Kent: I went back and looked at your code a bit closer and see what you're doing now. That is a better idea. Way to take it and run. 🙂

Message 27 of 50
kameron1967
in reply to: alanjt_

Alanjt -  your zoom list code works fine, but after I added my points, I get this error:

.../8Y/9Z]: 9Z
ERROR: AutoCAD: Invalid argument Center in ZoomCenter

 

Any idea?  Thanks.

Message 28 of 50
alanjt_
in reply to: kameron1967

Post the code and let's see. If you follow the same list formatting, you should be fine.

 

eg.

(STRING number number number)

Message 29 of 50
kameron1967
in reply to: alanjt_

Here you go, Alanjt.  I took off some "extra" points. 🙂

 

(defun c:TEST (/ _lst2str zoomlist zoom)
  (vl-load-com)
  (setq zoomlist '(
("1A" 108671.99971 220404 0.)
("2A" 108671.99971 220044 0.)
("3A" 108671.99971 219684 0.)
("4A" 108671.99971 219324 0.)
("5A" 108671.99971 218964 0.)
 
                   )  )


  (defun _lst2str (l s)
      (apply 'strcat (cdr (apply 'append (mapcar (function (lambda (i) (list s (car i)))) l))))  )
	  (initget (_lst2str zoomlist " "))
	    (if (setq zoom (cdr (assoc
		(getkword (strcat "\nSpecify zoom point [" (_lst2str zoomlist "/") "]: "))
		                        zoomlist
                      )                 )      )
					  
    (vlax-invoke
	     (cond (*Acad*)
	            ((setq *Acad* (vlax-get-acad-object)))
)
				
				   
      'zoomcenter      
	  zoom 
	  (* (getvar 'VIEWSIZE) 0.02) 
	  )  )  
	  (princ)
	  )
(C:TEST)

 

Message 30 of 50
alanjt_
in reply to: kameron1967

You are using integers rather than reals. Change them and everything will work.

 

eg.

9939019 to 9939019.0 or 9939019.

 

or you could replace the line in the zoomcenter call from 'zoom' to (mapcar 'float zoom), which will convert your integers to reals.

Message 31 of 50
kameron1967
in reply to: alanjt_

Thanks.  I just noticed as well the missing .  I will use your suggestion to overcome the missing period at the end.  Thanks, Alanjt.  I think we've got it.  I really appreciate your help and everyone's excellent inputs.

Message 32 of 50
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

....  Suppose something that asks the User for the location for position 1A, which corner that's in, and the spacing between columns and rows ....



For instance, the attached [minimally tested].  It requires all column spacings to be equal, and all row spacings, but the column and row spacings can be different from each other.  No defaults yet, or some other things that could be included, etc., but see what you think.

 

Type ZGS for Zoom-to-Grid Setup, to define the origin and direction and spacings, and then ZG to Zoom to a Grid location.

Kent Cooper, AIA
Message 33 of 50
alanjt_
in reply to: kameron1967


@kameron1967 wrote:

Thanks.  I just noticed as well the missing .  I will use your suggestion to overcome the missing period at the end.  Thanks, Alanjt.  I think we've got it.  I really appreciate your help and everyone's excellent inputs.


No problem.
You *could* also use the other method I posted where it creates a seperate command for each zoom to point.

Message 34 of 50
Kent1Cooper
in reply to: kameron1967


@kameron1967 wrote:

....

'(

  ("1A" 108671.99971 220404 0.)

  ("2A" 108671.99971 220044 0.)

  ("3A" 108671.99971 219684 0.)

  ("4A" 108671.99971 219324 0.)

  ("5A" 108671.99971 218964 0.)

....


For that, assuming constant spacings beyond the points included and in the X direction, try ZGS from ZoomToGrid.lsp, picking on that (108671.99971 220404 0.) point when it asks where 1A is, giving it UR [I'm guessing, from your earlier post, though I can't tell from the points included -- maybe UL] for which corner that is, something [I can't tell from the points included] for the column spacing, and 360 for the row spacing [which you can either type in or pick on-screen].  Then use ZG to go to any grid position.  No need to define any positions individually other than 1A.  It will Zoom to relative positions up to 99Z, whether or not you actually use that many, but how many you actually use makes no difference to the routine, because it doesn't keep track of them separately, but just finds the one you want relative to 1A.

 

And of course, if you always have 1A in the upper right, a version could easily be made that would work from that assumption, without asking the User.  Likewise if you always use the same column and/or row spacings.

Kent Cooper, AIA
Message 35 of 50
kameron1967
in reply to: Kent1Cooper

To answer your question, Kent - the corner would be constant.  I would choose the top right corner to start with and the grids would be going negative (as in the 3rd quadrant).  This is ideal for when the grid rows and columns are uniform in distance.  If you can make it so that we can specify the negative distance -x and -y direction from the point we specify or hard code, that would be awesome.

 

Alan's routine works with inconsistent row heights and column widths.  They of course, require grid coordinates to be generated, but that's fine.  I'm happy with everyone's methods.

Message 36 of 50
alanjt_
in reply to: alanjt_
Message 37 of 50
Kent1Cooper
in reply to: kameron1967


@kameron1967 wrote:

To answer your question, Kent - the corner would be constant.  I would choose the top right corner to start with and the grids would be going negative (as in the 3rd quadrant).  This is ideal for when the grid rows and columns are uniform in distance.  If you can make it so that we can specify the negative distance -x and -y direction from the point we specify or hard code, that would be awesome.

....


Here's a version for the 1A location always being in the upper right corner.

 

You will specify the column and row spacing distances without specifying the negative aspect -- that is accounted for in the fact that it's working from the upper right corner.  Using (getdist), you have your choice of either typing in numbers or picking the distances on-screen.  When you pick a distance from right to left or from top to bottom in response to (getdist), it doesn't return a negative distance, but the "absolute-value" raw distance, so the routine is built to work with that, and it will need typed values to be likewise not expressed as negative.

 

When you say "or hard code," do you mean that the column and row spacings are [or might be] always the same?  If so, just change these lines:
 

    _zgdeltaX (getdist "\nHorizontal spacing between grid-location columns: ")
    _zgdeltaY (getdist "\nVertical Spacing between grid-location rows: ")

 

to

 

    _zgdeltaX YourColumnSpacing

    _zgdeltaY YourRowSpacing

 

or, eliminate those lines altogether, and substitute those fixed values in wherever _zgdeltaX and _zgdeltaY occur.

Kent Cooper, AIA
Message 38 of 50
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

....
For instance, the attached [minimally tested].  ....


Change the top line of the original ZoomToGrid.lsp file to

 

(defun C:ZGS (/ zg1A); = Zoom-to-Grid Setup

 

[I had commented out the localizing of that variable for testing, and just noticed that I hadn't put it back.]

Kent Cooper, AIA
Message 39 of 50
kameron1967
in reply to: alanjt_

Alanjt - where is this inserted?  There was an error message previously (due to my mistake) so I never tested it.  There's several versions, I'm lost which one to insert it into..

 

(foreach zoom '(("1A" 1. 1. 0.) ("1B" 1. 2. 0.) ("1C" 1. 3. 0.) ("1D" 1. 4. 0.))
  (eval (list 'defun
              (read (strcat "c:" (car zoom)))
              nil
              (list 'vla-zoomcenter
                    '(vlax-get-acad-object)
                    (vlax-3d-point (cdr zoom))
                    '(* (getvar "VIEWSIZE") 0.02)
              )
              '(princ)
        )
  )
)

Message 40 of 50
alanjt_
in reply to: kameron1967


@kameron1967 wrote:

Alanjt - where is this inserted?  There was an error message previously (due to my mistake) so I never tested it. 



Where is what inserted?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost