How do I extract data from a named model space view?

How do I extract data from a named model space view?

Anonymous
Not applicable
1,193 Views
7 Replies
Message 1 of 8

How do I extract data from a named model space view?

Anonymous
Not applicable

I'm trying to find a function somewhere or just some direction on how to extract data/properties from a named model space view. I haven't been able to find any information on this.

I am trying to get coordinates to draw a boundary around these views.  

 

0 Likes
1,194 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

(tblsearch "view" "YourViewName")  will give you the entity data list for a Model Space view.

 

The DXF Reference for Tables shows that the associated-with-2 entry in that list is the name, the 10 entry is the center of view, 40 is the view height, and 41 the view width.  Are you capable of calculating boundaries from those, to apply in [presumably] a RECTANG command?

Kent Cooper, AIA
Message 3 of 8

Anonymous
Not applicable

Well I thought I did but what i came up with didnt quite do the trick... lol

Any suggestions?

 

 

(FOREACH	V VIEWS
	 (IF
	   (SETQ DATA  (TBLSEARCH "VIEW" V)
		 MIDPT (CDR (ASSOC 10 DATA))
		 WID   (/ (CDR (ASSOC 40 DATA)) 2)
		 LEN   (/ (CDR (ASSOC 41 DATA)) 2)
	   )
	    (PROGN
	      (SETQ X (CAR MIDPT)
		    Y (CADR MIDPT)
	      )
	      (SETQ MINPT (LIST (- X LEN) (- Y WID))
		    MAXPT (LIST (+ X LEN) (+ Y WID))
	      )
	      (COMMAND "RECTANGLE" MINPT MAXPT)
	    )
	 )
       )

 

 

 

 

 

 

 

0 Likes
Message 4 of 8

cadffm
Consultant
Consultant
(IF (SETQ DATA  (TBLSEARCH "VIEW" "1"))
     (PROGN
       (setq
		 MIDPT (CDR (ASSOC 10 DATA))
		 WID   (/ (CDR (ASSOC 40 DATA)) 2)
		 LEN   (/ (CDR (ASSOC 41 DATA)) 2)
                 X     (CAR MIDPT)
		 Y     (CADR MIDPT)
	         MINPT (LIST (- X LEN) (- Y WID))
		 MAXPT (LIST (+ X LEN) (+ Y WID))
	)
	(COMMAND "RECTANGLE" MINPT MAXPT)
     );_progn
 );_if


Sebastian

0 Likes
Message 5 of 8

pbejse
Mentor
Mentor

@Anonymous wrote:

Well I thought I did but what i came up with didnt quite do the trick... lol

Any suggestions?

 

(while
  	(setq data  (tblnext "view" (null data)))
	    (setq midpt	(cdr (assoc 10 data))
		  wid	(/ (cdr (assoc 40 data)) 2)
		  len	(/ (cdr (assoc 41 data)) 2)
		  x	(car midpt)
		  y	(cadr midpt)
		  minpt	(list (- x len) (- y wid))
		  maxpt	(list (+ x len) (+ y wid))
		)
  (command "rectangle" minpt maxpt)
  )
0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... what i came up with didnt quite do the trick...

