- UID
- 14
- 积分
- 8264
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-4
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
- ;;;*************************************************************************;;;
- ;;; DSX-API-Objects.LSP ;;;
- ;;; Visual LISP ActiveX Object Methods for DSX Tools 2002 ;;;
- ;;; Copyright (C) 2002 David M. Stein, All Rights Reserved. ;;;
- ;;;*************************************************************************;;;
- ;;; Version 2001.00 07/10/01: Initial release ;;;
- ;;; Version 2002.22 05/15/02: updated error handlers ;;;
- ;;;*************************************************************************;;;
- ;;; Code provided AS-IS without warranty of any kind given for any purpose ;;;
- ;;; or use, either explicitly, implicitly or as a derivative work item. ;;;
- ;;; User assumes ANY AND ALL RISK and LIABILITY for use of any of this code ;;;
- ;;; for any consequential damages of any kind. These functions are defined ;;;
- ;;; within DSX Tools 2002.22 when loaded into AutoCAD. This document is ;;;
- ;;; provided for informational purposes only. ;;;
- ;;;*************************************************************************;;;
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddArc ;;;
- ;;; DESCRIPTION: Creates an ARC object with given properties ;;;
- ;;; ARGS: centerpoint, radius, start-angle, end-angle, layer, color, ltype ;;;
- ;;; EXAMPLE: (DSX-AddArc pt1 0.5 "WALLS" 2 nil) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (vl-load-com)
- (defun DSX-AddArc
- (cpt rad ang-s ang-e lay col ltype / obj)
- (dsx-princ "\n(DSX-AddArc)")
- (cond
- ( (vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'vla-AddArc
- (list (DSX-ActiveSpace) (vlax-3d-point cpt) rad (DTR ang-s) (DTR ang-e))
- )
- )
- )
- (dsx-objerr obj)
- )
- ( T
- (if lay (vla-put-Layer obj lay))
- (if col (vla-put-Color obj col))
- (if ltype (DSX-ApplyLtype obj ltype))
- (vla-update obj)
- (vlax-Release-Object obj)
- (entlast)
- )
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddCircle ;;;
- ;;; DESCRIPTION: Creates a CIRCLE object with given properties ;;;
- ;;; ARGS: centerpoint, radius, layer, color, linetype ;;;
- ;;; EXAMPLE: (DSX-AddCircle p1 0.5 "WALLS" 2 nil) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AddCircle
- (cpt rad lay col ltype / obj)
- (dsx-princ "\n(DSX-AddCircle)")
- (cond
- ( (vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'vla-AddCircle
- (list
- (DSX-ActiveSpace)
- (vlax-3d-point cpt)
- rad
- )
- )
- )
- )
- (dsx-objerr obj)
- )
- ( T
- (if lay (vla-put-layer obj lay))
- (if col (vla-put-color obj col))
- (if ltype (DSX-ApplyLtype obj ltype))
- (vla-update obj)
- (vlax-release-object obj)
- (entlast)
- )
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddLine ;;;
- ;;; DESCRIPTION: Creates a LINE object with given properties ;;;
- ;;; ARGS: point1, point2, layer, color, linetype ;;;
- ;;; EXAMPLE: (DSX-AddLine p1 p2 "WALLS" nil nil) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AddLine
- (p1 p2 lay col ltype / obj)
- (dsx-princ "\n(DSX-AddLine)")
- (cond
- ( (vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'vla-AddLine
- (list
- (DSX-ActiveSpace)
- (vlax-3d-Point p1)
- (vlax-3d-Point p2)
- )
- )
- )
- )
- (dsx-objerr obj)
- )
- ( T
- (if lay (vla-put-Layer obj lay))
- (if col (vla-put-Color obj col))
- (if ltype (DSX-ApplyLtype obj ltype))
- (vla-Update obj)
- (vlax-release-object obj)
- (entlast)
- )
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddLineC ;;;
- ;;; DESCRIPTION: Creates multiple segment LINEs from list of points ;;;
- ;;; ARGS: points-list, closed-flag, layer, color, linetype ;;;
- ;;; EXAMPLE: (DSX-AddLineC plist T "WALLS" nil nil) --> closed at end ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AddLineC
- (ptlist Bclosed strLayer intColor strLtype / pt1 ptz)
- (dsx-princ "\n(DSX-AddLineC)")
-
- (cond
- ( (and ptlist (listp ptlist) (listp (car ptlist)))
- (setq pt1 (car ptlist);; save first point
- ptz (last ptlist);; save last point
- )
- (while (and ptlist (>= (length ptlist) 2))
- (DSX-AddLine (car ptlist) (cadr ptlist) strLayer intColor strLtype)
- (setq ptlist (cdr ptlist))
- )
- (if (= Bclosed T) (DSX-AddLine pt1 ptz strLayer intColor strLtype) )
- )
- ); cond
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddPoint ;;;
- ;;; DESCRIPTION: Creates a POINT object with given properties ;;;
- ;;; ARGS: point, layer, color ;;;
- ;;; EXAMPLE: (DSX-AddPoint pt1 "WALLS" nil) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AddPoint
- (pt strLayer col / obj)
- (dsx-princ "\n(DSX-AddPoint)")
- (cond
- ( (vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'vla-AddPoint
- (list
- (DSX-ActiveSpace)
- (vlax-3d-point pt)
- )
- )
- )
- )
- (dsx-objerr obj)
- )
- ( T
- (if strLayer (vla-Put-Layer obj strLayer))
- (if col (vla-Put-Color obj col))
- (vla-Update obj)
- (vlax-Release-Object obj)
- (entlast)
- )
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddEllipse ;;;
- ;;; DESCRIPTION: Creates a closed ELLIPSE with given properties ;;;
- ;;; ARGS: centerpoint, hmajor-pt, roll-angle(deg), layer, color, linetype ;;;
- ;;; EXAMPLE: (DSX-AddEllipse pt1 pt2 45 "WALLS" nil nil) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AddEllipse
- (ctr hmpt roll strLayer intColor strLtype / obj)
- (dsx-princ "\n(DSX-AddEllipse)")
-
- (cond
- ( (and
- (setq hmpt (list
- (- (car hmpt) (car ctr))
- (- (cadr hmpt) (cadr ctr))
- )
- )
- )
- (cond
- ( (vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'vla-addEllipse
- (list
- (DSX-ActiveSpace)
- (vlax-3D-Point ctr)
- (vlax-3D-Point hmpt)
- (Roll->Ratio roll)
- )
- )
- )
- )
- (dsx-objerr obj)
- )
- ( T
- (if strLayer (vla-Put-Layer obj strLayer))
- (if intColor (vla-Put-Color obj intColor))
- (if strLtype (DSX-ApplyLtype obj strLtype))
- (vla-Update obj)
- (vlax-Release-Object obj)
- (entlast)
- )
- )
- )
- ( T (princ "\n(DSX-AddEllipse): Invalid parameter list!") )
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddEllipseArc1 ;;;
- ;;; DESCRIPTION: Creates ARC-Ellipse with given properties using roll-angle ;;;
- ;;; ARGS: center-pt, hmajor-pt, roll(deg), start-ang, end-ang, layer, color, linetype
- ;;; EXAMPLE: (DSX-AddEllipseArc1 pt1 pt2 45 90 180 "WALLS" nil nil) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AddEllipseArc1
- (ctr hmpt roll StartAng EndAng strLayer intColor strLtype / obj rang)
- (dsx-princ "\n(DSX-AddEllipseArc1)")
-
- (cond
- ( (and
- (setq hmpt (list
- (- (car hmpt) (car ctr))
- (- (cadr hmpt) (cadr ctr))
- )
- )
- )
- (cond
- ( (vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'vla-AddEllipse
- (list
- (DSX-ActiveSpace)
- (vlax-3D-Point ctr)
- (vlax-3D-Point hmpt)
- (Roll->Ratio roll)
- )
- )
- )
- )
- (dsx-objerr obj)
- )
- ( T
- (vla-Put-StartAngle obj (DTR StartAng))
- (vla-Put-EndAngle obj (DTR EndAng))
- (if strLayer (vla-Put-Layer obj strLayer))
- (if intColor (vla-Put-Color obj intColor))
- (if strLtype (DSX-ApplyLtype obj strLtype))
- (vla-Update obj)
- (vlax-Release-Object obj)
- (entlast)
- )
- )
- )
- ( T (princ "\n(DSX-AddEllipseArc1): Invalid parameter list...") )
- )
- )
- ;;;************************************************************************;;;
- ;;; MODULE: DSX-AddEllipseArc2 () ;;;
- ;;; DESCRIPTION: Same as DSX-AddEllipseArc1 but uses h-minor ratio ;;;
- ;;; ARGS: centerpoint, h-major-pt, h-minor-ratio, start-ang(deg), end-ang(deg), layer, color, linetype
- ;;; EXAMPLE: ;;;
- ;;;************************************************************************;;;
- (defun DSX-AddEllipseArc2
- (ctr hmpt hmin StartAng EndAng strLayer intColor strLtype / obj rang)
- (dsx-princ "\n(DSX-AddEllipseArc2)")
-
- (cond
- ( (and
- ctr (listp ctr) hmpt (listp hmpt) hmin StartAng EndAng
- (setq hmpt (list
- (- (car hmpt) (car ctr))
- (- (cadr hmpt) (cadr ctr))
- )
- )
- )
- (cond
- ( (vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'vla-AddEllipse
- (list
- (DSX-ActiveSpace)
- (vlax-3D-Point ctr)
- (vlax-3D-Point hmpt)
- hmin ; radius-ratio value
- )
- )
- )
- )
- (dsx-objerr obj)
- )
- ( T
- (vla-Put-StartAngle obj (DTR StartAng))
- (vla-Put-EndAngle obj (DTR EndAng))
- (if strLayer (vla-Put-Layer obj strLayer))
- (if intColor (vla-Put-Color obj intColor))
- (if strLtype (DSX-ApplyLtype obj strLtype))
- (vla-Update obj)
- (vlax-release-object obj)
- (entlast)
- )
- )
- )
- ( T (princ "\n(DSX-AddEllipseArc2): Invalid Parameter list...") )
- )
- )
- ;;;************************************************************************;;;
- ;;; MODULE: DSX-AddPline () ;;;
- ;;; DESCRIPTION: Create LwPolyline object with given properties & width. ;;;
- ;;; ARGS: pointlist, close, layer, color, linetype, lweight, lt-gen-flag ;;;
- ;;; EXAMPLE: (DSX-AddPline ptlist "Layer" T 3 "CENTER3" 0 nil) ;;;
- ;;;************************************************************************;;;
- (defun DSX-AddPline
- (ptlist strLayer Bclosed intColor strLt dblWidth bLTG
- / vrtcs plgen plist plpoints obj)
-
- (dsx-princ "\n(DSX-AddPline)")
-
- (cond
- ( (and ptlist (listp ptlist) (listp (car ptlist)))
- (setq plist (apply 'append (mapcar '3dpoint->2dpoint ptlist))
- plpoints (List->VariantArray plist)
- )
- (cond
- ( (vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'vla-AddLightWeightPolyline
- (list
- (DSX-ActiveSpace)
- plpoints
- )
- )
- )
- )
- (dsx-objerr obj)
- )
- ( T
- (if Bclosed (vla-Put-Closed obj :vlax-True));; make closed
- (if strLayer (vla-Put-Layer obj strLayer));; apply layer
- (if intColor (vla-Put-Color obj intColor));; apply color
- (if dblWidth (vla-Put-ConstantWidth obj dblWidth));; apply constant width
- (if strLt (DSX-ApplyLtype obj strLt))
- (if bLTG (DSX-ApplyLtypeGen obj))
- (vla-Update obj);; force graphic update
- (vlax-Release-Object obj)
- (entlast)
- )
- )
- )
- ( T (princ "\n(DSX-AddPline): Invalid parameter list...") )
- )
- )
- ;;;************************************************************************;;;
- ;;; MODULE: DSX-AddSolid ;;;
- ;;; DESCRIPTION: Create solid region with given properties and points ;;;
- ;;; ARGS: pointlist, layer, color ;;;
- ;;; EXAMPLE: (DSX-AddSolid (list p1 p2 p3) "0" 3) ;;;
- ;;;************************************************************************;;;
- (defun DSX-AddSolid
- (ptlist strLayer intColor / plist obj)
-
- (dsx-princ "\n(DSX-AddSolid)")
-
- (cond
- ( (and ptlist (listp ptlist) (listp (car ptlist)))
- (if (= (length ptlist) 3)
- (setq plist (append ptlist (list (last ptlist))))
- (setq plist ptlist)
- )
- (dsx-princ "\nMaking solid object...")
- (cond
- ( (vl-catch-all-error-p
- (setq obj
- (vl-catch-all-apply
- 'vla-AddSolid
- (list
- (DSX-ActiveSpace)
- (vlax-3D-Point (car plist))
- (vlax-3D-Point (cadr plist))
- (vlax-3D-Point (caddr plist))
- (vlax-3D-Point (cadddr plist))
- )
- )
- )
- )
- (dsx-objerr obj)
- )
- ( T
- (if strLayer (vla-Put-Layer obj strLayer))
- (if intColor (vla-Put-Color obj intColor))
- (vla-Update obj)
- (vlax-Release-Object obj)
- (entlast)
- )
- )
- )
- ( T (princ "\n(DSX-AddSolid): Invalid parameter list...") )
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddText ;;;
- ;;; DESCRIPTION: Create TEXT objects with given properties ;;;
- ;;; ARGS: textstring, inspt, justification, stylename, height(real), width(real), rotation(real), layer, color
- ;;; EXAMPLE: (DSX-AddText "TITLE" pt1 "MC" "Standard" 0.15 1.0 0 "TEXT" nil)
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AddText
- (strTxt pt Just strStyle dblHgt dblWid dblRot strLay intCol
- / txtobj
- )
- (dsx-princ "\n(DSX-AddText)")
-
- (cond
- ( (vl-catch-all-error-p
- (setq txtobj
- (vl-catch-all-apply
- 'vla-AddText
- (list
- (DSX-ActiveSpace)
- strTxt
- (if (not (member (strcase Just) '("A" "F")))
- (vlax-3d-Point pt)
- (vlax-3d-Point (car pt))
- )
- dblHgt ;; ignored for ALIGNED justified text
- )
- )
- )
- )
- (dsx-objerr txtobj)
- )
- ( T
- (if strstyle (vla-put-StyleName txtobj strStyle))
- (if strLay (vla-put-Layer txtobj strLay))
- (if intCol (vla-put-Color txtobj intCol))
- ;; Left/Align/Fit/Center/Middle/Right/BL/BC/BR/ML/MC/MR/TL/TC/TR
- ;; Note that "Left" is not a normal default.
- ;;
- ;; ALIGNMENT TYPES...
- ;; AcAlignmentLeft=0
- ;; AcAlignmentCenter=1
- ;; AcAlignmentRight=2
- ;; AcAlignmentAligned=3
- ;; AcAlignmentMiddle=4
- ;; AcAlignmentFit=5
- ;; AcAlignmentTopLeft=6
- ;; AcAlignmentTopCenter=7
- ;; AcAlignmentTopRight=8
- ;; AcAlignmentMiddleLeft=9
- ;; AcAlignmentMiddleCenter=10
- ;; AcAlignmentMiddleRight=11
- ;; AcAlignmentBottomLeft=12
- ;; AcAlignmentBottomCenter=13
- ;; AcAlignmentBottomRight=14
- ;;
- ;; HORIZONTAL JUSTIFICATIONS...
- ;; AcHorizontalAlignmentLeft=0
- ;; AcHorizontalAlignmentCenter=1
- ;; AcHorizontalAlignmentRight=2
- ;; AcHorizontalAlignmentAligned=3
- ;; AcHorizontalAlignmentMiddle=4
- ;; AcHorizontalAlignmentFit=5
- ;;
- ;; VERTICAL JUSTIFICATIONS...
- ;; AcVerticalAlignmentBaseline=0
- ;; AcVerticalAlignmentBottom=1
- ;; AcVerticalAlignmentMiddle=2
- ;; AcVerticalAlignmentTop=3
-
- (cond
- ( (= Just "L")
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "C")
- (vla-put-Alignment txtobj 1)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "R")
- (vla-put-Alignment txtobj 2)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "A")
- (vla-put-Alignment txtobj 3)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point (cadr pt)))
- )
- ( (= Just "M")
- (vla-put-Alignment txtobj 4)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "F")
- (vla-put-Alignment txtobj 5)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point (cadr pt)))
- )
- ( (= Just "TL");; Top-Left
- (vla-put-Alignment txtobj 6)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "TC");; Top-Center
- (vla-put-Alignment txtobj 7)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "TR");; Top-Right
- (vla-put-Alignment txtobj 8)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "ML")
- (vla-put-Alignment txtobj 9)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "MC")
- (vla-put-Alignment txtobj 10)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "MR")
- (vla-put-Alignment txtobj 11)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "BL")
- (vla-put-Alignment txtobj 12)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "BC")
- (vla-put-Alignment txtobj 13)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- ( (= Just "BR")
- (vla-put-Alignment txtobj 14)
- (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
- (if dblWid (vla-put-ScaleFactor txtobj dblWid))
- (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
- )
- )
- (vla-update txtobj)
- (vlax-Release-Object txtobj)
- (entlast)
- )
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddPolygon ;;;
- ;;; DESCRIPTION: Creates a circumscribed polygon ;;;
- ;;; ARGS: center, radius, sides, flag ("C" or "I"), width, layer, color, ltype, ltgen
- ;;; EXAMPLE: (DSX-AddPolygon pt1 1.0 6 "C" 0 "0" nil "DASHED" T) ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AddPolygon
- (ctrpt dblRad intSides strType dblWid strLay intCol strLtype Bltgen
- / pa dg ptlist deg)
- (dsx-princ "\n(DSX-AddPolygon)")
- (if (= (strcase strType) "C")
- (setq dblRad (* dblRad (/ 1 (/ (sqrt 3.0) 2.0))))
- )
- (setq pa (polar ctrpt 0 dblRad)
- dg (/ 360.0 intSides);; get angles between faces
- deg dg
- )
- (repeat intSides
- (setq ptlist
- (if ptlist
- (append ptlist (list (polar ctrpt (DTR deg) dblRad)))
- (list (polar ctrpt (DTR deg) dblRad))
- )
- )
- (setq deg (+ dg deg))
- )
- (DSX-AddPline ptlist strLay T intCol strLtype dblWid Bltgen)
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AddRectangle ;;;
- ;;; DESCRIPTION: Creates LwPolyline rectangle with given properties ;;;
- ;;; ARGS: pt1, pt2, layer, color, linetype, lineweight, ltgen-flag ;;;
- ;;; EXAMPLE: (DSX-AddRectangle p1 p2 "DOORS" 1 "DASHED" 0 nil) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AddRectangle
- (p1 p3 strLayer intColor strLtype dblWid bLTG / p2 p4 obj)
- (dsx-princ "\n(DSX-AddRectangle)")
- (setq p2 (list (car p1) (cadr p3))
- p4 (list (car p3) (cadr p1))
- )
- (cond
- ( (setq obj
- (DSX-AddPline (list p1 p2 p3 p4)
- strLayer T intColor strLtype dblWid bLTG
- )
- )
- obj ;; raise object (entity name)
- )
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-AttachXREF ;;;
- ;;; DESCRIPTION: Attaches named drawing as an XREF-ATTACHment ;;;
- ;;; ARGS: pathname, fulldwgname ;;;
- ;;; EXAMPLE: (DSX-AttachXREF "c:\\dwgfiles" "c:\\dwgfiles\\dwg1.dwg") ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-AttachXREF (pathname fullname)
- (dsx-princ "\n(DSX-AttachXREF)")
- (vlax-for layout
- (vla-get-layouts (DSX-ActiveDocument))
- (vla-AttachExternalReference
- (vla-get-Block layout)
- pathname
- fullname
- (vlax-3d-point '(0.0 0.0 0.0))
- 1.0 1.0 1.0 0.0
- :vlax-false
- )
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: Roll->Ratio ;;;
- ;;; DESCRIPTION: Converts a roll angle into the h-major/minor ratio value ;;;
- ;;; ARGS: roll-angle (deg) ;;;
- ;;; EXAMPLE: (Roll->Ratio 45) --> 0.707107 ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun Roll->Ratio (RollAngle)
- (cos (DTR RollAngle))
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-GetEllipseArcPoints ;;;
- ;;; DESCRIPTION: Returns coordinates of Elliptical-Arc endpoints in current UCS or WCS (default)
- ;;; ARGS: entity-or-object ;;;
- ;;; EXAMPLE: (DSX-GetEllipseArcPoints ellObj) -->((1.0 2.0 0.0) (1.0 3.0 0.0))
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-GetEllipseArcPoints
- (ellent / ename-ellipse vlaobject-ellipse p-start p-end out)
-
- (dsx-princ "\n(DSX-GetEllipseArcPoints)")
-
- (setq vlaObject-Ellipse (DSX-MakeObject ellent);; convert ename to object
- p-start (vla-Get-StartPoint vlaObject-Ellipse)
- p-end (vla-Get-EndPoint vlaObject-Ellipse)
- out (list
- (vlax-SafeArray->List (vlax-Variant-Value p-start))
- (vlax-SafeArray->List (vlax-Variant-Value p-end))
- )
- )
- out
- ); defun
- ;;;************************************************************************;;;
- ;;; MODULE: DeltaPt ;;;
- ;;; DESCRIPTION: Determine delta offset from point<p1> to point<p2> ;;;
- ;;; ARGS: point1, point2 ;;;
- ;;; EXAMPLE: (DeltaPt p1 p2) returns (1.0 2.4 0.0) ;;;
- ;;; NOTES: ;;;
- ;;;************************************************************************;;;
- (defun DeltaPt (p1 p2)
- (list
- (- (car p2) (car p1));; x-delta
- (- (cadr p2) (cadr p1));; y-delta
- (- (caddr p2) (caddr p1));; z-delta
- )
- )
- ;;;************************************************************************;;;
- ;;; MODULE: DSX-ApplyLtype ;;;
- ;;; DESCRIPTION: Apply linetype to vla-object or entity ;;;
- ;;; ARGS: entname(or vla-object), linetype-name ;;;
- ;;; EXAMPLE: (DSX-ApplyLtype line-ent "DASHED") ;;;
- ;;; NOTES: ;;;
- ;;;************************************************************************;;;
- (defun DSX-ApplyLtype
- (obj strLtype / ent els try ltobj ltn)
- (dsx-princ "\n(DSX-ApplyLtype)")
-
- (cond
- ( (not (member (strcase strLtype) '("CONTINUOUS" "BYBLOCK" "BYLAYER")))
- (if (setq ltobj (dsx-loadltype strLtype nil))
- (progn
- (setq ltn (vla-get-name ltobj))
- (vlax-put-property (dsx-makeobject obj) ltn)
- (vlax-release-object ltobj)
- )
- )
- ( T
- (vlax-put-property (dsx-makeobject obj) strLtype)
- )
- )
- )
- )
- ;;;************************************************************************;;;
- ;;; MODULE: DSX-ApplyLtScale ;;;
- ;;; DESCRIPTION: Apply object linetype scaling ;;;
- ;;; ARGS: ename or object, scale (real) ;;;
- ;;; EXAMPLE: (DSX-ApplyLtScale line-ent 24.0) ;;;
- ;;; NOTES: ;;;
- ;;;************************************************************************;;;
- (defun DSX-ApplyLtScale
- (ent sc / obj)
- (dsx-princ "\n(DSX-ApplyLtScale)")
- (setq obj (DSX-MakeObject ent))
- (if (vlax-property-available-p obj "linetypescale")
- (vla-Put-LinetypeScale obj sc)
- (princ "\n(DSX-ApplyLtScale): Unable to modify object linetype scale property...")
- )
- (vlax-Release-Object obj)
- )
- ;;;************************************************************************;;;
- ;;; MODULE: DSX-ApplyLtypeGen ;;;
- ;;; DESCRIPTION: Apply linetype-generation to polyline or lwpolyline object;;;
- ;;; ARGS: linetype-name, object or ename ;;;
- ;;; EXAMPLE: (DSX-ApplyLtypeGen "CENTER3" pline-obj) ;;;
- ;;; NOTES: ;;;
- ;;;************************************************************************;;;
- (defun DSX-ApplyLtypeGen (object)
- (dsx-princ "\n(DSX-ApplyLtypeGen)")
- (if (vlax-property-available-p object "linetypegeneration")
- (vla-Put-LinetypeGeneration object :vlax-True)
- (princ "\nError: Object has not 'linetypegeneration' property.")
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-GetAttributes ;;;
- ;;; DESCRIPTION: Returns attribute data list ((tag . value) (tag . value)...)
- ;;; ARGS: entity-or-object (blockref) ;;;
- ;;; EXAMPLE: (DSX-GetAttributes blkent) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-GetAttributes (ent / blkref lst)
- (dsx-princ "\n(DSX-GetAttributes)")
- (setq blkref (DSX-MakeObject ent))
- (if (= (vla-get-objectname blkref) "AcDbBlockReference")
- (if (vla-get-hasattributes blkref)
- (mapcar
- '(lambda (x)
- (setq lst
- (cons
- (cons
- (vla-get-tagstring x)
- (vla-get-textstring x)
- )
- lst
- )
- )
- )
- (vlax-safearray->list
- (vlax-variant-value (vla-getattributes blkref))
- )
- ); mapcar
- ); endif
- ); endif
- (reverse lst)
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-ModAttributes ;;;
- ;;; DESCRIPTION: Updates block attribute values with cons list ;;;
- ;;; ARGS: block-object, att-value-list ;;;
- ;;; EXAMPLE: (DSX-ModAttributes blkobj '(("tag1" . "value1")...)) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-ModAttributes
- (blkobj datlst / itm atts)
- (dsx-princ "\n(DSX-ModAttributes)")
- (if (= (vla-Get-HasAttributes blkobj) :vlax-true)
- (progn
- (setq atts
- (vlax-SafeArray->list
- (vlax-Variant-Value (vla-GetAttributes blkobj))
- )
- ); setq
- (foreach item datlst
- (mapcar
- '(lambda (x)
- (if
- (= (strcase (car item)) (strcase (vla-get-TagString x)))
- (vla-put-TextString x (cdr item))
- )
- )
- atts
- ); mapcar
- ); foreach
- (vla-Update blkobj)
- )
- ); endif
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-CopyProp ;;;
- ;;; DESCRIPTION: Copies named properties from one object to another ;;;
- ;;; ARGS: property-name(string), source(object), target(object) ;;;
- ;;; EXAMPLE: (DSX-CopyProp "Layer" obj1 obj2) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-CopyProp (propName source target)
- (dsx-princ "\n(DSX-CopyProp)")
- (cond
- ( (and
- (not (vlax-erased-p source));; is source accessible?
- (not (vlax-erased-p target));; is target accessible?
- (vlax-property-available-p source propName);; is property valid?
- (vlax-property-available-p target propName T);; is property modifiable?
- )
- (vlax-put-property
- target propName
- (vlax-get-property source propName)
- )
- T ;; return TRUE
- )
- ( T (princ "\nOne or more objects inaccessible!") )
- ); cond
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: DSX-MapPropertyList ;;;
- ;;; DESCRIPTION: Copies multiple properties from one object to another ;;;
- ;;; ARGS: list, object, object ;;;
- ;;; EXAMPLE: (DSX-MapPropertyList '("Layer" "Color") obj1 obj2) ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun DSX-MapPropertyList (propList source target)
- (dsx-princ "\n(DSX-MapPropertyList)")
- (foreach prop propList
- (DSX-CopyProp prop source target)
- )
- )
- ;;;*************************************************************************;;;
- ;;; MODULE: Tol ;;;
- ;;; DESCRIPTION: checks to see if num is between two values be them upper or lower limits or a toleranced target value. ;;;
- ;;; ARGS: num, target, toler, uplim, lolim ;;;
- ;;; EXAMPLE: (Tol 4.5 4.52 0.05 nil nil) or (Tol 4.5 nil nil 3 5) returns T ;;;
- ;;; NOTES: ;;;
- ;;;*************************************************************************;;;
- (defun Tol (num target toler uplim lolim)
- (cond
- ( (and (/= toler nil) (/= target nil))
- (if (<= (- target toler) num (+ target toler)) T)
- )
- ( T (if (<= lolim num uplim) T) )
- )
- )
- ;;;*************************************************************************
- ;;; MODULE: DSX-AddLeader-Simple
- ;;; DESCRIPTION: Add LEADER with TEXT using 2 points and text string value
- ;;; ARGS: point1, point2, textstring
- ;;; EXAMPLE: (DSX-AddLeader-Simple p1 p2 "REFERENCE LINE")
- ;;;*************************************************************************
- (defun DSX-AddLeader-Simple
- (p1 p2 text)
- (vl-cmdf "leader" "_NON" p1 "_NON" p2 "A" text "")
- (entlast)
- )
- ;;;*************************************************************************
- ;;; MODULE: DSX-AddLeader
- ;;; DESCRIPTION: Creates leader with given properties and text string
- ;;; ARGS: points-list, textstring (or list of strings) , txtheight, justification key ("T" "M" "B"), pointer (ACAD enum), layer(opt), color(opt), dimstyle(opt)
- ;;; EXAMPLE: (DSX-AddLeader ptlist "DATUM LINE" 0.15 "T" acArrowDefault $lay $tlay acByLayer nil) returns Ename
- ;;;*************************************************************************
- (defun DSX-AddLeader
- (ptlist txtstr hgt justky pntr lay mlay col style / Make3dPt xlist xarray xvariant oLeader mtpt oMtext tmp i)
- (defun Make3dPt (pt)
- (if (not (caddr pt))
- (list
- (car pt)
- (cadr pt)
- (getvar "elevation")
- )
- pt
- )
- )
- ;; Odd stuff here: A Leader object uses a flat matrix for
- ;; its coordinates list. The array is simply a list of all
- ;; coordinate points appended into a single 1 dimensional list
- ;; In order to make a Leader, you must first stuff all the
- ;; supplied points into a flat list, then convert that list
- ;; into a safearray and then convert the safearray into a
- ;; variant object. Then the AddLeader function will accept
- ;; it.
- ;; Also, the AnnotationObject property will not allow anything
- ;; but a valid object handle. The documentation says it will
- ;; accept NULL (aka nil, vlax-vbNull, etc.) but this causes
- ;; an error and fails entirely. You must supply an object of
- ;; some kind to make the Leader object work in VLISP.
-
- ;; pack coords into a flat matrix list
- (setq xlist (apply 'append (mapcar 'Make3dPt ptlist)))
- ;; Convert flat list into a safearray
- (setq xarray
- (vlax-safearray-fill
- (vlax-make-safearray
- vlax-vbDouble
- (cons
- 0
- (1- (length xlist))
- )
- )
- xlist
- )
- )
- ;; Convert safearray into a variant object
- (setq xvariant (vlax-make-variant xarray))
- ;; Calculate attachment point of Mtext object off of end of
- ;; last point in leader coordinates list
- ;; Only Justifications on the ends are supported --
- ;; (TL, ML, BL, TR, MR, & BR) therefore the justky tells whether
- ;; its T (top) M (middle) or B (bottom) concatenated with "L" or "R"
- ;; upon examination of the point list.
- (if
- (>
- (car (nth 0 (reverse ptlist)))
- (car (nth 1 (reverse ptlist)))
- )
- (setq mtpt (DSX-PTOFF (last ptlist) 0.125 (/ (ASWPM-TextSize1) 2.0))
- mtjs (strcat justky "L")
- )
- (setq mtpt (PTOFF (last ptlist) -0.125 (/ (ASWPM-TextSize1) 2.0))
- mtjs (strcat justky "R")
- )
- )
- (cond
- ( (or (= mtjs "TL") (= mtjs "TR")) (setq offst (- (/ hgt 2.0))))
- ( (or (= mtjs "BR") (= mtjs "BL")) (setq offst (/ hgt 2.0)))
- ( T (setq offst nil))
- )
- ;; function allows for a list of strings which correspond to different lines
- ;; of text. This portion will concatenate the strings in the list to reflect
- ;; the different lines of text using the control code "\\P" for new lines.
- (cond
- ( (listp txtstr)
- (setq i 0
- tmp ""
- )
- (repeat (length txtstr)
- (if (= tmp "")
- (setq tmp (nth i txtstr))
- (setq tmp (strcat tmp "\\P" (nth i txtstr)))
- )
- (setq i (1+ i))
- )
- (setq txtstr tmp)
- )
- )
- ;; Create Mtext annotation object
- (setq oMtext (DSX-AddMtext1 txtstr mtpt hgt 0 mtjs))
- (if mlay (vla-put-layer oMtext mlay))
- (cond
- ( (not
- (vl-catch-all-error-p
- (setq oLeader
- (vl-catch-all-apply
- 'vla-AddLeader
- (list
- (DSX-ActiveSpace)
- xvariant ; points
- oMtext ; annotation object
- acLineWithArrow ; leadertype
- )
- ); vl-catch-all-apply
- ); setq
- ); vl-catch-all-error-p
- ); not
- (if lay (vla-put-Layer oLeader lay))
- (if col (vla-put-Color oLeader col))
- (if style (vla-put-StyleName oLeader style))
- (if pntr (vla-put-arrowheadtype oLeader pntr))
- (if offst
- (progn
- (setq ename (vlax-vla-object->ename oLeader)
- elist (entget ename)
- prev (assoc 213 elist)
- new (cons 213 (list 0.0 offst 0.0))
- elist (subst new prev elist)
- )
- (entmod elist)
- (entupd ename)
- (vla-evaluate (DSX-MakeObject ename))
- )
- )
- )
- ( T
- (princ
- (strcat "\nError: "
- (vl-catch-all-error-message oLeader)
- )
- )
- (vlax-release-object oLeader)
- )
- )
- ename
- )
- (defun DSX-AddMtext1 (txt pt hgt wid jus)
- (vl-cmdf "-mtext" "_NON" pt "_j" jus "_h" hgt "_w" wid txt "")
- (DSX-MakeObject (entlast))
- )
- ;;;*************************************************************************
- ;;; MODULE: dsx-Copy
- ;;; DESCRIPTION: Copy method for picksets, entities or objects, returns object if possible, ignores osmode
- ;;; ARGS: entity-or-object, point1, point2
- ;;; EXAMPLE: (DSx-Copy (entlast) p1 p2)
- ;;;*************************************************************************
- (defun dsx-copy (obj p1 p2 / o1 o2 i)
- (dsx-princ "\n(dsx-copy)")
- (cond
- ( (= 'PICKSET (type obj))
- (setq i 0)
- (repeat (sslength obj)
- (setq o1 (dsx-MakeObject (ssname obj i)))
- (setq o2 (vla-copy o1))
- (vla-move o2 (vlax-3d-point p1) (vlax-3d-point p2))
- (vlax-release-object o1)
- (vlax-release-object o2)
- (setq i (1+ i))
- )
- )
- ( (= 'vla-object (type obj))
- (setq o2 (vla-copy o1))
- (vla-move o2 (vlax-3d-point p1) (vlax-3d-point p2))
- (vlax-release-object o1)
- o2
- )
- ( (= 'ename (type obj))
- (setq o1 (dsx-MakeObject obj))
- (setq o2 (vla-copy o1))
- (vla-move o2 (vlax-3d-point p1) (vlax-3d-point p2))
- (vlax-release-object o1)
- o2
- )
- )
- )
- ;;;*************************************************************************
- ;;; MODULE: dsx-Move
- ;;; DESCRIPTION: Move method for picksets, entities or objects, returns nil, ignores osmode
- ;;; ARGS: entity-or-object-or-pickset, point1, point2
- ;;; EXAMPLE: (DSX-Move (entlast) p1 p2)
- ;;;*************************************************************************
- (defun dsx-Move (obj p1 p2 / i o)
- (dsx-princ "\n(dsx-move)")
- (cond
- ( (= 'PICKSET (type obj))
- (setq i 0)
- (repeat (sslength obj)
- (setq o (dsx-MakeObject (ssname obj i)))
- (vla-move o (vlax-3d-point p1) (vlax-3d-point p2))
- (vlax-release-object o)
- (setq i (1+ i))
- )
- )
- ( (= 'VLA-OBJECT (type obj))
- (vla-move obj (vlax-3d-point p1) (vlax-3d-point p2))
- )
- ( (= 'ENAME (type obj))
- (setq o (dsx-MakeObject obj))
- (vla-move o (vlax-3d-point p1) (vlax-3d-point p2))
- (vlax-release-object o)
- )
- )
- )
- ;;;*************************************************************************
- ;;; MODULE: dsx-Rotate
- ;;; DESCRIPTION: Rotate method for picksets, entities or objects, returns nil, ignores osmode
- ;;; ARGS: entity-or-object-or-pickset, point, angle-degrees
- ;;; EXAMPLE: (dsx-Rotate sset pt1 180)
- ;;;*************************************************************************
- (defun dsx-Rotate (obj pt ang-deg / i o)
- (dsx-princ "\n(dsx-rotate)")
- (cond
- ( (= 'VLA-OBJECT (type obj))
- (if (vlax-method-applicable-p obj "rotate")
- (vla-rotate obj (vlax-3d-point pt) (DTR ang-deg))
- )
- )
- ( (= 'ENAME (type obj))
- (setq o (dsx-MakeObject obj))
- (if (vlax-method-applicable-p o "rotate")
- (vla-rotate o (vlax-3d-point pt) (DTR ang-deg))
- )
- (vlax-release-object o)
- )
- ( (= 'PICKSET (type obj))
- (setq i 0)
- (repeat (sslength obj)
- (setq o (dsx-MakeObject (ssname obj i)))
- (if (vlax-method-applicable-p o "rotate")
- (vla-rotate o (vlax-3d-point pt) (DTR ang-deg))
- )
- (vlax-release-object o)
- (setq i (1+ i))
- )
- )
- )
- )
- ;;;*************************************************************************
- ;;; MODULE: dsx-Mirror
- ;;; DESCRIPTION: Mirror method for picksets, entities or objects, returns new object or nil
- ;;; ARGS: ename/object/pickset, point1, point2, delete-flag
- ;;; EXAMPLE: (dsx-Mirror sset p1 p2 T) mirrors and deletes original
- ;;;*************************************************************************
- (defun dsx-Mirror (obj p1 p2 delete / o i out)
- (dsx-princ "\n(dsx-Mirror)")
- (cond
- ( (= (type obj) 'vla-object)
- (if (vlax-method-applicable-p obj "mirror")
- (progn
- (setq out (vla-mirror obj (vlax-3d-point p1) (vlax-3d-point p2)))
- (if delete (vla-delete obj))
- )
- )
- )
- ( (= (type obj) 'ename)
- (setq o (vlax-ename->vla-object obj))
- (if (vlax-method-applicable-p o "Mirror")
- (progn
- (setq out (vlax-invoke-method o "Mirror" (vlax-3d-point p1) (vlax-3d-point p2)))
- (if delete (vla-delete o))
- )
- )
- (vlax-release-object o)
- )
- ( (= (type obj) 'pickset)
- (setq i 0)
- (repeat (sslength obj)
- (setq o (vlax-ename->vla-object (ssname obj i)))
- (if (vlax-method-applicable-p o "Mirror")
- (progn
- (vlax-invoke-method o "Mirror" (vlax-3d-point p1) (vlax-3d-point p2))
- (if delete (vla-delete o))
- )
- )
- (vlax-release-object o)
- (setq i (1+ i))
- )
- )
- )
- out
- )
- (princ)
- ;;;*************************************************************************
- ;;; MODULE: dsx-Scale
- ;;; DESCRIPTION: Scale method for picksets, entities or objects, returns nil, ignores osmode
- ;;; ARGS: entity-or-object-or-pickset, point, scalefactor
- ;;; EXAMPLE: (dsx-Scale sset pt1 2)
- ;;;*************************************************************************
- (defun dsx-Scale (obj pt scafac / i o)
- (cond
- ( (= 'PICKSET (type obj))
- (setq i 0)
- (repeat (sslength obj)
- (setq o (dsx-MakeObject (ssname obj i)))
- (vla-ScaleEntity o (vlax-3d-point pt) scafac)
- (vlax-release-object o)
- (setq i (1+ i))
- )
- )
- ( (= 'VLA-OBJECT (type obj))
- (vla-ScaleEntity obj (vlax-3d-point pt) scafac)
- )
- ( (= 'ENAME (type obj))
- (setq o (dsx-MakeObject obj))
- (vla-ScaleEntity obj (vlax-3d-point pt) scafac)
- (vlax-release-object o)
- )
- )
- )
- (princ)
|
|