List Named Views

List Named Views

jmartt
Collaborator Collaborator
3,293 Views
18 Replies
Message 1 of 19

List Named Views

jmartt
Collaborator
Collaborator

I've become pretty good at deciphering LISP code and copy-and-pasting stuff I might need, but I can't find anything like what I'm looking for.

 

Nobody seems to have written anything that does this.

 

I'm perfectly willing to accept "That's really hard to do." as an answer and leave it at that, but just in case this is relatively easily accomplished:

 

I'd like to list any named modelspace views that a point I pick in modelspace is within.

 

Whadayathink? I believe I could get the interface patched together. I can make the command line ask for input and make an alert box come up. But the meat of this - the searching for views and evaluating whether a point is within one or more - that's well beyond me and I dunno if it's even possible.

0 Likes
Accepted solutions (2)
3,294 Views
18 Replies
Replies (18)
Message 2 of 19

Ranjit_Singh
Advisor
Advisor
Accepted solution

If we are talking strictly 2d views then try below for example

(defun c:somefunc  (/ testpt)
 (setq testpt (getpoint "\nSelect Point: "))
 (vlax-map-collection (vla-get-views (vla-get-activedocument (vlax-get-acad-object)))
		      '(lambda (x)
			(if (somefunc2 x testpt)
			 (princ (strcat "\nPoint lies in view \"" (vla-get-name x) "\"\n")))))
(princ))