(FOREACH	V VIEWS
….

You don't include how the VIEWS variable is arrived at, so we can't tell whether that could be the problem.  Presumably there's some surrounding code such as to encase what you posted in a command definition, but we can't evaluate that.  And there's no information about what "didn't quite do the trick" means.  If it draws rectangles but not quite in the right places, do you have any running Object Snap mode(s) on?  Try it with Osnap off.  Or could it be the command name?  I don't have AutoCAD running, and I'm having trouble with the Help website, but I think the command name is RECTANG, not RECTANGLE.

 

In any case, I don't see anything obviously wrong if the VIEWS variable is a list of text strings and they're all actually names of model-space views.  But it can be shortened considerably -- something like [untested]:

(FOREACH V VIEWS
  (IF
(SETQ
DATA (TBLSEARCH "VIEW" V) MIDPT (CDR (ASSOC 10 DATA)) halfrect (list (/ (CDR ASSOC 41 DATA) 2) (/ (CDR (ASSOC 40 DATA)) 2)) ); setq (COMMAND "_.rectang" "_non" (mapcar '- midpt halfrect) "_non" (mapcar '+ midpt halfrect)) ); if ); foreach
Kent Cooper, AIA
0 Likes
Message 7 of 8

Anonymous
Not applicable

Well.... I had a message typed back to everyone but I must have closed my browser before posting it... (my bad)

Anyway... 

This is working to draw the views but doesnt draw the view in the correct place... see the attached pictures

(works perfectly in NEW drawings....????? i just found out) Any clue as to what could cause that. I did double check if the boundaries were correct.

 

 

(DEFUN C:VBOUND	(/ DATA MIDPT LEN WID X Y MINPT MAXPT VIEW)
  (SETQ VIEW (GETSTRING "\nENTER VIEW OR PRESS ENTER...")
	VIEWS (ai_table "view" 0))
  (COND
    ((EQ "" VIEW )
     (setq view nil)
     ))
  (IF
    (eq VIEW NIL)
     (PROGN
       (FOREACH	V VIEWS
	 (IF (SETQ DATA  (TBLSEARCH "VIEW" V))
     (PROGN
       (setq
		 MIDPT (CDR (ASSOC 10 DATA))
		 WID   (/ (CDR (ASSOC 40 DATA)) 2)
		 LEN   (/ (CDR (ASSOC 41 DATA)) 2)
                 X     (CAR MIDPT)
		 Y     (CADR MIDPT)
	         MINPT (LIST (- X LEN) (- Y WID))
		 MAXPT (LIST (+ X LEN) (+ Y WID))
	)
	(COMMAND "RECTANGLE" MINPT MAXPT)
     );_progn
 );_if
       )
     )
  )
    
(IF (SETQ DATA  (TBLSEARCH "VIEW" View))
     (PROGN
       (setq
		 MIDPT (CDR (ASSOC 10 DATA))
		 WID   (/ (CDR (ASSOC 40 DATA)) 2)
		 LEN   (/ (CDR (ASSOC 41 DATA)) 2)
                 X     (CAR MIDPT)
		 Y     (CADR MIDPT)
	         MINPT (LIST (- X LEN) (- Y WID))
		 MAXPT (LIST (+ X LEN) (+ Y WID))
	)
	(COMMAND "RECTANGLE" MINPT MAXPT)
     );_progn
  )
 )

 

@Kent1Cooper  there is some missing parentheses in your attached code which i added and came up with this.(btw thanks for that, AND thanks for the replies to everyone else!)

 

 

(DEFUN C:VBOUND	(/ DATA MIDPT LEN WID X Y MINPT MAXPT VIEW)
  (SETQ VIEW (GETSTRING "\nENTER VIEW OR PRESS ENTER...")
	VIEWS (ai_table "view" 0))
  (COND
    ((EQ "" VIEW)
     (setq view nil)
     ))
  (IF
    (= VIEW NIL)
     (PROGN
       (FOREACH V VIEWS
  (IF
    (SETQ
      DATA (TBLSEARCH "VIEW" VIEW)
      MIDPT (CDR (ASSOC 10 DATA))
      halfrect (list (/ (CDR (ASSOC 41 DATA)) 2) (/ (CDR (ASSOC 40 DATA)) 2))
    ); setq
    (COMMAND "_.rectang" "_non" (mapcar '- midpt halfrect) "_non" (mapcar '+ midpt halfrect))
  ); if
); foreach
     )
  )
    
(IF
    (SETQ
      DATA (TBLSEARCH "VIEW" VIEW)
      MIDPT (CDR (ASSOC 10 DATA))
      halfrect (list (/ (CDR (ASSOC 41 DATA)) 2) (/ (CDR (ASSOC 40 DATA)) 2))
    ); setq
    (COMMAND "_.rectang" "_non" (mapcar '- midpt halfrect) "_non" (mapcar '+ midpt halfrect))
  )
 )

 

However, I didnt have luck with this one. 

It it kept saying something about command-s which I havent had a chance to dig into. 

in the "missed placed views -1.png" the top leftish is where it was placing the supposed views which you can see in "missed placed views -2&3.png"  thats not where the view was.

Sorry this is a tad lengthy. 

thanks guys

have a great weekend!

Cheers

 

 

 

 

 

 

 

0 Likes
Message 8 of 8

dlanorh
Advisor
Advisor

The command-s is in reference to the express tools error handler which you are invoking by using ai_table. You can read about it HERE

I am not one of the robots you're looking for

0 Likes