AutoLISP: 3D View – Section View with Depth

Here is a handy routine that lets you easily define a view and define its view-depth.
With cluttered 3D drawings, you may want to view objects from a side view but also not see the clutter behind and in front of the desired object(s).

Here’s how:

  • DBS_Section <enter> to start
  • Define the section view by picking 2 points. (This will define the front view)
  • Define the Depth of the view by picking a point away from the first line that you defined. (the depth can be on either side of the first line that you define)

When you are finished with this view and want to return to “normal,” set the following:

  • UCS <enter> <enter>
  • PLAN <enter> <enter>
  • REGENMODE <1>

Link to AutoCAD Tips http://www.autocadtips.wordpress.com


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;											;;;
;;; View Clip function that lets you easily define a view and the depth of the view	;;;
;;; After finished with the view: UCS <enter> PLAN  REGENMODE 1	;;;
;;; Found @ http://www.theswamp.org/index.php?topic=105.0				;;;
;;;											;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:DBS_Section (/)
  (setvar "cmdecho" 0)
  (setvar "expert" 5)
  (command "ucs" "s" "tmp")  ;;;;  saves ucs to "tmp"
  (setq pt1 (getpoint "\nCutline pt1: "))
  (setq pt2 (getpoint pt1 "\nCutline pt2: "))
  (setq pt1 (polar pt1 (angle pt1 pt2) (/ (distance pt1 pt2) 2)))
  (setq pt2 (getpoint pt1 "\nSection depth: "))

  (setq pt1 (trans pt1 1 0) pt2 (trans pt2 1 0))
  (command "ucs" "w")
	(setvar "regenmode" 1)
	(command "dview" "" "po" pt2 pt1 "cl" "f" (distance pt2 pt1) "cl" "b" 0 "")

;;;;  move ucs origin to middle of section cut line & sets to view
;;;   this causes grips to be actinve in dview box because ucs origin is in box  

  (command "ucs" "or" pt2)
  (command "ucs" "v")

;;;  by passed next line when added setting ucs to origin.
;;;  (command "ucs" "r" "tmp")   ;;;;  restores ucs to "tmp"

  (setvar "regenmode" 0)
  (setvar "expert" 0)
	(setvar "cmdecho" 1)
	(princ)
)

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, AutoLISP: 3D. Bookmark the permalink.

3 Responses to AutoLISP: 3D View – Section View with Depth

  1. Brad says:

    Below is another routine that does the same thing. It also has a routine at the end to undo everything. I’ve had this for years but can’t remember where I got it. One thing: I’ve had objects appear that are outside the clip area when using Autocad 2011 and later (although plotting is correct). For this reason, I am still using Autocad 2010.

    (defun C:VS ( / )
    (setq VS:#:PrevViewCenter (getvar “viewctr”)
    VS:#:PrevViewDist (getvar “viewsize”)
    VS:#:PrevViewDirect (getvar “VIEWDIR”) )

    ;(setq VS:ent (entsel “\nPick Line: “))
    ;(if (and VS:ent (setq VS:ent (entget (car VS:ent))) (= “LINE” (cdr (assoc 0 VS:ent))))
    ; (progn
    (setq ptF (getpoint “\nPick Camera Point: “);(VS:transpoint (cdr (assoc 10 VS:ent)) (cdr (assoc 210 VS:ent)))
    ptB (getpoint ptF “\nPick Target Point: “);(VS:transpoint (cdr (assoc 11 VS:ent)) (cdr (assoc 210 VS:ent)))
    DistFB (distance ptF ptB)
    ;Cdir (mapcar ‘/ (mapcar ‘- ptB ptF) (list DistFB DistFB DistFB))
    ;Tdir (mapcar ‘/ (mapcar ‘- ptF ptB) (list DistFB DistFB DistFB))
    )
    (vl-cmdf “dview” (entlast) “”
    “POints” ptB ptF ;|(mapcar ‘+ ptF (mapcar ‘* (list 10 10 10) Tdir)) (mapcar ‘+ ptB (mapcar ‘* (list 10 10 10) Cdir))|;
    ;”” “dview” (entlast) “”
    “Clip” “back” 0 ;(* -1 (/ DistFB 2.0))
    “Clip” “front” DistFB
    “” ) ;) )
    (vl-cmdf “ucs” “view”)
    )
    ;==========================================================
    (defun VS:transpoint ( TP:pt TP:vect / )
    (setq TP:tmpPt (trans TP:pt TP:vect 0))
    (if TP:tmpPt
    TP:tmpPt
    TP:pt )
    )
    ;==========================================================
    (defun C:EndViewSect ( / )
    (vl-cmdf “ucs” “world”)
    (cond
    ((or (= 2 (logand (getvar “viewmode”) 2))(= 4 (logand (getvar “viewmode”) 4)))
    (vl-cmdf “dview” (entlast) “”
    “Clip” “back” “off”
    “Clip” “front” “off” “” ) ) )

    (if (and VS:#:PrevViewCenter VS:#:PrevViewDist VS:#:PrevViewDirect)
    (progn
    (if (not (equal (getvar “VIEWDIR”) VS:#:PrevViewDirect 0.01)) (vl-cmdf “VPOINT” VS:#:PrevViewDirect) )
    (vl-cmdf “zoom” “c” VS:#:PrevViewCenter VS:#:PrevViewDist) ) )
    )

  2. Tristram Harris says:

    Hi 2015 comment.

    Thanks that a very useful LSP file.

    Do you know a way of saving this depth view on the UCS tab or other. Per have there is a paper space view port lsp to control the depth you may know of?

    I am using Advanced steel 2015 and this works well with the views how ever ( due to certain camera restraints) I am still finding the autocad view ports still are supperior for when detailing views with alot finishes on the steelwork are needed to show/ not show.

    ( I am a experienced Revit user aswell and know that this program I have the control I need but alas the fabrication side I go back to Advanced steel )

Leave a comment