(defun somefunc2 (x y / a b)
(not (member nil (mapcar '<=
			 (mapcar '-
				 (setq a (vlax-get x 'center))
				 (setq b (list (/ (vlax-get x 'width) 2.0) (/ (vlax-get x 'height) 2.0))))
			 y
			 (mapcar '+ a b)))))

 

Message 3 of 19

jmartt
Collaborator
Collaborator

Wow. Top drawer, man! Thanks!

0 Likes
Message 4 of 19

Ranjit_Singh
Advisor
Advisor

You are welcome. Glad it worked for you.

Message 5 of 19

jmartt
Collaborator
Collaborator

Oh, shoot. Maybe it doesn't work as well as I had thought. 

It seems to often not find the view or leave one of the views off of the list.

Not all the time, though. Weird.

It seems to have a problem if the boundary for one view is within a boundary of another view(?)

 

I made a screencast. First one so I'm not sure how or if it'll work.

I am able to get the somefunc command to report multiple views. I mention this bc in the screencast, it only reports one at a time. But it can report more than one. I just think it trips up if the boundaries are overlapped in a certain way.

0 Likes
Message 6 of 19

Ranjit_Singh
Advisor
Advisor

  I tried similar view configuration at my end and it works. One thing I would recommend is using the define window option and not the display area option when defining view names. Give that a try and if it still does not work then post your drawing  with the subject views and I will take a look.

Message 7 of 19

jmartt
Collaborator
Collaborator

Hmm. I'm getting random results.

 

I attached a dwg that I defined windows for views, like you suggested. somefunk.lsp doesn't report views 1 or 2 or a or b usually, (although I can get it to after I save and reopen), but it's good at reporting a AND b, if I pick in that area.

 

Dunno.

0 Likes
Message 8 of 19

john.uhden
Mentor
Mentor

The attached code may help you understand.  It's half of a pair of programs to write views to a file and read views from a file.

John F. Uhden

Message 9 of 19

jmartt
Collaborator
Collaborator

Thanks, but I'm not proficient enough with LISP to really understand that code. I'm not sure how sending views to an .avf file would help to list views at a point picked. The last thing I want is to list, or to send, all the hundreds of views I have somewhere. I just want the views that a picked point is within.

 

I'd never heard of an avf filetype before. I'm curious: was the sending and importing views to avg files a way to "copy" views among drawings?

 

As far as my endeavor, I think I'm gonna go with "That's really hard to do."

0 Likes
Message 10 of 19

john.uhden
Mentor
Mentor

That's sad that you look so forlorn lost in the snow bank.  I recommend that you get inside with a bottle of cognac.  If you don't see things more clearly, it won't matter.

 

Yes, the AVF extension I made up myself ("AutoCAD View File").  Yes it was for copying views to other drawings.  Yes, it is very old (as I am becoming).

 

No, I don't understand about finding a point within a view.  Might you mean a point in Modelspace that is within a viewport?  That could be done, but not so easily for me, though I did write my own ChangeSpace before there ever was such a command.  I wouldn't be surprised if @ВeekeeCZ already has it written.  Probably started it at least 10 minutes ago.

John F. Uhden

0 Likes
Message 11 of 19

jmartt
Collaborator
Collaborator

It's not a snowbank. That's the banked concrete of the original track at Monza. And it'd be bourbon for me.

 

I don't know how else to put it other than how I did originally: I'd like to list any named modelspace views that a point I pick in modelspace is within.

 

I originally posted on the regular CAD forum hoping there was some command that I didn't know about that did this. Then Ranjit's code, although I didn't know all the syntax or whatever, I could follow and seemed to make sense but it produced random results, at least for me, as evidenced by the screencast above.

 

Again, probably too hard to do. I can live without it.

0 Likes
Message 12 of 19

Ranjit_Singh
Advisor
Advisor

It works fine here, even with nested views. See screencast. I see your issue in your screencast. But it seems specific to your AutoCAD environment and how the views were created.

I have attached a drawing exactly with the same viewports as your drawing2, but created from a acad.dwt file. Try this drawing out with the function I provided and let me know if you still get issues. if so then there is something specific with your autoCAD environment and not the drawing, since this exact same drawing works fine at my end.

Message 13 of 19

jmartt
Collaborator
Collaborator

Ah-ha! Spurred on by your (much appreciated) diligence in regard to this matter, I have done some testing and have a theory and half a solution:

 

I tested on your Drawing2.dwg and found absolutely nothing wrong. I created a drawing from a certain template that I have, a template which is most-like regular CAD, and found nothing wrong as well. 

 

But a template that is, or was ever, georeferenced has a problem. Which is to say that I have a problem, since the drawing I want to use somefunc.lsp on is definitely georeferenced. In a georeferenced dwg, the named modelspace views work as they should as views: you zoom right to the views' defined extents. However, the definition of the views as far as how somefunc.lsp "sees" them gets shifted. The views end up to the east about 1800 feet and south about 900 feet.

 

These numbers don't ring any bells with me. If you said that something (in Fairbanks) was shifted by about 8 feet north I'd say it'd be the US survey/International feet conversion. But I know nothing that's 1800 x -900 in relation to Zone AK 3F, which is what I'm using. Not to say that there isn't something, quite likely another coordinate system, maybe one that CAD uses internally or something, just I have no clue how to begin to "fix" that.

 

But I can just tell CAD that the point of query is actually 1800 east and 900 south of where I pick. That'd do it. I don't know how to do that, but I'll look into it. If you have any ideas, please let me know.

 

Thanks again. Sorry I doubted your somefunc.lsp. It works great! I'm just too good at breaking things.

0 Likes
Message 14 of 19

Ranjit_Singh
Advisor
Advisor

Thanks for sharing your finding. Now that you have pointed out, I notice that the center property for all those views are off. Moving on, if you have figured out that the center is off, lets say along x by 1800 and y by 900 units. Simply change this

(setq a (vlax-get x 'center))

to

 

(setq a (mapcar '+ (vlax-get x 'center) '(1800 900))

Just pay attention to 1800 and 900 if they need to be positive or negative offsets. Good luck.

 

Message 15 of 19

jmartt
Collaborator
Collaborator

Appreciate it, but it don't werk.

 

0 Likes
Message 16 of 19

Ranjit_Singh
Advisor
Advisor

Two things that went wrong. There is a parentheses missing. Second, I read your post again and realized that center has shifted south. So y needs to decrease. Try this

(setq a (mapcar '+ (vlax-get x 'center) '(1800 (- 900))))

Or flip the signs

(setq a (mapcar '+ (vlax-get x 'center) '((- 1800) 900)))

I am not on AutoCAD right now and can't check which version will work. 

0 Likes
Message 17 of 19

jmartt
Collaborator
Collaborator

It doesn't like the negatives.

 

Select Point: ; error: bad argument type: numberp: (- 1800)

 

Same thing for -900. I've tried again with less and more parentheses. I feel like I'm lost inside these stupid things. Haha.

 

 

0 Likes
Message 18 of 19

Ranjit_Singh
Advisor
Advisor
Accepted solution

This is what happens when I am replying without testing Smiley Frustrated use list instead of quote ('). Same for the other version. Now you know who is good at breaking things Smiley Wink

(setq a (mapcar '+ (vlax-get x 'center) (list 1800 (- 900))))

 

Message 19 of 19

jmartt
Collaborator
Collaborator

BOOM! It works.

I tested on multiple views overlapping, too. Perfect! You're a freakin saint you are.

 

It was opposite of the coordinates. Had to be -1800 and plus 900. I had some hiccups trying to not get "error: bad function: 900", or similar, but I figured it out.