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).
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
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
@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
@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
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).
My guess is the following will need to happen:
Another, more automated option could be:
@joshua_jones2 wrote:
My guess is the following will need to happen:
- Set UCS to align with object (rectangle block).
- Prompt to flip the UCS 180 degrees around the Z, if needed.
- Prompt for view name.
- Create named view matching the limits of selected rectangle block.
- Add view name as text in the center of the rectangle block.
- 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
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