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

Named View from Rectangle

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
joshua_jones2
1670 Views, 12 Replies

Named View from Rectangle

Does anyone know how to create a named view (command: VIEW) from a rectangle? I would like to have the user select a rectangle to create a named view (prompted for view name).

Tags (1)
12 REPLIES 12
Message 2 of 13
Shneuph
in reply to: joshua_jones2

This is a very basic way to do it:

(Defun C:ViewRect ( / rect tlcmdecho)
  (setq tlcmdecho (getvar "cmdecho"))
  (setq rect (car (entsel "\nSelect Rectangle to create View: ")))
  (command "zoom" "o" rect "")
  (setvar "cmdecho" 1)
  (command "view" "s" pause)
  (command "zoom" "p")
  (setvar "cmdecho" tlcmdecho)
  );defun

 

---sig---------------------------------------
'(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)
Message 3 of 13
hmsilva
in reply to: joshua_jones2


@joshua_jones2 wrote:

Does anyone know how to create a named view (command: VIEW) from a rectangle? I would like to have the user select a rectangle to create a named view (prompted for view name).


If I have correctly understood,  perhaps something like this

 

(defun c:myview	(/ esel nm)
  (if (and (setq esel (car (entsel "Select rectangle: ")))
	   (setq nm (getstring T "\nEnter view name: "))
	   )
      (command "_.zoom" "_O" esel "" "_.-view" "_S" nm  "_.zoom" "_P")
  )
  (princ)
)

 

EDIT:too slow...

 

HTH

Henrique

EESignature

Message 4 of 13

Both of the options presented below are close, but I would like the named view boundaries to match the rectangle exactly (including rotation).
Message 5 of 13
hmsilva
in reply to: joshua_jones2


@joshua_jones2 wrote:
Both of the options presented below are close, but I would like the named view boundaries to match the rectangle exactly (including rotation).

Post  a sample dwg with a named view as you intend.

 

Henrique

EESignature

Message 6 of 13
joshua_jones2
in reply to: hmsilva

Here is an example file (type VIEW to see the named view for the first rectangle). I want to create named views with boundaries that match the limits and rotations of each rectangle. As a bonus it would be great to add text to the center of each rectangle with the view name (see example in the attached drawing).

Message 7 of 13
hmsilva
in reply to: joshua_jones2

Joshua,
The 'rectangle' defining the boundary is a 'block', later on I'll see what I can do.
Now I have real work to do...

Henrique

EESignature

Message 8 of 13
joshua_jones2
in reply to: hmsilva

Thanks for taking a look at it!
Message 9 of 13
joshua_jones2
in reply to: hmsilva

My guess is the following will need to happen:

 

  1. Set UCS to align with object (rectangle block).
  2. Prompt to flip the UCS 180 degrees around the Z, if needed.
  3. Prompt for view name.
  4. Create named view matching the limits of selected rectangle block.
  5. Add view name as text in the center of the rectangle block.
  6. Set the UCS back to World.

Another, more automated option could be:

 

  1. Prompt to select all the rectangle blocks.
  2. Prompt for a view name prefix (such as PLAN)
  3. Set UCS to align with the first object (rectangle block).
  4. Prompt to flip the UCS 180 degrees around the Z, if needed.
  5. Create named views matching the limits of each selected rectangle block. View names would have sequential numbers after the prefix (such as PLAN-02, PLAN-02, PLAN-03, etc.).
  6. Add view names as text in the center of each rectangle block.
  7. Set the UCS back to World.
Message 10 of 13
hmsilva
in reply to: joshua_jones2


@joshua_jones2 wrote:

My guess is the following will need to happen:

 

  1. Set UCS to align with object (rectangle block).
  2. Prompt to flip the UCS 180 degrees around the Z, if needed.
  3. Prompt for view name.
  4. Create named view matching the limits of selected rectangle block.
  5. Add view name as text in the center of the rectangle block.
  6. Set the UCS back to World.

Another, more automated option could be:

...


