找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1269|回复: 6

[转贴]:DSX-API-Objects.LSP

[复制链接]

已领礼包: 593个

财富等级: 财运亨通

发表于 2003-7-24 23:04:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

  1. ;;;*************************************************************************;;;
  2. ;;; DSX-API-Objects.LSP                                                     ;;;
  3. ;;; Visual LISP ActiveX Object Methods for DSX Tools 2002                   ;;;
  4. ;;; Copyright (C) 2002 David M. Stein, All Rights Reserved.                 ;;;
  5. ;;;*************************************************************************;;;
  6. ;;; Version 2001.00 07/10/01: Initial release                               ;;;
  7. ;;; Version 2002.22 05/15/02: updated error handlers                        ;;;
  8. ;;;*************************************************************************;;;
  9. ;;; Code provided AS-IS without warranty of any kind given for any purpose  ;;;
  10. ;;; or use, either explicitly, implicitly or as a derivative work item.     ;;;
  11. ;;; User assumes ANY AND ALL RISK and LIABILITY for use of any of this code ;;;
  12. ;;; for any consequential damages of any kind.  These functions are defined ;;;
  13. ;;; within DSX Tools 2002.22 when loaded into AutoCAD.  This document is    ;;;
  14. ;;; provided for informational purposes only.                               ;;;
  15. ;;;*************************************************************************;;;

  16. ;;;*************************************************************************;;;
  17. ;;; MODULE: DSX-AddArc                                                      ;;;
  18. ;;; DESCRIPTION: Creates an ARC object with given properties                ;;;
  19. ;;; ARGS: centerpoint, radius, start-angle, end-angle, layer, color, ltype  ;;;
  20. ;;; EXAMPLE: (DSX-AddArc pt1 0.5 "WALLS" 2 nil)                             ;;;
  21. ;;; NOTES:                                                                  ;;;
  22. ;;;*************************************************************************;;;

  23. (vl-load-com)

  24. (defun DSX-AddArc
  25.         (cpt rad ang-s ang-e lay col ltype / obj)
  26.         (dsx-princ "\n(DSX-AddArc)")
  27.   (cond
  28.     ( (vl-catch-all-error-p
  29.                                 (setq obj
  30.                                         (vl-catch-all-apply
  31.                         'vla-AddArc
  32.                                                 (list (DSX-ActiveSpace)        (vlax-3d-point cpt) rad (DTR ang-s) (DTR ang-e))
  33.                 )
  34.               )
  35.                         )
  36.                   (dsx-objerr obj)
  37.                 )
  38.                 ( T
  39.                   (if lay (vla-put-Layer obj lay))
  40.                   (if col (vla-put-Color obj col))
  41.                   (if ltype (DSX-ApplyLtype obj ltype))
  42.                   (vla-update obj)
  43.                   (vlax-Release-Object obj)
  44.                   (entlast)
  45.                 )
  46.         )
  47. )

  48. ;;;*************************************************************************;;;
  49. ;;; MODULE: DSX-AddCircle                                                   ;;;
  50. ;;; DESCRIPTION: Creates a CIRCLE object with given properties              ;;;
  51. ;;; ARGS: centerpoint, radius, layer, color, linetype                       ;;;
  52. ;;; EXAMPLE: (DSX-AddCircle p1 0.5 "WALLS" 2 nil)                           ;;;
  53. ;;; NOTES:                                                                  ;;;
  54. ;;;*************************************************************************;;;

  55. (defun DSX-AddCircle
  56.   (cpt rad lay col ltype / obj)
  57.         (dsx-princ "\n(DSX-AddCircle)")
  58.         (cond
  59.                 ( (vl-catch-all-error-p
  60.                                 (setq obj
  61.                                         (vl-catch-all-apply
  62.                                                 'vla-AddCircle
  63.                                                 (list
  64.                                                         (DSX-ActiveSpace)
  65.                                                         (vlax-3d-point cpt)
  66.                                                         rad
  67.                                                 )
  68.                                         )
  69.                                 )
  70.                         )
  71.                   (dsx-objerr obj)
  72.                 )
  73.                 ( T
  74.                   (if lay (vla-put-layer obj lay))
  75.                   (if col (vla-put-color obj col))
  76.                   (if ltype (DSX-ApplyLtype obj ltype))
  77.                   (vla-update obj)
  78.                   (vlax-release-object obj)
  79.                   (entlast)
  80.                 )
  81.         )
  82. )

  83. ;;;*************************************************************************;;;
  84. ;;; MODULE: DSX-AddLine                                                     ;;;
  85. ;;; DESCRIPTION: Creates a LINE object with given properties                ;;;
  86. ;;; ARGS: point1, point2, layer, color, linetype                            ;;;
  87. ;;; EXAMPLE: (DSX-AddLine p1 p2 "WALLS" nil nil)                            ;;;
  88. ;;; NOTES:                                                                  ;;;
  89. ;;;*************************************************************************;;;

  90. (defun DSX-AddLine
  91.         (p1 p2 lay col ltype / obj)
  92.         (dsx-princ "\n(DSX-AddLine)")
  93.         (cond
  94.                 ( (vl-catch-all-error-p
  95.                                 (setq obj
  96.                                         (vl-catch-all-apply
  97.                                                 'vla-AddLine
  98.                                                 (list
  99.                                                         (DSX-ActiveSpace)
  100.                                                         (vlax-3d-Point p1)
  101.                                                         (vlax-3d-Point p2)
  102.                                                 )
  103.                                         )
  104.                                 )
  105.                         )
  106.                         (dsx-objerr obj)
  107.                 )
  108.                 ( T
  109.                          (if lay (vla-put-Layer obj lay))
  110.                   (if col (vla-put-Color obj col))
  111.                   (if ltype (DSX-ApplyLtype obj ltype))
  112.                   (vla-Update obj)
  113.                   (vlax-release-object obj)
  114.                   (entlast)
  115.                 )
  116.         )
  117. )

  118. ;;;*************************************************************************;;;
  119. ;;; MODULE: DSX-AddLineC                                                    ;;;
  120. ;;; DESCRIPTION: Creates multiple segment LINEs from list of points         ;;;
  121. ;;; ARGS: points-list, closed-flag, layer, color, linetype                  ;;;
  122. ;;; EXAMPLE: (DSX-AddLineC plist T "WALLS" nil nil) --> closed at end       ;;;
  123. ;;; NOTES:                                                                  ;;;
  124. ;;;*************************************************************************;;;

  125. (defun DSX-AddLineC
  126.         (ptlist Bclosed strLayer intColor strLtype / pt1 ptz)
  127.   (dsx-princ "\n(DSX-AddLineC)")
  128.   
  129.   (cond
  130.     ( (and ptlist (listp ptlist) (listp (car ptlist)))
  131.                         (setq pt1 (car  ptlist);; save first point
  132.                                                 ptz (last ptlist);; save last point
  133.                         )
  134.                         (while (and ptlist (>= (length ptlist) 2))
  135.                                 (DSX-AddLine (car ptlist) (cadr ptlist) strLayer intColor strLtype)
  136.                                 (setq ptlist (cdr ptlist))
  137.                         )
  138.                         (if (= Bclosed T) (DSX-AddLine pt1 ptz strLayer intColor strLtype) )
  139.                 )
  140.         ); cond
  141. )

  142. ;;;*************************************************************************;;;
  143. ;;; MODULE: DSX-AddPoint                                                    ;;;
  144. ;;; DESCRIPTION: Creates a POINT object with given properties               ;;;
  145. ;;; ARGS: point, layer, color                                               ;;;
  146. ;;; EXAMPLE: (DSX-AddPoint pt1 "WALLS" nil)                                 ;;;
  147. ;;; NOTES:                                                                  ;;;
  148. ;;;*************************************************************************;;;

  149. (defun DSX-AddPoint
  150.         (pt strLayer col / obj)
  151.   (dsx-princ "\n(DSX-AddPoint)")
  152.   (cond
  153.     ( (vl-catch-all-error-p
  154.                                 (setq obj
  155.                                         (vl-catch-all-apply
  156.                                                 'vla-AddPoint
  157.                                                 (list
  158.                                                         (DSX-ActiveSpace)
  159.                                                         (vlax-3d-point pt)
  160.                                                 )
  161.                                         )
  162.                                 )
  163.                         )
  164.                         (dsx-objerr obj)
  165.                 )
  166.                 ( T
  167.                         (if strLayer (vla-Put-Layer obj strLayer))
  168.                   (if col      (vla-Put-Color obj col))
  169.                         (vla-Update obj)
  170.                         (vlax-Release-Object obj)
  171.                         (entlast)
  172.                 )
  173.         )
  174. )

  175. ;;;*************************************************************************;;;
  176. ;;; MODULE: DSX-AddEllipse                                                  ;;;
  177. ;;; DESCRIPTION: Creates a closed ELLIPSE with given properties             ;;;
  178. ;;; ARGS: centerpoint, hmajor-pt, roll-angle(deg), layer, color, linetype   ;;;
  179. ;;; EXAMPLE: (DSX-AddEllipse pt1 pt2 45 "WALLS" nil nil)                    ;;;
  180. ;;; NOTES:                                                                  ;;;
  181. ;;;*************************************************************************;;;

  182. (defun DSX-AddEllipse
  183.   (ctr hmpt roll strLayer intColor strLtype / obj)
  184.   (dsx-princ "\n(DSX-AddEllipse)")
  185.   
  186.   (cond
  187.     ( (and
  188.                                 (setq hmpt         (list
  189.                                                                                         (- (car  hmpt) (car  ctr))
  190.                                                                                         (- (cadr hmpt) (cadr ctr))
  191.                                                                                 )
  192.                                 )
  193.                         )
  194.                   (cond
  195.                                 ( (vl-catch-all-error-p
  196.                                                 (setq        obj
  197.                                                         (vl-catch-all-apply
  198.                                                                 'vla-addEllipse
  199.                                                                 (list
  200.                                                                         (DSX-ActiveSpace)
  201.                                                                         (vlax-3D-Point ctr)
  202.                                                                         (vlax-3D-Point hmpt)
  203.                                                                         (Roll->Ratio roll)
  204.                                                                 )
  205.                                                         )
  206.                                                 )
  207.                                         )
  208.                                   (dsx-objerr obj)
  209.                                 )
  210.                                 ( T
  211.                                         (if strLayer (vla-Put-Layer obj strLayer))
  212.                                         (if intColor (vla-Put-Color obj intColor))
  213.                                         (if strLtype (DSX-ApplyLtype   obj strLtype))
  214.                                         (vla-Update obj)
  215.                                   (vlax-Release-Object obj)
  216.                                   (entlast)
  217.                                 )
  218.                         )
  219.                 )
  220.                 ( T (princ "\n(DSX-AddEllipse): Invalid parameter list!") )
  221.         )
  222. )

  223. ;;;*************************************************************************;;;
  224. ;;; MODULE: DSX-AddEllipseArc1                                              ;;;
  225. ;;; DESCRIPTION: Creates ARC-Ellipse with given properties using roll-angle ;;;
  226. ;;; ARGS: center-pt, hmajor-pt, roll(deg), start-ang, end-ang, layer, color, linetype
  227. ;;; EXAMPLE: (DSX-AddEllipseArc1 pt1 pt2 45 90 180 "WALLS" nil nil)         ;;;
  228. ;;; NOTES:                                                                  ;;;
  229. ;;;*************************************************************************;;;

  230. (defun DSX-AddEllipseArc1
  231.   (ctr hmpt roll StartAng EndAng strLayer intColor strLtype / obj rang)
  232.   (dsx-princ "\n(DSX-AddEllipseArc1)")
  233.   
  234.   (cond
  235.     ( (and
  236.                                 (setq hmpt  (list
  237.                                                                                 (- (car  hmpt) (car  ctr))
  238.                                                                                 (- (cadr hmpt) (cadr ctr))
  239.                                                                         )
  240.                                 )
  241.                         )
  242.                   (cond
  243.                                 ( (vl-catch-all-error-p
  244.                                                 (setq        obj
  245.                                                         (vl-catch-all-apply
  246.                                                                 'vla-AddEllipse
  247.                                                                 (list
  248.                                                                         (DSX-ActiveSpace)
  249.                                                                         (vlax-3D-Point ctr)
  250.                                                                         (vlax-3D-Point hmpt)
  251.                                                                         (Roll->Ratio roll)
  252.                                                                 )
  253.                                                         )
  254.                                                 )
  255.                                         )
  256.                                   (dsx-objerr obj)
  257.                                 )
  258.                                 ( T
  259.                                         (vla-Put-StartAngle obj (DTR StartAng))
  260.                                         (vla-Put-EndAngle   obj (DTR EndAng))
  261.                                         (if strLayer (vla-Put-Layer obj strLayer))
  262.                                         (if intColor (vla-Put-Color obj intColor))
  263.                                         (if strLtype (DSX-ApplyLtype obj strLtype))
  264.                                         (vla-Update obj)
  265.                                         (vlax-Release-Object obj)
  266.                                         (entlast)
  267.                                 )
  268.                         )
  269.                 )
  270.                 ( T (princ "\n(DSX-AddEllipseArc1): Invalid parameter list...") )
  271.         )
  272. )

  273. ;;;************************************************************************;;;
  274. ;;; MODULE: DSX-AddEllipseArc2 ()                                          ;;;
  275. ;;; DESCRIPTION: Same as DSX-AddEllipseArc1 but uses h-minor ratio         ;;;
  276. ;;; ARGS: centerpoint, h-major-pt, h-minor-ratio, start-ang(deg), end-ang(deg), layer, color, linetype
  277. ;;; EXAMPLE:                                                               ;;;
  278. ;;;************************************************************************;;;

  279. (defun DSX-AddEllipseArc2
  280.   (ctr hmpt hmin StartAng EndAng strLayer intColor strLtype / obj rang)
  281.   (dsx-princ "\n(DSX-AddEllipseArc2)")
  282.   
  283.   (cond
  284.     ( (and
  285.                                 ctr (listp ctr) hmpt (listp hmpt) hmin StartAng EndAng
  286.                                 (setq hmpt  (list
  287.                                                                                         (- (car  hmpt) (car  ctr))
  288.                                                                                         (- (cadr hmpt) (cadr ctr))
  289.                                                                                 )
  290.                                 )
  291.                         )
  292.                   (cond
  293.                                 ( (vl-catch-all-error-p
  294.                                                 (setq obj
  295.                                                         (vl-catch-all-apply
  296.                                                                 'vla-AddEllipse
  297.                                                                 (list
  298.                                                                         (DSX-ActiveSpace)
  299.                                                                         (vlax-3D-Point ctr)
  300.                                                                         (vlax-3D-Point hmpt)
  301.                                                                         hmin ; radius-ratio value
  302.                                                                 )
  303.                                                         )
  304.                                                 )
  305.                                         )
  306.                                   (dsx-objerr obj)
  307.                                 )
  308.                                 ( T
  309.                                         (vla-Put-StartAngle obj (DTR StartAng))
  310.                                         (vla-Put-EndAngle   obj (DTR EndAng))
  311.                                         (if strLayer (vla-Put-Layer obj strLayer))
  312.                                         (if intColor (vla-Put-Color obj intColor))
  313.                                         (if strLtype (DSX-ApplyLtype obj strLtype))
  314.                                         (vla-Update obj)
  315.                                         (vlax-release-object obj)
  316.                                         (entlast)
  317.                                 )
  318.                         )
  319.                 )
  320.                 ( T (princ "\n(DSX-AddEllipseArc2): Invalid Parameter list...") )
  321.         )
  322. )


  323. ;;;************************************************************************;;;
  324. ;;; MODULE: DSX-AddPline ()                                                ;;;
  325. ;;; DESCRIPTION: Create LwPolyline object with given properties & width.   ;;;
  326. ;;; ARGS: pointlist, close, layer, color, linetype, lweight, lt-gen-flag   ;;;
  327. ;;; EXAMPLE: (DSX-AddPline ptlist "Layer" T 3 "CENTER3" 0 nil)             ;;;
  328. ;;;************************************************************************;;;

  329. (defun DSX-AddPline
  330.   (ptlist strLayer Bclosed intColor strLt dblWidth bLTG
  331.    / vrtcs plgen plist plpoints obj)
  332.   
  333.   (dsx-princ "\n(DSX-AddPline)")
  334.   
  335.   (cond
  336.     ( (and ptlist (listp ptlist) (listp (car ptlist)))
  337.                         (setq plist     (apply 'append (mapcar '3dpoint->2dpoint ptlist))
  338.                                                 plpoints  (List->VariantArray plist)
  339.                         )
  340.                   (cond
  341.                                 ( (vl-catch-all-error-p
  342.                                                 (setq obj
  343.                                                         (vl-catch-all-apply
  344.                                                                 'vla-AddLightWeightPolyline
  345.                                                                 (list
  346.                                                                         (DSX-ActiveSpace)
  347.                                                                         plpoints
  348.                                                                 )
  349.                                                         )
  350.                                                 )
  351.                                         )
  352.                                   (dsx-objerr obj)
  353.                                 )
  354.                                 ( T
  355.                                         (if Bclosed  (vla-Put-Closed obj :vlax-True));; make closed
  356.                                         (if strLayer (vla-Put-Layer obj strLayer));; apply layer
  357.                                         (if intColor (vla-Put-Color obj intColor));; apply color
  358.                                         (if dblWidth (vla-Put-ConstantWidth obj dblWidth));; apply constant width
  359.                                         (if strLt    (DSX-ApplyLtype obj strLt))
  360.                                   (if bLTG                  (DSX-ApplyLtypeGen obj))
  361.                                         (vla-Update obj);; force graphic update
  362.                                         (vlax-Release-Object obj)
  363.                                         (entlast)
  364.                                 )
  365.                         )
  366.                 )
  367.                 ( T (princ "\n(DSX-AddPline): Invalid parameter list...") )
  368.         )
  369. )

  370. ;;;************************************************************************;;;
  371. ;;; MODULE: DSX-AddSolid                                                   ;;;
  372. ;;; DESCRIPTION: Create solid region with given properties and points      ;;;
  373. ;;; ARGS: pointlist, layer, color                                          ;;;
  374. ;;; EXAMPLE: (DSX-AddSolid (list p1 p2 p3) "0" 3)                          ;;;
  375. ;;;************************************************************************;;;

  376. (defun DSX-AddSolid
  377.   (ptlist strLayer intColor / plist obj)
  378.   
  379.   (dsx-princ "\n(DSX-AddSolid)")
  380.   
  381.   (cond
  382.     ( (and ptlist (listp ptlist) (listp (car ptlist)))
  383.                         (if (= (length ptlist) 3)
  384.                                 (setq plist (append ptlist (list (last ptlist))))
  385.                                 (setq plist ptlist)
  386.                         )
  387.                         (dsx-princ "\nMaking solid object...")
  388.                   (cond
  389.                           ( (vl-catch-all-error-p
  390.                                                 (setq obj
  391.                                                         (vl-catch-all-apply
  392.                                                                 'vla-AddSolid
  393.                                                                 (list
  394.                                                                         (DSX-ActiveSpace)
  395.                                                                         (vlax-3D-Point (car plist))
  396.                                                                         (vlax-3D-Point (cadr plist))
  397.                                                                         (vlax-3D-Point (caddr plist))
  398.                                                                         (vlax-3D-Point (cadddr plist))
  399.                                                                 )
  400.                                                         )
  401.                                                 )
  402.                                         )
  403.                                   (dsx-objerr obj)
  404.                                 )
  405.                                 ( T
  406.                                         (if strLayer (vla-Put-Layer obj strLayer))
  407.                                         (if intColor (vla-Put-Color obj intColor))
  408.                                         (vla-Update obj)
  409.                                   (vlax-Release-Object obj)
  410.                                   (entlast)
  411.                                 )
  412.                   )
  413.                 )
  414.                 ( T (princ "\n(DSX-AddSolid): Invalid parameter list...") )
  415.         )
  416. )

  417. ;;;*************************************************************************;;;
  418. ;;; MODULE: DSX-AddText                                                     ;;;
  419. ;;; DESCRIPTION: Create TEXT objects with given properties                  ;;;
  420. ;;; ARGS: textstring, inspt, justification, stylename, height(real), width(real), rotation(real), layer, color
  421. ;;; EXAMPLE: (DSX-AddText "TITLE" pt1 "MC" "Standard" 0.15 1.0 0 "TEXT" nil)   
  422. ;;; NOTES:                                                                  ;;;
  423. ;;;*************************************************************************;;;

  424. (defun DSX-AddText
  425.         (strTxt pt Just strStyle dblHgt dblWid dblRot strLay intCol
  426.          / txtobj
  427.         )

  428.         (dsx-princ "\n(DSX-AddText)")
  429.        
  430.         (cond
  431.                 ( (vl-catch-all-error-p
  432.                                 (setq txtobj
  433.                                         (vl-catch-all-apply
  434.                                           'vla-AddText
  435.                                                 (list
  436.                                                         (DSX-ActiveSpace)
  437.                                                         strTxt
  438.                                                         (if (not (member (strcase Just) '("A" "F")))
  439.                                                                 (vlax-3d-Point pt)
  440.                                                                 (vlax-3d-Point (car pt))
  441.                                                         )
  442.                                                         dblHgt ;; ignored for ALIGNED justified text
  443.                                                 )
  444.                                         )
  445.                                 )
  446.                         )
  447.                   (dsx-objerr txtobj)
  448.                 )
  449.                 ( T
  450.                   (if strstyle (vla-put-StyleName txtobj strStyle))
  451.                   (if strLay (vla-put-Layer txtobj strLay))
  452.                   (if intCol (vla-put-Color txtobj intCol))

  453.                         ;; Left/Align/Fit/Center/Middle/Right/BL/BC/BR/ML/MC/MR/TL/TC/TR
  454.                         ;; Note that "Left" is not a normal default.
  455.                         ;;
  456.                         ;; ALIGNMENT TYPES...
  457.                         ;; AcAlignmentLeft=0
  458.                         ;; AcAlignmentCenter=1
  459.                         ;; AcAlignmentRight=2
  460.                         ;; AcAlignmentAligned=3
  461.                         ;; AcAlignmentMiddle=4
  462.                         ;; AcAlignmentFit=5
  463.                         ;; AcAlignmentTopLeft=6
  464.                         ;; AcAlignmentTopCenter=7
  465.                         ;; AcAlignmentTopRight=8
  466.                         ;; AcAlignmentMiddleLeft=9
  467.                         ;; AcAlignmentMiddleCenter=10
  468.                         ;; AcAlignmentMiddleRight=11
  469.                         ;; AcAlignmentBottomLeft=12
  470.                         ;; AcAlignmentBottomCenter=13
  471.                         ;; AcAlignmentBottomRight=14
  472.                         ;;                                                               
  473.                         ;; HORIZONTAL JUSTIFICATIONS...                                 
  474.                         ;; AcHorizontalAlignmentLeft=0                                   
  475.                         ;; AcHorizontalAlignmentCenter=1                                 
  476.                         ;; AcHorizontalAlignmentRight=2                                 
  477.                         ;; AcHorizontalAlignmentAligned=3                                
  478.                         ;; AcHorizontalAlignmentMiddle=4                                 
  479.                         ;; AcHorizontalAlignmentFit=5                                    
  480.                         ;;                                                               
  481.                         ;; VERTICAL JUSTIFICATIONS...                                    
  482.                         ;; AcVerticalAlignmentBaseline=0                                 
  483.                         ;; AcVerticalAlignmentBottom=1                                   
  484.                         ;; AcVerticalAlignmentMiddle=2                                   
  485.                         ;; AcVerticalAlignmentTop=3                                      
  486.                  
  487.                   (cond
  488.                                 ( (= Just "L")
  489.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  490.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  491.                           )
  492.                                 ( (= Just "C")
  493.                                   (vla-put-Alignment txtobj 1)
  494.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  495.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  496.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  497.                           )
  498.                                 ( (= Just "R")
  499.                                   (vla-put-Alignment txtobj 2)
  500.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  501.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  502.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  503.                                 )
  504.                                 ( (= Just "A")
  505.                                   (vla-put-Alignment txtobj 3)
  506.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point (cadr pt)))
  507.                           )
  508.                                 ( (= Just "M")
  509.                                   (vla-put-Alignment txtobj 4)
  510.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  511.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  512.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  513.                                 )
  514.                                 ( (= Just "F")
  515.                                   (vla-put-Alignment txtobj 5)
  516.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point (cadr pt)))
  517.                                 )
  518.                                 ( (= Just "TL");; Top-Left
  519.           (vla-put-Alignment txtobj 6)
  520.           (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  521.           (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  522.           (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  523.         )
  524.         ( (= Just "TC");; Top-Center
  525.           (vla-put-Alignment txtobj 7)
  526.           (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  527.           (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  528.           (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  529.         )
  530.         ( (= Just "TR");; Top-Right
  531.           (vla-put-Alignment txtobj 8)
  532.           (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  533.           (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  534.           (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  535.         )
  536.                                 ( (= Just "ML")
  537.                                   (vla-put-Alignment txtobj 9)
  538.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  539.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  540.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  541.                           )
  542.                                 ( (= Just "MC")
  543.                                   (vla-put-Alignment txtobj 10)
  544.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  545.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  546.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  547.                            )
  548.                                 ( (= Just "MR")
  549.                                   (vla-put-Alignment txtobj 11)
  550.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  551.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  552.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  553.                           )
  554.                                 ( (= Just "BL")
  555.                                   (vla-put-Alignment txtobj 12)
  556.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  557.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  558.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  559.                           )
  560.                                 ( (= Just "BC")
  561.                                   (vla-put-Alignment txtobj 13)
  562.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  563.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  564.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  565.                           )
  566.                                 ( (= Just "BR")
  567.                                   (vla-put-Alignment txtobj 14)
  568.                                   (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  569.                                   (if dblWid (vla-put-ScaleFactor txtobj dblWid))
  570.                                   (if dblRot (vla-put-Rotation txtobj (DTR dblRot)))
  571.                           )
  572.                         )
  573.       (vla-update txtobj)
  574.                   (vlax-Release-Object txtobj)
  575.                   (entlast)
  576.                 )
  577.         )
  578. )

  579. ;;;*************************************************************************;;;
  580. ;;; MODULE: DSX-AddPolygon                                                  ;;;
  581. ;;; DESCRIPTION: Creates a circumscribed polygon                            ;;;
  582. ;;; ARGS: center, radius, sides, flag ("C" or "I"), width, layer, color, ltype, ltgen
  583. ;;; EXAMPLE: (DSX-AddPolygon pt1 1.0 6 "C" 0 "0" nil "DASHED" T)            ;;;
  584. ;;;*************************************************************************;;;

  585. (defun DSX-AddPolygon
  586.   (ctrpt dblRad intSides strType dblWid strLay intCol strLtype Bltgen
  587.    / pa dg ptlist deg)
  588.   (dsx-princ "\n(DSX-AddPolygon)")
  589.   (if (= (strcase strType) "C")
  590.     (setq dblRad (* dblRad (/ 1 (/ (sqrt 3.0) 2.0))))
  591.   )
  592.   (setq pa (polar ctrpt 0 dblRad)      
  593.         dg (/ 360.0 intSides);; get angles between faces
  594.         deg dg
  595.   )
  596.   (repeat intSides
  597.     (setq ptlist
  598.       (if ptlist
  599.         (append ptlist (list (polar ctrpt (DTR deg) dblRad)))
  600.         (list (polar ctrpt (DTR deg) dblRad))
  601.       )
  602.     )
  603.     (setq deg (+ dg deg))
  604.   )
  605.   (DSX-AddPline ptlist strLay T intCol strLtype dblWid Bltgen)
  606. )

  607. ;;;*************************************************************************;;;
  608. ;;; MODULE: DSX-AddRectangle                                                ;;;
  609. ;;; DESCRIPTION: Creates LwPolyline rectangle with given properties         ;;;
  610. ;;; ARGS: pt1, pt2, layer, color, linetype, lineweight, ltgen-flag          ;;;
  611. ;;; EXAMPLE: (DSX-AddRectangle p1 p2 "DOORS" 1 "DASHED" 0 nil)              ;;;
  612. ;;; NOTES:                                                                  ;;;
  613. ;;;*************************************************************************;;;

  614. (defun DSX-AddRectangle
  615.         (p1 p3 strLayer intColor strLtype dblWid bLTG / p2 p4 obj)
  616.         (dsx-princ "\n(DSX-AddRectangle)")

  617.         (setq p2 (list (car p1) (cadr p3))
  618.                                 p4 (list (car p3) (cadr p1))
  619.         )
  620.         (cond
  621.                 ( (setq obj
  622.                                 (DSX-AddPline (list p1 p2 p3 p4)
  623.                                         strLayer T intColor strLtype dblWid bLTG
  624.                                 )
  625.                         )
  626.                   obj ;; raise object (entity name)
  627.           )
  628.         )
  629. )

  630. ;;;*************************************************************************;;;
  631. ;;; MODULE: DSX-AttachXREF                                                  ;;;
  632. ;;; DESCRIPTION: Attaches named drawing as an XREF-ATTACHment               ;;;
  633. ;;; ARGS: pathname, fulldwgname                                             ;;;
  634. ;;; EXAMPLE: (DSX-AttachXREF "c:\\dwgfiles" "c:\\dwgfiles\\dwg1.dwg")       ;;;
  635. ;;; NOTES:                                                                  ;;;
  636. ;;;*************************************************************************;;;

  637. (defun DSX-AttachXREF (pathname fullname)
  638.         (dsx-princ "\n(DSX-AttachXREF)")
  639.         (vlax-for layout
  640.                 (vla-get-layouts (DSX-ActiveDocument))
  641.                 (vla-AttachExternalReference
  642.                         (vla-get-Block layout)
  643.                         pathname
  644.                         fullname
  645.                         (vlax-3d-point '(0.0 0.0 0.0))
  646.                         1.0 1.0        1.0        0.0
  647.                         :vlax-false
  648.                 )
  649.         )
  650. )

  651. ;;;*************************************************************************;;;
  652. ;;; MODULE: Roll->Ratio                                                     ;;;
  653. ;;; DESCRIPTION: Converts a roll angle into the h-major/minor ratio value   ;;;
  654. ;;; ARGS: roll-angle (deg)                                                  ;;;
  655. ;;; EXAMPLE: (Roll->Ratio 45) --> 0.707107                                  ;;;
  656. ;;; NOTES:                                                                  ;;;
  657. ;;;*************************************************************************;;;

  658. (defun Roll->Ratio (RollAngle)
  659.   (cos (DTR RollAngle))
  660. )

  661. ;;;*************************************************************************;;;
  662. ;;; MODULE: DSX-GetEllipseArcPoints                                         ;;;
  663. ;;; DESCRIPTION: Returns coordinates of Elliptical-Arc endpoints in current UCS or WCS (default)
  664. ;;; ARGS: entity-or-object                                                  ;;;
  665. ;;; EXAMPLE: (DSX-GetEllipseArcPoints ellObj) -->((1.0 2.0 0.0) (1.0 3.0 0.0))
  666. ;;; NOTES:                                                                  ;;;
  667. ;;;*************************************************************************;;;

  668. (defun DSX-GetEllipseArcPoints
  669.   (ellent / ename-ellipse vlaobject-ellipse p-start p-end out)
  670.   
  671.   (dsx-princ "\n(DSX-GetEllipseArcPoints)")
  672.   
  673.   (setq vlaObject-Ellipse (DSX-MakeObject ellent);; convert ename to object
  674.         p-start (vla-Get-StartPoint vlaObject-Ellipse)
  675.         p-end   (vla-Get-EndPoint   vlaObject-Ellipse)
  676.         out     (list
  677.                   (vlax-SafeArray->List (vlax-Variant-Value p-start))
  678.                   (vlax-SafeArray->List (vlax-Variant-Value p-end))
  679.                 )
  680.   )
  681.   out
  682. ); defun

  683. ;;;************************************************************************;;;
  684. ;;; MODULE: DeltaPt                                                        ;;;
  685. ;;; DESCRIPTION: Determine delta offset from point<p1> to point<p2>        ;;;
  686. ;;; ARGS: point1, point2                                                   ;;;
  687. ;;; EXAMPLE: (DeltaPt p1 p2) returns (1.0 2.4 0.0)                         ;;;
  688. ;;; NOTES:                                                                 ;;;
  689. ;;;************************************************************************;;;

  690. (defun DeltaPt (p1 p2)
  691.   (list
  692.     (- (car p2) (car p1));; x-delta
  693.     (- (cadr p2) (cadr p1));; y-delta
  694.     (- (caddr p2) (caddr p1));; z-delta
  695.   )
  696. )

  697. ;;;************************************************************************;;;
  698. ;;; MODULE: DSX-ApplyLtype                                                 ;;;
  699. ;;; DESCRIPTION: Apply linetype to vla-object or entity                    ;;;
  700. ;;; ARGS: entname(or vla-object), linetype-name                            ;;;
  701. ;;; EXAMPLE: (DSX-ApplyLtype line-ent "DASHED")                            ;;;
  702. ;;; NOTES:                                                                 ;;;
  703. ;;;************************************************************************;;;

  704. (defun DSX-ApplyLtype
  705.         (obj strLtype / ent els try ltobj ltn)
  706.   (dsx-princ "\n(DSX-ApplyLtype)")
  707.   
  708.   (cond
  709.                 ( (not (member (strcase strLtype) '("CONTINUOUS" "BYBLOCK" "BYLAYER")))
  710.                   (if (setq ltobj (dsx-loadltype strLtype nil))
  711.                     (progn
  712.                             (setq ltn (vla-get-name ltobj))
  713.                             (vlax-put-property (dsx-makeobject obj) ltn)
  714.                             (vlax-release-object ltobj)
  715.                     )
  716.                   )
  717.                   ( T
  718.                     (vlax-put-property (dsx-makeobject obj) strLtype)
  719.                   )
  720.                 )
  721.         )
  722. )

  723. ;;;************************************************************************;;;
  724. ;;; MODULE: DSX-ApplyLtScale                                               ;;;
  725. ;;; DESCRIPTION: Apply object linetype scaling                             ;;;
  726. ;;; ARGS: ename or object, scale (real)                                    ;;;
  727. ;;; EXAMPLE: (DSX-ApplyLtScale line-ent 24.0)                              ;;;
  728. ;;; NOTES:                                                                 ;;;
  729. ;;;************************************************************************;;;

  730. (defun DSX-ApplyLtScale
  731.         (ent sc / obj)
  732.   (dsx-princ "\n(DSX-ApplyLtScale)")

  733.   (setq obj (DSX-MakeObject ent))

  734.   (if (vlax-property-available-p obj "linetypescale")
  735.     (vla-Put-LinetypeScale obj sc)
  736.     (princ "\n(DSX-ApplyLtScale): Unable to modify object linetype scale property...")
  737.   )
  738.   (vlax-Release-Object obj)
  739. )

  740. ;;;************************************************************************;;;
  741. ;;; MODULE: DSX-ApplyLtypeGen                                              ;;;
  742. ;;; DESCRIPTION: Apply linetype-generation to polyline or lwpolyline object;;;
  743. ;;; ARGS: linetype-name, object or ename                                   ;;;
  744. ;;; EXAMPLE: (DSX-ApplyLtypeGen "CENTER3" pline-obj)                       ;;;
  745. ;;; NOTES:                                                                 ;;;
  746. ;;;************************************************************************;;;

  747. (defun DSX-ApplyLtypeGen (object)
  748.   (dsx-princ "\n(DSX-ApplyLtypeGen)")
  749.         (if (vlax-property-available-p object "linetypegeneration")
  750.           (vla-Put-LinetypeGeneration object :vlax-True)
  751.                 (princ "\nError: Object has not 'linetypegeneration' property.")
  752.         )
  753. )

  754. ;;;*************************************************************************;;;
  755. ;;; MODULE: DSX-GetAttributes                                               ;;;
  756. ;;; DESCRIPTION: Returns attribute data list ((tag . value) (tag . value)...)
  757. ;;; ARGS: entity-or-object (blockref)                                       ;;;
  758. ;;; EXAMPLE: (DSX-GetAttributes blkent)                                     ;;;
  759. ;;; NOTES:                                                                  ;;;
  760. ;;;*************************************************************************;;;

  761. (defun DSX-GetAttributes (ent / blkref lst)
  762.         (dsx-princ "\n(DSX-GetAttributes)")
  763.         (setq blkref (DSX-MakeObject ent))
  764.   (if (= (vla-get-objectname blkref) "AcDbBlockReference")
  765.     (if (vla-get-hasattributes blkref)
  766.       (mapcar
  767.                                 '(lambda (x)
  768.                                          (setq lst
  769.                                                                  (cons
  770.                                                                          (cons
  771.                                                                                  (vla-get-tagstring x)
  772.                                                                                  (vla-get-textstring x)
  773.                                                                          )
  774.                                                                          lst
  775.                                                                 )
  776.                                         )
  777.               )
  778.               (vlax-safearray->list
  779.                                         (vlax-variant-value (vla-getattributes blkref))
  780.                                 )
  781.       ); mapcar
  782.     ); endif
  783.   ); endif
  784.   (reverse lst)
  785. )

  786. ;;;*************************************************************************;;;
  787. ;;; MODULE: DSX-ModAttributes                                               ;;;
  788. ;;; DESCRIPTION: Updates block attribute values with cons list              ;;;
  789. ;;; ARGS: block-object, att-value-list                                      ;;;
  790. ;;; EXAMPLE: (DSX-ModAttributes blkobj '(("tag1" . "value1")...))           ;;;
  791. ;;; NOTES:                                                                  ;;;
  792. ;;;*************************************************************************;;;

  793. (defun DSX-ModAttributes
  794.         (blkobj datlst / itm atts)
  795.         (dsx-princ "\n(DSX-ModAttributes)")
  796.   (if (= (vla-Get-HasAttributes blkobj) :vlax-true)
  797.     (progn
  798.       (setq atts
  799.                                                          (vlax-SafeArray->list
  800.                                                            (vlax-Variant-Value (vla-GetAttributes blkobj))
  801.                                                          )
  802.       ); setq
  803.       (foreach item datlst
  804.                                 (mapcar
  805.                                   '(lambda (x)
  806.                                      (if
  807.                                        (= (strcase (car item)) (strcase (vla-get-TagString x)))
  808.                                                         (vla-put-TextString x (cdr item))
  809.                                      )
  810.                                    )
  811.                                   atts
  812.                                 ); mapcar
  813.       ); foreach
  814.       (vla-Update blkobj)
  815.     )
  816.   ); endif
  817. )

  818. ;;;*************************************************************************;;;
  819. ;;; MODULE: DSX-CopyProp                                                    ;;;
  820. ;;; DESCRIPTION: Copies named properties from one object to another         ;;;
  821. ;;; ARGS: property-name(string), source(object), target(object)             ;;;
  822. ;;; EXAMPLE: (DSX-CopyProp "Layer" obj1 obj2)                               ;;;
  823. ;;; NOTES:                                                                  ;;;
  824. ;;;*************************************************************************;;;

  825. (defun DSX-CopyProp (propName source target)
  826.         (dsx-princ "\n(DSX-CopyProp)")
  827.   (cond
  828.     ( (and
  829.         (not (vlax-erased-p source));; is source accessible?
  830.         (not (vlax-erased-p target));; is target accessible?
  831.         (vlax-property-available-p source propName);; is property valid?
  832.         (vlax-property-available-p target propName T);; is property modifiable?
  833.       )
  834.                   (vlax-put-property
  835.                     target propName
  836.                     (vlax-get-property source propName)
  837.                   )
  838.                   T ;; return TRUE
  839.                 )
  840.                 ( T (princ "\nOne or more objects inaccessible!")        )
  841.   ); cond
  842. )

  843. ;;;*************************************************************************;;;
  844. ;;; MODULE: DSX-MapPropertyList                                             ;;;
  845. ;;; DESCRIPTION: Copies multiple properties from one object to another      ;;;
  846. ;;; ARGS: list, object, object                                              ;;;
  847. ;;; EXAMPLE: (DSX-MapPropertyList '("Layer" "Color") obj1 obj2)             ;;;
  848. ;;; NOTES:                                                                  ;;;
  849. ;;;*************************************************************************;;;

  850. (defun DSX-MapPropertyList (propList source target)
  851.         (dsx-princ "\n(DSX-MapPropertyList)")
  852.   (foreach prop propList
  853.     (DSX-CopyProp prop source target)
  854.   )
  855. )

  856. ;;;*************************************************************************;;;
  857. ;;; MODULE: Tol                                                             ;;;
  858. ;;; DESCRIPTION: checks to see if num is between two values be them upper or lower limits or a toleranced target value.        ;;;
  859. ;;; ARGS: num, target, toler, uplim, lolim                                  ;;;
  860. ;;; EXAMPLE: (Tol 4.5 4.52 0.05 nil nil) or (Tol 4.5 nil nil 3 5) returns T ;;;
  861. ;;; NOTES:                                                                  ;;;
  862. ;;;*************************************************************************;;;

  863. (defun Tol (num target toler uplim lolim)
  864.   (cond
  865.     ( (and (/= toler nil) (/= target nil))
  866.       (if (<= (- target toler) num (+ target toler)) T)
  867.     )
  868.     ( T (if (<= lolim num uplim) T) )
  869.   )
  870. )

  871. ;;;*************************************************************************
  872. ;;; MODULE: DSX-AddLeader-Simple
  873. ;;; DESCRIPTION: Add LEADER with TEXT using 2 points and text string value
  874. ;;; ARGS: point1, point2, textstring
  875. ;;; EXAMPLE: (DSX-AddLeader-Simple p1 p2 "REFERENCE LINE")
  876. ;;;*************************************************************************

  877. (defun DSX-AddLeader-Simple
  878.         (p1 p2 text)
  879.         (vl-cmdf "leader" "_NON" p1 "_NON" p2 "A" text "")
  880.         (entlast)
  881. )

  882. ;;;*************************************************************************
  883. ;;; MODULE: DSX-AddLeader
  884. ;;; DESCRIPTION: Creates leader with given properties and text string
  885. ;;; ARGS: points-list, textstring (or list of strings) , txtheight, justification key ("T" "M" "B"), pointer (ACAD enum), layer(opt), color(opt), dimstyle(opt)
  886. ;;; EXAMPLE: (DSX-AddLeader ptlist "DATUM LINE" 0.15 "T" acArrowDefault $lay $tlay acByLayer nil) returns Ename
  887. ;;;*************************************************************************

  888. (defun DSX-AddLeader
  889.         (ptlist txtstr hgt justky pntr lay mlay col style / Make3dPt xlist xarray xvariant oLeader mtpt oMtext tmp i)

  890.         (defun Make3dPt (pt)
  891.                 (if (not (caddr pt))
  892.                         (list
  893.                                 (car pt)
  894.                                 (cadr pt)
  895.                                 (getvar "elevation")
  896.                         )
  897.                         pt
  898.                 )
  899.         )
  900.         ;; Odd stuff here: A Leader object uses a flat matrix for
  901.         ;; its coordinates list.  The array is simply a list of all
  902.         ;; coordinate points appended into a single 1 dimensional list
  903.         ;; In order to make a Leader, you must first stuff all the
  904.         ;; supplied points into a flat list, then convert that list
  905.         ;; into a safearray and then convert the safearray into a
  906.         ;; variant object.  Then the AddLeader function will accept
  907.         ;; it.
  908.         ;; Also, the AnnotationObject property will not allow anything
  909.         ;; but a valid object handle.  The documentation says it will
  910.         ;; accept NULL (aka nil, vlax-vbNull, etc.) but this causes
  911.         ;; an error and fails entirely.  You must supply an object of
  912.         ;; some kind to make the Leader object work in VLISP.
  913.        
  914.         ;; pack coords into a flat matrix list
  915.         (setq xlist (apply 'append (mapcar 'Make3dPt ptlist)))

  916.         ;; Convert flat list into a safearray
  917.         (setq xarray
  918.                 (vlax-safearray-fill
  919.                         (vlax-make-safearray
  920.                                 vlax-vbDouble
  921.                                 (cons
  922.                                         0
  923.                                         (1- (length xlist))
  924.                                 )
  925.                         )
  926.                         xlist
  927.                 )
  928.         )

  929.         ;; Convert safearray into a variant object
  930.         (setq xvariant (vlax-make-variant xarray))

  931.         ;; Calculate attachment point of Mtext object off of end of
  932.         ;; last point in leader coordinates list
  933.   ;; Only Justifications on the ends are supported --
  934.   ;;   (TL, ML, BL, TR, MR, & BR) therefore the justky tells whether
  935.   ;;   its T (top) M (middle) or B (bottom) concatenated with "L" or "R"
  936.   ;;   upon examination of the point list.
  937.         (if
  938.                 (>
  939.                         (car (nth 0 (reverse ptlist)))
  940.                         (car (nth 1 (reverse ptlist)))
  941.                 )
  942.     (setq mtpt (DSX-PTOFF (last ptlist) 0.125 (/ (ASWPM-TextSize1) 2.0))
  943.           mtjs (strcat justky "L")
  944.     )
  945.                 (setq mtpt (PTOFF (last ptlist) -0.125 (/ (ASWPM-TextSize1) 2.0))
  946.           mtjs (strcat justky "R")
  947.     )
  948.   )
  949.   (cond
  950.     ( (or (= mtjs "TL") (= mtjs "TR")) (setq offst (- (/ hgt 2.0))))
  951.     ( (or (= mtjs "BR") (= mtjs "BL")) (setq offst (/ hgt 2.0)))
  952.     ( T (setq offst nil))
  953.         )

  954.   ;; function allows for a list of strings which correspond to different lines
  955.   ;; of text.  This portion will concatenate the strings in the list to reflect
  956.   ;; the different lines of text using the control code "\\P" for new lines.

  957.   (cond
  958.     ( (listp txtstr)
  959.       (setq i 0
  960.             tmp ""
  961.       )
  962.       (repeat (length txtstr)
  963.         (if (= tmp "")
  964.           (setq tmp (nth i txtstr))
  965.           (setq tmp (strcat tmp "\\P" (nth i txtstr)))
  966.         )
  967.         (setq i (1+ i))
  968.       )
  969.       (setq txtstr tmp)
  970.     )
  971.   )

  972.         ;; Create Mtext annotation object
  973.         (setq oMtext (DSX-AddMtext1 txtstr mtpt hgt 0 mtjs))
  974.   (if mlay (vla-put-layer oMtext mlay))
  975.         (cond
  976.                 ( (not
  977.                                 (vl-catch-all-error-p
  978.                                         (setq oLeader
  979.                                                 (vl-catch-all-apply
  980.                                                         'vla-AddLeader
  981.                                                         (list
  982.                                                                 (DSX-ActiveSpace)
  983.                                                                 xvariant ; points
  984.                                                           oMtext ; annotation object
  985.                                                                 acLineWithArrow ; leadertype
  986.                                                         )
  987.                                                 ); vl-catch-all-apply
  988.                                         ); setq
  989.                                 ); vl-catch-all-error-p
  990.                         ); not
  991.                   (if lay (vla-put-Layer oLeader lay))
  992.                   (if col (vla-put-Color oLeader col))
  993.                   (if style (vla-put-StyleName oLeader style))
  994.       (if pntr (vla-put-arrowheadtype oLeader pntr))
  995.       (if offst
  996.         (progn
  997.                                   (setq ename (vlax-vla-object->ename oLeader)
  998.                             elist (entget ename)
  999.                             prev  (assoc 213 elist)
  1000.                             new   (cons 213 (list 0.0 offst 0.0))
  1001.                             elist (subst new prev elist)
  1002.                       )
  1003.                       (entmod elist)
  1004.                       (entupd ename)
  1005.           (vla-evaluate (DSX-MakeObject ename))
  1006.         )
  1007.       )
  1008.                 )
  1009.                 ( T
  1010.                   (princ
  1011.                                 (strcat "\nError: "
  1012.                                         (vl-catch-all-error-message oLeader)
  1013.                                 )
  1014.                         )
  1015.                   (vlax-release-object oLeader)
  1016.                 )
  1017.         )
  1018.   ename
  1019. )

  1020. (defun DSX-AddMtext1 (txt pt hgt wid jus)
  1021.         (vl-cmdf "-mtext" "_NON" pt "_j" jus "_h" hgt "_w" wid txt "")
  1022.         (DSX-MakeObject (entlast))
  1023. )

  1024. ;;;*************************************************************************
  1025. ;;; MODULE: dsx-Copy
  1026. ;;; DESCRIPTION: Copy method for picksets, entities or objects, returns object if possible, ignores osmode
  1027. ;;; ARGS: entity-or-object, point1, point2
  1028. ;;; EXAMPLE: (DSx-Copy (entlast) p1 p2)
  1029. ;;;*************************************************************************

  1030. (defun dsx-copy (obj p1 p2 / o1 o2 i)
  1031.         (dsx-princ "\n(dsx-copy)")
  1032.         (cond
  1033.                 ( (= 'PICKSET (type obj))
  1034.                   (setq i 0)
  1035.                   (repeat (sslength obj)
  1036.                                 (setq o1 (dsx-MakeObject (ssname obj i)))
  1037.                                 (setq o2 (vla-copy o1))
  1038.                                 (vla-move o2 (vlax-3d-point p1) (vlax-3d-point p2))
  1039.                                 (vlax-release-object o1)
  1040.                                 (vlax-release-object o2)
  1041.                                 (setq i (1+ i))
  1042.                         )
  1043.                 )
  1044.                 ( (= 'vla-object (type obj))
  1045.                   (setq o2 (vla-copy o1))
  1046.                   (vla-move o2 (vlax-3d-point p1) (vlax-3d-point p2))
  1047.                   (vlax-release-object o1)
  1048.                   o2
  1049.                 )
  1050.                 ( (= 'ename (type obj))
  1051.                   (setq o1 (dsx-MakeObject obj))
  1052.                   (setq o2 (vla-copy o1))
  1053.                   (vla-move o2 (vlax-3d-point p1) (vlax-3d-point p2))
  1054.                   (vlax-release-object o1)
  1055.                   o2
  1056.                 )
  1057.         )
  1058. )

  1059. ;;;*************************************************************************
  1060. ;;; MODULE: dsx-Move
  1061. ;;; DESCRIPTION: Move method for picksets, entities or objects, returns nil, ignores osmode
  1062. ;;; ARGS: entity-or-object-or-pickset, point1, point2
  1063. ;;; EXAMPLE: (DSX-Move (entlast) p1 p2)
  1064. ;;;*************************************************************************

  1065. (defun dsx-Move (obj p1 p2 / i o)
  1066.         (dsx-princ "\n(dsx-move)")
  1067.         (cond
  1068.                 ( (= 'PICKSET (type obj))
  1069.                   (setq i 0)
  1070.                   (repeat (sslength obj)
  1071.                                 (setq o (dsx-MakeObject (ssname obj i)))
  1072.                                 (vla-move o (vlax-3d-point p1) (vlax-3d-point p2))
  1073.                                 (vlax-release-object o)
  1074.                                 (setq i (1+ i))
  1075.                         )
  1076.                 )
  1077.                 ( (= 'VLA-OBJECT (type obj))
  1078.                         (vla-move obj (vlax-3d-point p1) (vlax-3d-point p2))
  1079.                 )
  1080.                 ( (= 'ENAME (type obj))
  1081.                         (setq o (dsx-MakeObject obj))
  1082.                         (vla-move o (vlax-3d-point p1) (vlax-3d-point p2))
  1083.                         (vlax-release-object o)
  1084.                 )
  1085.         )
  1086. )

  1087. ;;;*************************************************************************
  1088. ;;; MODULE: dsx-Rotate
  1089. ;;; DESCRIPTION: Rotate method for picksets, entities or objects, returns nil, ignores osmode
  1090. ;;; ARGS: entity-or-object-or-pickset, point, angle-degrees
  1091. ;;; EXAMPLE: (dsx-Rotate sset pt1 180)
  1092. ;;;*************************************************************************

  1093. (defun dsx-Rotate (obj pt ang-deg / i o)
  1094.         (dsx-princ "\n(dsx-rotate)")
  1095.         (cond
  1096.                 ( (= 'VLA-OBJECT (type obj))
  1097.                   (if (vlax-method-applicable-p obj "rotate")
  1098.                                 (vla-rotate obj (vlax-3d-point pt) (DTR ang-deg))
  1099.                         )
  1100.                 )
  1101.                 ( (= 'ENAME (type obj))
  1102.                         (setq o (dsx-MakeObject obj))
  1103.                   (if (vlax-method-applicable-p o "rotate")
  1104.                                 (vla-rotate o (vlax-3d-point pt) (DTR ang-deg))
  1105.                         )
  1106.                         (vlax-release-object o)
  1107.                 )
  1108.                 ( (= 'PICKSET (type obj))
  1109.                   (setq i 0)
  1110.                   (repeat (sslength obj)
  1111.                                 (setq o (dsx-MakeObject (ssname obj i)))
  1112.                                 (if (vlax-method-applicable-p o "rotate")
  1113.                                         (vla-rotate o (vlax-3d-point pt) (DTR ang-deg))
  1114.                                 )
  1115.                                 (vlax-release-object o)
  1116.                                 (setq i (1+ i))
  1117.                         )
  1118.                 )
  1119.         )
  1120. )

  1121. ;;;*************************************************************************
  1122. ;;; MODULE: dsx-Mirror
  1123. ;;; DESCRIPTION: Mirror method for picksets, entities or objects, returns new object or nil
  1124. ;;; ARGS: ename/object/pickset, point1, point2, delete-flag
  1125. ;;; EXAMPLE: (dsx-Mirror sset p1 p2 T) mirrors and deletes original
  1126. ;;;*************************************************************************

  1127. (defun dsx-Mirror (obj p1 p2 delete / o i out)
  1128.         (dsx-princ "\n(dsx-Mirror)")
  1129.         (cond
  1130.                 ( (= (type obj) 'vla-object)
  1131.                   (if (vlax-method-applicable-p obj "mirror")
  1132.                                 (progn
  1133.                                   (setq out (vla-mirror obj (vlax-3d-point p1) (vlax-3d-point p2)))
  1134.                                   (if delete (vla-delete obj))
  1135.                                 )
  1136.                         )
  1137.                 )
  1138.                 ( (= (type obj) 'ename)
  1139.                   (setq o (vlax-ename->vla-object obj))
  1140.                   (if (vlax-method-applicable-p o "Mirror")
  1141.                                 (progn
  1142.                                         (setq out (vlax-invoke-method o "Mirror" (vlax-3d-point p1) (vlax-3d-point p2)))
  1143.                                   (if delete (vla-delete o))
  1144.                                 )
  1145.                         )
  1146.                   (vlax-release-object o)
  1147.                 )
  1148.                 ( (= (type obj) 'pickset)
  1149.                   (setq i 0)
  1150.                   (repeat (sslength obj)
  1151.                                 (setq o (vlax-ename->vla-object (ssname obj i)))
  1152.                                 (if (vlax-method-applicable-p o "Mirror")
  1153.                                         (progn
  1154.                                                 (vlax-invoke-method o "Mirror" (vlax-3d-point p1) (vlax-3d-point p2))
  1155.                                                 (if delete (vla-delete o))
  1156.                                         )
  1157.                                 )
  1158.                                 (vlax-release-object o)
  1159.                                 (setq i (1+ i))
  1160.                         )
  1161.                 )
  1162.         )
  1163.         out
  1164. )

  1165. (princ)

  1166. ;;;*************************************************************************
  1167. ;;; MODULE: dsx-Scale
  1168. ;;; DESCRIPTION: Scale method for picksets, entities or objects, returns nil, ignores osmode
  1169. ;;; ARGS: entity-or-object-or-pickset, point, scalefactor
  1170. ;;; EXAMPLE: (dsx-Scale sset pt1 2)
  1171. ;;;*************************************************************************

  1172. (defun dsx-Scale (obj pt scafac / i o)
  1173.         (cond
  1174.                 ( (= 'PICKSET (type obj))
  1175.                   (setq i 0)
  1176.                   (repeat (sslength obj)
  1177.                                 (setq o (dsx-MakeObject (ssname obj i)))
  1178.                                 (vla-ScaleEntity o (vlax-3d-point pt) scafac)
  1179.                                 (vlax-release-object o)
  1180.                                 (setq i (1+ i))
  1181.                         )
  1182.                 )
  1183.                 ( (= 'VLA-OBJECT (type obj))
  1184.                         (vla-ScaleEntity obj (vlax-3d-point pt) scafac)
  1185.                 )
  1186.                 ( (= 'ENAME (type obj))
  1187.                         (setq o (dsx-MakeObject obj))
  1188.                         (vla-ScaleEntity obj (vlax-3d-point pt) scafac)
  1189.                         (vlax-release-object o)
  1190.                 )
  1191.         )
  1192. )

  1193. (princ)

本帖被以下淘专辑推荐:

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 2个

财富等级: 恭喜发财

发表于 2005-11-22 16:46:37 | 显示全部楼层
[php];;;*************************************************************************;;;
;;; DSX-API-Excel.LSP                                                       ;;;
;;; Visual LISP ActiveX API for Excel 97, 2000 and XP                       ;;;
;;; Copyright (C)2002 David M. Stein, All rights reserved                   ;;;
;;;*************************************************************************;;;
;;; Version 2002.22 05/15/02: Initial release                               ;;;
;;;*************************************************************************;;;
;;; 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.                               ;;;
;;;*************************************************************************;;;

(vl-load-com)

;;;*************************************************************************
;;; MODULE: DSX-TypeLib-Excel
;;; DESCRIPTION: Returns typelib (olb) file for either Excel 97, 2000, or XP
;;; ARGS: none
;;; EXAMPLE: (DSX-TypeLib-Excel)
;;;*************************************************************************

(defun DSX-TypeLib-Excel ( / sysdrv tlb)
        (setq sysdrv (getenv "systemdrive"))
        (cond
                ( (setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel8.olb")))
                         tlb
                )
                ( (setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel9.olb")))
                  tlb
                )
                ( (setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel10.olb")))
                  tlb
                )
                ( (setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office\\Excel.exe")))
                        tlb
                )
                ( (setq tlb (findfile (strcat sysdrv "\\Program Files\\Microsoft Office\\Office10\\Excel.exe")))
                  tlb
                )
        )
)
                  
;;;*************************************************************************
;;; MODULE: DSX-Load-TypeLib-Excel
;;; DESCRIPTION: Loads typelib for Excel 97, 2000 or XP (whichever is found)
;;; ARGS: none
;;; EXAMPLE: (DSX-Load-TypeLib-Excel)
;;;*************************************************************************

(defun DSX-Load-TypeLib-Excel ( / tlbfile tlbver out)
  (dsx-princ "\n(DSX-Load-TypeLib-Excel)")
  (cond
    ( (null msxl-xl24HourClock)
      (if (setq tlbfile (DSX-TypeLib-Excel))
        (progn
                                        (setq tlbver (substr (vl-filename-base tlbfile) 6))
                                        (cond
                                                ( (= tlbver "9")  (princ "\nInitializing Microsoft Excel 2000...") )
                                                ( (= tlbver "8")  (princ "\nInitializing Microsoft Excel 97...") )
                                                ( (= (vl-filename-base tlbfile) "Excel.exe")
                                                         (princ "\nInitializing Microsoft Excel XP...")
                                                )
                                        )
                      (vlax-import-type-library
            :tlb-filename       tlbfile
                        :methods-prefix                 "msxl-"
                        :properties-prefix         "msxl-"
                        :constants-prefix         "msxl-"
                      )
                      (if msxl-xl24HourClock (setq out T))
                    )
                  )
    )
    ( T (setq out T) )
  )
        out
)

;;;*************************************************************************
;;; MODULE: DSX-Open-Excel-New
;;; DESCRIPTION: Opens a new session of Excel 97, 2000 or XP
;;; ARGS: display-mode ("SHOW" or "HIDE")
;;; EXAMPLE: (setq xlapp (DSX-Open-Excel-New "SHOW"))
;;;*************************************************************************

(defun DSX-Open-Excel-New (dmode / appsession)
  (dsx-princ "\n(DSX-Open-Excel-New)")
        (princ "\nCreating new Excel Spreadsheet file...")
        (cond
                ( (setq appsession (vlax-create-object "Excel.Application"))

      (vlax-invoke-method
        (vlax-get-property appsession 'WorkBooks)
        'Add
      )
                  (if (= (strcase dmode) "SHOW")
                          (vla-put-visible appsession 1)
                                (vla-put-visible appsession 0)
                        )
          )
  )
        appsession
)

;;;*************************************************************************
;;; MODULE: DSX-Open-Excel-Exist
;;; DESCRIPTION: Gets handle to existing (running) session of Excel 97, 2000, XP
;;; ARGS: xls-filename, display-mode ("SHOW" or "HIDE")
;;; EXAMPLE: (setq xlapp (DSX-Open-Excel-Exist "myfile.xls" "SHOW"))
;;;*************************************************************************

(defun DSX-Open-Excel-Exist (xfile dmode / appsession)
  (dsx-princ "\n(DSX-Open-Excel-Exist)")
        (princ "\nOpening Excel Spreadsheet file...")
  (cond
                ( (setq fn (findfile xfile))
                        (cond
                                ( (setq appsession (vlax-get-or-create-object "Excel.Application"))
                      (vlax-invoke-method
                        (vlax-get-property appsession 'WorkBooks)
                        'Open fn
                      )
                                  (if (= (strcase dmode) "SHOW")
                                          (vla-put-visible appsession 1)
                                                (vla-put-visible appsession 0)
                                        )
                                )
                        )
          )
                ( T (alert (strcat "\nCannot locate source file: " xfile)) )
  )
        appsession
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Put-ColumnList
;;; DESCRIPTION: Write each list member to a column (startcol) starting at row (startrow)
;;; ARGS: list, startrow, startcol
;;; EXAMPLE: (DSX-Excel-Put-ColumnList '("A" "B" "C") 1 2) puts members into cells (1,B) (2,B) (3,B) respectively
;;;*************************************************************************

(defun DSX-Excel-Put-ColumnList (lst startrow startcol)
  (dsx-princ "\n(DSX-Excel-Put-ColumnList)")
  (foreach itm lst
    (msxl-put-value
      (DSX-Excel-Get-Cell range startrow startcol)
      itm
    )
    (setq startrow (1+ startrow))
  ); repeat
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Put-RowList
;;; DESCRIPTION: Write each list member to row (startrow) starting at column (startcol)
;;; ARGS: list, startrow, startcol
;;; EXAMPLE: (DSX-Excel-Put-RowList '("A" "B" "C") 2 1) puts members into cells (1,B) (1,C) (1,D) respectively
;;;*************************************************************************

(defun DSX-Excel-Put-RowList (lst startrow startcol)
  (dsx-princ "\n(DSX-Excel-Put-RowList)")
  (foreach itm lst
    (msxl-put-value
      (DSX-Excel-Get-Cell range startrow startcol)
      itm
    )
    (setq startcol (1+ startcol))
  ); repeat
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Put-CellColor
;;; DESCRIPTION: Applies fill-color to specified cell
;;; ARGS: row, column, color (integer)
;;; EXAMPLE: (DSX-Excel-Put-CellColor 1 1 14) apply color #14 to cell (1,A)
;;;*************************************************************************

(defun DSX-Excel-Put-CellColor (row col intcol / rng)
  (setq rng (DSX-Excel-Get-Cell (msxl-get-ActiveSheet xlapp) row col))
  (msxl-put-colorindex (msxl-get-interior rng) intcol)
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Put-RowCellsColor
;;; DESCRIPTION: Applies fill-color to a row of cells
;;; ARGS: startrow, startcol, num-cols, color (integer)
;;; EXAMPLE: (DSX-Excel-Put-RowCellsColor 1 1 5 14) Start at row=1 col=1 repeat for 5 columns using color #14
;;;*************************************************************************

(defun DSX-Excel-Put-RowCellsColor
        (startrow startcol cols intcol / next)
  (dsx-princ "\n(DSX-Excel-Put-RowCellsColor)")

  (setq next startcol)
  (repeat cols
    (DSX-Excel-Put-CellColor startrow next intcol)
    (setq next (1+ next))
  )
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Put-ColumnCellsColor
;;; DESCRIPTION: Change fill color in a column of cells
;;; ARGS: startrow, startcol, num-rows, color (integer)
;;; EXAMPLE: (DSX-Excel-Put-ColumnCellsColor 1 1 5 14) Start at row=1 col=1 repeat for 5 rows using color #14
;;;*************************************************************************

(defun DSX-Excel-Put-ColumnCellsColor
        (startrow startcol rows intcol / next)
  (dsx-princ "\n(DSX-Excel-Put-ColumnCellsColor)")

  (setq next startrow)
  (repeat rows
    (DSX-Excel-Put-CellColor next startcol intcol)
    (setq next (1+ next))
  )
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Get-Cell
;;; DESCRIPTION: Get cell object relative to range using (relrow) and (relcol) offsets
;;; ARGS: range-object, relative-row, relative-col
;;; EXAMPLE: (DSX-Excel-Get-Cell rng1 2 2)
;;;*************************************************************************

(defun DSX-Excel-Get-Cell (rng relrow relcol)
  (dsx-princ "\n(DSX-Excel-Get-Cell)")
  (vlax-variant-value
    (msxl-get-item (msxl-get-cells rng)
      (vlax-make-variant relrow)
      (vlax-make-variant relcol)
    )
  )
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Get-CellValue
;;; DESCRIPTION: Return value in given cell (row, column) of active session object (xlapp)
;;; ARGS: row(int), column(int)
;;; EXAMPLE: (DSX-Excel-Get-CellValue 1 2)
;;;*************************************************************************

(defun DSX-Excel-Get-CellValue (row col)
  (dsx-princ "\n(DSX-Excel-Get-CellValue)")

  (vlax-variant-value
    (msxl-get-value
      (DSX-Excel-Get-Cell
        (msxl-get-ActiveSheet xlapp)
        row col
      )
    )
  )
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Get-RowValues
;;; DESCRIPTION: Returns a list of cell values within a given row
;;; ARGS: row-number(int), startcol, num-cells
;;; EXAMPLE: (DSX-Excel-Get-RowValues 3 1 20) get first 20 values in row 3
;;;*************************************************************************

(defun DSX-Excel-Get-RowValues
        (row startcol numcells / next out)
  (dsx-princ "\n(DSX-Excel-Get-RowValues)")

        (setq next startcol)
        (repeat numcells
                (setq out                (if out
                  (append out (list (DSX-Excel-Get-CellValue row next))); row x col
                  (list (DSX-Excel-Get-CellValue row next)); row x col
                                                                )
                                        next         (1+ next)
                )
        ); repeat
        out
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Get-ColumnValues
;;; DESCRIPTION: Returns a list of cell values within a given column
;;; ARGS: column-number(int), startrow, num-cells
;;; EXAMPLE: (DSX-Excel-Get-ColumnValues 2 1 20) get top-20 entries in column 2 ("B")
;;;*************************************************************************

(defun DSX-Excel-Get-ColumnValues
        (col startrow numcells / next out)
  (dsx-princ "\n(DSX-Excel-Get-ColumnValues)")

        (setq next startrow)
        (repeat numcells
                (setq out
                        (if out
        (append out (list (DSX-Excel-Get-CellValue next col)))
        (list (DSX-Excel-Get-CellValue next col))
                        )
                                        next (1+ next)
                )
        ); repeat
        out
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-GetRangeValues-ByRows
;;; DESCRIPTION: Get range values in row order and return as nested lists
;;; ARGS: startrow, startcol, num-rows, num-cols
;;; EXAMPLE: (DSX-Excel-GetRangeValues-ByRows 1 1 5 10) get range values from 1A to 5J where each sublist is one row
;;;*************************************************************************

(defun DSX-Excel-GetRangeValues-ByRows
        (startrow startcol numrows numcols / nextrow rowlst outlst)
  (dsx-princ "\n(DSX-Excel-GetRangeValues-ByRows)")
        (setq nextrow startrow)
        (repeat numrows
    (setq rowlst  (DSX-Excel-Get-RowValues nextrow startcol numcols)
                                        outlst  (if outlst (append outlst (list rowlst)) (list rowlst))
                                  nextrow (1+ nextrow)
                )
        )
        outlst
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-GetRangeValues-ByCols
;;; DESCRIPTION: Get range values in column order and return as nested lists
;;; ARGS: startrow, startcol, num-rows, num-cols
;;; EXAMPLE: (DSX-Excel-GetRangeValues-ByCols 1 1 5 10) get range values from 1A to 5J where each sublist is one column
;;;*************************************************************************

(defun DSX-Excel-GetRangeValues-ByCols
  (startrow startcol numrows numcols / nextrow nextcol collst outlst)
  (dsx-princ "\n(DSX-Excel-GetRangeValues-ByCols)")
        (setq nextcol startcol)
        (repeat numcols
    (setq collst  (DSX-Excel-Get-ColumnValues nextcol startrow numrows)
                                        outlst  (if outlst (append outlst (list collst)) (list collst))
                                  nextcol (1+ nextcol)
                )
        )
        outlst
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Get-ActiveWorkSheet
;;; DESCRIPTION: Returns object of active worksheet in active Excel session
;;; ARGS: app (session object)
;;; EXAMPLE: (DSX-Excel-Get-ActiveWorkSheet xlapp)
;;;*************************************************************************

(defun DSX-Excel-Get-ActiveWorkSheet (xlapp)
  (dsx-princ "\n(DSX-Excel-Get-ActiveWorkSheet)")
        (msxl-get-ActiveSheet xlapp)
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-RangeAutoFit
;;; DESCRIPTION: Applies Auto-Fit to columns within active range
;;; ARGS: active-sheet (object)
;;; EXAMPLE: (DSX-Excel-RangeAutoFit myxlws)
;;;*************************************************************************

(defun DSX-Excel-RangeAutoFit (active-sheet)
        (dsx-princ "\n(DSX-Excel-RangeAutoFit)")
        (vlax-invoke-method
                (vlax-get-property
                        (vlax-get-property
                                (vlax-get-property active-sheet 'UsedRange)
                                'Cells
                        )
                        'Columns
                )
                'AutoFit
        )
)

(defun DSX-Excel-RangeDataFormat (active-sheet)
        (dsx-princ "\n(DSX-Excel-RangeDataFormat)")
        (vlax-put-property
                (vlax-get-property active-sheet "Cells")
                'NumberFormat "@"
        )
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Quit
;;; DESCRIPTION: Quit and close Excel session (app)
;;; ARGS: app (session object)
;;; EXAMPLE: (DSX-Excel-Quit xlapp)
;;;*************************************************************************

(defun DSX-Excel-Quit (appsession)
  (dsx-princ "\n(DSX-Excel-Quit)")
        (cond
                ( (not (vlax-object-released-p appsession))
                        (vlax-invoke-method appsession 'QUIT)
                        (vlax-release-object appsession)
                )
        )
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Kill
;;; DESCRIPTION: Forces any open Excel sessions to be closed
;;; ARGS: none
;;; EXAMPLE: (DSX-Excel-Kill)
;;;*************************************************************************

(defun DSX-Excel-Kill ( / eo)
        (while (setq eo (vlax-get-object "Excel.Application"))
                (DSX-Excel-Quit eo)
                (vlax-release-object eo)
                (setq eo nil)
                (gc)(gc);; even this doesn't always kill the damn thing!
  )
)

;;;*************************************************************************
;;; MODULE:
;;; DESCRIPTION:
;;; ARGS:
;;; EXAMPLE:
;;;*************************************************************************
;;; Remove trailing 'nil' members from a given list

(defun DSX-TrimList (lst)
        (cond
                ( (/= nil (last lst)) lst)
                ( T
      (DSX-TrimList (reverse (cdr (reverse lst))))
                )
        )
)

;;;*************************************************************************
;;; MODULE:
;;; DESCRIPTION:
;;; ARGS:
;;; EXAMPLE:
;;;*************************************************************************
;;; Convert a list of values into a list of string equivalents

(defun DSX-ListStr (lst / mbr out)
        (setq out '())
        (foreach mbr lst
                (cond
                        ( (= mbr nil) (setq out (cons "" out)) )
                        ( (= (type mbr) 'STR)
                          (if (member mbr '(" " "  " "   "))
                                        (setq out (cons "" out))
                                  (setq out (cons mbr out))
                                )
                        )
                        ( (= (type mbr) 'INT) (setq out (cons (itoa mbr) out)) )
                        ( (= (type mbr) 'REAL)(setq out (cons (rtos mbr 2 6) out)))
                )
        )
        (reverse out)
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-Sheets
;;; DESCRIPTION: Returns SHEETS collection from active workbook
;;; ARGS: Excel-application
;;; EXAMPLE: (setq sheets (DSX-Excel-Sheets xlApp))
;;;*************************************************************************

(defun DSX-Excel-Sheets (xlapp)
        (setq xlsheets         (vlax-get-property xlapp "sheets"))
)

;;;*************************************************************************
;;; MODULE:DSX-Excel-SheetDelete
;;; DESCRIPTION: Delete sheet (tab) from active workbook sheets collection
;;; ARG: sheet-name, sheets-collection
;;; EXAMPLE: (DSX-Excel-SheetDelete "Sheet3" xlSheets)
;;;*************************************************************************

(defun DSX-Excel-SheetDelete (name xlsheets)
        (vlax-for sh xlsheets
                (if (= (vlax-get-property sh "Name") name)
                        (vlax-invoke-method sh "Delete")
                )
        )
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-SheetAdd
;;; DESCRIPTION: Add new sheet (tab) to sheets collection in workbook, returns sheet object
;;; ARG: sheet-name, sheets-collection
;;; EXAMPLE: (setq newsheet (DSX-Excel-SheetAdd "SheetX" xlSheets))
;;;*************************************************************************

(defun DSX-Excel-SheetAdd (name xlsheets)
        (setq newsheet                 (vlax-invoke-method xlsheets "Add"))
        (vlax-put-property newsheet "Name" name)
        newsheet
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-WorkbookSave
;;; DESCRIPTION: Saves active workbook to specified filename, if file exists, it is overwritten if user accepts prompt
;;; ARG: workbook-object, filename
;;; EXAMPLE: (DSX-Excel-WorkbookSave objWB "myfile.xls")
;;;*************************************************************************

(defun DSX-Excel-WorkbookSave (workbook filename)
  (if (findfile filename)
                (vlax-invoke-method awb "Save")
                (vlax-invoke-method awb "SaveAs"
                        filename msxl-xlNormal "" ""
                        :vlax-False :vlax-False nil
                )
        )
)

;;;*************************************************************************
;;; MODULE: DSX-Excel-ActiveWorkbook
;;; DESCRIPTION: Returns active workbook object from given Excel application session
;;; ARG: Excel-application
;;; EXAMPLE: (setq objWB (DSX-Excel-ActiveWorkbook xlApp))
;;;*************************************************************************

(defun DSX-Excel-ActiveWorkbook (xlapp)
        (vlax-get-property xlapp "ActiveWorkbook")
)

(princ)[/php]

版主加分,很受鼓舞!再贴,
[php];;;*************************************************************************;;;
;;; API-MENUS.LSP                                                           ;;;
;;; Visual LISP ActiveX Menu/Toolbar Method Utilities                       ;;;
;;; Copyright (C)2001 David M. Stein, All Rights Reserved.                  ;;;
;;;*************************************************************************;;;
;;; Version 2001.00 06/06/01: Initial release                               ;;;
;;;*************************************************************************;;;

(vl-load-com)
(setq $acad (vlax-get-acad-object)
      $adoc (vla-get-activedocument $acad)
)

;;;*************************************************************************
;;; DESCRIPTION: Returns vla-object to menugroups collection
;;;*************************************************************************

(defun Get-MenuGroups ()
  (vla-get-MenuGroups $acad)
)

;;;*************************************************************************
;;; DESCRIPTION: Returns menugroup object for given menugroup name (string)
;;;*************************************************************************

(defun Get-MenuGroup (mgname)
        (if (menugroup mgname)
                (vla-item (Get-MenuGroups) mgname)
        )
)

;;;*************************************************************************
;;; DESCRIPTION: Adds new menugroup to menugroup collection, returns menugroup object
;;;*************************************************************************

(defun MenuGroup-Add (mgname)
        (vla-Add (Get-MenuGroups) mgname)
)

;;;*************************************************************************
;;; DESCRIPTION: Removes named menugroup from menugroups collection
;;;*************************************************************************

(defun MenuGroup-Delete (mgname)
        (if (setq mg (Get-MenuGroup mgname))
                (vla-Delete mg)
        )
)

;;;*************************************************************************
;;; MODULE: MenuGroups-ListAll
;;; DESCRIPTION: Returns list of all menugroup names in current application session
;;; ARGS: none
;;; EXAMPLE: (Get-MenuGroups-ListAll) --> ("ACAD" "ASW2K" "ASW2K-P" ...)
;;;*************************************************************************

(defun MenuGroups-ListAll ( / out)
  (vlax-for each (Get-MenuGroups)
                (setq out (cons (vla-get-name each) out))
        )
        out
)

;;;*************************************************************************
;;; DESCRIPTION: Boolean test for existence of named menugroup, returns menugroup object if found
;;;*************************************************************************

(defun MenuGroup-Exists-p (name)
        (Get-MenuGroup name)
)

;;;*************************************************************************
;;; DESCRIPTION: Returns vla-object to popupmenus collection for named menugroup
;;;*************************************************************************

(defun PopupMenus (mgroup / mg)
        (if (setq mg (Get-MenuGroup mgroup))
                (vla-get-Menus mg)
                (princ (strcat "\nMenugroup not found: " mgroup))
        )
)

;;;*************************************************************************
;;; DESCRIPTION: Returns list of all popup menu names for given menugroup
;;;*************************************************************************

(defun PopupMenus-ListAll (mgroup / pm out)
  (if (setq pm (ASW-PopupMenus mgroup))
                (vlax-for each pm
                        (setq out (cons (vla-get-Name each) out))
                )
        )
        out
)

;;;*************************************************************************
;;; DESCRIPTION: Returns popupmenu object from specified menugroup object
;;;*************************************************************************

(defun PopupMenu (mgroup popname)
        (vla-item (ASW-PopupMenus mgroup) popname)
)

;;;*************************************************************************
;;; MODULE: PopupMenu-ListSubs
;;; DESCRIPTION: Returns list of submenu captions (not labels) for popupmenu object
;;; ARGS: popupmenu-object
;;; EXAMPLE: (ASW-PopupMenu myPopMenu) --> ("File" "Edit" "View" "Draw" "Modify"...)
;;;*************************************************************************

(defun PopupMenu-ListSubs (oPopupMenu / i out)
        (setq i 0)
        (repeat (vla-get-Count oPopupMenu)
                (setq out
                                                (cons
                                                        (vla-get-Caption (vla-Item oPopupMenu i))
                                                        out
                                                )
                                        i (1+ i)
                )
        ); repeat
        (if out (reverse out))
)

; IAcadPopupMenu: An AutoCAD cascading menu
;
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00a876f8>
;   Count (RO) = 20
;   Name = "&ShipWorks"
;   NameNoMnemonic (RO) = "ShipWorks"
;   OnMenuBar (RO) = -1
;   Parent (RO) = #<VLA-OBJECT IAcadPopupMenus 00f648b4>
;   ShortcutMenu (RO) = 0
;   TagString (RO) = "ID_ASW000"
; Methods supported:
;   AddMenuItem (3)
;   AddSeparator (1)
;   AddSubMenu (2)
;   InsertInMenuBar (1)
;   Item (1)
;   RemoveFromMenuBar ()

; IAcadPopupMenuItem: A single menu item on an AutoCAD pull-down menu
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00a876f8>
;   Caption (RO) = "File..."
;   Check = 0
;   Enable = -1
;   EndSubMenuLevel = 0
;   HelpString = ""
;   Index (RO) = 0
;   Label = "File..."
;   Macro = ""
;   Parent (RO) = #<VLA-OBJECT IAcadPopupMenu 00ecc9f8>
;   SubMenu (RO) = #<VLA-OBJECT IAcadPopupMenu 00ecc998>
;   TagString = ""
;   Type (RO) = 2
; Methods supported:
;   Delete ()

; IAcadPopupMenuItem: A single FLY-OUT menu item on an AutoCAD pull-down menu
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00a876f8>
;   Caption (RO) = "Fast-Plot..."
;   Check = 0
;   Enable = -1
;   EndSubMenuLevel = 0
;   HelpString = "Execute one-click plot to selected device: FPLOT"
;   Index (RO) = 5
;   Label = "Fast-Plot..."
;   Macro = "\003\003\020FPLOT "
;   Parent (RO) = #<VLA-OBJECT IAcadPopupMenu 00ecc9f8>
;   SubMenu (RO) = Exception occurred
;   TagString = "ID_Print1"
;   Type (RO) = 0
; Methods supported:
;   Delete ()

;;;*************************************************************************
;;; MODULE: PopupMenu-SubMenu
;;; DESCRIPTION: Returns submenu object for given submenu within a PopupMenu object
;;; ARGS: popupmenu-object, submenu-name
;;; EXAMPLE: (ASW-PopupMenu-SubMenu myPopMenu "Flyout1...")
;;;*************************************************************************

(defun PopupMenu-SubMenu
        (oPopupMenu subname / tries out looked found)
       
        (setq tries (vla-get-Count oPopupMenu) looked 0)
       
        (while
                (and
                        (< looked tries)
                        (not found)
                )
                (if (= subname (vla-get-Label (vla-item oPopupMenu looked)))
                        (progn
                                (setq found T)
                                (vla-get-SubMenu (vla-item oPopupMenu looked))
                        )
                        (setq looked (1+ looked))
                )
        )
)

;;;*************************************************************************
;;; MODULE: Toolbars
;;; DESCRIPTION: Returns toolbars collection object for specified menugroup
;;; ARGS: menugroup-name (string)
;;; EXAMPLE: (ASW-Toolbars "ASW2K") --> [vla-object]
;;;*************************************************************************

(defun Toolbars (mgroup / mg)
        (if (setq mg (ASW-MenuGroup mgroup))
                (vla-get-Toolbars mg)
                (princ (strcat "\nMenugroup not found: " mgroup))
        )
)

;;;*************************************************************************
;;; MODULE: Toolbars-ListAll
;;; DESCRIPTION: Returns list of toolbar names for specified menugroup
;;; ARGS: menugroup-name (string)
;;; EXAMPLE: (ASW-Toolbars-ListAll "ASW2K") --> ("Toolbar1" "Toolbar2" ...)
;;;*************************************************************************

(defun Toolbars-ListAll (mgroup / tb out)
  (if (setq tb (ASW-Toolbars mgroup))
                (vlax-for each tb
                        (setq out (cons (vla-get-name each) out))
                )
        )
        out
)

;;;*************************************************************************
;;; MODULE: Toolbar-Exists-p
;;; DESCRIPTION: Returns T if toolbar exists within name menugroup toolbar collection
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar-Exists-p "ASW2K" "ASW: Sheets") returns T
;;;*************************************************************************

(defun Toolbar-Exists-p (mgroup tbname)
        (and
                (ASW-MenuGroup mgroup)
                (ASW-Toolbar mgroup tbname)
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar
;;; DESCRIPTION: Returns vla-object to a named toolbar within a named menugroup
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar myMenuGroup "ASW: Sheets") --> [vla-object]
;;;*************************************************************************

(defun Toolbar (mgroup tbname / loc)
  (vla-item (ASW-Toolbars mgroup) tbname)
)

; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00a876f8>
;   Count (RO) = 0
;   DockStatus (RO) = 4
;   FloatingRows = 1
;   Height (RO) = 52
;   HelpString = ""
;   LargeButtons (RO) = 0
;   left = 212
;   Name = "Foo"
;   Parent (RO) = #<VLA-OBJECT IAcadToolbars 00f6b924>
;   TagString (RO) = "ID_Foo_0"
;   top = 186
;   Visible = -1
;   Width (RO) = 27
; Methods supported:
;   AddSeparator (1)
;   AddToolbarButton (5)
;   Delete ()
;   Dock (1)
;   Float (3)
;   Item (1)

;;;*************************************************************************
;;; MODULE: Toolbar-Add
;;; DESCRIPTION: Adds toolbar to given menugroup, returns toolbar object
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar-Add "ASW2K" "MyToolbar1")
;;;*************************************************************************

(defun Toolbar-Add (mgroup name)
        (vla-Add (ASW-Toolbars mgroup) name)
)

;;;*************************************************************************
;;; MODULE: Toolbar-Delete
;;; DESCRIPTION: Removes named toolbar from menugroup object collection
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar-Delete "ASW2K" "MyToolbar1")
;;;*************************************************************************

(defun Toolbar-Delete (mgroup tbname / tb)
        (if (setq tb (ASW-Toolbar mgroup tbname))
                (vla-Delete tb)
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar-ButtonNames
;;; DESCRIPTION: Returns list of button names for a given toolbar object
;;; ARGS: toolbar (vla-object)
;;; EXAMPLE: (ASW-Toolbar-ButtonNames myToolbar) --> ("Button1" "Button2" ...)
;;;*************************************************************************

(defun Toolbar-ButtonNames (tbobject / i out)
        (setq i 0)
        (repeat (vla-get-count tbobject)
                (setq out (cons (vla-get-Name (vla-Item tbobject i)) out))
                (setq i (1+ i))
        )
        out
)

;;;*************************************************************************
;;; MODULE: Toolbar-Button
;;; DESCRIPTION: Returns button object from given toolbar using button name
;;; ARGS: toolbar (vla-object), button-name (string)
;;; EXAMPLE: (ASW-Toolbar-Button myToolbar "Button1")
;;;*************************************************************************

(defun Toolbar-Button (tbobject btname / out)
        (vla-Item tbobject btname)
)

; IAcadToolbarItem: A single button item on an AutoCAD toolbar
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00a876f8>
;   Flyout (RO) = AutoCAD: The toolbar item is not a flyout button
;   HelpString = "Insert a plain or reducing coupling: CPL"
;   Index (RO) = 0
;   Macro = "\003\003\020(ASWLF (list '(c:pff07 \"pff07\")))\npff07 "
;   Name = "Coupling"
;   Parent (RO) = #<VLA-OBJECT IAcadToolbar 00f676bc>
;   TagString = "ID_ASWP023"
;   Type (RO) = 0
; Methods supported:
;   AttachToolbarToFlyout (2)
;   Delete ()
;   GetBitmaps (2)
;   SetBitmaps (2)

;;;*************************************************************************
;;; MODULE: Toolbar-ButtonAdd
;;; DESCRIPTION: Add new button to given toolbar object, returns button object
;;; ARGS: toolbar-object, button-name, macro-string, bitmap-name, tagstring, helpstring
;;; EXAMPLE: (ASW-Toolbar-ButtonAdd myToolbar "Button1" "\003\003\020\nLine" "ICON_16_LINE" "Button001" "Draws a line: LINE")
;;;*************************************************************************

(defun Toolbar-ButtonAdd
        (tbobject name macro bitmap1 tagstring helpstring / newButton index)
        (setq index (vla-get-Count tbobject))
        (cond
                ( (setq newButton (vla-AddToolbarButton tbobject
                                                                                                (vlax-make-variant index vlax-vbInteger)
                                                                                                name
                                                                                                helpstring
                                                                                                macro
                                                                                        )
                        )
                  (vla-put-TagString newButton tagstring)
                  (vla-SetBitMaps newButton bitmap1 bitmap1)
                  newButton
                )
        )
)

(defun C:ADDTB ( / tb buttons)
        (if
                (or
                        (setq tb (ASW-Toolbar G$APP "Foo"))
                        (setq tb (ASW-Toolbar-Add G$APP "Foo"))
                )
                (progn
                        (setq buttons (vla-get-Count tb))
                        (ASW-Toolbar-ButtonAdd tb (strcat "Button" (itoa buttons))
                                "\003\003\020\nLINE"
                                "ICON_16_LINE"
                                (strcat "FooButton" (itoa buttons))
                                "Draws a line: LINE"
                        )
                )
        )
        (princ)
)

(defun C:DELTB ( / tb buttons)
        (if (setq tb (ASW-Toolbar G$APP "Foo"))
                (progn
                        (vla-Delete tb)
                        (vlax-release-object tb)
                )
        )
        (princ)
)

;;;*************************************************************************
;;; MODULE: Toolbar-ButtonDelete
;;; DESCRIPTION: Removes named button from given toolbar object
;;; ARGS: toolbar-object, button-name
;;; EXAMPLE: (ASW-Toolbar-ButtonDelete myToolbar "Button1")
;;;*************************************************************************

(defun Toolbar-ButtonDelete (tbobject name / btn)
        (if (setq btn (ASW-Toolbar-Button tbobject name))
                (progn
                        (vla-Delete btn)
                        (vlax-release-object btn)
                )
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar-Show
;;; DESCRIPTION: Un-Hides a named toolbar
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar-Show "ASW2K" "ASW: Sheets")
;;;*************************************************************************

(defun Toolbar-Show (mgroup tbname / tb)
  (if (setq tb (ASW-Toolbar mgroup tbname))
          (if (= (vla-get-Visible tb) :vlax-False)
                        (progn
                                (vla-put-Visible tb :vlax-True)
                                T
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar-Hide
;;; DESCRIPTION: Hides a named toolbar
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar-Hide "ASW2K" "ASW: Sheets")
;;;*************************************************************************

(defun Toolbar-Hide (mgroup tbname / tb)
  (if (setq tb (ASW-Toolbar mgroup tbname))
          (if (= (vla-get-Visible tb) :vlax-True)
                        (progn
                          (vla-put-Visible tb :vlax-False)
                                T
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar-Dock
;;; DESCRIPTION: Dock named toolbar in one of four locations
;;; ARGS: menugroup-name, toolbar-name, location (acToolbarDockTop, acToolbarDockBottom, acToolbarDockLeft, acToolbarDockRight)
;;; EXAMPLE: (ASW-Toolbar-Dock "ASW2K" "Sheets" 2) --> docks on left side of window
;;;*************************************************************************;;;

(defun Toolbar-Dock (mgroup tbname dock / tb)
  (if (setq tb (ASW-Toolbar mgroup tbname))
          (if (= (vla-get-Visible tb) :vlax-True)
                        (if (member dock '(0 1 2 3))
                                (progn
                                        (vla-Dock tb dock)
                                        1
                                )
                                -2 ;; invalid parameter value
                        )
                        -1 ;; toolbar not visible
          )
                0 ;; toolbar not found
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar-DockTop
;;; DESCRIPTION: Dock named toolbar at top of screen
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar-DockTop "ASW2K" "ASW: PowerPlot")
;;;*************************************************************************

(defun Toolbar-DockTop (mgroup tbname)
        (if (setq tbobject (ASW-Toolbar mgroup tbname))
                (vla-Dock tbobject acToolbarDockTop)
                (princ (strcat "\nToolbar (" tbname ") not found."))
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar-DockBottom
;;; DESCRIPTION: Dock named toolbar at bottom of screen
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar-DockBottom "ASW2K" "ASW: PowerPlot")
;;;*************************************************************************

(defun Toolbar-DockBottom (mgroup tbname)
        (if (setq tbobject (ASW-Toolbar mgroup tbname))
                (vla-Dock tbobject acToolbarDockBottom)
                (princ (strcat "\nToolbar (" tbname ") not found."))
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar-DockLeft
;;; DESCRIPTION: Dock named toolbar at left of screen
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar-DockLeft "ASW2K" "ASW: PowerPlot")
;;;*************************************************************************

(defun Toolbar-DockLeft (mgroup tbname)
        (if (setq tbobject (ASW-Toolbar mgroup tbname))
                (vla-Dock tbobject acToolbarDockLeft)
                (princ (strcat "\nToolbar (" tbname ") not found."))
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar-DockRight
;;; DESCRIPTION: Dock named toolbar at right of screen
;;; ARGS: menugroup-name, toolbar-name
;;; EXAMPLE: (ASW-Toolbar-DockRight "ASW2K" "ASW: PowerPlot")
;;;*************************************************************************

(defun Toolbar-DockRight (mgroup tbname)
        (if (setq tbobject (ASW-Toolbar mgroup tbname))
                (vla-Dock tbobject acToolbarDockRight)
                (princ (strcat "\nToolbar (" tbname ") not found."))
        )
)

;;;*************************************************************************
;;; MODULE: Toolbar-Float
;;; DESCRIPTION: Position named toolbar at specified location
;;; ARGS: menugroup-name, toolbar-name, top-int, left-int, rows-int
;;; EXAMPLE: (ASW-Toolbar-Float "ASW2K" "Sheets" 200 300 1)
;;;*************************************************************************

(defun Toolbar-Float (mgroup tbname top left rows)
  (if (setq tb (ASW-Toolbar mgroup tbname))
                (if (= (vla-get-Visible tb) :vlax-True)
                        (progn
                                (vla-Float tb top left rows)
                                1
                        )
                        -1 ;; toolbar not visible
                )
                0 ;; toolbar not found
        )
)

;;;*************************************************************************\
;;; MODULE: Menu-Locate
;;; DESCRIPTION: Returns full path+filename for named menu file
;;; ARGS: menu-filename (without extension)
;;; EXAMPLE: (ASW-Menu-Locate "asw2k")
;;;************************************************************************;;;

(defun MENU-LOCATE (mnfn)
        (DPR "\n(ASW-MENU-LOAD)")
       
        (cond
                ;( (findfile (strcat mnfn ".mnc")) )
                ;( (findfile (strcat mnfn ".mns")) )
                ( (findfile (strcat mnfn ".mnu")) )
                ( (findfile (strcat G$MENU "\\" mnfn ".mnu")) )
                ( (findfile (strcat G$ASL  "\\" mnfn ".mnu")) )
                ( (findfile (strcat G$SYS "\\Menu\\" mnfn ".mnu")) )
                ( T nil )
        )
)

;;;********************************************************************
;;; Force menu reload/recompile
;;;********************************************************************

(if (null C:UPDATE)
        (defun C:UPDATE ()
                (load "update.vlx")
                (C:UPDATE)
                (princ)
        )
)

;;;*************************************************************************
;;; MODULE: Menu-ReLoadAll
;;; DESCRIPTION: Reloads and repositions (merges) all ShipWorks menu stubs
;;; ARGS: none
;;; EXAMPLE: (ASW-Menu-ReLoadAll)
;;;********************************************************************

(defun MENU-RELOADALL ( / cmdstr appkey local_copy client-menu)
        (DPR "\n(ASW-MENU-RELOADALL)")
        (setq client-menu (vl-filename-base G$PRO))
        (setq cmdstr (strcat "COPY " G$MENU "\\ASW2K.MNU " G$DAT "\\ASW2K.MNU"))
        (vl-cmdf "SHELL" cmdstr)
        (setq cmdstr (strcat "COPY " G$ASL "\\" G$APP ".MNU " G$DAT "\\" G$APP ".MNU"))
        (vl-cmdf "SHELL" cmdstr)
        (cond
                ( (findfile (strcat G$MENU "\\" client-menu ".MNU"))
                  (setq cmdstr (strcat "COPY " G$MENU "\\" client-menu ".MNU " G$DAT "\\" client-menu ".MNU"))
                  (vl-cmdf "SHELL" cmdstr)
                )
        )
               
        (princ "\nMenus downloaded to client folder.")
        (cond
                ( (menugroup "ASW2K")
                  (DPR "\nRemoving base services menu stub...")
                  (vl-cmdf "MENUUNLOAD" "ASW2K")
          )
        )
        (cond
                ( (setq local_copy (findfile (strcat G$DAT "\\asw2k.mnu")))
                  (vl-cmdf "MENULOAD" local_copy)
                        (if (menugroup "ASW2K")
                                (menucmd "P4=+ASW2K.POP1")
                                (princ "\nFailed (1)!")
                        )
          )
          ( T (princ "\nFailed (2)!") )
        )
       
        (cond
                ( (menugroup G$APP)
                  (foreach appkey '("ASW2K-S" "ASW2K-E" "ASW2K-P" "ASW2K-V")
                                (if (menugroup appkey)
                                        (vl-cmdf "MENUUNLOAD" appkey)
                                )
                        )
                )
        )
        (cond
                ( (setq local_copy (findfile (strcat G$DAT "\\" G$APP ".mnu")))
                  (vl-cmdf "MENULOAD" local_copy)
                  (if (menugroup G$APP)
                          (menucmd (strcat "P5=+" G$APP ".POP1"))
                                (princ "\nFailed (3)!")
                        )
                )
                ( T
                  (princ "\nFailed (4)!")
                )
        )
        (cond
                ( (menugroup client-menu)
                  (DPR "\nRemoving client-specific menu stub...")
                  (vl-cmdf "MENUUNLOAD" client-menu)
                )
        )
        (cond
                ( (setq local_copy (findfile (strcat G$DAT "\\" client-menu ".mnu")))
                  (vl-cmdf "MENULOAD" local_copy)
                  (if (menugroup client-menu)
                          (menucmd (strcat "P6=+" client-menu ".POP1"))
                                (princ "\nFailed (5)!")
                        )
                )
                ( T
                  (princ "\nFailed (6)!")
                )
        )
)

;;;*************************************************************************
;;; MODULE: MenuMerge
;;; DESCRIPTION: Loads and positions all ShipWorks menu stubs
;;; ARGS: none
;;; EXAMPLE: (ASW-MenuMerge)
;;;********************************************************************

(defun MenuMerge
        ( / local_copy remote_copy client-menu)
  (DPR "\n(ASW-MenuMerge)")
        (cond
                ( (menugroup "ASW2K")
                  (vl-cmdf "MENUUNLOAD" "ASW2K")
                  (if (setq local_copy (findfile (strcat G$DAT "\\asw2k.mnu")))
                                (vl-File-Delete local_copy)
                        )
                  (vl-File-Copy (strcat G$MENU "\\asw2k.mnu") (strcat G$DAT "\\asw2k.mnu"))
                  (if (setq local_copy (findfile (strcat G$DAT "\\asw2k.mnu")))
                          (progn
                                        (vl-cmdf "MENULOAD" local_copy)
                                        (menucmd "P4=+ASW2K.POP1")
                                )
                                (princ "\nFailed to reload new base menu update.")
                        )
                )
                ;; Cond-2: Local MNU exists, load it
                ( (and
                                (not (menugroup "ASW2K"))
                                (setq local_copy (findfile (strcat G$DAT "\\asw2k.mnu")))
                        )
                  (DPR "\nReloading from local directory...")
                  (vl-cmdf "MENULOAD" local_copy)
                  (if (menugroup "ASW2K")
                                (menucmd "P4=+ASW2K.POP1")
                                (princ "\nFailed to load local copy of ShipWorks Base menu.")
                        )
                )
                ;; Cond-3: Remote MNU exists, copy to local, load local copy
                ( (and
                                (not (menugroup "ASW2K"))
                                (setq remote_copy (findfile (strcat G$MENU "\\asw2k.mnu")))
                                (vl-File-Copy remote_copy (strcat G$DAT "\\asw2k.mnu"))
                                (setq local_copy (findfile (strcat G$DAT "\\asw2k.mnu")))
                        )
                  ;(vl-cmdf "delay" 400)
                  (DPR "\nReloading from new download copy...")
                        (vl-cmdf "MENULOAD" local_copy)
                  (if (menugroup "ASW2K")
                                (menucmd "P4=+ASW2K.POP1")
                                (princ "\nFailed to load remote copy of ShipWorks Base menu.")
                        )
                )
                ;; Cond-4: Horrible failure, cry in shame
                ( T (princ "\nSystem failure: Unable to download server menu update."))
        ); cond
        (setq remote_copy nil local_copy nil)
        (cond
                ( (menugroup G$APP)
                  (vl-cmdf "MENUUNLOAD" G$APP)
                  (if (setq local_copy (findfile (strcat G$DAT "\\" G$APP ".mnu")))
                                (vl-File-Delete local_copy)
                        )
                  (vl-File-Copy (strcat G$ASL "\\" G$APP ".mnu") (strcat G$DAT "\\" G$APP ".mnu"))
                  (if (setq local_copy (findfile (strcat G$DAT "\\" G$APP ".mnu")))
                          (progn
                                        (vl-cmdf "MENULOAD" local_copy)
                                        (menucmd (strcat "P5=+" G$APP ".POP1"))
                                )
                                (princ "\nFailed to reload new extended services menu update.")
                        )
                );; Cond-2: Local MNU exists, load it
                ( (and
                                (not (menugroup G$APP))
                                (setq local_copy (findfile (strcat G$DAT "\\" G$DAT ".mnu")))
                        )
                  (DPR "\nReloading from local directory...")
                        (vl-cmdf "MENULOAD" local_copy)
                        (if (menugroup G$APP)
                                (menucmd (strcat "P5=+" G$APP ".POP1"))
                                (princ "\nFailed to load local copy of extended services menu.")
                        )
                )
                ;; Cond-3: Remote MNU exists, copy to local, load local copy
                ( (and
                                (not (menugroup G$APP))
                                (setq remote_copy (findfile (strcat G$ASL "\\" G$APP ".mnu")))
                                (vl-File-Copy remote_copy (strcat G$DAT "\\" G$APP ".mnu"))
                                (setq local_copy (findfile (strcat G$DAT "\\" G$APP ".mnu")))
                        )
                  ;(vl-cmdf "delay" 400)
                  (DPR "\nReloading from downloaded copy...")
                  (vl-cmdf "MENULOAD" local_copy)
                  (if (menugroup G$APP)
                          (menucmd (strcat "P5=+" G$APP ".POP1"))
                                (princ "\nFailed to load remote copy of extended services menu.")
                        )
                )
                ;; Cond-4: Oh my God, two failures?  What a shame
                ( T (princ "\nSystem Failure: Unable to download server menu update.") )
        ); cond
        (DPR "\nChecking for project-based client menus...")
        (setq client-menu (vl-filename-base G$PRO))
        (cond
                ( (menugroup client-menu)
                  (vl-cmdf "MENUUNLOAD" client-menu)
                  (if (setq local_copy (findfile (strcat G$DAT "\\" client-menu ".mnu")))
                                (vl-File-Delete local_copy)
                        )
                  (vl-File-Copy (strcat G$MENU "\\" G$APP ".mnu") (strcat G$DAT "\\" client-menu ".mnu"))
                  (if (setq local_copy (findfile (strcat G$DAT "\\" client-menu ".mnu")))
                          (progn
                                        (vl-cmdf "MENULOAD" local_copy)
                                        (menucmd (strcat "P6=+" client-menu ".POP1"))
                                )
                                (princ "\nFailed to reload new client-specific menu update.")
                        )
                );; Cond-2: Local MNU exists, load it
                ( (and
                                (not (menugroup client-menu))
                                (setq local_copy (findfile (strcat G$DAT "\\" client-menu ".mnu")))
                        )
                  (DPR "\nReloading from local directory...")
                        (vl-cmdf "MENULOAD" local_copy)
                        (if (menugroup client-menu)
                                (menucmd (strcat "P6=+" client-menu ".POP1"))
                                (princ "\nFailed to load local copy of client-specific menu.")
                        )
                )
                ;; Cond-3: Remote MNU exists, copy to local, load local copy
                ( (and
                                (not (menugroup client-menu))
                                (setq remote_copy (findfile (strcat G$MENU "\\" client-menu ".mnu")))
                                (vl-File-Copy remote_copy (strcat G$DAT "\\" client-menu ".mnu"))
                                (setq local_copy (findfile (strcat G$DAT "\\" client-menu ".mnu")))
                        )
                  ;(vl-cmdf "delay" 400)
                  (DPR "\nReloading from downloaded copy...")
                  (vl-cmdf "MENULOAD" local_copy)
                  (if (menugroup client-menu)
                          (menucmd (strcat "P6=+" client-menu ".POP1"))
                                (princ "\nFailed to load remote copy of client-specific menu.")
                        )
                )
                ;; Cond-4: Oh my God, two failures?  What a shame
                ( T (princ "\nSystem Failure: Unable to download server menu update.") )
        )       
        (DPR "\nSearching for Express Tools stub menu to load...")
       
  (cond
    ( (and
        (not (menugroup "EXPRESS"))
                                (or
                (setq expmn (findfile "acetmain.mnu"))
                                        (setq expmn (findfile "express.mnu"))
                                )
                        )
                  (princ "\nLoading AutoCAD Express Tools menus...")
      (vl-cmdf "_.MENULOAD" expmn)
      (if (menugroup "EXPRESS")
        (menucmd "P9=+EXPRESS.POP1")
        (alert "Failed to load Express Tools menus...")
      )
    )
  )
); defun

;;;*************************************************************************
;;; MODULE: Menu-DeleteFiles
;;; DESCRIPTION: Deletes all four extension-type files for named menu file
;;; ARGS: basename (without extension), pathname
;;; EXAMPLE: (ASW-Menu-DeleteFiles "mymenu" "c:\\mystuff")
;;;*************************************************************************

(defun MENU-DeleteFiles
        (menubase pathname / mnuext mnu)
        (DPR "\n(ASW-MENU-DeleteFiles)")
        (foreach mnuext '(".mnu" ".mns" ".mnc" ".mnr")
                (if (setq mnu (findfile (strcat pathname "\\" menubase mnuext)))
                        (progn
                                (DPR (strcat "\nDeleting menu file: " mnu))
                                (vl-File-Delete mnu)
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: Menu-CompareDates
;;; DESCRIPTION: Compare file dates, returns T if file1 is same or newer than file2
;;; ARGS: filename1, filename2
;;; EXAMPLE: (ASW-Menu-CompareDates localMenu serverMenu) returns T (filename1 is same or newer than filename2)
;;;*************************************************************************

(defun Menu-CompareDates (f1 f2 / st1 st2)
        (if
          (and
                        (setq f1 (findfile f1))
                        (setq f2 (findfile f2))
                        (setq st1 (vl-file-systime f1)); (2001 2 2 13 10 53 12 855)
                        (setq st2 (vl-file-systime f2)); (2001 2 2 13 10 53 12 855)
                )
                (if (> (nth 0 st1) (nth 0 st2));; newer year?
                        T
                        (if (= (nth 0 st1) (nth 0 st2));; same year?
                                (if (> (nth 1 st1) (nth 1 st2));; newer month?
                                        T
                                        (if (> (nth 3 st1) (nth 3 st2));; newer day of month?
                                                T
                                                (if (= (nth 3 st1) (nth 3 st2));; same day of month?
                                                        (if (> (nth 4 st1) (nth 4 st2));; newer hour of day?
                                                                T
                                                                (if (= (nth 4 st1) (nth 4 st2));; same hour of day?
                                                                        (if (>= (nth 5 st1) (nth 5 st1));; newer minutes of same hour?
                                                                                T
                                                                        )
                                                                )
                                                        )
                                                )
                                        )
                                )
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: Menu-CheckDates
;;; DESCRIPTION: Compare menu filenames dates between two folders
;;; ARGS: none
;;; EXAMPLE:
;;;*************************************************************************

(defun Menu-CheckDates
        (forceload / choice fail)
        (DPR "\n(ASW-Menu-CheckDates)")
        (cond
                ( (not
                                (ASW-Menu-CompareDates
                                        (strcat G$DAT "\\asw2k.mnu")
                                        (strcat G$MENU "\\asw2k.mnu")
                                )
                        )
                  (setq fail 1)
                )
        )
        (cond
                ( (not
                                (ASW-Menu-CompareDates
                                        (strcat G$DAT "\\" G$APP ".mnu")
                                        (strcat G$ASL "\\" G$APP ".mnu")
                                )
                        )
                  (if fail
                                (setq fail 2)
                                (setq fail -1)
                        )
                )
        )
        (cond
                ( (= fail 1) (DPR "\nBase menu failed comparison.") )
                ( (= fail 2) (DPR "\nBoth menus failed comparison.") )
                ( (= fail -1)(DPR "\nExtended menu failed comparison.") )
                ( T (DPR "\nMenus are up to date.") )
        )
        (cond
                ( (and fail (not forceload))
                        (setq choice
                                (DOS_MsgBox
                                        (strcat
                                                        "One of your ShipWorks menus is out of date."
                                                "\nYou can update it now by picking the Yes"
                                                "\nbutton, or pick No to defer until later.\n"
                                                "\nIf you defer now, you will be reminded each"
                                                "\ntime you open a drawing until you update."
                                        )
                                        "ShipWorks Menu Update"
                                        4 3
                                )
                        )
                  (if (= 6 choice)
                                (ASW-MENU-RELOADALL)
                                (princ "\nShipWorks menu update notice deferred.")
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: Toolbars-HideAll
;;; DESCRIPTION: Hide all toolbars related to specified menugroup
;;; ARGS: menugroup-name
;;; EXAMPLE: (ASW-Toolbars-HideAll "ASW2K")
;;;*************************************************************************

(defun Toolbars-HideAll (mgroup / tbars)
        (cond
                ( (setq tbars (asw-toolbars-listall mgroup))
                  (foreach tbar tbars
                                (ASW-Toolbar-Hide mgroup tbar)
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: Toolbars-ShowAll
;;; DESCRIPTION: Show all toolbars related to specified menugroup
;;; ARGS: menugroup-name
;;; EXAMPLE: (ASW-Toolbars-ShowAll "ASW2K")
;;;*************************************************************************

(defun Toolbars-ShowAll (mgroup / tbars)
        (cond
                ( (setq tbars (asw-toolbars-listall mgroup))
                  (foreach tbar tbars
                                (ASW-Toolbar-Show mgroup tbar)
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: Toolbars-Hidden
;;; DESCRIPTION: Returns list of toolbars that are hidden for a specified menugroup
;;; ARGS: menugroup-name
;;; EXAMPLE: (ASW-Toolbars-Hidden "ASW2K") returns ("toolbar1" "toolbar2"...)
;;;*************************************************************************

(defun Toolbars-Hidden (mgroup / tbars each tbar)
        (cond
                ( (setq tbars (ASW-Toolbars-ListAll mgroup))
                  (foreach each tbars
                                (setq tbar (ASW-Toolbar mgroup each))
                                (if (= :vlax-True (vla-get-Visible tbar))
                                        (setq out (cons (vla-get-name tbar) out))
                                )
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: C:TBOFF
;;; DESCRIPTION: Turns off ShipWorks toolbars
;;; ARGS: none
;;; EXAMPLE:
;;;*************************************************************************

(defun C:TBOFF ( / hbars1 hbars2)
        (setq G$TBOFF1 (KWORD '("A""V") "Hide All toolbars or Visible toolbars only..." G$TBOFF1 T))
        (cond
                ( (= G$TBOFF1 "V")
                  (setq G$TBOFF2 (ASW-Toolbars-Hidden "ASW2K"))
                  (setq G$TBOFF3 (ASW-Toolbars-Hidden G$APP))
                )
        )
        (ASW-Toolbars-HideAll "ASW2K")
        (ASW-Toolbars-HideAll G$APP)
        (princ)
)

;;;*************************************************************************
;;; MODULE: C:TBON
;;; DESCRIPTION: Turns on ShipWorks toolbars
;;; ARGS: none
;;; EXAMPLE:
;;;*************************************************************************

(defun C:TBON ( / opt)
        (cond
                ( (and G$TBOFF1 (= G$TBOFF1 "V") (or G$TBOFF2 G$TBOFF3))
                  (setq opt (KWORD '("A""H") "Display All toolbars or only those Hidden before..." opt T))
                  (cond
                                ( (= opt "A")
                                        (ASW-Toolbars-ShowAll "ASW2K")
                                        (ASW-Toolbars-ShowAll G$APP)
                                )
                                ( T
                                  (if G$TBOFF2
                                          (vlax-for each (ASW-Toolbars "ASW2K")
                                                        (setq tbname (vla-get-name each))
                                                        (if (member tbname G$TBOFF2)
                                                                (ASW-Toolbar-Show "ASW2K" tbname)
                                                        )
                                                )
                                        )
                                  (if G$TBOFF3
                                          (vlax-for each (ASW-Toolbars G$APP)
                                                        (setq tbname (vla-get-name each))
                                                        (if (member tbname G$TBOFF3)
                                                                (ASW-Toolbar-Show G$APP tbname)
                                                        )
                                                )
                                        )
                                )
                        ); cond
                )
                ( T
                        (ASW-Toolbars-ShowAll "ASW2K")
                        (ASW-Toolbars-ShowAll G$APP)
                )
        )
        (princ)
)

;;;*************************************************************************
;;; MODULE: Menu-SaveAll
;;; DESCRIPTION: Saves all ShipWorks menu settings to MNS or MNC files
;;; ARGS: menu-type ("mns" or "mnc") not case sensitive, nil = "mns"
;;; EXAMPLE: (ASW-Menu-SaveAll "mnc") returns nil
;;;*************************************************************************

(defun MENU-SAVEALL (mtype)
        (DPR "\n(ASW-MENU-SAVEALL)")
        (vlax-for each (Get-MenuGroups)
                (if (wcmatch (strcase (vla-get-name each)) "ASW2K*")
                        (if (= (strcase mtype) "MNC")
                                (vla-save each acMenuFileCompiled)
                                (vla-save each acMenuFileSource)
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: MenuUpdate-LoadClientMenus
;;; DESCRIPTION: Loads client menu files as menugroups for ShipWorks session
;;; ARGS: none
;;; EXAMPLE:
;;;*************************************************************************

(defun MenuUpdate-LoadClientMenus
        ( / mg svclist svcmnu)
        (ASW-PRINC "\n(ASW-MenuUpdate-LoadClientMenus)")
        (princ "\nLoading ShipWorks menugroups from client folder...")
        (setq svclist
                '("ASW2K-E" "&Electrical" "ASW2K-P" "&Piping" "ASW2K-S" "&Structure" "ASW2K-V" "HVAC")
                                svcmnu (cadr (member G$APP svclist))
        )
        (cond
                ( (not (menugroup "asw2k"))
                  (if (setq mg (asw-menu-load "asw2k" (strcat G$DAT "\\asw2k.mnu")))
                                (progn
                                        (if (ASW-PopMenu-Insert "asw2k" "&ShipWorks" 4)
                                                (princ "\nBase menubar loaded from file.")
                                        )
                                        (vlax-release-object mg)
                                )
                        )
                )
                ( T
                  (if (not (ASW-PopMenu-MenuBar-p "&ShipWorks"))
                                (if (ASW-PopMenu-Insert "asw2k" "&ShipWorks" 4)
                                        (princ "\nBase menubar loaded.")
                                        (princ "\nFailed to get base popmenu from menugroup collection.")
                                )
                        )
                )
        )
        (if
                (and
                        (/= G$APP "ASW2K-E")
                        (menugroup "ASW2K-E")
                )
                (ASW-Menu-UnLoad "ASW2K-E")
        )
        (if
                (and
                        (/= G$APP "ASW2K-P")
                        (menugroup "ASW2K-P")
                )
                (ASW-Menu-Unload "ASW2K-P")
        )
        (if
                (and
                        (/= G$APP "ASW2K-S")
                        (menugroup "ASW2K-S")
                )
                (ASW-Menu-Unload "ASW2K-S")
        )
        (if
                (and
                        (/= G$APP "ASW2K-V")
                        (menugroup "ASW2K-V")
                )
                (ASW-Menu-Unload "ASW2K-V")
        )
        (cond
                ( (not (menugroup G$APP))
                  (if (setq mg (asw-menu-load G$APP (strcat G$DAT "\\" G$APP ".mnu")))
                                (progn
                                        (if (ASW-PopMenu-Insert G$APP svcmnu 5)
                                                (princ (strcat "\nService menubar loaded from file: " G$APP))
                                        )
                                        (vlax-release-object mg)
                                )
                        )
                )
                ( T
                         (if (not (ASW-PopMenu-MenuBar-p svcmnu))
                                (if (ASW-PopMenu-Insert G$APP svcmnu 5)
                                        (princ "\nServer menubar loaded.")
                                        (princ "\nFailed to get service popmenu from menugroup collection.")
                                )
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: MenuUpdate-DeleteClientFiles
;;; DESCRIPTION: Deletes client-side menu files for ShipWorks
;;; ARGS: none
;;; EXAMPLE:
;;;*************************************************************************

(defun MenuUpdate-DeleteClientFiles
        ( / mfile)
        (ASW-PRINC "\n(ASW-MenuUpdate-DeleteClientFiles)")
        (foreach mext '(".mnu" ".mns" ".mnc" ".mnr")
                (if (setq mfile (findfile (strcat G$DAT "\\asw2k" mext)))
                        (if (vl-file-delete mfile)
                                (princ);(princ (strcat "\nDeleted menu file: " mfile))
                                (princ (strcat "\nFailed to delete menu file: " mfile))
                        )
                )
        )
        (foreach mext '(".mnu" ".mns" ".mnc" ".mnr")
                (if (setq mfile (findfile (strcat G$DAT "\\" G$APP mext)))
                        (if (vl-file-delete mfile)
                                (princ);(princ (strcat "\nDeleted menu file: " mfile))
                                (princ (strcat "\nFailed to delete menu file: " mfile))
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: MenuUpdate-UnloadMenus
;;; DESCRIPTION: Unloads all ShipWorks menugroups
;;; ARGS: none
;;; EXAMPLE:
;;;*************************************************************************

(defun MenuUpdate-UnloadMenus ()
        (ASW-PRINC "\n(ASW-MenuUpdate-UnloadMenus)")
        (princ "\nUnloading ShipWorks menugroups...")
        (ASW-Menu-Unload "asw2k")
        (foreach n '("ASW2K-E" "ASW2K-P" "ASW2K-S" "ASW2K-V")
                (ASW-Menu-Unload n)
        )
)

;;;*************************************************************************
;;; MODULE: MenuUpdate-DownloadMenus
;;; DESCRIPTION: Downloads server files to client for all ShipWorks menus
;;; ARGS: none
;;; EXAMPLE:
;;;*************************************************************************

(defun MenuUpdate-DownloadMenus
        ( / msrc1 msrc2 mtarget1 mtarget2 go)
        (ASW-PRINC "\n(ASW-MenuUpdate-DownloadMenus)")
        (cond
                ( (setq msrc1 (findfile (strcat G$MENU "\\asw2k.mnu")))
                  (if (setq mtarget1 (findfile (strcat G$DAT "\\asw2k.mnu")))
                                (if (vl-file-delete mtarget1)
                                        (setq go T)
                                )
                                (setq go T)
                        )
                  (if go
                                (if (vl-file-copy msrc1 (strcat G$DAT "\\asw2k.mnu"))
                                        (princ "\nBase menu file downloaded successfully.")
                                        (princ "\nFailed to download base menu file!")
                                )
                                (princ "\nFailed to remove client base menu cache, download failed.")
                        )
                )
        )
        (setq go nil)
        (cond
                ( (setq msrc2 (findfile (strcat G$MENU "\\" G$APP ".mnu")))
                  (if (setq mtarget2 (findfile (strcat G$DAT "\\" G$APP ".mnu")))
                                (if (vl-file-delete mtarget2)
                                        (setq go T)
                                )
                                (setq go T)
                        )
                  (if go
                                (if (vl-file-copy msrc2 (strcat G$DAT "\\" G$APP ".mnu"))
                                        (princ "\nService menu file downloaded successfully.")
                                        (princ "\nFailed to download service menu file!")
                                )
                                (princ "\nFailed to remove client service menu cache, download failed.")
                        )
                )
        )
)
                 
(defun ObjErr (errobj)
        (princ (strcat "\nError: " (vl-catch-all-error-message errobj)))
)

(defun Obj-ReleaseAll (objects)
        (foreach obj objects
                (if (= (type obj) 'vla-object); symbol bound to vla-object type?
                        (if (not (vlax-object-released-p obj)); not already released?
                                (vlax-release-object obj); release it!
                        )
                )
                (set (quote obj) nil)
        )
)

;;;*************************************************************************
;;; MODULE: Menu-LoadPartialMenus
;;; DESCRIPTION: Loads default menu items for ShipWorks at start-up
;;; ARGS: none
;;; EXAMPLE: (ASW-Menu-LoadPartialMenus)
;;;*************************************************************************

(defun Menu-LoadPartialMenus
        ( / mgroups mgnames omg mgf)
        (ASW-Princ "\n(ASW-Menu-LoadPartialMenus)")
        (if (not (menugroup "asw2k"))
                (progn
                        (ASW-MenuUpdate-UnloadMenus)
                        (ASW-MenuUpdate-DeleteClientFiles)
                        (ASW-MenuUpdate-DownloadMenus)
                        (ASW-MenuUpdate-LoadClientMenus)
                )
                (ASW-MenuUpdate-LoadClientMenus)
        )
        (setq mgroups (Get-MenuGroups)
                                mgnames (Get-MenuGroups-listall)
        )
        (if (and C:UPDATE (null (menugroup "asw2k"))) (C:UPDATE))
        (if (not (menugroup G$APP))
                (progn
                        (princ "\nReloading extended services menu group...")
                        (foreach mg '("ASW2K-E" "ASW2K-P" "ASW2K-S" "ASW2K-V")
                                (if
                                        (and
                                                (member mg mgnames)
                                                (setq omg (vla-item mg mgroups))
                                        )
                                        (vla-unload omg)
                                        (vlax-release-object omg)
                                )
                        ); foreach - unload
                        (cond
                                ( (or
                                                (setq mgf (findfile (strcat G$APP ".mns")))
                                                (setq mgf (findfile (strcat G$APP ".mnc")))
                                        )
                                  (princ "\nLoading ShipWorks partial menu data...")
                                  (vla-load mgroups mgf)
                                  (if (menugroup G$APP)
                                                (menucmd (strcat "P5=+" G$APP ".POP1"))
                                                (princ (strcat "\nUnable to load partial menu for service: " G$APP))
                                        )
                                )
                                ( T
                                  (C:UPDATE)
                                )
                        )
                )
                (princ "\nMenugroup already loaded."); menugroup already loaded, do nothing
        )
        (princ)
)

;;;*************************************************************************
;;; MODULE: Menu-Unload
;;; DESCRIPTION: Unloads specified menugroup, returns if successful or menugroup not loaded
;;; ARGS: menugroup-name
;;; EXAMPLE: (ASW-Menu-Unload "ASW2K")
;;;*************************************************************************

(defun Menu-Unload (name / omg)
        (ASW-PRINC "\n(ASW-Menu-Unload)")
        (if (menugroup name)
                (if (setq omg (vla-item (Get-MenuGroups) name))
                        (progn
                                (vla-unload omg)
                                (vlax-release-object omg)
                                T
                        )
                )
                T
        )
)

;;;*************************************************************************
;;; MODULE: Menu-Reload
;;; DESCRIPTION: Reloads menugroup popmenu if loaded, loads otherwise
;;; ARGS: menugroup-name, path to menufile
;;; EXAMPLE:
;;;*************************************************************************

(defun Menu-Reload (name path / mnu1)
        (ASW-PRINC "\n(ASW-Menu-Reload)")
  (cond
                ( (menugroup name)
                  (menucmd (strcat "P5=+" name ".POP1"))
                )
                ( (or
                                (setq mnu1 (findfile (strcat path "\\" name ".mns")))
                                (setq mnu1 (findfile (strcat path "\\" name ".mnc")))
                        )
                  (vl-cmdf "_.menuload" mnu1)
                  (menucmd (strcat "P5=+" name ".POP1"))
                )
                ( T (C:UPDATE) )
        )
)

(defun PopMenu-Insert (mgroup name loc / pmnu)
        (ASW-PRINC "\n(ASW-PopMenu-Insert)")
        (if (not (ASW-PopMenu-MenuBar-p name))
          (if (setq pmnu (ASW-PopupMenu mgroup name))
                        (progn
                                (vla-insertinmenubar pmnu loc)
                                (vlax-release-object pmnu)
                                T
                        )
                        (princ (strcat "\nMenugroup or popmenu not loaded or defined: " name))
                )
                (princ (strcat "\nPopmenu already loaded: " name))
        )
)

;;;*************************************************************************
;;; MODULE: PopMenu-Remove
;;; DESCRIPTION: Removes specified popmenu from menubar, returns nil
;;; ARGS: menugroup-name, pop-menu-name
;;; EXAMPLE: (ASW-PopMenu-Remove "ASW2K" "&ShipWorks")
;;;*************************************************************************

(defun PopMenu-Remove (mgname name / pmnu)
        (ASW-PRINC "\n(ASW-PopMenu-Remove)")
        (if (menugroup mgname)
                (if (ASW-PopMenu-MenuBar-p name)
                        (if (setq pmnu (vla-item (vla-get-menubar (ASW-AcadObject)) name))
                                (progn
                                        (vla-removefrommenubar pmnu)
                                        (vlax-release-object pmnu)
                                        (princ (strcat "\nPopmenu successfully removed: " name))
                                )
                                (princ (strcat "\nPopmenu not found/Unable to remove: " name))
                        )
                        (princ (strcat "\nPopmenu not loaded/Unable to remove: " name))
                )
        )
)

;;;*************************************************************************
;;; MODULE: PopMenu-MenuBar-p
;;; DESCRIPTION: Returns T if menubar contains specified pop-menu item
;;; ARGS: pop-menu-name (string, case sensitive, includes mnemonics if used)
;;; EXAMPLE: (ASW-PopMenu-MenuBar-p "&ShipWorks") returns T or nil
;;;*************************************************************************

(defun PopMenu-MenuBar-p (name / mbar i found)
        (ASW-PRINC "\n(ASW-PopMenuLoaded)")
        (setq mbar (vla-get-menubar (asw-acadobject)) i 0)
        (while (and (not found) (< i (1- (vla-get-count mbar))))
                (if (= (strcase name) (strcase (vla-get-name (vla-item mbar i))))
                        (setq found T)
                )
                (setq i (1+ i))
        )
        (vlax-release-object mbar)
        found
)

;;;*************************************************************************
;;;*************************************************************************

(defun Toolbars-Backup (mgroup / tbars name show pair out $regpath)
        (ASW-PRINC "\n(ASW-Toolbars-Backup)")
        (setq $regpath (strcat "Menus\\Toolbars\\" mgroup))
        (cond
                ( (setq tbars (ASW-Toolbars mgroup))
                  (vlax-for each tbars
                                (setq name (vla-get-name each)
                                                        show (vla-get-visible each)
                                                        pair (list name (if (= show :vlax-true) "1" "0"))
                                                        out  (cons pair out)
                                )
                        )
                  (vlax-release-object tbars)
                  (if out
                                (progn
                                        (foreach tb out
                                                (ASW-RegSet (strcat $regpath "\\" (car tb)) (cadr tb))
                                        )
                                )
                        )
                )
                ( T (princ (strcat "\nMenugroup (" mgroup ") has no toolbars.")) )
        )
        out
)

;;;*************************************************************************
;;;*************************************************************************

(defun Toolbars-Restore (mgroup / keys $regpath dat out)
        (ASW-PRINC "\n(ASW-Toolbars-Restore)")
        (setq $regpath (strcat G$REGROOT "\\Menus\\Toolbars\\" mgroup))
        (cond
                ( (menugroup mgroup)
                  (cond
                                ( (setq keys (vl-registry-descendents $regpath))
                                  (foreach key keys
                                                (setq dat (vl-registry-read (strcat $regpath "\\" key) nil)
                                                                        out (cons (list key dat) out)
                                                )
                                        )
                                )
                                ( T (princ (strcat "\nNo saved toolbar info to retrieve: " mgroup)) )
                        )
                )
        )
        out
)

;;;*************************************************************************
;;; MODULE: Menu-Load
;;; DESCRIPTION: Loads menugroup from specified MNU, MNS or MNC file
;;; ARGS: menugroup-name, menufile
;;; EXAMPLE:
;;;*************************************************************************

(defun Menu-Load (mgroup mfile / mgroups omg)
        (ASW-PRINC "\n(ASW-Menu-Load)")
        (cond
                ( (not (menugroup mgroup))
                  (setq mgroups (Get-MenuGroups))
                  (if (findfile mfile)
                          (setq omg (vla-load mgroups (findfile mfile)))
                                (princ (strcat "\nUnable to load menu file: " mfile))
                        )
                )
                ( T (princ (strcat "\nMenugroup (" mgroup ") is alread loaded.")) )
        )
        omg
)

(princ)[/php]

再来,

[php];;;*************************************************************************;;;
;;; DSX-TableOut.LSP (VLX)                                                  ;;;
;;; Export Table Data to Excel Spreadsheet File                             ;;;
;;; Part of DSX Tools Suite                                                 ;;;
;;; Copyright (C)2001-2002 David M. Stein, All rights reserved.             ;;;
;;;*************************************************************************;;;
;;; Version 2001.00  07/13/01: Initial release.                             ;;;
;;; Version 2001.30  11/07/01: Updated for 1.3                              ;;;
;;; Version 2002.00  02/24/02: Updated for 2002.20 beta 5                   ;;;
;;; Version 2002.21  03/24/02: Fixed bugs, Dropped typelib interfacing      ;;;
;;;                            because of incompatabilities between Office  ;;;
;;;                            2000 and XP versions of Excel TypeLib sets.  ;;;
;;; Version 2002.22  04/26/02: Added data formatting option and preview     ;;;
;;;                            option for table formats                     ;;;
;;; Version 2002.30  07/21/02: Fixed bugs with Office XP interface          ;;;
;;; Version 2002.12.22: Added XML output option                             ;;;
;;;*************************************************************************;;;
;;; Global Variables...                                                     ;;;
;;;                                                                         ;;;
;;;         G$TBXL = Imported list of formats                               ;;;
;;;                                        G$TBXF = Export filename                                        ;;;
;;;         G$TBXT = Format selection (index) in formats list               ;;;
;;;         G$TBX1 = 1/0 toggle for Show Column Headings                    ;;;
;;;         G$TBX2 = 1/0 toggle for Auto-Fit Columns                        ;;;
;;;         G$TBX3 = Row height value                                       ;;;
;;;         G$TBX4 = Tab-name (worksheet name) in Excel                     ;;;
;;;         G$TBX5 = Apply cell data format as TEXT only to all cells       ;;;
;;;*************************************************************************;;;

(defun C:TABLEOUT
        ( / dch dloc opt ok $inifile)
        (defun *error* (s)
                (dsx-error s)
                (if (and xlapp (not (vlax-object-released-p xlapp))) (vlax-release-object xlapp))
                (setq master nil datalist nil basept nil nextpt nil)
                (gc)(gc); attempt to clear stack
                (dsx-undoend)
                (princ)
        )
        (setq $inifile (dsx-regget "TableOut\\TableDefFile" "data\\tableout.ini")
              dch  (load_dialog "dsx-tableout")
                                dloc (dsx-form-getloc "TableOutMain")
                                opt  (dsx-regget "TableOut\\FormatType" "1")
        )
        (if (not (new_dialog "main" dch "" dloc))
                (progn
                        (alert "DCL Load Failure (tableout:main)...")
                        (exit)
                )
        )
        (set_tile "option" opt)
        (action_tile "option" "(setq opt $value)")
        (action_tile "accept" "(setq ok 1 dloc (done_dialog))")
        (action_tile "cancel" "(princ)")
        (start_dialog)
        (unload_dialog dch)
        (cond
                ( (= ok 1)
                  (dsx-form-saveloc "TableOutMain" dloc)
                  (if (= opt "1")
                                (dsx-tableout-excel)
                                (dsx-tableout-xml)
                        )
                )
        )
        (princ)
)

(defun dsx-tableout-excel
        ( / tblforms ok master datalist basept nextpt
                        dch op1 op2 op3 op4 op5 op6
                        outfl form dloc
        )
       
        (dsx-princ "\n(dsx-tableout-excel)")
       
        ;;-------------------------------------
        ;; Main dialog interaction process...
        ;;-------------------------------------
       
        (setq dch  (load_dialog "dsx-tableout"))
        (setq dloc (dsx-form-getloc "TableOut"))
       
        ;; Set default global variable settings...
       
        (DSX-TBX-LoadForms nil); list of forms

  (dsx-princ "\nChecking default settings...")
       
        (setq G$TBXF (dsx-regget "TableOut\\ExcelFilename" "")
                                G$TBXT (dsx-regget "TableOut\\FormIndex" "0")
                                G$TBX1 (dsx-regget "TableOut\\ShowHeadings" "1")
                                G$TBX2 (dsx-regget "TableOut\\AutoFitColumns" "1")
                                G$TBX3 (dsx-regget "TableOut\\RowHeight" "0.25")
                                G$TBX4 (vl-filename-base (dsx-getvar "dwgname"))
                                G$TBX5 (dsx-regget "TableOut\\AutoDataFormat" "0")
                                G$TBX6 (dsx-regget "TableOut\\ExcelRetain" "1")
        )

  (if (not (new_dialog "excel" dch "" dloc))
                (progn
                        (alert "DCL Load Failure (tableout:excel)...")
                        (exit)
                )
        )
                 
        (dsx-listbox-fill1 "form" G$TBXL 0); fill popup-list with form names
       
        ;; Set tiles to default values/settings...
       
        (set_tile "1" G$TBX1)
        (set_tile "2" G$TBX2)
        (set_tile "3" G$TBX3)
        (set_tile "filename" G$TBXF)
        (set_tile "form" G$TBXT)
  (set_tile "4" G$TBX4)
        (set_tile "5" G$TBX5)
        (set_tile "6" G$TBX6)
       
        ;; Get actions from user...
       
        (action_tile "select"   "(DSX-TBX-SelectFile)")
        (action_tile "filename" "(DSX-TBX-ValidateFilename $value)")
        (action_tile "form"     "(setq form $value)")
        (action_tile "1"        "(setq op1 $value)")
        (action_tile "2"        "(setq op2 $value)")
        (action_tile "3"        "(setq op3 $value)")
  (action_tile "4"        "(setq op4 $value)")
        (action_tile "5"        "(setq op5 $value)")
        (action_tile "6"        "(setq op6 $value)")
  (action_tile "edit"     "(DSX-TBX-EditForms)")
        (action_tile "show"     "(DSX-TBX-FormInfo)")
       
        (action_tile "help"     "(DSX-TBX-ShowHelp)")
        (action_tile "accept"   "(setq ok 1 dloc (done_dialog))")
        (action_tile "cancel"   "(princ)")
        (start_dialog)
        (unload_dialog dch)
                       
        ;; Check action results, save global variable changes
        ;; Execute process to extract data from table...
       
        (cond
                ( (= ok 1)
                  (dsx-form-saveloc "TableOut" dloc)
                  (if outfl (setq G$TBXF outfl))
                  (if form  (setq G$TBXT form))
                  (if op1   (setq G$TBX1 op1))
                  (if op2   (setq G$TBX2 op2))
                  (if op3   (setq G$TBX3 op3))
                  (if op4   (setq G$TBX4 op4))
                  (if op5   (setq G$TBX5 op5))
                  (if op6   (setq G$TBX6 op6))
                  
                        (dsx-regset "TableOut\\ExcelFilename" G$TBXF)
                        (dsx-regset "TableOut\\FormIndex" G$TBXT)
                        (dsx-regset "TableOut\\ShowHeadings" G$TBX1)
                        (dsx-regset "TableOut\\AutoFitColumns" G$TBX2)
                        (dsx-regset "TableOut\\RowHeight" G$TBX3)
                  (dsx-regset "TableOut\\AutoDataFormat" G$TBX5)
                  (dsx-regset "TableOut\\ExcelRetain" G$TBX6)

                  ;(DSX-TBX-SaveOutputFilename G$TBXF)

                  (setq G$TBXX (nth (atoi G$TBXT) G$TBXL))
                  (if (setq G$TBXROW (cdr G$TBXX))
                    (DSX-TBX-ExportTable)
                                (alert "System error: Rowset not defined...")
                        )
                )
        )
        (dsx-undoend);; close Undo block
)

;|
[9090-600 Electrical Install BOM]
Item=0.75
Qty=0.75
Description=5.0
MatlSpec=2.0
Material=1.25
PartNum=2.0
Source=0.75
APL=1.25
UnitWt=0.75
Remarks=5.5
|;

; Each sublist in the form of...

; ("9090-600 Electrical Install BOM" ("Item" "0.75") ("Qty" "0.75") ("Description" "5.0") ("MatlSpec" "2.0") ("Material" "1.25") ("PartNum" "2.0") ("Source" "0.75") ("APL" "1.25") ("UnitWt" "0.75") ("Remarks" "5.5"))

(defun DSX-TBX-FormInfo
        ( / fid fname fcols)
        (dsx-princ "\n(DSX-TBX-FormInfo)")
        (cond
                ( form
                  (setq fid (nth (atoi form) G$TBXL)
                                                fname (car fid); form name
                                                fcols (cdr fid); column pairs (name width)
                        )
                  (dos_proplist fname "Table Structure" fcols)
                )
        )
)

;;;*************************************************************************
;;; MODULE: DSX-TBX-ExportTable
;;; DESCRIPTION: Prompt to window table, then fetch row data into list and export
;;; ARGS: none
;;; EXAMPLE:
;;;*************************************************************************

(defun DSX-TBX-ExportTable
        (mode / rowh top-left bot-left top-right bot-right rownum nextpt datalist master)
        (dsx-princ "\n(DSX-TBX-ExportTable)")

        (setq rowh (atof (DSX-RegGet "TableOut\\RowHeight" G$TBX3));; row height
                    osm  (dsx-getvar "osmode");; save!
        )
        (DSX-SetVar "osmode" 1)

        (cond
                ( (and
                                (setq top-left  (getpoint "\nPick top-left of grid region: "))
                                (setq bot-right (getcorner top-left "\nPick bottom-right of grid region: "))
                        )

                  (dsx-setvar "osmode" 0)

                  (dsx-princ "\nSetting up region boundary points...")

                  (setq top-right (list (car bot-right) (cadr top-left)  0);; top-right
                                    bot-left  (list (car top-left)  (cadr bot-right) 0);; bottom-left
                                    rownum    (fix (/ (distance top-left bot-left) rowh));; number of rows in region
                                    nextpt    (dsx-ptoff top-left 0 (- rowh));; first row basepoint
                        ); setq

                  (princ (strcat "\n" (itoa rownum) " rows detected in region."))
                  (princ "\nScanning table region from top to bottom...")

                  (repeat rownum
                                (setq datalist (DSX-TBX-GetRowData nextpt);; row data list as string
                                      master   (if master  ;; master list
                                                                                                 (append master (list datalist))
                                                                                                 (list datalist)
                                                                                         )
                                nextpt   (dsx-ptoff nextpt 0 (- rowh));; increment row basepoint
                                ); setq
                        ); repeat

                  (dsx-princ "\nProcessing master list to prepare output...")

                        (cond
                                ( (and master (listp master) (> (length master) 0))
                          (cond
                                                ( (= mode 1)
                                                         (DSX-TBX-ExportExcel master)
                                                  (alert
                                                                (strcat
                                                                        "Spreadsheet file updated and saved:\n\n"
                                                                        (dsx-regget "TableOut\\ExcelFilename" G$TBXF);G$TBXF
                                                                )
                                                        )
                                                )
                                                ( (= mode 2)
                                                  (DSX-TBX-ExportXML master)
                                                  (dos_htmlbox "TableOut XML Report" G$TBXF 500 300)
                                                )
                                        )
                                )
                                ( T (alert "Failed to collect master table list...") )
                        ); cond
                )
                ( T (alert "Incomplete selection, operation cancelled.") )
        ); cond
); defun

;;;*************************************************************************
;;; MODULE: DSX-TBX-ExportExcel
;;; DESCRIPTION: Exports data list to Excel spreadsheet
;;; ARGS: datalist (list of lists)
;;; EXAMPLE:
;;;*************************************************************************

(defun DSX-TBX-ExportExcel
        (datlst
                 / xlapp ash range cursor out xlsheets newsheet awb xlFilename        oldSht dwg
                         exists rang1 rang1s rang1x rang1f span rng
        )
        (dsx-princ "\n(DSX-TBX-ExportExcel)")
        (cond
    ( (dsx-load-typelib-excel)
      (cond
                                ( (setq xlapp (vlax-create-object "Excel.Application"))
                                  (vlax-put-property xlapp "visible" :vlax-true)
                                        ;(setq xlFilename G$TBXF dwg G$TBX4)
       
                                  (if (setq fn (findfile G$TBXF))
                                                (progn
                                                        (setq exists T)
                                                        (princ (strcat "\nOpening file: " fn))
                                                        (vlax-invoke-method
                                                                (vlax-get-property xlapp "WorkBooks")
                                                                "Open" fn
                                                        )
                                                )
                                                (progn
                                                        (setq wbooks  (vlax-get-property xlapp "workbooks")
                                                                                newbook (vlax-invoke-method wbooks "add")
                                                        )
                                                )
                                        )
                                  
                                  (setq awb                  (vlax-get-property xlapp "ActiveWorkbook"))
                                  (setq xlsheets (vlax-get-property xlapp "sheets"))

                                  ; Note: I can't figure out why using the Item and Select methods
                                  ; on the Sheets collection won't accept the <dwg> string value
                                  ; even when it has been cast as an object of any type.  Therefore,
                                  ; I resort to iterating the collection until I find the sheet
                                  ; with a matching name and invoke the Delete method on it.

                                  ; Epilogue: I figured this out.  The ITEM method is actually not
                                  ; a 'method' but a property.  This only applies to worksheets,
                                  ; not to sheets, and you have to retrieve it by using the form
                                  ; (vlax-get-property worksheets "item" "name")  Due to laziness,
                                  ; nice weather and excessive beer intake, I am not up to modifying
                                  ; this section as such.  You can do that if you care to. - DMS
                                 
                                        (vlax-for sh xlsheets
                                                (if (= (vlax-get-property sh "Name") G$TBX4)
                                                        (vlax-invoke-method sh "Delete")
                                                )
                                        )

                                        (princ "\nAdding new worksheet to workbook...")
                                  (setq newsheet (vlax-invoke-method xlsheets "Add"))
                                  (vlax-put-property newsheet "Name" G$TBX4)

                                  (setq ash (vlax-get-property xlapp "activesheet")
                                                                rng (vlax-get-property xlapp "activecell")
                                                                cursor 1
                                        )
                                 
                                  (if (= "1" G$TBX1); show column headings?
                                                (setq datlst
                                                        (cons (DSX-TBX-FieldNames G$TBXROW) datlst)
                                                )
                                        )
                                 
                                  (if (= G$TBX5 "1") (dsx-excel-rangedataformat ash))
                                 
                                  (foreach row datlst
                                                (dsx-excel-rowput newsheet "A" (itoa cursor) row); function defined below
                                                (setq cursor (1+ cursor))
                                        )
                                  ;; The following section of code allows you to specify the
                                  ;; font properties for a selected range by first selecting
                                  ;; the range with given cell references, and then applying
                                  ;; the desired font properties to the selection object...

                                  ;; Select top-row if headings are shown and apply BOLD font...

                                  (cond
                                                ( (= G$TBX1 "1")
                                                  ;; Note: the "Rows" property will not accept a parameter
                                                  ;; of "1:1" as does the "Range" property, when invoked from
                                                  ;; Vlisp for some stupid ass reason.  Rows("1:1") selects
                                                  ;; row 1 infinite columns, whereas Range("A1:_1") must be
                                                  ;; calculated to select a finite range of columns.
                                                  (setq span    (strcat "A1:"
                                                                                                                                                (chr
                                                                                                                                                        (+ 64 (length G$TBXROW))
                                                                                                                                                )
                                                                                                                                                "1"
                                                                                                                )
                                                                                rang1         (vlax-get-property         xlapp  "Range" span)
                                                              rang1s         (vlax-invoke-method rang1  "Select")
                                                              rang1x         (vlax-get-property         xlapp  "Selection")
                                                              rang1f         (vlax-get-property         rang1x "Font")
                                                        )
                                                  (dsx-princ "\nApplying formatting to heading columns...")
                                                        (foreach prop
                                                                (list
                                                                        (list "Name"                                         "Verdana"); Arial, Tahoma, etc.
                                                                        (list "Size"                                         10); 8, 10, 12, 14, etc.
                                                                        (list "Bold"          :vlax-True)
                                                                        (list "ColorIndex"                 -4105);msxl-xlAutomatic
                                                                        (list "Strikethrough" :vlax-False)
                                                                        (list "Superscript"   :vlax-False)
                                                                        (list "Subscript"     :vlax-False)
                                                                        (list "OutlineFont"   :vlax-False)
                                                                        (list "Underline"     -4142);msxl-xlUnderlineStyleNone
                                                                        (list "Shadow"        :vlax-False)
                                                                )
                                                                (vlax-put-property rang1f (car prop) (cadr prop))
                                                        ); foreach
                                                  (setq rang1 (vlax-get-property xlapp "Range" "A1:A1"))
                                                  (vlax-invoke-method rang1 "Select")
                                                )
                                        )
                                  (dsx-princ "\nApplying column formatting...")
          (if (= G$TBX2 "1") (dsx-excel-rangeautofit ash))

                                  (dsx-princ "\nSelecting range to apply formatting...")
                                  (vlax-invoke-method
                                                (vlax-get-property ash "Cells")
                                                "Select"
                                        )
                                  (dsx-princ "\nApplying formatting to range...")
                                  (vlax-put-property
                                                (vlax-get-property xlapp "Selection")
                                                "VerticalAlignment" -4160;msxl-xlTop
                                        )
                                  (dsx-princ "\nSelecting range A1:A1 for default scope...")
                                  (vlax-invoke-method
                                                (vlax-get-property xlapp "Range" "A1:A1")
                                                "Select"
                                        )
                                  (dsx-princ "\nSaving workbook...")
                                  (if exists
                                                (vlax-invoke-method awb "Save")
                                          (vlax-invoke-method awb "SaveAs" G$TBXF
                                                        -4143;|msxl-xlNormal|; "" "" :vlax-False :vlax-False nil)
                                        )
                                        ;(dsx-excel-kill)
                                  (dsx-princ "\nReleasing objects...")
                                  (vlax-release-object rng)
                                  (vlax-release-object ash)
                                  (if (= G$TBX6 "0") (vlax-invoke-method xlapp "Quit"))
                                  (foreach obj
                                          (list rng ash range rang1 rang1x rang1s rang1f xlsheets newsheet awb xlapp)
                                          (if (= 'VLA-OBJECT (type obj))
                                                   (if (not (vlax-object-released-p obj))
                                                           (vlax-release-object obj)
                                                   )
                                          )
                                  )
                                  ;(vlax-release-object xlapp)
                                  ;(setq range nil ash nil xlapp nil)
                                  (gc);; Explicit clean-up after killing Excel is required!!!!!!!!!!!!!
                                  (gc);; Double-ensure garbage collection on Win2K and XP systems using Office XP!!!!!
                                  (princ (strcat "\nData saved to spreadsheet file: " G$TBXF))
        )
      )
    )
    ( T (alert "Failed to initialize type library for MS-Excel...") )
        )
  (princ)
)

;;;*************************************************************************
;;; MODULE:
;;; DESCRIPTION:
;;; ARGS:
;;; EXAMPLE:
;;;*************************************************************************

(defun DSX-TBX-DwgInfo ()
        (dsx-princ "\n(DSX-TBX-DwgInfo)")
        (strcat
                "Exported From: "
    (dsx-get-dwgname nil)
                " Username: " (getenv "username")
                " Date: " (Date)
                " Time: " (Time)
        )
)

;;;*************************************************************************
;;; MODULE: DSX-TBX-GetRowData
;;; DESCRIPTION: Fetch text string data for one row, return data as list of strings (each member denotes one cell in the row)
;;; ARGS: basepoint (bottom-left of row)
;;; EXAMPLE:
;;;*************************************************************************
;;; Fetch text data from row and return as a list of strings.  If a cell is
;;; empty, it's cell value is set to "" in the returned list.
;;;*************************************************************************

(defun DSX-TBX-GetRowData
        (pa / pb txlist cell cw tx ts)
        (dsx-princ "\n(DSX-TBX-GetRowData)")
        ;(SaveSnaps)
       
        (cond
                ( (and pa (listp pa));; if point was selected
                  (foreach cell G$TBXROW
                                (setq cw         (atof (cadr cell));; current cell width
                                                        pb         (dsx-ptoff pa cw rowh);; top-right of current cell
                                            ts  (DSX-TBX-GetCellData pa pb)
                                                        txlist (if txlist (append txlist (list ts)) (list ts));; append to return list
                                                        pa        (dsx-ptoff pa cw 0);; step over to next cell
                                )
                                (setq tx nil ts        nil)
                        ); foreach
                )
                ( T (princ) )
        ); cond
        ;(SetSnaps);; restore osnap setting
        txlist
)

;;;*************************************************************************
;;; MODULE: DSX-TBX-GetCellData
;;; DESCRIPTION: Fetches string values from a given cell defined by diagonal window points
;;; ARGS: point1, point2
;;; EXAMPLE:
;;;*************************************************************************
;;; Retrieve text data from one cell in a table row.  If multiple lines are
;;; collected, sort them from top-down and return as a single string using
;;; a special delimiter to denote line separation.  Delimiter is "^"
;;;*************************************************************************

(defun DSX-TBX-GetCellData
        (p1 p2 / sstxt return index txstr txdat yloc sortlst newsort item)
        (dsx-princ "\n(DSX-TBX-GetCellData)")
        (cond
                ( (setq sstxt (ssget "c" p1 p2 '((0 . "TEXT"))));; any text objects?
                        (dsx-princ "\nFound text objects in cell.")
                  (cond
                                ( (> (sslength sstxt) 1);; more than one found?
                                  (dsx-princ "\nMultiple text objects in cell.")
                                  (setq index 0 return "")

                                  (repeat (sslength sstxt)
                                                (setq txdat         (entget (ssname sstxt index));; properties list
                                                            txstr         (dxf 1 txdat);; string value
                                                            yloc          (cadr (dxf 10 txdat));; y-coordinate
                                                            sortlst (if sortlst
                                                                                                                (append sortlst        (list (list yloc txstr)))
                                                                                                                (list (list yloc txstr))
                                                                                                        ); if
                                                            index         (1+ index);; increment index
                                                ); setq
                                        ); repeat

                                  (dsx-princ "\nSorting cell data list...")
                                  (setq newsort (listsort 0 sortlst));; sort from bottom to top

                                  (foreach item (reverse newsort);; step thru in reverse order
                                                (setq return
                                                        (if (= return "")
                                                                (cadr item)
                                                          (strcat return " " (cadr item))
                                                        ); if
                                                ); setq
                                        ); foreach

                                  (setq sstxt nil)
                                  (dsx-princ " Done.")
                                )
                                ( T
                                  (dsx-princ "\nSingle text object in cell.")
                                  (setq return (DXF 1 (entget (ssname sstxt 0)))
                                        sstxt nil
                                        )
                                )
                        ); cond
                )
                ( T
                  (dsx-princ "\nCell is empty.")
                  (setq return "")
                )
        ); cond

        return

); defun

;;;*************************************************************************
;;; MODULE: DSX-TBX-FieldNames
;;; DESCRIPTION: Returns field names from column data list
;;; ARGS: column-data-list
;;; EXAMPLE:
;;;*************************************************************************

(defun DSX-TBX-FieldNames (lst / out)
        (dsx-princ "\n(DSX-TBX-FieldNames)")
        (foreach mbr lst
                (setq out (cons (car mbr) out))
        )
        (reverse out)
)

;;;*************************************************************************
;;; MODULE: DSX-TBX-ColumnJustify
;;; DESCRIPTION: Apply horizontal and vertical justifications to given column
;;; ARGS: column-letter, horiz-just-letter, vert-just-letter
;;; EXAMPLE: (DSX-TBX-ColumnJustify "B" "C" "T") justify column "B" as Top-Center
;;;*************************************************************************

(defun DSX-TBX-ColumnJustify (colltr hJust vJust / rang rangs rangx justH justV)
        (dsx-princ "\n(DSX-TBX-ColumnJustify)")
        (cond
                ( (setq rang (vlax-get-property xlapp "Columns" (strcat colltr ":" colltr)))
                  (setq rangs (vlax-invoke-method rang "Select"))
                  (setq rangx (vlax-get-property xlapp "Selection"))
                  (cond
                                ( (= hJust "R") (setq justH -4152) );msxl-xlRight) )
                                ( (= hJust "C") (setq justH -4108) );msxl-xlCenter) )
                                ( T (setq justH 1) );msxl-xlGeneral) )
                        )
                  (cond
                                ( (= vJust "T") (setq justV -4160) );msxl-xlTop) )
                                ( (= vJust "M") (setq justV -4143) );msxl-xlDefault) )
                                ( T (setq justV -4107) ); msxl-xlBottom) )
                        )
                  (vlax-put-property rangx "HorizontalAlignment" justH)
                  (vlax-put-property rangx "VerticalAlignment"   justV)
                )
        )
)

;;;*************************************************************************
;;; MODULE: DSX-TBX-Column-SetWidth
;;; DESCRIPTION: Apply column widths and text-wrapping to a given column
;;; ARGS: column-letter, width-value, wrap-text-flag
;;; EXAMPLE: (DSX-TBX-Column-SetWidth "B" 0.50 T) set column "B" width to 0.50 and apply text-wrapping
;;;*************************************************************************

(defun DSX-TBX-Column-SetWidth (colltr width wraptext / rang rangs rangx)
        (dsx-princ "\n(DSX-TBX-Column-SetWidth)")
        (cond
                ( (setq rang (vlax-get-property xlapp "Columns" (strcat colltr ":" colltr)))
                  (setq rangs (vlax-invoke-method rang "Select")
                        rangx (vlax-get-property xlapp "Selection")
                        )
                  (vlax-put-property rangx ColumnWidth width)
                  (if wraptext
                                (vlax-put-property rangx "WrapText" :vlax-True)
                        )
                )
        )
)

;;;*************************************************************************
;;; MODULE: Concat_NthStrings
;;; DESCRIPTION: Returns a string out of (nth) member of multiple lists
;;; ARGS: nested-list-of-lists-of-strings, nth-value
;;; EXAMPLE: (Concat_NthStrings '(("A" "B" "C")("D" "E" "F")) 1) returns "BE"
;;;*************************************************************************

(defun Concat_NthsStrings (ts n / out)
        (dsx-princ "\n(Concat_NthsStrings)")
        (setq out "")
        (foreach m ts
                (setq out (strcat out (nth n m)))
        )
        out
)

;;-------------------------------------
;; Load formats from INI file into list.
;; Load list into listbox for selection.
;;-------------------------------------
       
(defun DSX-TBX-LoadForms
        (reload / ff forms fieldnames colwidth fields fieldset formslist)
        (dsx-princ "\n(DSX-TBX-LoadForms)")
        (cond
                ( (setq ff (findfile $inifile))
                        (cond
                                ( (setq forms (dos_getini nil nil ff))
                                  (foreach formname forms
                                                ;; get field names for this table form...
                                          (setq fieldnames (dos_getini formname nil ff))
                                                ;; get each field column width...
                                          (foreach fieldname fieldnames
                                                  (setq colwidth (dos_getini formname fieldname ff)
                                                                                fieldset (list fieldname colwidth)
                                                                          fields   (cons fieldset fields)
                                                                                ;; fieldset=(fieldname width)
                                                                                ;; fields=((fieldname width) (fieldname width)...)
                                                  )
                                          ); foreach
                                               
                                                (setq fields (cons formname (reverse fields)))
                                                ; fields list= (formname (fieldname width) (fieldname width)...)
                                               
                                          (setq formslist (if formslist
                                                                                                                        (append formslist        (list fields))
                                                                                                                        (list fields)
                                                                                                                )
                                                                        fields         nil
                                                )
                                  )
                                  ;(setq formslist (reverse formslist))
                                  (setq G$TBXL formslist)
                                  (if reload
                                          (DSX-ListBox-Fill1 "form" G$TBXL 0)
                                                G$TBXL
                                        )
                                )
                                ( T (alert "Unable to load table list...") )
                        )
                )
                ( (setq ff (findfile (strcat G$DATA $inifile)))
                  (dsx-regset "TableOut\\TableDefFile" ff)
                        (cond
                                ( (setq forms (dos_getini nil nil ff))
                                  (foreach formname forms
                                                ;; get field names for this table form...
                                          (setq fieldnames (dos_getini formname nil ff))
                                                ;; get each field column width...
                                          (foreach fieldname fieldnames
                                                  (setq colwidth (dos_getini formname fieldname ff)
                                                                                fieldset (list fieldname colwidth)
                                                                          fields   (cons fieldset fields)
                                                                                ;; fieldset=(fieldname width)
                                                                                ;; fields=((fieldname width) (fieldname width)...)
                                                  )
                                          ); foreach
                                               
                                                (setq fields (cons formname (reverse fields)))
                                                ; fields list= (formname (fieldname width) (fieldname width)...)
                                               
                                          (setq formslist (if formslist
                                                                                                                        (append formslist        (list fields))
                                                                                                                        (list fields)
                                                                                                                )
                                                                        fields         nil
                                                )
                                  )
                                  ;(setq formslist (reverse formslist))
                                  (setq G$TBXL formslist)
                                  (if reload
                                          (dsx-listbox-fill1 "form" G$TBXL 0)
                                                G$TBXL
                                        )
                                )
                                ( T (alert "Unable to load table list...") )
                        )
                )
                ( T (alert "Unable to locate table list file...") )
        )
); defun

(defun DSX-TBX-SelectFile ( / ff)
        (dsx-princ "\n(DSX-TBX-SelectFile)")
        (cond
                ( (setq ff (getfiled "Spreadsheet File" (if G$TBXF G$TBXF "") "XLS" 1))
                        (setq outfl ff)
                        (set_tile "filename" outfl)
                )
        )
)

(defun DSX-TBX-ShowHelp ()
        (dsx-help "tableout.txt" "TABLEOUT: Exporting Table Data to Excel")
)

;;--------------------------------
;; Verify keyed-in filename is valid
;;--------------------------------

(defun DSX-TBX-ValidateFilename (name)
        (dsx-princ "\n(DSX-TBX-ValidateFilename)")
  (cond
                ( (not (member name '("" " " "  ")))
                        (if (= (strcase (substr name (- (strlen name) 3)) ".XLS"))
                                (progn
                                        (setq outfl name)
                                )
                                (progn
                                        (alert "Filename must have .XLS extension...")
                                        (mode_tile "filename" 2)
                                )
                        )
                )
                ( T
                        (alert "Filename cannot be blank...")
                        (DSX-TBX-SelectFile)
                )
        ); cond
); defun

;;-------------------------------------
;; Open INI file in Notepad to edit.
;; Reload formats in listbox when done.
;;-------------------------------------

(defun DSX-TBX-EditForms ( / fn)
        (dsx-princ "\n(DSX-TBX-EditForms)")
        (cond
                ( (setq fn (findfile $inifile))
                        (DOS_ExeWait (strcat "notepad.exe " fn))
                        (DSX-TBX-LoadForms T)
                )
                ( T (alert "No table forms loaded...") )
        )
); defun

(defun DSX-Excel-RowPut (worksheet col row datalist)
        (foreach val datalist
                (dsx-excel-cellput worksheet
                        (strcat        col row)
                        val
                )
                (setq col (chr (1+ (ascii col))))
        )
        (strcat col row)
)

(defun DSX-Excel-CellPut (worksheet range value)
  (vlax-put-property
          (DSX-Excel-RangeSelect worksheet range)
          "value2"
          value
  )
)

(defun DSX-Excel-RangeSelect (worksheet range)
  (vlax-get-property worksheet "range" range);; returns vla-object
)

(defun DSX-Excel-Worksheet (worksheets name)
        (vlax-get-property worksheets "item" name);; returns vla-object
)

(defun DSX-tableout-xml
        ( / tblforms ok master datalist basept nextpt
                        dch op1 op2 op3 op4 op5 op6
                        outfl form dloc tmp
        )
        (dsx-princ "\n(dsx-tableout-xml)")
       
        ;;-------------------------------------
        ;; Main dialog interaction process...
        ;;-------------------------------------
       
        (setq dch  (load_dialog "dsx-tableout"))
        (setq dloc (dsx-Form-GetLoc "TableOut"))
       
        ;; Set default global variable settings...
       
        (DSX-TBX-LoadForms nil); list of forms

  (dsx-princ "\nChecking default settings...")
        (setq tmp
                                 (strcat
                                         (dsx-getvar "dwgprefix")
                                         (vl-filename-base (dsx-get-dwgname t)) ".xml")
        )
        (setq G$TBXF tmp;(dsx-regget "TableOut\\XMLFilename" tmp)
                                G$TBXT (dsx-regget "TableOut\\FormIndex" "0")
                                G$TBX3 (dsx-regget "TableOut\\RowHeight" "0.25")
        )

  (if (not (new_dialog "xmlout" dch "" dloc))
                (progn
                        (alert "DCL Load Failure (tableout:xmlout)...")
                        (exit)
                )
        )

        (dsx-listbox-fill1 "form" G$TBXL 0); fill popup-list with form names
       
        ;; Set tiles to default values/settings...
       
        (set_tile "3" G$TBX3)
        (set_tile "filename" G$TBXF)
        (set_tile "form" G$TBXT)
       
        ;; Get actions from user...

        (action_tile "select"   "(DSX-TBX-SelectFile)")
        (action_tile "filename" "(DSX-TBX-ValidateFilename $value)")
        (action_tile "form"     "(setq form $value)")
        (action_tile "3"        "(setq op3 $value)")
  (action_tile "edit"     "(DSX-TBX-EditForms)")
        (action_tile "show"     "(DSX-TBX-FormInfo)")
        (action_tile "help"     "(DSX-TBX-ShowHelp)")
        (action_tile "accept"   "(setq ok 1 dloc (done_dialog))")
        (action_tile "cancel"   "(princ)")
        (start_dialog)
        (unload_dialog dch)
                       
        ;; Check action results, save global variable changes
        ;; Execute process to extract data from table...
       
        (cond
                ( (= ok 1)
                  (dsx-form-saveloc "TableOut" dloc)
                  (if outfl (setq G$TBXF outfl))
                  (if form  (setq G$TBXT form))
                  (if op3   (setq G$TBX3 op3))
                  
                        (dsx-regset "TableOut\\FormIndex" G$TBXT)
                        (dsx-regset "TableOut\\RowHeight" G$TBX3)

                  (setq G$TBXX (nth (atoi G$TBXT) G$TBXL))
                  (if (setq G$TBXROW (cdr G$TBXX))
                    (DSX-TBX-ExportTable 2)
                                (alert "System error: Rowset not defined...")
                        )
                )
        )
)

(defun DSX-TBX-ExportXML
        (datlst        / fieldnames fl row itm)
        (dsx-princ "\n(DSX-tbx-exportXML)")

        (setq fieldnames (DSX-TBX-FieldNames G$TBXROW))
        (cond
                ( (setq fl (open G$TBXF "w"))
                         (write-line "<?xml version=\"1.0\" standalone=\"yes\"?>" fl)
                        (write-line "<document>" fl)
                  (write-line "  <document-info>" fl)
                        (write-line "    <title>DSX Tools TableOut XML Report</title>" fl)
                        (write-line "    <comment>Generated by DSX Tools 2002</comment>" fl)
                        (write-line (strcat "    <author>" (getenv "username") "</author>") fl)
                        (write-line "    <comment>Web: http://www.dsxcad.com</comment>" fl)
                        (write-line "    <drawing>" fl)
                        (write-line (strcat "            <filename>" (dsx-get-dwgname t) "</filename>") fl)
                        (write-line "    </drawing>" fl)
                  (write-line "  </document-info>" fl)
                  (write-line "  <material-table>" fl)
                  (foreach row datlst
                                (write-line "  <material-row>" fl)
                                (setq count (1- (length row)) i 0); number of fields in row
                                (foreach itm row
                                        (setq fieldname (nth i fieldnames))
                                        (if (= (stripstr itm) "")
                                                (write-line (strcat "    <" fieldname ">$NULL$</" fieldname ">") fl)
                                                (progn
                                                        (setq itm (DSX-TBX-Ampersand itm))
                                                        (write-line (strcat "    <" fieldname ">" itm "</" fieldname ">") fl)
                                                )
                                        )
                                        (setq i (1+ i))
                                )
                                (write-line "  </material-row>" fl)
                        )
                  (write-line "  </material-table>" fl)
                  (write-line "</document>" fl)
                  (close fl)
    )
    ( T (alert "Unable to open XML document for output...") )
        )
  (princ)
)

(defun DSX-TBX-Ampersand (string / newstr)
        (setq newstr (dsx-string->list string " "))
        (setq out (mapcar
                '(lambda (x)
                         (if (= x "&")
                                 "&amp; "
                                 (strcat x " ")
                         )
                )
                newstr
        ))
        (apply 'strcat out)
)

;;;*************************************************************************;;;
(princ)[/php]

dsx-api用法說明:
[php]

DSX Tools
API Reference
All Functions and Documentation: U.S. Copyright (C) 2001-2002 David M. Stein, All Rights Reserved.
Version 2002.08.09.00  Dated: 08/09/2002
Public License Hereby Granted for reuse upon acceptance of terms below in their entirety without modification.
Legal Notice and License for General Non-Profit Public Use:
Users may develop derivative works based upon the information provided herein, but only if they agree not to sell said derivative works for profit without first obtaining explicit prior written consent of the author.  In addition, users agree not to hold liable the author of this work for any subsequent damages or loss of business profit, productivity, whether said damages occur as a result of derivative works or the information provided herein.  The author of this work gives NO WARRANTY or GARANTEE of any kind whatsoever as to the fitness or functionality of the information or examples provided herein.  This information is provided solely for informational purposes and is not intended to coerce, convince or otherwise invite anyone to make use of this information for their own benefit or the benefit of others.

TERMS OF ACCEPTANCE:  Users agree to accept and claim all risks and responsibilities for any use of this information in any form whatsoever.  Users that do not wish to accept these conditions are hereby NOT granted permission to use, adapt, derive or base any derivative or parallel works upon the information provided herein.  Any and all derivative works must clearly display the copyright notice as follows in all forms of the derived work, whether electronic, printed or otherwise:

Portions of this application are based upon DSX Tools 2002, Copyright (C) 2001-2002 David M. Stein, All Rights Reserved.

In addition, developers that create derivative works for public use must clearly state to all recipients of said work the complete terms and conditions stated herein.  In the event that users of derivative works are not properly notified of these conditions and terms of use, and/or have not agreed to them in their entirety, are hereby NOT authorized to use said derivative works for any reason whatsoever.

AutoCAD, Visual LISP, and AutoLISP are registered trademarks of Autodesk.  Autodesk is a registered trademark.  Office, XP, Excel, Word, Access, PowerPoint, Outlook and Windows are registered trademarks of Microsoft corp.  All other trademarks are the property of their respective owners.  DSX Tools is not affiliated with or endorsed by Autodesk or Microsoft in any respect.

Introduction
With the release of DSX Tools 2002, the underlying API library has evolved and matured somewhat to a point of being of potential benefit to external use.  Once DSX Tools is loaded into a given AutoCAD session (via the DSX.VLX component), all of the functions defined below are exposed and readily available for use.  These can be derived upon to build yet even more complex API functions or libraries, as well as specialized applications.  The advantage of this is that there is no license royalty fee required, provided that usage is in compliance with terms and conditions stated herein.  Why do I bother?  Why do I do all this?  Why no charge?  Because I'm a nice guy.

Basic Functions
(DSX-AcadObject)
Returns the vla-object to the base AcadApplication object.

(DSX-ActiveDoc)
Returns the vla-object to the ActiveDocument object.

(DSX-MSpace)
Returns the vla-object to the ModelSpace collection object for the active document.

(DSX-PSpace)
Returns the vla-object to the PaperSpace collection object for the active document.

(DSX-ActiveSpace)
Returns the vla-object of the active working space (either ModelSpace or PaperSpace object).

(DSX-ActiveSpaceName)
Returns the name of the active space as either "Model" or "Paper".

(DSX-ActiveLayout)
Returns vla-object of the active layout in the active drawing.

(DSX-AcadPrefs)
Returns the vla-object to the AcadPreferences collection object for the AcadApplication object.  This applies to all preferences settings that are applied to the AcadApplication object and are persistent throughout all drawing sessions.

(DSX-DocPrefs)
Returns the vla-object collection for the DatabasePreferences collection.  This comprises preferences settings that apply to the document object only, as opposed to the AcadPreferences object, which applies to all documents by way of AutoCAD itself.

(DSX-Profiles)
Returns the vla-object collection of profiles within the AcadPreferences collection.  Instead of using (vla-get-Profiles (DSX-AcadPrefs)), this shortens to simply (dsx-profiles).

(DSX-AcadPrefs-Output)
Returns the vla-object to the Output collection within the AcadPreferences collection.  This relates to the Plotting tab of the OPTIONS dialog for those settings that are not drawing-specific.

(DSX-SetPlotStyleDefault-Objects stylename)
Sets the default plot style name the same way as is done via the OPTIONS dialog within the Plotting tab.

(DSX-SetPlotPolicy mode)
Defines plot style mode as either 0 (Named or STB), or 1 (Color-based or CTB) within the AcadPreferences/Output collection.  This is identical to setting it in OPTIONS within the Output tab.

(DSX-PlotConfigs)
Returns vla-object to pagesetups collection in active drawing.

(DSX-PlotConfigs-Space name)
Returns name of working space for given specified pagesetup in active drawing.  Returns "Model" or "Layout" (case sensitive!) as result.  If pagesetup is not found, returns nil.

(DSX-PlotConfig-ListActive)
Returns a list of all pagesetup names in active drawing that are associated with the active working space (modelspace or paperspace).  Ignores those associated with opposite working space.

(DSX-Delete-PageSetup name)
Deletes specified pagesetup from active drawing collection.

(DSX-SetPlotStyleDefault-Layer stylename)
(DSX-Load-PageSetup name source reload)
Imports a pagesetup name from a remote source drawing using ObjectDBX interface.  If reload is non-nil, the import will overwrite an existing pagesetup of the same name if found.

(DSX-List-PlotConfigs)
Returns a list of all defined pagesetups in the active drawing.  To return a list of pagesetups filtered by the active working space, use the (DSX-PlotConfig-ListActive) function.

(DSX-PlotConfig-Exists-p name)
Returns T or nil to verify that specified named pagesetup exists in the active drawing.

(DSX-SetPlotStyleTable stylename)

Entity Creation Functions
(DSX-AddArc point radius startangle endangle layer color linetype)
(DSX-AddCircle point radius layer color linetype)
(DSX-AddLine startpoint endpoint layer color linetype)
Creates LINE (AcDbLine) object with the specified properties: startpoint is a points list, as is endpoint.  layer is the string value of the layer name.  color is an integer or vla value (e.g. acRed, or 1 will do the same), linetype is the name of the linetype.  Note that when specifying a linetype that is not defined, this function will attempt to load it from the default linetype definition file (either ACAD.LIN or ACADISO.LIN).

(DSX-AddLineC points-list closed layer color linetype)
Works the same as DSX-AddLine except that it accepts a list of points with an option to close the final segment or leave it open.  The DSX-AddPline function is nearly identical in function except that it not only creates a single polyline object, but offers additional parameters (lineweight, linetype-generation).

(DSX-AddPline points-list closed layer color linetype linewidth ltypegen)
Creates a LWPOLYLINE (AcDb2dPolyline) object using a list of points and specified properties.  The properties (parameters) are as follows:

points-list is the list of points to connect
closed is a boolean (T or nil) flag to close or leave the polyline open
layer is the string name of the layer to assign
color is the integer or vla color to assign (or acByLayer)
linetype
lineweight
ltypegen is a boolean (T or nil) flag to apply linetype generation to the object (or not)

(DSX-AddText string point justification stylename height widthfactor rotation layername color)
Creates TEXT (AcDbText) object with specified properties: string is the string value of the text.  point is the insertion point, which is a point list value.  stylename is the style name, which is a string value.  height is the actual height (not scale), which is a real number.  widthfactor is a real number value.  rotation is the rotation angle in degrees (not radians), which is also a real number.  layername is a string value and must be defined, otherwise the text is put on layer "0" by default or the active layer.  color is an integer value for the color number, use acBylayer for default.

Example:

(DSX-AddText "THE DOG" pt1 "MC" "Standard" 0.125 1.0 90 "Text" acByLayer)

(DSX-AddPolygon ...)
(DSX-AddPoint point layername)
Creates a POINT (AcDbPoint) object at the specified point location, on the specified layer.

(DSX-AddEllipse ...)
(DSX-AddEllipseArc1 ...)
(DSX-AddEllipseArc2 ...)
(DSX-AddSolid ...)
(DSX-AddRectangle point1 point2 layer color linetype)
More coming soon...
Layer Functions
(DSX-AddLayer name color linetype lineweight plottable current)
Creates a new layer if the layer does not exist.  If layer is created, returns name as result.  If layer already exists, simply returns name as result.  If current is non-nil, the layer is set active.  Color is either an enumeration or integer.  Linetype is a string.  Lineweight is an enumeration or integer.  Plottable is T, :vlax-true or something non-nil. If set to :vlax-false, defines layer to not plot.

(DSX-LayerTable)
Returns vla-object to layers collection of active drawing document.

(DSX-LayActive name)
Sets layer name active, if defined.

(DSX-Layer-Frozen-p name)
Verifies if layer name is frozen.  Returns T (is frozen) or nil (not frozen or not defined).

(DSX-ListLayers-Frozen)
Returns a list of layer names that are currently frozen in the current drawing.  Returns nil if no layers are frozen.


String Manipulation Functions
(DSX-String->List string char)
Parses a string into a list of substrings (words) using the specified delimiter character char to define the breakpoints in the given string.  If no instances of the delimiter char exist in the string, the string itself is returned unchanged.  For example (DSX-String->List "THE DOG RAN" " ") would return ("THE" "DOG" RAN").

(DSX-List->String list char)
Assembles a list of characters into a single string result using the specified delimiter char in between each character or substring being assembled.  For example (DSX-List->String '("A" "B" "C") ",") would return "A,B,C".

More coming soon...
Selection Set Manipulation
(SSINTER pickset1 pickset2)
Returns the Boolean intersection of common entities found in both selection sets (pickset1 and pickset2).

(SSUNION pickset1 pickset2)
Returns the Boolean union of combined entities from both selection sets.

(SSDIFF pickset1 pickset2)
Returns a selection set of entities in pickset1 that are NOT also in pickset2.

(SSTYP pickset entity-type)
Returns subset of selection set of only those entities that are of the same type as entity-type.  For example, to fetch circle objects from a selection named "myset" you could use (SSTYP myset "CIRCLE")

(SSNOT pickset dxf-field dxf-value)
Returns subset of selection of all entities that do not match the criteria specified by dxf-field (DXF number code) and the corresponding dxf-value (e.g. "CIRCLE").  For example, to return all entities excluding text entities, you could use (SSNot myset 0 "TEXT").

(SSNOTList pickset dxf-field dxf-values-list)
Returns a subset of selection set of only those items that are not members of the criteria list.  In this case, the dxf-field is the DXF number code (eg. 0 is entity-type), and dxf-values-list is a list of entity types that you would not want returned.  To exclude circle and arc entities from selection set "myset", you could use (SSNotList myset 0 '("ARC" "CIRCLE")).

(SSLAY pickset layername)
Returns a new selection of only those objects within a given selection set pickset that are assigned to the specified layer layername.  Otherwise, returns nil.

(SSCOLOR pickset colornumber)
Returns a new selection of only those objects within a given selection set pickset that are assigned the specified color colornumber (integer value).  Returns matching objects regardless of whether they are the matching color by virtue of ByLayer assignment or are overriden with a specific (matching) color.

More coming soon...
Microsoft&reg; Office&reg; Interfaces (97,2000,XP)
Open dsx-api-excel.lsp to view source code and make your own notes!

(DSX-Open-Excel-New show)
Opens Excel&copy; with a new spreadsheet document.  If show is not nil, the Excel application is shown on the users desktop normally.  If show is nil, the Excel session is hidden (only available in the processes list in Task Manager).

(DSX-Open-Excel-Exist filename show)
Opens Excel and requests for spreadsheet file filename to be opened.  If show is not nil, the Excel application is shown on the users desktop normally.  If show is nil, the Excel session is hidden (only available in the processes list in Task Manager).

(DSX-Excel-Get-ActiveWorksheet appsession)
Returns vla-object to active worksheet in active Excel application session object appsession.

(DSX-Excel-Put-ColumnList values startingrow startingcolumn)
Inserts data from list values into spreadsheet currently opened via (dsx-open-excel-new) or (dsx-open-excel-exist).  Inserts list in a top-down order beginning at row startingrow and column and incrementing down to the next cell (row) for each remaining value in the list.

For example, (DSX-Excel-Put-ColumnList '("A" "B" "C") 1 2) puts members into cells (1,B) (2,B) (3,B) respectively in the active spreadsheet document.

(DSX-Excel-Put-RowList values startingcolumn row)
Inserts data from list values into spreadsheet currently opened via (dsx-open-excel-new) or (dsx-open-excel-exist).  Inserts list in a left-to-right order in row beginning in column startingcolumn and stepping over to the next cell (column) for each remaining list value.

For example, (DSX-Excel-Put-RowList '("A" "B" "C") 2 1) puts members into cells (1,B) (1,C) (1,D) respectively in the active spreadsheet document.

(DSX-Excel-Put-CellColor row column color)
Applies color to background of specified cell in active worksheet (Excel).  All parameters are integer values.

(DSX-Excel-Put-RowCellsColor startrow startcolumn columns color)
Applies color to background of specifed cells within a defined row within the active worksheet (Excel).  All parameters are integer values.  Begins applying color change at row startrow, column startcolumn and repeats for the number of columns stated.

(DSX-Excel-Put-ColumnCellsColor)
(DSX-Excel-Get-Cell)
(DSX-Excel-Get-CellValue)
(DSX-Excel-Get-RowValues)
(DSX-Excel-Get-ColumnValues)
(DSX-Excel-GetRangeValues-ByCols startrow startcolumn num-rows num-columns)
Returns an array of cell values as a nested column-based list of lists starting with cell at (startrow, startcolumn) and ending at an offset of rows (num-rows) and columns (num-columns).

For example, (DSX-Excel-GetRangeValues-ByCols 1 1 5 10) get range values from 1A to 5J where each sublist is one column.

(DSX-Excel-GetRangeValues-ByRows startrow startcolumn num-rows num-columns)
Returns an array of cell values as a nested row-based list of lists starting with cell at (startrow, startcolumn) and ending at an offset of rows (num-rows) and columns (num-columns).

For example, (DSX-Excel-GetRangeValues-ByRows 1 1 5 10) get range values from 1A to 5J where each sublist is one row.

More coming soon...
Utility Functions
(dsx-princ message)
Debug princ function that displays string message only if $DBG is non-nil.  The function (dsx-debug-enabled) returns T or nil as a test function if desired.  

Example: (dsx-princ "\nThis is a debugging message only.")  If $DBG is non-nil, the string is displayed, otherwise it is not.

(dsx-debug-enabled)
Returns T if debugging/diagnostics are enabled, otherwise returns nil.  Helps to use for multiple (princ) calls instead of using multiple (dsx-princ) calls.

Example: (if (dsx-debug-enabled) (progn (princ "1") (princ "2") (princ "3")...)) instead of (dsx-princ "1")(dsx-princ "2")(dsx-princ "3")

(DSX-Vsave (varnames))
Defines a global list of paired sublists, each containing the specified system variable name and its related current setting value.  This list (G$VARS) is saved until restored and cleared by the DSX-Vrestore function call.

(DSX-Vrestore)
Reads global list of system variables and their respective settings (G$VARS) saved previously using DSX-Vsave, and restores them to the saved settings.  Following this process, it then clears the global list from memory (sets it to nil).

(DSX-MakeObject ename-or-object)
Returns a vla-object from a specified vla-object or ename symbol value.  Ensures functions that expect vla-object input are properly referencing the entity/object.

(DSX-RegSet regkey value)
Defines or updates registry with string value provided.  Nested or sub-level registry keys must be defined as double-backslashes (e.g. "MyRegistryKeys\\RegKey1").

(DSX-RegGet regkey default)
Returns the current registry key value if found.  If not found, the registry key is defined and set to the given default value, which is then returned as the result.

(DSX-DimVar 'symbol expression)
Validates quoted global symbol to return current value.  If symbol is not defined (evaluates to nil), it is defined and assigned the value resulting from expression.  Example: (ASW-DimVar 'G$MYVAR '(1 2 3)) would either return the current value of global symbol G$MYVAR or define G$MYVAR as list (1 2 3) and return it as the result.

(DSX-PtOff point x-value y-value)
Returns a new point list by applying x and y offset distance values to specified point.

(DSX-UndoBegin)
Defines an UNDO marker beginning in the current drawing.  This is used to start a mark before performing multiple operations, and then ending the operations with a call to DSX-UndoEnd to close the UNDO group as one operation.  This enables a single U (undo) to undo the entire collection of operations back to the initial (DSX-UndoBegin) call.

(DSX-UndoEnd)
Closes an open UNDO marker to enable single U (undo) reversal of multiple operations performed since the last (DSX-UndoBegin) call.

(DSX-Delete objects)
Deletes (erases) an entity, a vla-object or a selection set (pickset) without having to convert or iterate first.  Can be used to easily delete objects without having to convert them or worry about being the result of (entsel) or (ssget) either.

(DSX-HighLight object mode)
Toggles highlighting on or off on given objects.  object may be an ename, vla-object or a selection set (pickset).  Mode is T (or non-nil) for "on", or nil for "off".

(DSX-Collect ename)
Returns a selection set (pickset) of all objects in the current drawing that were created after the occurence of ename in the drawing database.  In most cases, you would set ename to an arbitrary entity via (entlast) prior to performing multiple entity operations that create new entites.  Then you would collect those new entities by using this function with the initial arbitrary entity as the marker.  The result is a pickset or nil.

(DSX-PurgeAllDocs)
Performs complete PURGE on all currently opened drawings.

(DSX-AuditAllDocs)
Performs AUDIT with data recovery enabled on all currently opened drawings.

(DSX-SaveAllDocs)
Performs QSAVE on all currently opened drawings.

(DSX-ZoomExtents)
Zooms to current drawing extents.

(DSX-ZoomAll)
Zooms to ALL display.

(DSX-ZoomPrevious)
Zooms to previous display if any.

(DSX-ZoomWindow point1 point2)
Zooms current display to specified window based upon provided points point1 and point2.

(DSX-ZoomIn)
Zooms current display in 2x

(DSX-ZoomOut)
Zooms current display out .5x

Collection Objects
(DSX-Table name mode)
Returns a list of member names for a given table. If mode is non-nil, each member is returned as a sub-list of its table properties in detail.  For example, (DSX-Table "layer" nil) would return a list of layer names in the active drawing.  Using (DSX-Table "layer" T) would return the list as sublists as if using (tblsearch "layer" name) on each member.

(DSX-TextStyles)
Returns vla-object to text styles collection in current drawing.

(DSX-LineTypes)
Returns vla-object to linetypes collection in current drawing.

(DSX-DimStyles)
Returns vla-object to dimension styles collection in current drawing.

(DSX-LayerTable)
Returns vla-object to layers collection in current drawing.

(DSX-BlockDefs)
Returns vla-object to block definitions collection in current drawing.

(DSX-PlotConfigs)
See description above.


For more information or to send feedback, send e-mail to davidmstein@yahoo.com[/php]
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-4-9 09:52:23 | 显示全部楼层
有些基本涵数没有定义,只有说明。比如DSX-MAKEOBJECT 能不能请版主再发上来
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2006-9-25 23:38:11 | 显示全部楼层
请朋友们地道些,别把一些坏代码贴上来。。。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2007-2-5 09:34:47 | 显示全部楼层
好难过,我的现金和积分怎么就没了呢,
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2013-6-19 09:20:30 | 显示全部楼层
参数太齐全了反而用起来麻烦,有些可以用当前设置,不必弄那么多属性的
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 3719个

财富等级: 富可敌国

发表于 2013-6-19 13:14:38 | 显示全部楼层
英文不好,这个程序主要的作用是什么呢?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-6 12:42 , Processed in 0.265553 second(s), 45 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表