Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
kameron1967
Posts: 174
Registered: ‎09-05-2008
Message 41 of 50 (137 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-16-2011 01:28 PM in reply to: Kent1Cooper

That worked, Kent.  Thanks for whipping that up.  It'll be handy with grids that aren't so uniform. 

*Expert Elite*
pbejse
Posts: 2,500
Registered: ‎11-24-2009
Message 42 of 50 (124 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-16-2011 07:27 PM in reply to: kameron1967

kameron1967 wrote:

Hi pbejse - Just so you'd know, I tested your code and it gave me this error:  ERROR: bad argument type: numberp: nil

 

 


Dont worry about it. it's crappy idea anyway :smileyvery-happy:, besides, after reading thru the discussion, it doesnt fit your requirements as per your intention, it would've been fun write a code similar to kents/alanjt but that would be re-inventing the wheel and i'm a bit too late in the game.

 

FWIW (setq dist 1.00) should be (setq size 1.00)

 

Cheers

 

Valued Mentor
alanjt_
Posts: 483
Registered: ‎08-25-2008
Message 43 of 50 (122 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-16-2011 07:31 PM 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.  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)
        )
  )
)


You insert your desired values in the list in the foreach statement. It steps throgh the list and creates a seperate function for each item in the list, each function's syntax being the first item in list's item. (eg. "1A"....)

 

Kent has you happy, so I'll leave it at that. :smileyhappy:

Active Member
kam1967
Posts: 7
Registered: ‎11-03-2011
Message 44 of 50 (118 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-16-2011 07:49 PM in reply to: alanjt_

alanjt_ wrote: 

Kent has you happy, so I'll leave it at that. :smileyhappy:


I'm happy for people like you, Kent, pbejse, Tharwat313 and Lee who frequently lend their expertise to individuals like myself who comes up with some odd ideas and you helped everyone by doing exactly what you've done.  I want to give kudos to everyone who helped make it happen.  Cheers! :smileyhappy:

 

 

Valued Mentor
alanjt_
Posts: 483
Registered: ‎08-25-2008
Message 45 of 50 (114 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-16-2011 07:55 PM in reply to: kam1967

I wish I had a Kudos bar. I loved those things when I was a kid.

*Expert Elite*
Kent1Cooper
Posts: 5,657
Registered: ‎09-13-2004
Message 46 of 50 (112 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-16-2011 07:59 PM in reply to: kameron1967

kameron1967 wrote:

That worked, Kent.  Thanks for whipping that up.  It'll be handy with grids that aren't so uniform. 


You're welcome, but you understand that it is in fact for grids that are uniform, at least as to their spacing in each direction [i.e. all columns are the same distance apart, and all rows are], though the column and row spacings don't need to be the same as each other.

 

If there can be non-uniform spacings within each direction, consider the following [also attached as a .lsp file, along with a drawing you can try it out in].  It uses some arbitrary unequally-spaced column and row positions, in a comparatively simple 5 x 5 grid.

 

(defun C:ZG ; = Zoom to Grid location
  (/ Xcols Yrows zg)
  (setq Xcols '(15 12 8 3 1) Yrows '(21 17 12 9 4)); *sample* 5x5 grid, arbitrary values
  (if
    (setq zg (getstring "\nSpecify Number-Letter zoom coordinate [e.g. 1A, 27G, etc.]: "))
    (if ; then
      (and
        (<= (strlen (setq zg (strcase zg))) 3)
        (< 47 (ascii (substr zg 1 1)) 58); 1st between 0 & 9
        (if (= (strlen zg) 3); two-digit numerical portion
          (< 47 (ascii (substr zg 2 1)) 58); 2nd [if any] between 0 & 9
          T ; no second digit
        ); if
        (< 64 (ascii (substr zg (strlen zg))) 91); last between A & Z
      ); and
      (command ; then -- Zoom to it
        "_.zoom" "_c"
        "_none"
        (list
          (nth (1- (atoi (substr zg 1 (1- (strlen zg))))) Xcols); X
          (nth (- (ascii (substr zg (strlen zg))) 65) Yrows); Y
        ); list
        5 ; [height arbitrarily = largest row interval -- adjust if desired]
      ); command
      (prompt "\nInvalid entry."); else
    ); if
  ); if
  (princ)
); defun

 

[It could be shorter if limited to single-digit numerical parts.]

 

It defines all 25 grid locations with just this part:

 

(setq Xcols '(15 12 8 3 1) Yrows '(21 17 12 9 4))

 

and finds them using a couple of (nth) functions later on.  By contrast, the "other approach" would require all of this to define the grid locations:

 

(setq zoomlist
  '(
    ("1A" 15 21 0)
    ("2A" 15 17 0)
    ("3A" 15 12 0)
    ("4A" 15 9 0)
    ("5A" 15 4 0)
    ("1B" 12 21 0)
    ("2B" 12 17 0)
    ("3B" 12 12 0)
    ("4B" 12 9 0)
    ("5B" 12 4 0)
    ("1C" 8 21 0)
    ("2C" 8 17 0)
    ("3C" 8 12 0)
    ("4C" 8 9 0)
    ("5C" 8 4 0)
    ("1D" 3 21 0)
    ("2D" 3 17 0)
    ("3D" 3 12 0)
    ("4D" 3 9 0)
    ("5D" 3 4 0)
    ("1E" 1 21 0)
    ("2E" 1 17 0)
    ("3E" 1 12 0)
    ("4E" 1 9 0)
    ("5E" 1 4 0)
  )
)

 

And that's just a 5 x 5 grid.  Expand that to the earlier-described 1-to-10 / A-to-Z situation, and ZG can handle it with something like this [again, arbitrary values]:

 

(setq

  Xcols '(33 29 24 21 17 15 12 8 3 1)

  Yrows '(97 94 89 83 81 77 75 72 68 62 60 57 52 46 43 39 37 32 29 23 21 17 12 9 4 1)

)

 

whereas the other approach would require, count 'em, 235 more lines than the above 25 in the zoomlist, to define all the number-letter location designators and their coordinates.

 

And by the way, if you use (command "_.zoom" "_c" ...), integers are valid for the numbers; they're not required to be reals as apparently they are under (vlax-invoke ... 'zoomcenter ...).  Also, it doesn't require you to give it a Z coordinate at all -- compare that to the 0 contained in every one of those total 260 lines in the zoomlist, assuming (vlax-invoke ... 'zoomcenter ...) requires that [I haven't tried it without].

Kent Cooper
Active Member
kam1967
Posts: 7
Registered: ‎11-03-2011
Message 47 of 50 (108 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-16-2011 08:08 PM in reply to: Kent1Cooper

Wow -  that's wonderful, Kent.  I believe you've covered both ends.  I really appreciate your efforts in this.  Thank you!

*Expert Elite*
Kent1Cooper
Posts: 5,657
Registered: ‎09-13-2004
Message 48 of 50 (103 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-16-2011 08:26 PM in reply to: kam1967

kam1967 wrote:

Wow -  that's wonderful, Kent.  I believe you've covered both ends.  I really appreciate your efforts in this.  Thank you!


You're welcome -- I enjoyed figuring out how to get it to work.

 

And I should point out that, despite what it says at the top of the ZoomToGrid-IS.lsp file, it's not actually limited to having 1A in the upper right corner.  The "direction" of the grid can be defined however one desires, just by how the values in the Xcols and Yrows variables are sequenced -- high-to-low in both [as in the sample] puts 1A at the upper right corner, low-to-high in both puts it at the lower left, high-to-low in Xcols / low-to-high in Yrows puts it at the lower right, and low-to-high in Xcols / high-to-low in Yrows puts it at the upper left.  [You could even have them not in numerical order, though I can't imagine why anyone would want to.]

Kent Cooper
Distinguished Contributor
kameron1967
Posts: 174
Registered: ‎09-05-2008
Message 49 of 50 (80 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-22-2011 09:31 AM in reply to: Kent1Cooper

Kent - I like the ability to just list the X coordinates on just one line and the Y coordinates on a separate line.  Can you list the column/row header information - for instance A1 or 1A as the first pair that matches with the first set of X or Y coordinate?

 

I guess what I'm getting at is that by listing the X and Y coordinates that way, it automatically assumes that the column header or row header is always going to be Letters and Numbers, respectively.  If we can assign the header information on another line so that when we type either 1A or A1, it knows to look for the 1st coordinate of X and Y coordinate.

 

By the way, some letters like 'i' or 'o' or 'L' is sometimes omitted - that is why I have the need to specify the header info.

 

Thank you in advance.

 


Kent1Cooper wrote:

[It could be shorter if limited to single-digit numerical parts.]

 

It defines all 25 grid locations with just this part:

 

(setq Xcols '(15 12 8 3 1) Yrows '(21 17 12 9 4))

 

and finds them using a couple of (nth) functions later on.  By contrast, the "other approach" would require all of this to define the grid locations:

 

(setq zoomlist
  '(
    ("1A" 15 21 0)
    ("2A" 15 17 0)
    ("3A" 15 12 0)
    ("4A" 15 9 0)
    ("5A" 15 4 0)
    ("1B" 12 21 0)
    ("2B" 12 17 0)
    ("3B" 12 12 0)
    ("4B" 12 9 0)
    ("5B" 12 4 0)
    ("1C" 8 21 0)
    ("2C" 8 17 0)
    ("3C" 8 12 0)
    ("4C" 8 9 0)
    ("5C" 8 4 0)
    ("1D" 3 21 0)
    ("2D" 3 17 0)
    ("3D" 3 12 0)
    ("4D" 3 9 0)
    ("5D" 3 4 0)
    ("1E" 1 21 0)
    ("2E" 1 17 0)
    ("3E" 1 12 0)
    ("4E" 1 9 0)
    ("5E" 1 4 0)
  )
)

 

And that's just a 5 x 5 grid.  Expand that to the earlier-described 1-to-10 / A-to-Z situation, and ZG can handle it with something like this [again, arbitrary values]:

 

(setq

  Xcols '(33 29 24 21 17 15 12 8 3 1)

  Yrows '(97 94 89 83 81 77 75 72 68 62 60 57 52 46 43 39 37 32 29 23 21 17 12 9 4 1)

)

 

whereas the other approach would require, count 'em, 235 more lines than the above 25 in the zoomlist, to define all the number-letter location designators and their coordinates.

 

And by the way, if you use (command "_.zoom" "_c" ...), integers are valid for the numbers; they're not required to be reals as apparently they are under (vlax-invoke ... 'zoomcenter ...).  Also, it doesn't require you to give it a Z coordinate at all -- compare that to the 0 contained in every one of those total 260 lines in the zoomlist, assuming (vlax-invoke ... 'zoomcenter ...) requires that [I haven't tried it without].


 

Distinguished Contributor
kameron1967
Posts: 174
Registered: ‎09-05-2008
Message 50 of 50 (79 Views)

Re: Zoom into a set of coordinates depending depending on selection

12-22-2011 09:33 AM in reply to: kameron1967

Alanjt - is it possible to leave out the zoomlist info when prompting a user to input the column/row info?  When there's a bunch of it, it looks really cluttery.  Thank you.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.