Joshua,
this is as far as you can go now...


As a starting point.

 

(defun c:myview	(/ ans blk esel n old-osm pt1 pt2 sel nm)
  (if (and (setq sel (nentsel "\nSelect rectangle: "))
	   (setq nm (getstring T "\nEnter view name: "))
      )
    (progn
      (setq old-osm (getvar 'OSMODE)
	    blk	    (car (last sel))
	    esel    (car sel)
	    n	    1
      )
      (setvar 'OSMODE 0)
      (command "_.ucs" "_OB" blk "_.plan" "" "")
      (initget "Yes No")
      (setq ans (getkword "\nRotate UCS 180 degrees [Yes/No] <No>:"))
      (if (and ans (wcmatch ans "Yes"))
	(progn
	  (command "_.ucs" "_Z" 180 "_.plan" "" "")
	  (setq n 2)
	)
      )
      (setq pt1	(vlax-curve-getPointAtParam esel 2)
	    pt2	(vlax-curve-getStartPoint esel)
      )
      (entmake
	(list
	  (cons 0 "TEXT")
	  (cons 100 "AcDbText")
	  (cons 10 '(0.0 0.0))
	  (cons 11 (trans '(0.0 0.0) 1 0))
	  (cons 40 25.0)
	  (cons 1 nm)
	  (cons 50 (angle '(0.0 0.0) (getvar 'ucsxdir)))
	  (cons 72 1)
	  (cons 100 "AcDbText")
	  (cons 73 2)
	)
      )
      (command "_.-view" "_W" nm pt1 pt2)
      (repeat n
	(command "_.ucs" "_P" "_.zoom" "_P")
      )
      (setvar 'OSMODE old-osm)
    )
  )
  (princ)
)

 

HTH

Henrique

EESignature

Message 11 of 13
joshua_jones2
in reply to: hmsilva

Woah! You nailed it!
Message 12 of 13
hmsilva
in reply to: joshua_jones2

Glad I could help!

Henrique

EESignature

Message 13 of 13
Anonymous
in reply to: joshua_jones2

Hello,

 

I've decided to share the help that @hmsilva kindly provided for my problem, that in a simple way solves the topic in subject.

 

My objective was to have a rectangle as the boundary and a string of text as the name of the view. Henrique provided two versions of the same, one for a TEXT string and another for a MTEXT string. Although I'm sharing this full credit goes to @hmsilva , to whom I thank once again.

 

Name with a TEXT string:

(defun c:mynview (/ PT1 PT2 REC SEL SEL1 STR TXT)
(while (and (setq sel (entsel "\nSelect rectangle: "))
(setq rec (car sel))
(= "LWPOLYLINE" (cdr (assoc 0 (entget rec))))
(setq sel1 (entsel "\nSelect text: "))
(= "TEXT" (cdr (assoc 0 (setq txt (entget (car sel1))))))
(setq str (cdr (assoc 1 txt)))
)
(progn
(setq pt1 (vlax-curve-getPointAtParam rec 2)
pt2 (vlax-curve-getStartPoint rec)
)
(command "_.-view" "_W" str pt1 pt2)
)
)
(princ)
)

 Name with a MTEXT string:

(defun c:mynview (/ PT1 PT2 REC SEL SEL1 STR TXT)
(while (and (setq sel (entsel "\nSelect rectangle: "))
(setq rec (car sel))
(= "LWPOLYLINE" (cdr (assoc 0 (entget rec))))
(setq sel1 (entsel "\nSelect text: "))
(wcmatch (cdr (assoc 0 (setq txt (entget (car sel1))))) "*TEXT")
(setq str (cdr (assoc 1 txt)))
)
(progn
(setq pt1 (vlax-curve-getPointAtParam rec 2)
pt2 (vlax-curve-getStartPoint rec)
)
(command "_.-view" "_W" str pt1 pt2)
)
)
(princ)
)

 

Regards,

 

TME

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

Post to forums  

Autodesk Design & Make Report

”Boost