Lisp for create viewport for polyline

Lisp for create viewport for polyline

Amriya_Exe
Advocate Advocate
526 Views
11 Replies
Message 1 of 12

Lisp for create viewport for polyline

Amriya_Exe
Advocate
Advocate

Requirements: 

1. Ask for layer name set active

2. Lisp Command Ask for start & End of Pline

3. create layout with same layer name and clear default viewport in new created viewport

4. Add new viewport at

(setq vpInsertPt (list 210.3216 220.0)) ; lower-left in layout

 (setq vpWidth 390.0)
 (setq vpHeight 135.0)
Scale of view port is 5:1 ( 5 paper space unit = 1 drawing unit)

in viewport cover that Polyline created in step 2. Alignspace pline to horizontally.

view port locked.

0 Likes
Accepted solutions (1)
527 Views
11 Replies
Replies (11)
Message 2 of 12

Sea-Haven
Mentor
Mentor

Like this, viewports are made by walking along a pline matching a title block and scale. They are rotated in the viewport to match.

SeaHaven_0-1751787656969.png

 

0 Likes
Message 3 of 12

Amriya_Exe
Advocate
Advocate

No not like this..
I have gone through you response on other posts. but this is not my requirement. 
i need only lisp that do above task I will use that in another lisp 

0 Likes
Message 4 of 12

Sea-Haven
Mentor
Mentor

Post a dwg so can see what you want, what happens When pline is longer than will fit in viewport at 1:5 scale ?

0 Likes
Message 5 of 12

Amriya_Exe
Advocate
Advocate

Check attached Drawing with 1 layout named Sample 

& Second is result using this lisp viewport.


in this lisp 
problem is this lisp adding two viewports. 
1st at where I mentioned in lisp.

2nd Center point of the line I draw

but I am not able to see anything in viewport not even close to Line.

 

 

0 Likes
Message 6 of 12

Moshe-A
Mentor
Mentor

@Amriya_Exe  hi,

 

Just an innocent question...why not putting this layout (including all its setting) in a template (dwt) file than when need import it in?

 

Moshe

 

0 Likes
Message 7 of 12

Amriya_Exe
Advocate
Advocate

That settings/blocks is changed per many segments.. 
its not constant.

 

0 Likes
Message 8 of 12

Sea-Haven
Mentor
Mentor

Like @Moshe-A if your using a layout with a title block, then the title block should be at a 1:1 scale ie true size and the viewport is scaled and a twist added. All our layouts in a project were this way with various scales in viewports. Ok so pick 2 points get the middle point and get the angle. Go into your layout with a title block and go into the viewport "Mspace" use Zoom c midpt scale. The "scale" should reflect the desired scale you want, the angle will be wrong, go Pspace get the Viewport via ssget and set the twist angle all done. If scale is wrong adjust Customscale of the viewport. You can shrink or increase the size of the viewport to suit.

 

Two choices, copy a layout in your current dwg/dwt or pull a layout from another dwg using "layout" "T" template option.

 

Just a comment your sample layout custom scale value of 4.0 works.

 

Can see what your trying to pick. Will see what I can do added to my To do List.

SeaHaven_0-1751936398105.png

 

 

 

 

0 Likes
Message 9 of 12

Sea-Haven
Mentor
Mentor
Accepted solution

This is a bit rough but uses your Sample layout with the viewport unlocked. And puts twist into view.

 

(defun c:dolayouts ( / pt1 pt2 oldaunits newname)
  (setq oldaunits (getvar 'aunits))
  (setvar 'aunits 3)
  (setq pt1 (getpoint "\nPick point 1 ") pt2 (getpoint pt1 "\nPick point 2 "))
  (setq mp (mapcar '* (mapcar '+ pt1 pt2) '(0.5 0.5)))
  (setq ang (angle pt1 pt2))
  (setq scale (/ 1000. (getreal "\nenter scale 1:X eg 250 ")))
  (setq newname (getstring "\nEnter new layout name " T))
  (command "layout" "c" "sample" newname )
  (setvar 'ctab newname)
  (command "zoom" "E")
  (setq ent (ssname (ssget "x" (list (cons 0  "Viewport")(cons 410 (getvar 'ctab)))) 0))
  (setq obj (vlax-ename->vla-object  ent))
  (command "mspace")
  (command "zoom" "C" mp 50)
  (command "UCS" "Z" ang "plan" "")
  (command "UCS" "W")
  (command "zoom" "C" mp (strcat (rtos scale 2 1) "XP") )
  (command "Psltscale" 1)
  (command "pspace")
  (vla-put-DisplayLocked obj  -1)
  (setvar 'aunits oldaunits)
  (princ)
)

SeaHaven_0-1752026607567.png

 

0 Likes
Message 10 of 12

Amriya_Exe
Advocate
Advocate

Thank you its working enough for me.  🤗

0 Likes
Message 11 of 12

Amriya_Exe
Advocate
Advocate

This code set angle unit to radians.. 
what is the logic? can you explain. 

0 Likes
Message 12 of 12

Sea-Haven
Mentor
Mentor

In nearly all lisp coding you need to work in radians for angles, the default say (angle pt1 pt2) returns the answer in radians. The twist in the viewport is set as radians, it is just what the original makers of Acad decided. and so on.