明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1916|回复: 1

vlex-函数的收集

[复制链接]
发表于 2012-11-8 15:28 | 显示全部楼层 |阅读模式
看到明经上没有vlex的函数,特发一篇,供大家学习,一同进步。请大家多多支持。
  1. ;;;***************************************************************************;;;
  2. ;;; vlex-vlisp.lsp                    ;;;
  3. ;;; Assorted Visual LISP ActiveX Extention Functions for AutoCAD 2004         ;;;
  4. ;;; Copyright (C)2003 Kama Whaley, All rights reserved.            ;;;
  5. ;;; Some functional code adapted from public sources.            ;;;
  6. ;;; Latest Modify Date : Friday 26th December 2003            ;;;
  7. ;;;***************************************************************************;;;
  8. ;;; Version 2004 1.00 12/2003: Initial release (compile to VLX)          ;;;
  9. ;;;***************************************************************************;;;

  10. (vl-Load-COM);; load ActiveX support in Visual LISP

  11. ;;; ***********************   <   First  Session   >   ***********************;;;

  12. ;;;***************************************************************************;;;
  13. ;;; MODULE: vlex-AcadObject ()                  ;;;
  14. ;;; DESCRIPTION: Returns COM handle to application object          ;;;
  15. ;;; ARGS: none                      ;;;
  16. ;;; EXAMPLE: (vlex-AcadObject) returns ActiveX object            ;;;
  17. ;;;***************************************************************************;;;

  18. (setq *acad-object* nil)  ; Initialize global variable
  19. (defun vlex-AcadObject ()
  20.   (cond (*acad-object*)    ; Return the cached object
  21.     (T
  22.       (setq *acad-object* (vlax-Get-Acad-Object))
  23.     )
  24.   )
  25. )

  26. ;;;***************************************************************************;;;
  27. ;;; MODULE: vlex-ActiveDocument ()                ;;;
  28. ;;; DESCRIPTION: Returns active document object from application object       ;;;
  29. ;;; ARGS: none                      ;;;
  30. ;;; EXAMPLE: (vlex-ActiveDocument) returns ActiveX object          ;;;
  31. ;;;***************************************************************************;;;

  32. (setq *vlex-ActiveDocument* nil)  ; Initialize global variable
  33. (defun vlex-ActiveDocument ()
  34.   (cond (*vlex-ActiveDocument*)    ; Return the cached object
  35.     (T
  36.       (setq *vlex-ActiveDocument* (vla-Get-ActiveDocument (vlex-AcadObject)))
  37.     )
  38.   )
  39. )

  40. ;;;***************************************************************************;;;
  41. ;;; MODULE: vlex-ModelSpace ()                  ;;;
  42. ;;; DESCRIPTION: Returns vlex-ModelSpace collection object of active document ;;;
  43. ;;; ARGS: none                      ;;;
  44. ;;; EXAMPLE: (vlex-ModelSpace) returns ActiveX object            ;;;
  45. ;;;***************************************************************************;;;

  46. (setq *vlex-ModelSpace* nil)  ; Initialize global variable
  47. (defun vlex-ModelSpace ()
  48.   (cond (*vlex-ModelSpace*)  ; Return the cached object
  49.     (T
  50.       (setq *vlex-ModelSpace* (vla-Get-ModelSpace (vlex-ActiveDocument)))
  51.     )
  52.   )
  53. )


  54. ;;;***************************************************************************;;;
  55. ;;; MODULE: vlex-PaperSpace                  ;;;
  56. ;;; DESCRIPTION: Returns paper-space collection object of active document     ;;;
  57. ;;; ARGS: none                      ;;;
  58. ;;; EXAMPLE: (vlex-PaperSpace) returns ActiveX object            ;;;
  59. ;;;***************************************************************************;;;

  60. (setq *vlex-PaperSpace* nil)  ; Intialize global variable
  61. (defun vlex-PaperSpace ()
  62.   (cond (*vlex-PaperSpace*)  ; Return the cached object
  63.     (T
  64.       (setq *vlex-PaperSpace* (vla-Get-PaperSpace (vlex-ActiveDocument)))
  65.     )
  66.   )
  67. )

  68. (defun vlex-ActiveSpace ()
  69.   (if (= 1 (vlax-get-Property (vlex-ActiveDocument) 'ActiveSpace))
  70.     (vlex-ModelSpace)
  71.     (vlex-PaperSpace)
  72.   ); endif
  73. )

  74. ;;;***************************************************************************;;;
  75. ;;; MODULE: vlex-ActiveSpace-Name ()                ;;;
  76. ;;; DESCRIPTION: Returns name(string) of current "space"          ;;;
  77. ;;                (either "Model" or "Paper")              ;;;
  78. ;;;***************************************************************************;;;

  79. (defun vlex-ActiveSpace-Name ()
  80.   (if (= 1 (vla-get-ActiveSpace (vlex-ActiveDocument)))
  81.     "Model" "Paper"
  82.   )
  83. )

  84. ;;;***************************************************************************;;;
  85. ;;; MODULE: vlex-AcadPrefs ()                  ;;;
  86. ;;; DESCRIPTION: Returns AcadPreferences object              ;;;
  87. ;;; ARGS: none                            ;;;
  88. ;;; EXAMPLE: (vlex-AcadPrefs) returns vla-object            ;;;
  89. ;;;***************************************************************************;;;

  90. (setq *vlex-AcadPrefs* nil)  ; Initialize global variable
  91. (defun vlex-AcadPrefs ()
  92.   (cond (*vlex-AcadPrefs*)
  93.     (T
  94.       (setq *vlex-AcadPrefs* (vlax-Get-Property (vlex-AcadObject) 'Preferences))
  95.     )
  96.   )
  97. )

  98. ;;;***************************************************************************;;;
  99. ;;; MODULE: vlex-GetPrefKey (tabname keyname)              ;;;
  100. ;;; DESCRIPTION: Returns value of specified preferences setting          ;;;
  101. ;;; ARGS: tabname(string), keyname(string)              ;;;
  102. ;;; EXAMPLE: (vlex-GetPrefKey 'Files 'SupportPath)            ;;;
  103. ;;;***************************************************************************;;;

  104. (defun vlex-GetPrefKey (TabName KeyName)
  105.   (vlax-get-property
  106.     (vlax-get-property
  107.       (vlex-AcadPrefs)
  108.       TabName
  109.     )
  110.     KeyName
  111.   )
  112. )

  113. ;;;***************************************************************************;;;
  114. ;;; MODULE: vlex-SetPrefKey (tabname keyname new-value)                       ;;;
  115. ;;; DESCRIPTION: Modifies preferences setting with new value                  ;;;
  116. ;;; ARGS: tabname(string), keyname(string), new-value(varies)                 ;;;
  117. ;;; EXAMPLE: (vlex-SetPrefKey "OpenSave" "IncrementalSavePercent" 0)        ;;;
  118. ;;;***************************************************************************;;;

  119. (defun vlex-SetPrefKey (TabName KeyName NewVal)
  120.   (vlax-put-property
  121.     (vlax-get-property
  122.       (vlex-AcadPrefs)
  123.       TabName
  124.     )
  125.     KeyName
  126.     NewVal
  127.   )
  128. )

  129. ;;;***************************************************************************;;;
  130. ;;; MODULE: vlex-AcadProp (propname)                ;;;
  131. ;;; DESCRIPTION: Returns value of acad-object property            ;;;
  132. ;;; ARGS: propname(string)                  ;;;
  133. ;;; EXAMPLE: (vlex-AcadProp 'FullName)                ;;;
  134. ;;;***************************************************************************;;;

  135. (defun vlex-AcadProp (PropName) (vlax-get-property (vlex-AcadObject) PropName))

  136. ;;;***************************************************************************;;;
  137. ;;; MODULE: vlex-Name (obj)                  ;;;
  138. ;;; DESCRIPTION:                    ;;;
  139. ;;; ARGS:                      ;;;
  140. ;;; EXAMPLE: (vlex-Name (vlex-AcadObject)) returns "AutoCAD"          ;;;
  141. ;;;***************************************************************************;;;

  142. (defun vlex-Name (obj)
  143.   (if (vlax-property-available-p obj 'Name)
  144.     (vlax-get-property obj 'Name)
  145.     "<NONE_NAME>"
  146.   )
  147. )

  148. ;;;***************************************************************************;;;
  149. ;;; MODULE: vlex-GetDocsCollection                ;;;
  150. ;;; DESCRIPTION: Returns the documents collection object          ;;;
  151. ;;; ARGS: none                      ;;;
  152. ;;; EXAMPLE:
  153. ;;;***************************************************************************;;;

  154. (defun vlex-GetDocsCollection () (vlex-AcadCollection "Documents"))

  155. ;;;***************************************************************************;;;
  156. ;;; MODULE: vlex-AcadCollection (name)                ;;;
  157. ;;; DESCRIPTION: Return a root collection of the AcadApplication object       ;;;
  158. ;;; ARGS:                      ;;;
  159. ;;; EXAMPLE:
  160. ;;;***************************************************************************;;;

  161. (defun vlex-AcadCollection (Cname) (vlax-Get-Property (vlex-AcadObject) Cname))

  162. ;;;***************************************************************************;;;
  163. ;;; MODULE: vlex-DocsCount ()                  ;;;
  164. ;;; DESCRIPTION: Returns the count of the documents collection          ;;;
  165. ;;; ARGS: none                      ;;;
  166. ;;; EXAMPLE: (setq NumDocsOpen (vlex-DocsCount))            ;;;
  167. ;;;***************************************************************************;;;

  168. (defun vlex-DocsCount () (vlex-CollectionCount (vlex-GetDocsCollection)))

  169. ;;;***************************************************************************;;;
  170. ;;; MODULE: vlex-CollectionCount (collection)              ;;;
  171. ;;; DESCRIPTION: Return the count of a given collection object          ;;;
  172. ;;; ARGS: collection-object                  ;;;
  173. ;;; EXAMPLE: (setq LayCount (vlex-CollectionCount (vlex-GetLayers)))        ;;;
  174. ;;;***************************************************************************;;;

  175. (defun vlex-CollectionCount (Collection)
  176.   (vlax-get-property Collection 'Count)
  177. )

  178. ;;;***************************************************************************;;;
  179. ;;; MODULE: vlex-DocsList (verbose)                ;;;
  180. ;;; DESCRIPTION: Returns a list of all opened document names          ;;;
  181. ;;; ARGS: Verbose<boolean>                  ;;;
  182. ;;; EXAMPLE: (setq alldocs (vlex-DocsList T))              ;;;
  183. ;;; NOTES: Verbose returns full path+filename for each document in the list   ;;;
  184. ;;;        if set to T (true), otherwise only the filenames are returned.     ;;;
  185. ;;;***************************************************************************;;;

  186. (defun vlex-DocsList (verbose / docname out)
  187.   (setq out '())
  188.   (vlax-for each (vlex-GetDocsCollection)
  189.     (if verbose
  190.       (setq docname
  191.         (strcat
  192.     (vlax-get-property each 'Path)
  193.     "\"
  194.     (vlex-Name each)
  195.   )
  196.       )
  197.       (setq docname (vlex-Name each))
  198.     ); endif
  199.     (setq out (cons docname out))
  200.   )
  201.   (reverse out)
  202. )

  203. ;;;***************************************************************************;;;
  204. ;;; MODULE: vlex-DumpIt                    ;;;
  205. ;;; DESCRIPTION: Dump all methods and properties for selected objects        ;;;
  206. ;;; ARGS: none                      ;;;
  207. ;;; EXAMPLES:
  208. ;;;***************************************************************************;;;

  209. (defun vlex-DumpIt ( / ent)
  210.   (while (setq ent (entsel))
  211.     (vlax-Dump-Object
  212.       (vlax-Ename->Vla-Object (car ent))
  213.     )
  214.   )
  215.   (princ)
  216. )

  217. ;;;***************************************************************************;;;
  218. ;;; MODULE: vlex-Get____ ()                  ;;;
  219. ;;; DESCRIPTION: Various collection functions to return collection objects    ;;;
  220. ;;; ARGS: none                      ;;;
  221. ;;; EXAMPLE: (setq collLayers (vlex-GetLayers))               ;;;
  222. ;;;***************************************************************************;;;

  223. (defun vlex-GetLayers ()  (vlex-DocCollection 'Layers))
  224. (defun vlex-GetLtypes ()  (vlex-DocCollection 'Linetypes))
  225. (defun vlex-GetTextStyles ()  (vlex-DocCollection 'TextStyles))
  226. (defun vlex-GetDimStyles ()  (vlex-DocCollection 'DimStyles))
  227. (defun vlex-GetLayouts ()  (vlex-DocCollection 'Layouts))
  228. (defun vlex-GetDictionaries ()  (vlex-DocCollection 'Dictionaries))
  229. (defun vlex-GetBlocks ()  (vlex-DocCollection 'Blocks))
  230. (defun vlex-GetPlotConfigs ()  (vlex-DocCollection 'PlotConfigurations))
  231. (defun vlex-GetViews ()    (vlex-DocCollection 'Views))
  232. (defun vlex-GetViewports ()  (vlex-DocCollection 'Viewports))
  233. (defun vlex-GetGroups ()  (vlex-DocCollection 'Groups))
  234. (defun vlex-GetRegApps ()  (vlex-DocCollection 'RegisteredApplications))

  235. ;;;***************************************************************************;;;
  236. ;;; MODULE: vlex-DocCollection (name)                ;;;
  237. ;;; DESCRIPTION: Return a collection from the vlex-ActiveDocument object      ;;;
  238. ;;; ARGS: collection-name(string or quote)              ;;;
  239. ;;; EXAMPLE: (setq all-ltypes (vlex-DocCollection 'LineTypes))          ;;;
  240. ;;;***************************************************************************;;;

  241. (defun vlex-DocCollection (Cname)
  242.   (vlax-Get-Property (vlex-ActiveDocument) Cname)
  243. )

  244. ;;;***************************************************************************;;;
  245. ;;; MODULE: vlex-ListCollectionMemberNames (collection)              ;;;
  246. ;;; DESCRIPTION: Return list of all collection member names          ;;;
  247. ;;; ARGS: collection<object>                  ;;;
  248. ;;; EXAMPLE: (vlex-List-Collection-Member-Names (vlex-GetLayers))        ;;;
  249. ;;;***************************************************************************;;;

  250. (defun vlex-ListCollectionMemberNames (collection / itemname out)
  251.   (setq out '())
  252.   (vlax-for each collection
  253.     (setq itemname (vlex-Name each)
  254.     out (cons itemname out)
  255.     )
  256.   )
  257.   (reverse out)
  258. )

  259. ;;;***************************************************************************;;;
  260. ;;; List Collection Member Names                ;;;
  261. ;;;***************************************************************************;;;

  262. (defun vlex-ListLtypes ()  (vlex-ListCollectionMemberNames (vlex-GetLtypes)))
  263. (defun vlex-ListLayers ()  (vlex-ListCollectionMemberNames (vlex-GetLayers)))
  264. (defun vlex-ListTextStyles ()  (vlex-ListCollectionMemberNames (vlex-GetTextStyles)))
  265. (defun vlex-ListDimStyles ()  (vlex-ListCollectionMemberNames (vlex-GetDimStyles)))
  266. (defun vlex-ListLayouts ()  (vlex-ListCollectionMemberNames (vlex-GetLayouts)))
  267. (defun vlex-ListDictionaries () (vlex-ListCollectionMemberNames (vlex-GetDictionaries)))
  268. (defun vlex-ListBlocks ()  (vlex-ListCollectionMemberNames (vlex-GetBlocks)))
  269. (defun vlex-ListPlotConfigs ()  (vlex-ListCollectionMemberNames (vlex-GetPlotConfigs)))
  270. (defun vlex-ListViews ()  (vlex-ListCollectionMemberNames (vlex-GetViews)))
  271. (defun vlex-ListViewPorts ()  (vlex-ListCollectionMemberNames (vlex-GetViewports)))
  272. (defun vlex-ListGroups ()  (vlex-ListCollectionMemberNames (vlex-GetGroups)))
  273. (defun vlex-ListRegApps ()  (vlex-ListCollectionMemberNames (vlex-GetRegApps)))

  274. ;;;***************************************************************************;;;
  275. ;;; MODULE: vlex-CountLtypes ()                  ;;;
  276. ;;; DESCRIPTION: Returns the count of the linetypes collection          ;;;
  277. ;;; ARGS: none                      ;;;
  278. ;;; EXAMPLE: (setq NumLtypes (vlex-CountLtypes))            ;;;
  279. ;;;***************************************************************************;;;

  280. (defun vlex-CountLtypes () (vlex-CollectionCount (vlex-GetLtypes)))

  281. ;;;***************************************************************************;;;
  282. ;;; MODULE: vlex-AcadCollection (name)                ;;;
  283. ;;; DESCRIPTION: Return a root collection of the AcadApplication object        ;;;
  284. ;;; ARGS:
  285. ;;; EXAMPLE:
  286. ;;;***************************************************************************;;;

  287. (defun vlex-AcadCollection (Cname) (vlax-Get-Property (vlex-AcadObject) Cname))

  288. ;;;***************************************************************************;;;
  289. ;;; MODULE: vlex-SortPoints (points-list sortfield)            ;;;
  290. ;;; DESCRIPTION: Sorts a list of point-list on x, y or z coordinates        ;;;
  291. ;;; ARGS: list of points (lists), sortfield(char "X", "Y" or "Z")        ;;;
  292. ;;; EXAMPLE: (vlex-SortPoints myPoints "Y") sorts on Y-coord values        ;;;
  293. ;;;***************************************************************************;;;

  294. (defun vlex-SortPoints (points-list xyz)
  295.   (setq xyz (strcase xyz))
  296.   (cond
  297.     ( (= xyz "Z") ;; 3-point lists required!
  298.      (if
  299.        (apply '=
  300.          (mapcar
  301.      '(lambda (lst) (length lst))
  302.      points-list
  303.    )
  304.        )
  305.        (vl-sort
  306.    points-list
  307.    (function
  308.      (lambda (p1 p2) (< (caddr p1) (caddr p2)))
  309.    )
  310.        )
  311.        (princ "\nCannot sort on Z-coordinates with 2D points!")
  312.      ); endif
  313.     );
  314.     ( (= xyz "X")
  315.      (vl-sort
  316.        points-list
  317.        (function
  318.    (lambda (p1 p2) (< (car p1) (car p2)) )
  319.        )
  320.      )
  321.     );
  322.     ( (= xyz "Y")
  323.      (vl-sort
  324.        points-list
  325.        (function
  326.    (lambda (p1 p2) (< (cadr p1) (cadr p2)) )
  327.        )
  328.      )
  329.     );
  330.   ); cond
  331. )

  332. ;;;***************************************************************************;;;
  333. ;;; MODULE: vlex-CollectionList (collection)              ;;;
  334. ;;; DESCRIPTION: Return a list of collection member names                ;;;
  335. ;;; ARGS: collection<object>                  ;;;
  336. ;;; EXAMPLE: (vlex-CollectionList (vlex-GetLtypes))            ;;;
  337. ;;;***************************************************************************;;;

  338. (defun vlex-CollectionList (Collection / name out)
  339.   (setq out '())
  340.   (vlax-for each Collection
  341.     (setq name (vlex-Name each))
  342.     (setq out (cons name out))
  343.   )
  344.   (reverse out)
  345. )

  346. ;;;***************************************************************************;;;
  347. ;;; MODULE: vlex-DumpCollection (collection)              ;;;
  348. ;;; DESCRIPTION: Display methods and properties for each collection member    ;;;
  349. ;;; ARGS: collection<object>                  ;;;
  350. ;;; EXAMPLE: (vlex-DumpCollection (vlex-GetLayers))            ;;;
  351. ;;;***************************************************************************;;;

  352. (defun vlex-DumpCollection (Collection)
  353.   (vlex-MapCollection Collection 'vlax-dump-object)
  354. )

  355. ;;;***************************************************************************;;;
  356. ;;; MODULE: vlex-MapCollection (collection function-expression)          ;;;
  357. ;;; DESCRIPTION: Apply a function to all members of a given collection        ;;;
  358. ;;; ARGS: collection(vla-object), function              ;;;
  359. ;;; EXAMPLE: (vlex-MapCollection all-arcs 'vlex-DeleteObject)          ;;;
  360. ;;;***************************************************************************;;;

  361. (defun vlex-MapCollection (Collection qFunction)
  362.   (vlax-map-collection Collection qFunction)
  363. )

  364. ;;;***************************************************************************;;;
  365. ;;; MODULE: vlex-DeleteObject (object)                ;;;
  366. ;;; DESCRIPTION: Invokes the Delete method on a given object to erase it      ;;;
  367. ;;; ARGS: object                    ;;;
  368. ;;; EXAMPLE: (vlex-DeleteObject arc-object1)              ;;;
  369. ;;;***************************************************************************;;;

  370. (defun vlex-DeleteObject (obj)
  371.   (princ "\n***DeleteObject")
  372.   (cond
  373.     ( (and
  374.   (not (vlax-erased-p obj))
  375.   (vlax-read-enabled-p obj)
  376.   (vlax-write-enabled-p obj)
  377.       )
  378.      (vlax-invoke-method obj 'Delete)
  379.      (if (not (vlax-object-released-p obj))
  380.        (vlax-release-object obj)
  381.      )
  382.     );
  383.     ( T (princ "\nCannot delete object!") )
  384.   ); cond
  385. )

  386. ;;;***************************************************************************;;;
  387. ;;; MODULE: vlex-MakeObject (object-or-ename)              ;;;
  388. ;;; DESCRIPTION: Converts an ENAME type into a Vla-Object          ;;;
  389. ;;; ARGS: ename-or-object                  ;;;
  390. ;;; EXAMPLE: (setq myobj (vlex-MakeObject (car (entsel))) )          ;;;
  391. ;;;***************************************************************************;;;

  392. (defun vlex-MakeObject (entname)
  393.   (cond
  394.     ( (= (type entname) 'ENAME)
  395.       (vlax-ename->vla-object entname)
  396.     )
  397.     ( (= (type entname) 'VLA-OBJECT)
  398.       entname
  399.     )
  400.   )
  401. )

  402. ;;;***************************************************************************;;;
  403. ;;; MODULE: vlex-ObjectType (object)                ;;;
  404. ;;; DESCRIPTION: Returns ObjectName value for given object          ;;;
  405. ;;; ARGS: object                    ;;;
  406. ;;; EXAMPLE: (= "AcDbArc" (vlex-ObjectType myobject))            ;;;
  407. ;;;***************************************************************************;;;

  408. (defun vlex-ObjectType (obj) (vlax-get-property obj 'ObjectName))

  409. ;;;***************************************************************************;;;
  410. ;;; MODULE: vlex-UndoBegin ()                  ;;;
  411. ;;; DESCRIPTION: Begins an UNDO-MAKE group              ;;;
  412. ;;; ARGS: none                       ;;;
  413. ;;; EXAMPLE: (vlex-UndoBegin)                  ;;;
  414. ;;;***************************************************************************;;;

  415. (defun vlex-UndoBegin () (vlax-invoke-method (vlex-ActiveDocument) 'StartUndoMark))

  416. ;;;***************************************************************************;;;
  417. ;;; MODULE: vlex-UndoEnd ()                  ;;;
  418. ;;; DESCRIPTION: Closes an UNDO group                ;;;
  419. ;;; ARGS: none                      ;;;
  420. ;;; EXAMPLE: (vlex-UndoEnd)                  ;;;
  421. ;;;***************************************************************************;;;

  422. (defun vlex-UndoEnd () (vlax-invoke-method (vlex-ActiveDocument) 'EndUndoMark))

  423. ;;;***************************************************************************;;;
  424. ;;; MODULE: vlex-CopyProp (property source-obj target-obj)          ;;;
  425. ;;; DESCRIPTION: Copy named property from one object to another          ;;;
  426. ;;; ARGS: property(string or quotedval), source(object), target(object)        ;;;
  427. ;;; EXAMPLE: (vlex-CopyProp "Layer" arc-object1 arc-object2)          ;;;
  428. ;;;***************************************************************************;;;

  429. (defun vlex-CopyProp (propName source target)
  430.   (cond
  431.     ( (member (strcase propName)
  432.         '("LAYER" "LINETYPE" "COLOR" "LINETYPESCALE" "LINEWEIGHT"
  433.     "PLOTSTYLENAME" "ELEVATION" "THICKNESS"
  434.    )
  435.       )
  436.       (cond
  437.   ( (and
  438.       (not (vlax-erased-p source))  ;; source not erased?
  439.       (not (vlax-erased-p target))  ;; target not erased?
  440.       (vlax-read-enabled-p source)  ;; can read from source object?
  441.       (vlax-write-enabled-p target) ;; can write to target object?
  442.     )
  443.    (vlax-put-property
  444.      target propName
  445.      (vlax-get-property source propName)
  446.    )
  447.   );
  448.   ( T (princ "\nOne or more objects inaccessible!") )
  449.       ); cond
  450.     );
  451.     ( T (princ "\nInvalid property-key request!") )
  452.   ); cond
  453. )

  454. ;;;***************************************************************************;;;
  455. ;;; MODULE: vlex-MapPropertyList (properties source-obj target-obj)        ;;;
  456. ;;; DESCRIIPTION: Copies a list of properties from one object to another      ;;;
  457. ;;; ARGS: properties(list), source(object), target(object)          ;;;
  458. ;;; EXAMPLE: (vlex-MapPropertyList '("Layer" "Color") arc-object1 arc-object2 ;;;
  459. ;;;***************************************************************************;;;

  460. (defun vlex-MapPropertyList (propList source target)
  461.   (foreach prop propList
  462.     (vlex-CopyProp prop source target)
  463.   )
  464. )

  465. ;;;***************************************************************************;;;
  466. ;;; MODULE: vlex-ProfileImport (profile-name arg-file)            ;;;
  467. ;;; DESCRIPTION: Imports ARG file as new profile            ;;;
  468. ;;; ARGS: profile-name(string), arg-file(string)            ;;;
  469. ;;; EXAMPLE: (vlex-ProfileImport "MyProfile" "c:/test.arg")          ;;;
  470. ;;;***************************************************************************;;;
  471. ;;; VBA equivalent:                    ;;;
  472. ;;;   ThisDrawing.Application.preferences._              ;;;
  473. ;;;     Profiles.ImportProfile _                ;;;
  474. ;;;       strProfileToImport, strARGFileSource, True            ;;;
  475. ;;;***************************************************************************;;;

  476. (defun vlex-ProfileImport (pName ARGfile)
  477.   (cond
  478.     ( (findfile ARGfile)
  479.       (vlax-invoke-method
  480.   (vlax-get-property (vlex-AcadPrefs) "Profiles")
  481.   'ImportProfile pName ARGfile
  482.   (vlax-make-variant 1 :vlax-vbBoolean) ;; == TRUE
  483.       )
  484.     );
  485.     ( T (princ "\nARG file not found to import!") )
  486.   ); cond
  487. )

  488. ;;;***************************************************************************;;;
  489. ;;; MODULE: vlex-ProfileExport (arg-file profile-name T  )          ;;;
  490. ;;; DESCRIPTION:                    ;;;
  491. ;;; ARGS: arg-file(string), profile-name(string), T(Boolean)            ;;;
  492. ;;; EXAMPLE: (vlex-ProfileImport "MyProfile" "c:/test.arg" T)          ;;;
  493. ;;;***************************************************************************;;;
  494. ;;; NOTES:                      ;;;
  495. ;;; Exports the active profile so it can be shared with other users.          ;;;
  496. ;;;***************************************************************************;;;

  497. (defun vlex-ProfileExport (strName strFilename BooleReplace)
  498.   (if (vlex-ProfileExists-p strName)
  499.     (if (not (findfile strFilename))
  500.       (progn
  501.   (vlax-Invoke-Method
  502.     (vlax-Get-Property (vlex-AcadPrefs) "Profiles")
  503.     'ExportProfile strName strFilename
  504.   )
  505.   T  ;; return TRUE
  506.       )
  507.       (if BooleReplace
  508.   (progn
  509.     (vl-file-delete (findfile strFilename))
  510.     (if (not (findfile strFilename))
  511.       (progn
  512.         (vlax-Invoke-Method
  513.     (vlax-Get-Property (vlex-AcadPrefs) "Profiles")
  514.     'ExportProfile strName strFilename
  515.         )
  516.         T  ;; return TRUE
  517.       ); progn
  518.       (princ "\nCannot replace ARG file, aborted.")
  519.     ); endif
  520.   ); progn
  521.   (princ (strcat "\n" strFilename " already exists, aborted."))
  522.       ); endif
  523.     ); endif
  524.   ); endif
  525. )
  526.   
  527. ;;;***************************************************************************;;;
  528. ;;; MODULE: vlex-ProfileDelete (profile-name)              ;;;
  529. ;;; DESCRIPTION: Deletes a profile from the AcadApplication object        ;;;
  530. ;;; ARGS: profile-name(string)                  ;;;
  531. ;;; EXAMPLE: (vlex-ProfileDelete "MyProfile")              ;;;
  532. ;;;***************************************************************************;;;

  533. (defun vlex-ProfileDelete (pName)
  534.   (vlax-invoke-method
  535.     (vlax-get-property (vlex-AcadPrefs) "Profiles")
  536.     'DeleteProfile pName
  537.   )
  538. )

  539. ;;;***************************************************************************;;;
  540. ;;; MODULE: vlex-ProfileExists-p (profile-name)              ;;;
  541. ;;; DESCRIPTION: Boolean test for profile existence            ;;;
  542. ;;; ARGS: profile-name(string)                  ;;;
  543. ;;; EXAMPLE: (if (vlxx-ProfileExists-p "MyProfile") ...)          ;;;
  544. ;;;***************************************************************************;;;

  545. (defun vlex-ProfileExists-p (pName)
  546.   ;;; Search for CAPS profile-name in CAPS list of profiles
  547.   (not
  548.     (not
  549.       (member
  550.   (strcase pName)
  551.   (mapcar 'strcase (vlex-ProfileList))
  552.       )
  553.     )
  554.   )
  555. )

  556. ;;;***************************************************************************;;;
  557. ;;; MODULE: vlex-ProfileList ()                  ;;;
  558. ;;; DESCRIPTION: Returns a list of all profile              ;;;
  559. ;;; ARGS: none                      ;;;
  560. ;;; EXAMPLE:                      ;;;
  561. ;;;***************************************************************************;;;

  562. (defun vlex-ProfileList ( / hold)
  563.   (vlax-invoke-method
  564.     (vlax-get-property (vlex-AcadPrefs) "Profiles")
  565.     'GetAllProfileNames
  566.     'hold
  567.   )
  568.   (if hold
  569.     (vlax-safearray->list hold)
  570.   )
  571. )

  572. ;;;***************************************************************************;;;
  573. ;;; MODULE: vlex-CloseALlDocs                  ;;;
  574. ;;; DESCRIPTION:                    ;;;
  575. ;;; ARGS:                            ;;;
  576. ;;; EXAMPLE:                      ;;;
  577. ;;;***************************************************************************;;;
  578. ;;; Closes all open documents without saving              ;;;
  579. ;;;***************************************************************************;;;

  580. (defun vlex-CloseAllDocs ( / item cur)
  581.   (vlax-For item (vla-Get-Documents (vlex-AcadObject))
  582.     (if (= (vla-Get-Active item) :vlax-False)
  583.       (vla-Close item :vlax-False)
  584.       (setq cur item)
  585.     )
  586.   )
  587.   (vla-SendCommand cur "_.CLOSE")
  588. )

  589. ;;;***************************************************************************;;;
  590. ;;; MODULE: vlex-SaveALlDocs                  ;;;
  591. ;;; DESCRIPTION:                    ;;;
  592. ;;; ARGS:                            ;;;
  593. ;;; EXAMPLE:                      ;;;
  594. ;;;***************************************************************************;;;
  595. ;;; Saves all open documents without saving              ;;;
  596. ;;;***************************************************************************;;;

  597. (defun vlex-SaveAllDocs ( / item cur)
  598.   (vlax-for item (vla-Get-Document (vlex-AcadObject))
  599.     (vla-save item)
  600.   )
  601. )

  602. ;;;***************************************************************************;;;
  603. ;;; MODULE: vlex-Saved-p ()                  ;;;
  604. ;;; DESCRIPTION:                    ;;;
  605. ;;; ARGS:                            ;;;
  606. ;;; EXAMPLE:                      ;;;
  607. ;;;***************************************************************************;;;
  608. ;;; Tests to determine if the Active Document is saved            ;;;
  609. ;;;***************************************************************************;;;

  610. (defun vlex-Saved-p ()
  611.   (= (vla-get-saved (vlex-ActiveDocument)) :vlax-True)
  612. )

  613. ;;;***************************************************************************;;;
  614. ;;; MODULE: vlex-SaveAs...                  ;;;
  615. ;;; DESCRIPTION: Save the ActiveDocument in different acSaveAsType        ;;;
  616. ;;; ARGS:                            ;;;
  617. ;;; EXAMPLE:                      ;;;
  618. ;;;***************************************************************************;;;

  619.   ;;;SaveAsType  acSaveAsType enum; read-write
  620.   ;;;
  621.       ;;;acR12_DXF
  622.       ;;; AutoCAD Release12/LT2 DXF (*.dxf)
  623.       ;;;
  624.       ;;;ac2000_dwg
  625.       ;;; AutoCAD 2000 DWG (*.dwg)
  626.       ;;;
  627.       ;;;ac2000_dxf
  628.       ;;; AutoCAD 2000 DXF (*.dxf)
  629.       ;;;
  630.       ;;;ac2000_Template
  631.       ;;; AutoCAD 2000 Drawing Template File (*.dwt)
  632.       ;;;
  633.       ;;;ac2004_dwg
  634.       ;;; AutoCAD 2004 DWG (*.dwg)
  635.       ;;;
  636.       ;;;ac2004_dxf
  637.       ;;; AutoCAD 2004 DXF (*.dxf)
  638.       ;;;
  639.       ;;;ac2004_Template
  640.       ;;; AutoCAD 2004 Drawing Template File (*.dwt)
  641.       ;;;
  642.       ;;;acNative
  643.       ;;; A synonym for the current drawing release format. If you want your application to save the drawing in the format of whatever version of AutoCAD the application is running on, then use the acNative format.
  644.       ;;;
  645.       ;;;AcUnknown
  646.       ;;; Read-only. The drawing type is unknown or invalid.
  647.    

  648. (defun vlex-SaveAs2000 (name)
  649.   (vla-saveas (vlex-ActiveDocument) name acR15_DWG)
  650. )

  651. (defun vlex-SaveAsR14 (name)
  652.   (vla-saveas (vlex-ActiveDocument) name acR14_DWG)
  653. )

  654. ;;;***************************************************************************;;;
  655. ;;; MODULE: vlex-PurgeAllDocs                  ;;;
  656. ;;; DESCRIPTION: Purges all documents currently opened.            ;;;
  657. ;;; ARGS:                            ;;;
  658. ;;; EXAMPLE:                      ;;;
  659. ;;;***************************************************************************;;;

  660. (defun vlex-PurgeAllDocs ( / item cur)
  661.   (vlax-for item (vla-Get-Document (vlex-AcadObject))
  662.     (vla-PurgeAll item)
  663.   )
  664. )

  665. ;;;***************************************************************************;;;
  666. ;;; MODULE: vlex-ChangeAttributes (lst)                ;;;
  667. ;;; DESCRIPTION:                    ;;;
  668. ;;; ARGS:                      ;;;
  669. ;;; EXAMPLE: (vlex-ChangeAttributes (list blk (cons "tag" "new-value")))      ;;;
  670. ;;;***************************************************************************;;;
  671. ;;; Arguments:
  672. ;;; A list containing one atom and one or more dotted pairs.
  673. ;;; The atom is the entity name of the block to change.
  674. ;;; The dotted pairs consist of the attribute tag and the new value for that attribute.
  675. ;;;
  676. ;;; Notes:
  677. ;;; Modifies the specified attribute in the specified block reference
  678. ;;;***************************************************************************;;;

  679. (defun vlex-ChangeAttributes (lst / blk itm atts)
  680.   (setq blk (vlax-Ename->vla-Object (car lst))
  681.   lst (cdr lst)
  682.   )
  683.   (if (= (vla-Get-HasAttributes blk) :vlax-true)
  684.     (progn
  685.       (setq atts (vlax-SafeArray->list
  686.        (vlax-Variant-Value (vla-GetAttributes blk))
  687.      )
  688.       ); setq
  689.       (foreach item lst
  690.   (mapcar
  691.     '(lambda (x)
  692.        (if (= (strcase (car item)) (strcase (vla-Get-TagString x)))
  693.          (vla-Put-TextString x (cdr item))
  694.        ); endif
  695.      )
  696.     atts
  697.   ); mapcar
  698.       ); foreach
  699.       (vla-Update blk)
  700.     )
  701.   ); endif
  702. )

  703. ;;;***************************************************************************;;;
  704. ;;; MODULE: vlex-GetAttributes (ent)                ;;;
  705. ;;; DESCRIPTION:                    ;;;
  706. ;;; ARGS:                      ;;;
  707. ;;; EXAMPLE:                      ;;;
  708. ;;;***************************************************************************;;;
  709. ;;; Arguments
  710. ;;; The entity name of an attributed block
  711. ;;;
  712. ;;; Example
  713. ;;; (ax::GetAttributes (car (entsel)))
  714. ;;; Returns a list of attribute tags and associated values
  715. ;;;***************************************************************************;;;

  716. (defun vlex-GetAttributes (ent / blkref lst)
  717.   (if (= (vla-Get-ObjectName (setq blkref (vlax-Ename->vla-Object ent))) "AcDbBlockReference")
  718.     (if (vla-Get-HasAttributes blkref)
  719.       (mapcar
  720.   '(lambda (x)
  721.      (setq lst (cons (cons (vla-Get-TagString x) (vla-Get-TextString x)) lst))
  722.    )
  723.   (vlax-safearray->list
  724.     (vlax-variant-value (vla-GetAttributes blkref))
  725.   )
  726.       ); mapcar
  727.     ); endif
  728.   ); endif
  729.   (reverse lst)
  730. )

  731. ;;;***************************************************************************;;;
  732. ;;; MODULE: vlex-ParseString (str delim)              ;;;
  733. ;;; DESCRIPTION:                    ;;;
  734. ;;; ARGS:                      ;;;
  735. ;;; EXAMPLE:                      ;;;
  736. ;;;***************************************************************************;;;
  737. ;;; Arguments
  738. ;;; A delimited string and the delimiter character.
  739. ;;;
  740. ;;; Example:
  741. ;;; (vlex-ParseString (getenv "ACAD") ";")
  742. ;;;
  743. ;;; Notes:
  744. ;;; AutoLISP does not correctly interpret any character code outside the range of
  745. ;;; 1 to 255, so you cannot parse a null-delimited string.
  746. ;;; Returns a list containing all tokens in a delimited string
  747. ;;;***************************************************************************;;;

  748. (defun vlex-ParseString (str delim / lst pos token)
  749.   (setq pos (vl-String-Search delim str))
  750.   (while pos
  751.     (setq lst (cons
  752.     (if (= (setq token (substr str 1 pos)) delim)
  753.       nil
  754.       token
  755.     ); endif
  756.     lst
  757.         )
  758.     str (subst str (+ (strlen delim) pos 1))
  759.     pos (vl-String-Search delim str)
  760.     ); setq
  761.   ); while
  762.   (if (> (strlen str) 0)
  763.     (setq lst (cons str lst))
  764.   )
  765.   (reverse lst)
  766. )
  767.    
  768. ;;;***************************************************************************;;;
  769. ;;; MODULE: vlex-PolyCentroid (poly)                ;;;
  770. ;;; DESCRIPTION:                    ;;;
  771. ;;; ARGS: poly(entity name)                  ;;;
  772. ;;; EXAMPLE:
  773. ;;;***************************************************************************;;;
  774. ;;; Arguments:
  775. ;;; The entity name of a closed, planar polyline
  776. ;;;
  777. ;;; Example:
  778. ;;; (ax:Centroid (car (entsel)))
  779. ;;;
  780. ;;; Returns the centroid of a closed polyline
  781. ;;; Thanks to Tony T for the original concept
  782. ;;;***************************************************************************;;;

  783. (defun vlex-PolyCentroid (poly / pl ms va reg cen)
  784.   (setq pl (vlax-Ename->vla-Object poly)
  785.   ms (vlex-ModelSpace)
  786.   va (vlax-Make-SafeArray vlax-vbObject '(0 . 0))
  787.   )
  788.   (vlax-SafeArray-Put-Element va 0 pl)
  789.   (setq reg (car (vlax-SafeArray->list
  790.        (vlax-Variant-Value (vla-AddRegion ms va))
  791.      )
  792.       )
  793.   cen (vla-Get-Centroid reg)
  794.   )
  795.   (vla-Delete reg)
  796.   (vlax-SafeArray->list (vlax-Variant-Value cen))     
  797. )

  798. ;;;***************************************************************************;;;
  799. ;;; MODULE: vlex-Massoc                          ;;;
  800. ;;; DESCRIPTION:                    ;;;
  801. ;;; ARGS:                      ;;;
  802. ;;; EXAMPLE:                      ;;;
  803. ;;;***************************************************************************;;;
  804. ;;; Originally written by Tony Tanzillo
  805. ;;; Returns a list containing cdrs for every occurence of key in alist
  806. ;;; Arguments:
  807. ;;; An integer and an entity definition list
  808. ;;;
  809. ;;; Usage:
  810. ;;; (vlex-Massoc 10 (entget (car (entsel))))
  811. ;;;
  812. ;;; Notes:
  813. ;;; This is especially useful for retrieving all points associated with a lightweight polyline.
  814. ;;;***************************************************************************;;;

  815. (defun vlex-Massoc (key alist)
  816.   (apply
  817.     'append
  818.     (mapcar '(lambda (x)
  819.          (if (eq (car x) key)
  820.      (list (cdr x))
  821.          )
  822.        )
  823.       alist
  824.     )
  825.   )
  826. )

  827. ;;;***************************************************************************;;;
  828. ;;; MODULE: vlex-Extents                  ;;;
  829. ;;; DESCRIPTION:                    ;;;
  830. ;;; ARGS:                      ;;;
  831. ;;; EXAMPLE:                      ;;;
  832. ;;;***************************************************************************;;;
  833. ;;; Originally written by Tony Tanzillo
  834. ;;; Returns a list containing the min and max points
  835. ;;;
  836. ;;; Arguments
  837. ;;; A list with three or more points
  838. ;;;
  839. ;;; Example
  840. ;;; (vlex-Extents '((1 0 0) (2 2 0) (1 2 0)))
  841. ;;;***************************************************************************;;;

  842. (defun vlex-Extents (plist /)
  843.   (list
  844.     (apply 'mapcar (cons 'min plist))
  845.     (apply 'mapcar (cons 'max plist))
  846.   )
  847. )

  848. ;;;***************************************************************************;;;
  849. ;;; MODULE: vlex-RectCenter                  ;;;
  850. ;;; DESCRIPTION:                    ;;;
  851. ;;; ARGS:                      ;;;
  852. ;;; EXAMPLE:                      ;;;
  853. ;;;***************************************************************************;;;
  854. ;;; Returns the "center" of a rectangle
  855. ;;;
  856. ;;; Arguments
  857. ;;; The entity name of a rectangle
  858. ;;;
  859. ;;; Example
  860. ;;; (vlex-RectCenter (car (entsel)))
  861. ;;;***************************************************************************;;;

  862. (defun vlex-RectCenter (rec)
  863.   (vlex-Mid (vlex-Extents (vlex-Massoc 10 (entget rec))))
  864. )

  865. ;;;***************************************************************************;;;
  866. ;;; MODULE: vlex-Mid (pts)                  ;;;
  867. ;;; DESCRIPTOIN:                    ;;;
  868. ;;; ARGS:                      ;;;
  869. ;;; EXAMPLE:                      ;;;
  870. ;;;***************************************************************************;;;
  871. ;;; Originally written by Michael Weaver
  872. ;;; Returns the point midway between two others
  873. ;;;
  874. ;;; Arguments
  875. ;;; A list of two points
  876. ;;;
  877. ;;; Example
  878. ;;; (mid '((1 1 0) (5 5 0)))
  879. ;;;***************************************************************************;;;

  880. (defun vlex-Mid (pts / p0 p1)
  881.   (setq p0 (nth 0 pts)
  882.   p1 (nth 1 pts)
  883.   )
  884.   (mapcar '(lambda (ord1 ord2) (/ (+ ord1 ord2) 2.0)) p0 p1)
  885. )

  886. ;;;***************************************************************************;;;
  887. ;;; MODULE: vlex-GetPolySegment (poly pt)              ;;;
  888. ;;; DESCRIPTION:                    ;;;
  889. ;;; ARGS:                      ;;;
  890. ;;; EXAMPLE:
  891. ;;;***************************************************************************;;;
  892. ;;; Returns a list containing the endpoints of the selected lwpoly segment    ;;;
  893. ;;; Thanks to Tony Tanzillo for showing me how to improve my routine        ;;;
  894. ;;;
  895. ;;; Arguments:
  896. ;;; The entity name of an lwpolyline and the point at which it was selected
  897. ;;;
  898. ;;; Example:
  899. ;;; (apply 'getseg (entsel))
  900. ;;;***************************************************************************;;;

  901. (defun vlex-GetPolySegment (poly pt / pts i)
  902.   (setq pts (vlex-Massoc 10 (entget poly))
  903.   i (caddar (ssnamex (ssget pt)))
  904.   )
  905.   (list
  906.     (nth (1- i) pts)
  907.     (if
  908.       (and
  909.   (vlex-IsClosed poly)
  910.   (= i (length pts))
  911.       )
  912.       (car pts)
  913.       (nth i pts)
  914.     ); endif
  915.   )
  916. )

  917. ;;;***************************************************************************;;;
  918. ;;; MODULE: vlex-IsClosed (pl)                  ;;;
  919. ;;; DESCRIPTION: Specifies whether the 3D polyline, lightweight polyline,     ;;;
  920. ;;;              polyline, or spline is open or closed.            ;;;
  921. ;;; ARGS: The entity name of an lwpolyline, polyline, or spline.        ;;;
  922. ;;; EXAMPLE: (vlex-IsClosed (car (entsel)))               ;;;
  923. ;;;***************************************************************************;;;
  924. ;;; Returns:
  925. ;;; T if the object has the specified 'Closed and it is really closed;
  926. ;;; nil, if the object hasn't the 'Closed property.
  927. ;;;***************************************************************************;;;

  928. (defun vlex-IsClosed (epl / vpl)
  929.   (setq vpl (vlex-MakeObject epl))
  930.   (if (vlax-property-available-p vpl 'Closed)
  931.     (= (vlax-get-property vpl 'Closed) :vlax-true)
  932.   )
  933. )

  934. ;;;***************************************************************************;;;
  935. ;;; MODULE:                      ;;;
  936. ;;; DESCRIPTION:                    ;;;
  937. ;;; ARGS:                      ;;;
  938. ;;; EXAMPLE:                      ;;;
  939. ;;;***************************************************************************;;;
  940. ;;; Example function that convert ARC objects into CIRCLE objects by first    ;;;
  941. ;;; creating a CIRCLE in place of the ARC and then inheriting the various     ;;;
  942. ;;; properties of the ARC before deleting the ARC itself.          ;;;
  943. ;;;***************************************************************************;;;

  944. (defun vlex-CloseArc ( / arcent arcobj trapobj circ)
  945.   (while (setq arcent (entsel "\nSelect ARC object: "))
  946.     (setq arcobj (vlex-MakeObject (car arcent)))
  947.     (cond
  948.       ( (= "AcDbArc" (vlex-ObjectType arcobj))
  949.       
  950.        (vlex-UndoBegin)
  951.       
  952.        (setq circ
  953.         (vla-addCircle
  954.     (vlex-ModelSpace)
  955.     (vla-Get-center arcobj)
  956.     (vla-Get-radius arcobj)
  957.               )
  958.        )
  959.        (vlex-MapPropertyList
  960.    '("Layer" "Color" "Thickness" "Linetype" "LinetypeScale")
  961.    arcobj circ
  962.        )
  963.        (vlex-DeleteObject arcobj)
  964.        (vlax-Release-Object circ)
  965.       
  966.        (vlex-UndoEnd)
  967.       );
  968.       ( T (princ "\nNot an ARC object, try again...") )
  969.     ); cond
  970.   ); endwhile
  971.   (princ)
  972. )

  973. ;;;***************************************************************************;;;
  974. ;;; MODULE: vlex-Ltype-Exists-p (strLtype)              ;;;
  975. ;;; DESCRIPTION:                      ;;;
  976. ;;; ARGS:                      ;;;
  977. ;;; EXAMPLE: (vlex-Ltype-Exists-p "DASHED")              ;;;
  978. ;;;***************************************************************************;;;

  979. (defun vlex-Ltype-Exists-p (strLtype)
  980.   (cond
  981.     ( (member
  982.   (strcase strLtype)
  983.   (mapcar 'strcase (vlex-ListLtypes))
  984.       )
  985.       T
  986.     );
  987.   )
  988. )

  989. ;;;***************************************************************************;;;
  990. ;;; MODULE: vlex-Apply-Ltype (obj strLtype)              ;;;
  991. ;;; DESCRIPTION:                    ;;;
  992. ;;; ARGS:                      ;;;
  993. ;;; EXAMPLE: (vlex-Apply-Ltype cirobj "DASHED")              ;;;
  994. ;;;***************************************************************************;;;

  995. (defun vlex-Apply-Ltype (obj strLtype / entlist)
  996.   (cond
  997.     ( (vlex-Ltype-Exists-p strLtype)
  998.       (cond
  999.   ( (and
  1000.       (vlax-Read-Enabled-p obj)  ;; object can be read from
  1001.       (vlax-Write-Enabled-p obj)  ;; object can be modified
  1002.     )
  1003.    (vla-Put-Linetype obj strLtype)
  1004.    T ;; return TRUE
  1005.   );
  1006.   ( T (princ "\nVlex-Apply-Ltype: Unable to modify object!") )
  1007.       )
  1008.     );
  1009.     ( T (princ (strcat "\nVlex-Apply-Ltype: Linetype [" strLtype "] not loaded.")) )
  1010.   ); cond
  1011. )

  1012. ;;;***************************************************************************;;;
  1013. ;;; MODULE:                      ;;;
  1014. ;;; DESCRIPTION:                    ;;;
  1015. ;;; ARGS:                      ;;;
  1016. ;;; EXAMPLE:                      ;;;
  1017. ;;;***************************************************************************;;;
  1018. ;;; EXAMPLE: (vlex-AddLine (vlex-ModelSpace) pt1 pt2 "DOORS" 4 "DASHED")
  1019. ;;; NOTES: <intColor> and <strLtype> can each be 'nil'
  1020. ;;;***************************************************************************;;;

  1021. (defun vlex-AddLine (StartPt EndPt strLayer intColor strLtype / obj)
  1022.   (cond
  1023.     ( (and StartPt (listp StartPt) EndPt (listp EndPt))
  1024.       (setq obj (vla-addLine
  1025.       (vlex-ModelSpace)
  1026.       (vlax-3D-Point StartPt)
  1027.       (vlax-3D-Point EndPt)
  1028.     )
  1029.       ); setq
  1030.       (cond
  1031.   ( (vlax-Write-Enabled-p obj)
  1032.     (if strLayer (vla-Put-Layer obj strLayer))
  1033.     (if intColor (vla-Put-Color obj intColor))
  1034.     (if strLtype (vlex-Apply-Ltype obj strLtype))
  1035.     (vla-Update obj)
  1036.     (vlex-MxRelease obj)
  1037.     (entlast)
  1038.   );
  1039.   ( T (princ "\nUnable to modify object properties...") )
  1040.       )
  1041.     );
  1042.     ( T (princ "\nVlex-AddLine: Invalid parameter list...") )
  1043.   )
  1044. ); defun

  1045. (defun vlex-MxRelease (obj) (vlax-Release-Object obj))

  1046. ;;;***************************************************************************;;;
  1047. ;;; MODULE:                      ;;;
  1048. ;;; DESCRIPTION:                    ;;;
  1049. ;;; ARGS:                      ;;;
  1050. ;;; EXAMPLE:                      ;;;
  1051. ;;;***************************************************************************;;;
  1052. ;;; EXAMPLE: (vlex-AddArc (vlex-ModelSpace) pt1 0.5 0 90 "0" 3 "DASHED")
  1053. ;;; NOTES:
  1054. ;;;    <StartAng> and <EndAng> are in DEGREE values, not Radians
  1055. ;;;    <intColor> and <strLtype> can each be 'nil'
  1056. ;;;***************************************************************************;;;

  1057. (defun vlex-AddArc
  1058.        (CenterPt Radius StartAng EndAng strLayer intColor strLtype / obj)
  1059.   (cond
  1060.     ( (and CenterPt (listp CenterPt) Radius StartAng EndAng)
  1061.       (setq obj
  1062.    (vla-addArc objSpace (vlax-3D-Point CenterPt) Radius (vlex-DTR StartAng) (vlex-DTR EndAng) )
  1063.       )
  1064.       (cond
  1065.   ( (vlax-Write-Enabled-p obj)
  1066.     (if strLayer (vla-Put-Layer obj strLayer))
  1067.     (if intColor (vla-Put-Color obj intColor))
  1068.     (if strLtype (vlex-Apply-Ltype obj strLtype))
  1069.     (vla-Update obj)
  1070.     (vlex-MxRelease obj)
  1071.     (entlast)
  1072.   );
  1073.   ( T (princ "\nUnable to modify object properties...") )
  1074.       )
  1075.     );
  1076.     ( T (princ "\nVlex-AddArc: Invalid parameter list...") )
  1077.   ); cond
  1078. )

  1079. ;;;***************************************************************************;;;
  1080. ;;; MODULE:                      ;;;
  1081. ;;; DESCRIPTION:                    ;;;
  1082. ;;; ARGS:                            ;;;
  1083. ;;; EXAMPLE:                            ;;;
  1084. ;;;***************************************************************************;;;
  1085. ;;; EXAMPLE: (vlex-AddCircle (vlex-ModelSpace) pt1 0.5 "0" 3 "DASHED")
  1086. ;;; NOTES: <intColor> and <strLtype> can each be 'nil'
  1087. ;;;***************************************************************************;;;

  1088. (defun vlex-AddCircle
  1089.        (CenterPt Radius strLayer intColor strLtype / obj)
  1090.   (cond
  1091.     ( (and CenterPt (listp CenterPt) Radius)
  1092.       (setq obj (vla-addCircle (vlex-ModelSpace) (vlax-3D-Point CenterPt) Radius))
  1093.       (cond
  1094.        ( (vlax-Write-Enabled-p obj)
  1095.    (if strLayer (vla-Put-Layer obj strLayer))
  1096.    (if intColor (vla-Put-Color obj intColor))
  1097.    (if strLtype (vlex-Apply-Ltype obj strLtype))
  1098.    (vla-Update obj)
  1099.    (vlex-MxRelease obj)
  1100.    (entlast)
  1101.        )
  1102.        ( T (princ "\nUnable to modify object properties...") )
  1103.       ); cond
  1104.     );
  1105.     ( T (princ "\nVlex-AddCircle: Invalid parameter list...") )
  1106.   ); cond
  1107. )

  1108. ;;;***************************************************************************;;;
  1109. ;;; MODULE: vlex-DTR (a)                  ;;;
  1110. ;;; DESCRIPTION:                    ;;;
  1111. ;;; ARGS:                      ;;;
  1112. ;;; EXAMPLE:                             ;;;
  1113. ;;;***************************************************************************;;;

  1114. (defun vlex-DTR (a) (* pi (/ a 180.0)) )

  1115. ;;;***************************************************************************;;;
  1116. ;;; MODULE: vlex-RTD (a)                  ;;;
  1117. ;;; DESCRIPTION:                    ;;;
  1118. ;;; ARGS:                      ;;;
  1119. ;;; EXAMPLE:                             ;;;
  1120. ;;;***************************************************************************;;;

  1121. (defun vlex-RTD (a) (/ (* a 180.0) pi) )

  1122. ;;;***************************************************************************;;;
  1123. ;;; MODULE: vlex-AddPline (space ptlist layer closed color ltype width)        ;;;
  1124. ;;; DESCRIPTION: Create LwPolyline with given properties          ;;;
  1125. ;;; ARGS: space, points-list, layername, closed(T or nil), <color> is        ;;;
  1126. ;;;   integer, <ltype> is string name, <width> is double/real number        ;;;
  1127. ;;; EXMAPLE: (vlex-AddPline (vlex-ModelSpace) ptlist "0" T 3 "DASHED" 0.125)  ;;;
  1128. ;;; NOTES: <Bclosed> <intColor> <dblWidth> and <strLtype> can each be 'nil'   ;;;
  1129. ;;;   which is ByLayer.
  1130. ;;;***************************************************************************;;;

  1131. (defun vlex-AddPline
  1132.        (ptlist strLayer Bclosed intColor strLtype dblWidth
  1133.   / vrtcs lst plgen plist plpoints obj)
  1134.   (cond
  1135.     ( (and ptlist (listp ptlist) (listp (car ptlist)))
  1136.       (setq plist (apply 'append (mapcar '3dpoint->2dpoint ptlist))
  1137.       plpoints (vlex-List->VariantArray plist)
  1138.       obj (vla-AddLightWeightPolyline (vlex-ModelSpace) plpoints)
  1139.       )
  1140.       (cond
  1141.   ( (and
  1142.       (vlax-Read-Enabled-p obj)  ;;; if able to read
  1143.       (vlax-Write-Enabled-p obj)  ;;; if open for change...
  1144.     )
  1145.     (if Bclosed (vla-Put-Closed obj :vlax-True))    ;; make closed
  1146.     (if strLayer (vla-Put-Layer obj strLayer))    ;; apply layer
  1147.     (if intColor (vla-Put-Color obj intColor))    ;; apply color
  1148.     (if dblWidth (vla-Put-ConstantWidth obj dblWidth))  ;; apply constant width
  1149.     (if strLtype ;; apply linetype and linetype generation
  1150.       (progn
  1151.         (vlex-Apply-Ltype obj strLtype)      ;; apply linetype
  1152.         (vla-Put-LinetypeGeneration obj :vlax-True)  ;; apply linetype-gen
  1153.       )
  1154.     )
  1155.     (vla-Update obj)    ;; force graphic update
  1156.     (vlex-MxRelease obj)
  1157.     (entlast)
  1158.   );
  1159.   ( T (princ "\nVlex-AddPline: Unable to modify object!") )
  1160.       ); cond
  1161.     );
  1162.     ( T (princ "\nVlex-AddPline: Invalid parameter list....") )
  1163.   ); cond
  1164. )

  1165. (defun 3dpoint->2dpoint (3dpt / 2dpt)
  1166.   (setq 2dpt (list (car 3dpt) (cadr 3dpt)) )
  1167. )

  1168. (defun 3dpoint-list->2dpoint-list (3dplist / 2dplist)
  1169.   (cond
  1170.     ( (and 3dplist (listp 3dplist) (listp (car 3dplist)))
  1171.       (setq 2dplist (mapcar '(lambda (pt) (list (car pt) (cadr pt))) 3dplist) )
  1172.     )
  1173.     ( T (princ "\n3dpoint-list->2dpoint-list: Invalid parameter list...") )
  1174.   ); cond
  1175. )

  1176. ;;;***************************************************************************;;;
  1177. ;;; MODULE: vlex-List->VariantArray (LIST)              ;;;
  1178. ;;; DESCRIPTION: Convert a LIST into a vla-Variant SafeArray date type        ;;;
  1179. ;;; ARGS: LIST                      ;;;
  1180. ;;; EXAMPLE:                      ;;;
  1181. ;;;***************************************************************************;;;

  1182. (defun vlex-DblList->VariantArray (nList / ArraySpace sArray)
  1183.   ; allocate space for an array of 2d points stored as doubles
  1184.   (setq ArraySpace
  1185.    (vlax-Make-SafeArray
  1186.      vlax-vbDouble  ; element type
  1187.      (cons 0
  1188.        (- (length nList) 1)
  1189.      )
  1190.    )
  1191.   )
  1192.   (setq sArray (vlax-SafeArray-Fill ArraySpace nList))

  1193.   ; return array variant
  1194.   (vlax-Make-Variant sArray)
  1195. )

  1196. (defun vlex-IntList->VarArray (aList)
  1197.   (vlax-SafeArray-Fill
  1198.     (vlax-Make-SafeArray
  1199.       vlax-vbInteger  ; (2) Integer
  1200.       (cons 0 (- (length aList) 1))
  1201.     )
  1202.     aList
  1203.   )
  1204. )

  1205. (defun vlex-VarList->VarArray (aList)
  1206.   (vlax-SafeArray-Fill
  1207.     (vlax-Make-SafeArray
  1208.       vlax-vbVariant   ;(12) Variant
  1209.       (cons 0 (- (length aList) 1))
  1210.     )
  1211.     aList
  1212.   )
  1213. )

  1214. ;;;***************************************************************************;;;
  1215. ;;; MODULE:                      ;;;
  1216. ;;; DESCRIPTION:                    ;;;
  1217. ;;; ARGS:                      ;;;
  1218. ;;; EXAMPLE:                      ;;;
  1219. ;;;***************************************************************************;;;

  1220. (defun vlex-AddLineC (ptlist Bclosed strLayer intColor strLtype / pt1 ptz)
  1221.   (cond
  1222.     ( (and ptlist (listp ptlist) (listp (car ptlist)))
  1223.       (setq pt1 (car ptlist)  ;; save first point
  1224.       ptz (last ptlist)  ;; save last point
  1225.       )
  1226.       (while (and ptlist (>= (length ptlist) 2))
  1227.   (vlex-AddLine (vlex-ModelSpace) (car ptlist) (cadr ptlist) strLayer intColor strLtype)
  1228.   (setq ptlist (cdr ptlist))
  1229.       )
  1230.       (if (= Bclosed T) (vlex-AddLine (vlex-ModelSpace) pt1 ptz strLayer intColor strLtype) )
  1231.     );
  1232.     ( T (princ "\nMakeLineC: Invalid parameter list...") )
  1233.   ); cond
  1234. )

  1235. ;;;***************************************************************************;;;
  1236. ;;; MODULE: vlex-Roll-Ratio (Angle)                ;;;
  1237. ;;; DESCRIPTION: Converts ANGLE<degrees> into ratio for Ellipse roll angles   ;;;
  1238. ;;; ARGS: angle<degrees>                  ;;;
  1239. ;;; EXAMPLE: (setq roll-ratio (vlex-Roll-Ratio 45.0))            ;;;
  1240. ;;;***************************************************************************;;;

  1241. (defun vlex-Roll-Ratio (RollAngle)
  1242.   (cos (vlex-DTR RollAngle))
  1243. )

  1244. ;;;***************************************************************************;;;

  1245. ;;;***************************************************************************;;;
  1246. ;;; MODULE: vlex-AddEllipse (space ctr hmaj roll layer color ltype)        ;;;
  1247. ;;; DESCRIPTION: Create ELLIPSE object with given properties          ;;;
  1248. ;;; ARGS: space centerpt hmajorpt rollangle layer color ltype          ;;;
  1249. ;;; EXAMPLE: (vlex-AddEllipse (vlex-ModelSpace) l1 p2 45 "PARTS" nil nil)     ;;;
  1250. ;;;***************************************************************************;;;
  1251. ;;; NOTES: <space> is object, <centerpt> and <hmajorpt> are point lists       ;;;
  1252. ;;;   <roll> is degrees angle, <layer> is string name, <color> is integer,    ;;;
  1253. ;;;   <ltype> is string name. <color> <ltype> may be 'nil' == ByLayer         ;;;
  1254. ;;;***************************************************************************;;;

  1255. (defun vlex-AddEllipse (ctr hmpt roll strLayer intColor strLtype / lst obj)
  1256.   (cond
  1257.     ( (and ctr (listp ctr) hmpt (listp hmpt) roll)
  1258.       (setq hmpt (list
  1259.        (- (car hmpt) (car ctr))
  1260.        (- (cadr hmpt) (cadr ctr))
  1261.      )
  1262.       obj (vla-addEllipse
  1263.       (vlex-ModelSpace)
  1264.       (vlax-3D-Point ctr)
  1265.       (vlax-3D-Point hmpt)
  1266.       (vlex-Roll-Ratio roll)
  1267.     )
  1268.       )
  1269.       (cond
  1270.   ( (vlax-Write-Enabled-p obj)
  1271.     (if strLayer (vla-Put-Layer obj strLayer))
  1272.     (if intColor (vla-Put-Color obj intColor))
  1273.     (if strLtype (vlex-Apply-Ltype obj strLtype))
  1274.     (vla-Update obj)
  1275.   );
  1276.   ( T (princ "\nUnable to modify object properties...") )
  1277.       ); cond
  1278.       (MxRelease obj)
  1279.       (entlast)
  1280.     );
  1281.     ( T (princ "\nInvalid paprameter list...") )
  1282.   ); cond
  1283. )

  1284. ;;;***************************************************************************;;;
  1285. ;;; MODULE: vlex-AddEllipseArc1                  ;;;
  1286. ;;; DESCRIPTION:                    ;;;
  1287. ;;; ARGS:                      ;;;
  1288. ;;; EXAMPLE:                       ;;;
  1289. ;;;***************************************************************************;;;

  1290. (defun vlex-AddEllipseArc1
  1291.        (ctr hmpt roll StartAng EndAng strLayer intColor strLtype / obj rang)
  1292.   (cond
  1293.     ( (and ctr (listp ctr) hmpt roll)
  1294.       (setq hmpt (list
  1295.        (- (car hmpt) (car ctr))
  1296.        (- (cadr hmhp) (cadr ctr))
  1297.      )
  1298.       obj (vla-addEllipse
  1299.       (vlex-ModelSpace)
  1300.       (vlax-3D-Point ctr)
  1301.       (vlax-3D-Point hmpt)
  1302.       (vlex-Roll->Ratio roll)
  1303.     )
  1304.       )
  1305.       (cond
  1306.   ( (vlax-Write-Enabled-p obj)
  1307.     (vla-Put-StartAngle obj (vlex-DTR StartAng))
  1308.     (vla-Put-EndAngle obj (vlex-DTR EndAng))
  1309.     (if strLayer (vla-Put-Layer obj strLayer))
  1310.     (if intColor (vla-Put-Color obj intColor))
  1311.     (if strLtype (vlex-Apply-Ltype obj strLtype))
  1312.     (vla-Update obj)
  1313.     (MxRelease obj)
  1314.     (entlast)
  1315.   );
  1316.   ( T (princ "\nUnable to modify object properties...") )
  1317.       ); cond
  1318.     );
  1319.     ( T (princ "\nMakeArcEllipse1: Invalid parameter list...") )
  1320.   ); cond
  1321. )

  1322. ;;;*************************************************************************;;;
  1323. ;;; MODULE:                                                                 ;;;
  1324. ;;; DESCRIPTION:                                                            ;;;
  1325. ;;; ARGS:                                                                   ;;;
  1326. ;;; EXAMPLE:                                                                ;;;
  1327. ;;;*************************************************************************;;;

  1328. (defun vlex-AddEllipseArc2
  1329.        (ctr hmpt hmin StartAng EndAng strLayer intColor strLtype / obj rang)
  1330.   (cond
  1331.     ( (and ctr (listp ctr) hmpt (listp hmpt) hmin)
  1332.       (setq hmpt (list
  1333.        (- (car hmpt) (car ctr))
  1334.        (- (cadr hmpt) (cadr ctr))
  1335.      )
  1336.       obj (vla-addEllipse
  1337.       (vlex-ModelSpace)
  1338.       (vlax-3D-Point ctr)
  1339.       (vlax-3D-Point hmpt)
  1340.       hmin
  1341.     )
  1342.       )
  1343.       (cond
  1344.   ( (vlax-Write-Enabled-p obj)
  1345.     (vla-Put-StartAngle obj (vlex-DTR StartAng))
  1346.     (vla-Put-EndAngle obj (vlex-DTR EndAng))
  1347.     (if strLayer (vla-Put-Layer obj strLayer))
  1348.     (if intColor (vla-Put-Color obj intColor))
  1349.     (if strLtype (vlex-Apply-Ltype obj strLtype))
  1350.     (vla-Update obj)
  1351.     (MxRelease obj)
  1352.     (entlast)
  1353.   );
  1354.   ( T (princ "\nUnable to modify object properties...") )
  1355.       ); cond
  1356.     );
  1357.     ( T (princ "\nMakeArcEllipse2: Invalid parameter list...") )
  1358.   ); cond
  1359. )
  1360.   
  1361. ;;;***************************************************************************;;;
  1362. ;;; MODULE:                                                                   ;;;
  1363. ;;; DESCRIPTION: Returns a list consistof start point and end point of the    ;;;
  1364. ;;;              arc, line, or ellipse.                ;;;
  1365. ;;; ARGS:                                                                     ;;;
  1366. ;;; EXAMPLE:                                                                  ;;;
  1367. ;;;***************************************************************************;;;

  1368. (defun vlex-GetEllipseArcPoints
  1369.        (ellent / ename-ellipse vlaobject-ellipse p-start p-end out)
  1370.   (setq vlaObject-Ellipse (vlex-MakeObject ellent)  ;; convert ename to object
  1371.   p-start (vla-Get-StartPoint vlaObject-Ellipse)
  1372.   p-end  (vla-Get-EndPoint   vlaObject-Ellipse)
  1373.   out  (list
  1374.       (vlax-SafeArray->List (vlax-Variant-Value p-start))
  1375.       (vlax-SafeArray->List (vlax-Variant-Value p-end))
  1376.     )
  1377.   )
  1378.   out
  1379. )

  1380. ;;;***************************************************************************;;;
  1381. ;;; MODULE: vlex-AddPoint                  ;;;
  1382. ;;; DESCRIPTION: Creates POINT object with specified properties          ;;;
  1383. ;;; ARGS: point, layer                    ;;;
  1384. ;;; EXAMPLE: (vlex-AddPoint p1 "DEFPOINTS")
  1385. ;;;***************************************************************************;;;

  1386. (defun vlex-AddPoint (pt strLayer / obj)
  1387.   (cond
  1388.     ( (and pt (listp pt))
  1389.       (setq obj (vla-addPoint (vlex-ModelSpace) (vlax-3D-Point pt) ) )
  1390.       (if (vlax-Write-Enabled-p obj)
  1391.   (progn
  1392.     (if strLayer (vla-Put-Layer obj strLayer))
  1393.     (vla-Update obj)
  1394.     (MxRelease obj)
  1395.     (entlast)
  1396.   )
  1397.   (princ "\nVlex-AddPoint: Unable to modify object!")
  1398.       ); if
  1399.     );
  1400.     ( T (princ "\nVlex-AddPoint: Invalid parameter list...") )
  1401.   ); cond
  1402. )

  1403. ;;;***************************************************************************;;;
  1404. ;;; MODULE: vlex-AddText                  ;;;
  1405. ;;; DESCRIPTION: Creates TEXT object with sepecified properties          ;;;
  1406. ;;; ARGS: string, point, justification, style, hgt, wid, rot, lay, color      ;;;
  1407. ;;; EXAMPLE: (vlex-AddText "ABC" p1 "MC" "STANDARD" 0.25 1.0 0 "TEXT" nil)    ;;;
  1408. ;;;***************************************************************************;;;

  1409. (defun vlex-AddText
  1410.        (strTxt pt Just strStyle dblHgt dblWid dblRot strLay intCol / txtobj)
  1411.   (cond
  1412.     ( (setq txtobj
  1413.        (vla-AddText
  1414.          (vlex-ActiveSpace)
  1415.          strTxt
  1416.          (if (not (member (strcase Just) '("A" "F")))
  1417.      (vlax-3d-Point pt)
  1418.      (vlax-3d-Point (car pt))
  1419.          ); endif
  1420.          dblHgt  ;; ignored if Just = "A" (aligned)
  1421.        )
  1422.       )
  1423.       (vla-put-StyleName txtobj strStyle)
  1424.       (vla-put-Layer txtobj strLay)
  1425.       (if intCol (vla-put-Color txtobj intCol))
  1426.       (setq Just (strcase Just))  ;; force to upper case for comparisons...
  1427.      
  1428.     ;; Left/Align/Fit/Center/Middle/Right/BL/BC/BR/ML/MC/MR/TL/TC/TR
  1429.     ;; Note that "Left" is not a normal default.
  1430.     ;;
  1431.     ;; ALIGNMENT TYPES...
  1432.     ;; AcAlignmentLeft=0
  1433.     ;; AcAlignmentCenter=1
  1434.     ;; AcAlignmentRight=2
  1435.     ;; AcAlignmentAligned=3
  1436.     ;; AcAlignmentMiddle=4
  1437.     ;; AcAlignmentFit=5
  1438.     ;; AcAlignmentTopLeft=6
  1439.     ;; AcAlignmentTopCenter=7
  1440.     ;; AcAlignmentTopRight=8
  1441.     ;; AcAlignmentMiddleLeft=9
  1442.     ;; AcAlignmentMiddleCenter=10
  1443.     ;; AcAlignmentMiddleRight=11
  1444.     ;; AcAlignmentBottomLeft=12
  1445.     ;; AcAlignmentBottomCenter=13
  1446.     ;; AcAlignmentBottomRight=14
  1447.     ;;                                                               
  1448.     ;; HORIZONTAL JUSTIFICATIONS...                                 
  1449.     ;; AcHorizontalAlignmentLeft=0                                   
  1450.     ;; AcHorizontalAlignmentCenter=1                                 
  1451.     ;; AcHorizontalAlignmentRight=2                                 
  1452.     ;; AcHorizontalAlignmentAligned=3                                
  1453.     ;; AcHorizontalAlignmentMiddle=4                                 
  1454.     ;; AcHorizontalAlignmentFit=5                                    
  1455.     ;;                                                               
  1456.     ;; VERTICAL JUSTIFICATIONS...                                    
  1457.     ;; AcVerticalAlignmentBaseline=0                                 
  1458.     ;; AcVerticalAlignmentBottom=1                                   
  1459.     ;; AcVerticalAlignmentMiddle=2                                   
  1460.     ;; AcVerticalAlignmentTop=3                                      

  1461.       (cond
  1462.   ( (= Just "L")  ;; Left
  1463.     (vla-put-ScaleFactor txtobj dblWid)
  1464.     (vla-put-Rotation txtobj (DTR dblRot))
  1465.   )
  1466.   ( (= Just "C")  ;; Center
  1467.     (vla-put-Alignment txtobj 1)
  1468.     (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1469.     (vla-put-ScaleFactor txtobj dblWid)
  1470.     (vla-put-Rotation txtobj (DTR dblRot))
  1471.   )
  1472.   ( (= Just "R")  ;; Right
  1473.     (vla-put-Alignment txtobj 2)
  1474.     (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1475.     (vla-put-ScaleFactor txtobj dblWid)
  1476.     (vla-put-Rotation txtobj (DTR dblRot))
  1477.   )
  1478.   ( (= Just "A")  ;; Alignment
  1479.     (vla-put-Alignment txtobj 3)
  1480.     (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1481.   )
  1482.   ( (= Just "M")  ;; Middle
  1483.     (vla-put-Alignment txtobj 4)
  1484.     (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1485.     (vla-put-ScaleFactor txtobj dblWid)
  1486.     (vla-put-Rotation txtobj (DTR dblRot))
  1487.   )
  1488.   ( (= Just "F")  ;; Fit
  1489.     (vla-put-Alignment txtobj 5)
  1490.     (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1491.   )
  1492.   ( (= Just "TL")  ;; Top-Left
  1493.     (vla-put-Alignment txtobj 6)
  1494.     (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1495.     (vla-put-ScaleFactor txtobj dblWid)
  1496.     (vla-put-Rotation txtobj (DTR dblRot))
  1497.   )
  1498.   ( (= Just "TC")  ;; Top-Center
  1499.     (vla-put-Alignment txtobj 7)
  1500.     (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1501.     (vla-put-ScaleFactor txtobj dblWid)
  1502.     (vla-put-Rotation txtobj (DTR dblRot))
  1503.   )
  1504.   ( (= Just "TR")  ;; Top-Right
  1505.     (vla-put-Alignment txtobj 8)
  1506.     (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1507.     (vla-put-ScaleFactor txtobj dblWid)
  1508.     (vla-put-Rotation txtobj (DTR dblRot))
  1509.   )
  1510.         ( (= Just "ML");; Middle-Left
  1511.           (vla-put-Alignment txtobj 9)
  1512.           (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1513.           (vla-put-ScaleFactor txtobj dblWid)
  1514.           (vla-put-Rotation txtobj (DTR dblRot))
  1515.         )
  1516.         ( (= Just "MC");; Middle-Center
  1517.           (vla-put-Alignment txtobj 10)
  1518.           (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1519.           (vla-put-ScaleFactor txtobj dblWid)
  1520.           (vla-put-Rotation txtobj (DTR dblRot))
  1521.         )
  1522.         ( (= Just "MR");; Middle-Right
  1523.           (vla-put-Alignment txtobj 11)
  1524.           (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1525.           (vla-put-ScaleFactor txtobj dblWid)
  1526.           (vla-put-Rotation txtobj (DTR dblRot))
  1527.         )
  1528.         ( (= Just "BL");; Bottom-Left
  1529.           (vla-put-Alignment txtobj 12)
  1530.           (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1531.           (vla-put-ScaleFactor txtobj dblWid)
  1532.           (vla-put-Rotation txtobj (DTR dblRot))
  1533.         )
  1534.         ( (= Just "BC");; Bottom-Center
  1535.           (vla-put-Alignment txtobj 13)
  1536.           (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1537.           (vla-put-ScaleFactor txtobj dblWid)
  1538.           (vla-put-Rotation txtobj (DTR dblRot))
  1539.         )
  1540.         ( (= Just "BR");; Bottom-Right
  1541.           (vla-put-Alignment txtobj 14)
  1542.           (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1543.           (vla-put-ScaleFactor txtobj dblWid)
  1544.           (vla-put-Rotation txtobj (DTR dblRot))
  1545.         )
  1546.       )
  1547.       (vla-Update txtobj)
  1548.       (vlax-Release-Object txtobj)
  1549.       (entlast)
  1550.     );
  1551.   ); cond
  1552. )

  1553. ;;;***************************************************************************;;;
  1554. ;;; MODULE: vlex-AddPolygon                  ;;;
  1555. ;;; DESCRIPTION: Creates a circumscribed polygon            ;;;
  1556. ;;; ARGS: center, radius, sides, flag, width, layer, color, ltype        ;;;
  1557. ;;; EXAMPLE: (vlex-AddPolygon pt1 1.0 6 nil 0 "0" nil "DASHED")            ;;;
  1558. ;;;***************************************************************************;;;

  1559. (defun vlex-AddPolygon
  1560.        (ctrpt dblRad intSides strType dblWid strLay intCol strLtype
  1561.   / pa dg ptlist deg)
  1562.   (setq pa (polar ctrpt 0 dblRad)
  1563.   dg (/ 360.0 intSides)  ;; get angles between faces
  1564.   deg dg
  1565.   )
  1566.   (repeat intSides
  1567.     (setq ptlist
  1568.      (if ptlist
  1569.        (append ptlist (list (polar ctrpt (vlex-DTR deg) dblRad)))
  1570.        (list (polar ctrpt (vlex-DTR deg) dblRad))
  1571.      )
  1572.     )
  1573.     (setq deg (+ dg deg))
  1574.   ); repeat
  1575.   (vlex-AddPline ptlist strLay T intCol strLtype dblWid)
  1576. )

  1577. ;;;***************************************************************************;;;
  1578. ;;; MODULE: vlex-AddRectangle                  ;;;
  1579. ;;; DESCRIPTION: Creates a rectangle with sepecified properties          ;;;
  1580. ;;; ARGS: p1(lower left), p3(upper right), layer, color, linetype, width      ;;;
  1581. ;;; EXAMPLE: (vlex-AddRectangle p1 p3 "0" nil "DASHED" 0.25)                  ;;;
  1582. ;;;***************************************************************************;;;

  1583. (defun vlex-AddRectangle
  1584.        (p1 p3 strLayer intColor strLtype dblWid / p2 p4 obj)
  1585.   (setq p2 (list (car p1) (cadr p3))
  1586.   p4 (list (car p3) (cadr p1))
  1587.   )
  1588.   (cond
  1589.     ( (setq obj (vlex-AddPline (list p1 p2 p3 p4) strLayer T intColor strLtype dblWidth))
  1590.       obj  ;; raise object (entity name)
  1591.     )
  1592.   ); cond
  1593. )

  1594. ;;;***************************************************************************;;;
  1595. ;;; MODULE: vlex-AddSolid                  ;;;
  1596. ;;; DESCRIPTION: Creates a Solid with sepecified properties          ;;;
  1597. ;;; ARGS: points-list, layer(string), color(integer)                  ;;;
  1598. ;;; EXAMPLE: (vlex-AddSolid ptlist "0" nil)                      ;;;
  1599. ;;;***************************************************************************;;;

  1600. (defun vlex-AddSolid (ptlist strLayer intColor / plist obj)
  1601.   (cond
  1602.     ( (and ptlist (listp ptlist) (listp (car ptlist)))
  1603.       (if (= (length ptlist) 3)
  1604.   (setq plist (append ptlist (list (last ptlist))))
  1605.   (setq plist ptlist)
  1606.       )
  1607.       (vlex-DPR "\nMaking solid object...")
  1608.       (cond
  1609.   ( (setq obj (vla-addSolid
  1610.           (vlex-ActiveSpace)
  1611.           (vlax-3D-Point (car plist))
  1612.           (vlax-3D-Point (cadr plist))
  1613.           (vlax-3D-Point (caddr plist))
  1614.           (vlax-3D-Point (cadddr plist))
  1615.                     )
  1616.           )
  1617.     (if strLayer (vla-Put-Layer obj strLayer))
  1618.     (if intColor (vla-Put-Color obj intColor))
  1619.     (vla-Update obj)
  1620.     (vlax-release-object obj)
  1621.     (entlast)
  1622.   );
  1623.   ( T (princ "\nUnable to create object...") )
  1624.       ); cond
  1625.     );
  1626.     ( T (princ "\nVlex-AddSolid: Invalid parameter list...") )
  1627.   ); cond
  1628. )

  1629. (defun vlex-DPR (msg)  ;; debugging status printer
  1630.   (if $DBG (princ msg))
  1631. )

  1632. ;;;***************************************************************************;;;
  1633. ;;; MODULE: vlex-Apply-LtScale (object ltscale)              ;;;
  1634. ;;; DESCRIPTION: Apply object linetype scaling              ;;;
  1635. ;;; ARGS: ename or object, scale (real)                ;;;
  1636. ;;; EXAMPLE: (vlex-Apply-LtScale objLine 24.0)              ;;;
  1637. ;;;***************************************************************************;;;

  1638. (defun vlex-Apply-LtScale (obj dblLtScale)
  1639.   (cond
  1640.     ( (and
  1641.   (vlax-Read-Enabled-p obj)  ;; object can be read from
  1642.   (vlax-Write-Enabled-p obj)  ;; object can be modified
  1643.       )
  1644.       (vla-Put-Linetype dblLtScale)
  1645.       T  ;; return TRUE
  1646.     );
  1647.     ( T (princ "\nVlex-Apply-LtScale: Unable to modify object!") )
  1648.   ); cond
  1649. )

  1650. ;;;***************************************************************************;;;
  1651. ;;; MODULE: vlex-VarSave (vlist)                                              ;;;
  1652. ;;; DESCRIPTION: Save sysvars to global list for restoring later.             ;;;
  1653. ;;; ARGS:                                                                     ;;;
  1654. ;;; EXAMPLE:                                                                  ;;;
  1655. ;;;***************************************************************************;;;

  1656. (setq G$VARS nil)  ; Initialize global variable
  1657. (defun vlex-VarSave (vlist / n)
  1658.   (foreach n vlist
  1659.     (setq G$VARS
  1660.       (if G$VARS
  1661.   (append G$VARS (list (list n (getvar n))))
  1662.   (list (list n (getvar n)))
  1663.       )
  1664.     )
  1665.   )
  1666. )

  1667. ;;;***************************************************************************;;;
  1668. ;;; MODULE: vlex-VarRestore ()                                                ;;;
  1669. ;;; DESCRIPTION: Restore sysvars from global list for restoring later.        ;;;
  1670. ;;; ARGS:                                                                     ;;;
  1671. ;;; EXAMPLE:                                                                  ;;;
  1672. ;;;***************************************************************************;;;

  1673. (defun vlex-VarRestore ( / $orr #err)
  1674.   (defun #err (s)
  1675.     (princ (strcat "\nError: " s))
  1676.     (setq G$VARS nil)
  1677.     (setq *error* $orr)
  1678.     (princ)
  1679.   )
  1680.   (setq $orr *error* *error* #err)
  1681.   (cond
  1682.     ( (and G$VARS (listp G$VARS))
  1683.       (foreach n  G$VARS
  1684.   (cond
  1685.     ( (= (strcase (car n)) "CLAYER")
  1686.       (command "_.layer" "_s" (cadr n) "")
  1687.     )
  1688.     ( (= (strcase (car n)) "VIEWPORT")
  1689.       (command "_.viewres" "_Y" (cadr n) "")
  1690.     )
  1691.     ( T (setvar (car n) (cadr n)) )
  1692.   ); cond
  1693.       ); foreach
  1694.       (setq G$VARS nil)
  1695.     )
  1696.   ); cond
  1697.   (setq *error* $orr $orr nil)
  1698. )

  1699. ;;; ***********************   <   Second Session   >   ***********************;;;

  1700. ;;; Layers -->>

  1701. ;;;***************************************************************************;;;
  1702. ;;; MODULE: vlex-LayerTable ()                                                ;;;
  1703. ;;; DESCRIPTION: Get Document Layers collection object                        ;;;
  1704. ;;; EXAMPLE:                                                                  ;;;
  1705. ;;;***************************************************************************;;;

  1706. (defun vlex-LayerTable()
  1707.   (vla-get-Layers (vlex-ActiveDocument))
  1708. )

  1709. ;;;***************************************************************************;;;
  1710. ;;; MODULE: vlex-LayZero ()                                                   ;;;
  1711. ;;; DESCRIPTION: Set Active Layer in Document to zero "0"                     ;;;
  1712. ;;; EXAMPLE:                                                                  ;;;
  1713. ;;;***************************************************************************;;;

  1714. (defun vlex-LayZero ()
  1715.   (vla-put-ActiveLayer
  1716.     (vlex-ActiveDocument)
  1717.     (vla-Item (vlex-LayerTable) 0)
  1718.   )
  1719. )

  1720. ;;;***************************************************************************;;;
  1721. ;;; MODULE: vlex-LayActive (name)                                             ;;;
  1722. ;;; DESCRIPTION: Set active layer to <name> if it exists                      ;;;
  1723. ;;; EXAMPLE:                                                                  ;;;
  1724. ;;;***************************************************************************;;;

  1725. (defun vlex-LayActive (name / iloc out)
  1726.   (cond
  1727.     ( (and
  1728.   (tblsearch "layer" name)
  1729.   (setq iloc (vl-Position name (vlex-ListLayers)))
  1730.       )
  1731.       (vla-put-ActiveLayer
  1732.   (vlex-ActiveDocument)
  1733.   (vla-Item (vlex-LayerTable) iloc)
  1734.       )
  1735.       (setq out name)
  1736.     );
  1737.     ( T (princ (strcat "\nLayer not defined: " name) ))
  1738.   ); cond
  1739.   out   
  1740. )

  1741. ;;;***************************************************************************;;;
  1742. ;;; MODULE: vlex-LayerOn (LayList)                                            ;;;
  1743. ;;; DESCRIPTION: Turn ON all layers in given list                             ;;;
  1744. ;;; EXAMPLE:                                                                  ;;;
  1745. ;;;***************************************************************************;;;

  1746. (defun vlex-LayerOn (LayList)
  1747.   (vlax-for each (vla-get-layers (vlex-ActiveDocument))
  1748.     (if (member (strcase (vla-get-name each)) LayList)
  1749.       (if (vlax-write-enabled-p each)
  1750.   (vla-put-LayerOn each :vlax-True)
  1751.       )
  1752.     )
  1753.     (vlax-release-object each)
  1754.   )
  1755. )

  1756. ;;;***************************************************************************;;;
  1757. ;;; MODULE: vlex-LayerOff (LayList)                                           ;;;
  1758. ;;; DESCRIPTION: Turn OFF all layers in given list                            ;;;
  1759. ;;; EXAMPLE:                                                                  ;;;
  1760. ;;;***************************************************************************;;;

  1761. (defun vlex-LayerOff (LayList)
  1762.   (vlax-for each (vlex-LayerTable)
  1763.     (if (member (strcase (vla-get-name each)) LayList)
  1764.       (if (vlax-write-enabled-p each)
  1765.   (vla-put-LayerOn each :vlax-False)
  1766.       )
  1767.     )
  1768.     (vlax-release-object each)
  1769.   )
  1770. )
  1771.    
  1772. ;;;***************************************************************************;;;
  1773. ;;; MODULE: vlex-LayerFreeze (LayList)                                        ;;;
  1774. ;;; DESCRIPTION: Freeze all layers in given list                              ;;;
  1775. ;;; EXAMPLE:                                                                  ;;;
  1776. ;;;***************************************************************************;;;

  1777. (defun vlex-LayerFreeze (LayList)
  1778.   (vlax-for each (vlex-LayerTable)
  1779.     (if (member (strcase (vla-get-name each)) LayList)
  1780.       (if (vlax-write-enabled-p each)
  1781.   (vla-put-Freeze each :vlax-True)
  1782.       )
  1783.     )
  1784.     (vlax-release-object each)
  1785.   )
  1786. )

  1787. ;;;***************************************************************************;;;
  1788. ;;; MODULE: vlex-LayerThaw (LayList)                                          ;;;
  1789. ;;; DESCRIPTION: Thaw all layers in given list                                ;;;
  1790. ;;; EXAMPLE:                                                                  ;;;
  1791. ;;;***************************************************************************;;;

  1792. (defun vlex-LayerThaw (LayList)
  1793.   (vlax-for each (vlex-LayerTable)
  1794.     (if (member (strcase (vla-get-name each)) LayList)
  1795.       (if (vlax-write-enabled-p each)
  1796.   (vla-put-Freeze each :vlax-False)
  1797.       )
  1798.     )
  1799.     (vlax-release-object each)
  1800.   )
  1801. )

  1802. ;;;***************************************************************************;;;
  1803. ;;; MODULE: vlex-LayerNoPlot (LayList)                                        ;;;
  1804. ;;; DESCRIPTION: Toggle Plot/No-Plot setting for layers.                      ;;;
  1805. ;;; EXAMPLE: (vlex-LayerNoPlot '("DOORS" "WINDOWS") T)            ;;;
  1806. ;;;                sets layers to NOT plot                  ;;;
  1807. ;;;          (vlex-LayerNoPlot '("DOORS" "WINDOWS") nil)          ;;;
  1808. ;;;                sets layers to PLOT                ;;;
  1809. ;;;***************************************************************************;;;

  1810. (defun vlex-LayerNoPlot (LayList On-Off)
  1811.   (vlax-for each (vlex-LayerTable)
  1812.     (if (member (strcase (vla-get-name each)) LayList )
  1813.       (if (vlax-write-enabled-p each)
  1814.   (if On-Off
  1815.     (vla-put-Plottable each :vlax-True)
  1816.     (vla-put-Plottable each :vlax-False)
  1817.   )
  1818.       )
  1819.     )
  1820.     (vlax-release-object each)
  1821.   )
  1822. )

  1823. ;;;***************************************************************************;;;
  1824. ;;; MODULE: vlex-LayerLock (LayList)                                          ;;;
  1825. ;;; DESCRIPTION: Lock all layers in given list                                ;;;
  1826. ;;; EXAMPLE:                                                                  ;;;
  1827. ;;;***************************************************************************;;;

  1828. (defun vlex-LayerLock (LayList)
  1829.   (vlax-for each (vlex-LayerTable)
  1830.     (if (member (strcase (vla-get-name each)) LayList)
  1831.       (if (vlax-write-enabled-p each)
  1832.   (vla-put-Lock each :vlax-True)
  1833.       )
  1834.     )
  1835.     (vlax-release-object each)
  1836.   )
  1837. )

  1838. ;;;***************************************************************************;;;
  1839. ;;; MODULE: vlex-LayerUnLock (LayList)                                        ;;;
  1840. ;;; DESCRIPTION: Unlock all layers in given list                              ;;;
  1841. ;;; EXAMPLE:                                                                  ;;;
  1842. ;;;***************************************************************************;;;

  1843. (defun vlex-LayerUnLock (LayList)
  1844.   (vlax-for each (vlex-LayerTable)
  1845.     (if (member (strcase (vla-get-name each)) LayList)
  1846.       (if (vlax-write-enabled-p each)
  1847.   (vla-put-Lock each :vlax-False)
  1848.       )
  1849.     )
  1850.     (vlax-release-object each)
  1851.   )
  1852. )

  1853. ;;;***************************************************************************;;;
  1854. ;;; MODULE: vlex-ListLayers-Locked ()                                         ;;;
  1855. ;;; DESCRIPTION: Returns a list of layers that are currently Locked           ;;;
  1856. ;;; EXAMPLE:                                                                  ;;;
  1857. ;;;***************************************************************************;;;

  1858. (defun vlex-ListLayers-Locked ( / each out)
  1859.   (vlax-for each (vlex-LayerTable)
  1860.     (if (= (vlax-get-property each "Lock") :vlax-true)
  1861.       (setq out (cons (vla-get-name each) out))
  1862.     )
  1863.   )
  1864.   out
  1865. )
  1866. ;;;***************************************************************************;;;
  1867. ;;; MODULE: vlex-ListLayers-Frozen ()                                         ;;;
  1868. ;;; DESCRIPTION: Returns a list of layers that are currently frozen or 'nil'  ;;;
  1869. ;;; EXAMPLE:                                                                  ;;;
  1870. ;;;***************************************************************************;;;

  1871. (defun vlex-ListLayers-Frozen ( / each out)
  1872.   (vlax-for each (vlex-LayerTable)
  1873.     (if (= (vlax-get-property each "Freeze") :vlax-true)
  1874.       (setq out (cons (vla-get-name each) out))
  1875.     )
  1876.   )
  1877.   out
  1878. )

  1879. ;;;***************************************************************************;;;
  1880. ;;; MODULE: vlex-ListLayers-Off ()                                            ;;;
  1881. ;;; DESCRIPTION: Returns a list of layers that are currently turned OFF       ;;;
  1882. ;;; EXAMPLE:                                                                  ;;;
  1883. ;;;***************************************************************************;;;

  1884. (defun vlex-ListLayers-Off ( / each out)
  1885.   (vlax-for each (vlex-LayerTable)
  1886.     (if (= (vlax-get-property each "LayerOn") :vlax-false)
  1887.       (setq out (cons (vla-get-name each) out))
  1888.     )
  1889.   )
  1890.   out
  1891. )

  1892. ;;;***************************************************************************;;;
  1893. ;;; MODULE: vlex-ListLayers-Plottable ()                                      ;;;
  1894. ;;; DESCRIPTION: Returns a list of layers that are currently Plottable        ;;;
  1895. ;;; EXAMPLE:                                                                  ;;;
  1896. ;;;***************************************************************************;;;

  1897. (defun vlex-ListLayers-Plottable ( / each out)
  1898.   (vlax-for each (vlex-LayerTable)
  1899.     (if (= (vlax-get-property each "Plottable") :vlax-true)
  1900.       (setq out (cons (vla-get-name each) out))
  1901.     )
  1902.   )
  1903.   out
  1904. )

  1905. ;;;***************************************************************************;;;
  1906. ;;; MODULE: vlex-ListLayers-Plottable-Not ()                                  ;;;
  1907. ;;; DESCRIPTION: Returns a list of layers that are currently NOT Plottable    ;;;
  1908. ;;; EXAMPLE:                                                                  ;;;
  1909. ;;;***************************************************************************;;;

  1910. (defun vlex-ListLayers-Plottalbe-Not ( / each out)
  1911.   (vlax-for each (vlex-LayerTable)
  1912.     (if (= (vlax-get-property each "Plottable") :vlax-false)
  1913.       (setq out (cons (vla-get-name each) out))
  1914.     )
  1915.   )
  1916.   out
  1917. )

  1918. ;;;***************************************************************************;;;
  1919. ;;; MODULE: vlex-Layer-Frozen-p (lname)                                       ;;;
  1920. ;;; DESCRIPTION: Returns T or nil if named layer is currently frozen          ;;;
  1921. ;;; EXAMPLE:                                                                  ;;;
  1922. ;;;***************************************************************************;;;

  1923. (defun vlex-Layer-Frozen-p (lname / each)
  1924.   (if
  1925.     (and
  1926.       (setq fl (vlex-ListLayers-Frozen))  ;; any frozen layers?
  1927.       (member (strcase lname) (mapcar 'strcase fl))
  1928.     )
  1929.     T
  1930.   )
  1931. )

  1932. ;;;***************************************************************************;;;
  1933. ;;; MODULE: vlex-SetLweight (obj intLwt)                                      ;;;
  1934. ;;; DESCRIPTION: Set LineWeight index property for given object (or layer)    ;;;
  1935. ;;; EXAMPLE:                                                                  ;;;
  1936. ;;; NOTES:                      ;;;
  1937. ;;;   "ByLwDefault" = -3                  ;;;
  1938. ;;;   "ByBlock" = -2                    ;;;
  1939. ;;;   "ByLayer" = -1                    ;;;
  1940. ;;;   Other values are 0, 5, 9, 13, 15, 18, 20, 25, 30, 35, 40, 50, 53, 60,   ;;;
  1941. ;;;   70, 80, 90, 100, 106, 120, 140, 158, 200, 211            ;;;
  1942. ;;;***************************************************************************;;;

  1943. (defun vlex-SetLweight (obj intLwt)
  1944.   (cond
  1945.     ( (member intLwt
  1946.         '(0 5 9 13 15 18 20 25 30 35 40 50 60
  1947.     70 80 90 100 106 120 140 158 200 211)
  1948.       )
  1949.       (vla-put-LineWeight obj ineLwt)
  1950.       T ;; return TRUE
  1951.     )
  1952.   ); cond
  1953. )

  1954. ;;;***************************************************************************;;;
  1955. ;;; MODULE: vlex-DefineLayer (strName intColor strLtype booleCur)             ;;;
  1956. ;;; DESCRIPTION: Returns name if named layer is correctly created.            ;;;
  1957. ;;; EXAMPLE: (vlex-DefineLayer "MyLayer1" 3 "DASHED" T)                       ;;;
  1958. ;;;***************************************************************************;;;

  1959. (defun vlex-DefineLayer (strName intColor strLtype booleCur / iloc obj out)
  1960.   (cond
  1961.     ( (not (tblsearch "layer" strName))
  1962.       (setq obj (vla-add (vlex-LayerTable) strName))
  1963.       (setq iloc (vl-position strName (vlex-ListLayers)))
  1964.       (cond
  1965.   ( (vlax-Write-Enabled-p obj)
  1966.     (if intColor (vla-put-Color obj intColor))
  1967.     (if strLtype (vlex-Apply-Ltype obj strLtype))
  1968.   )
  1969.    ( T (princ "\nUnable to modify object properties...") )
  1970.       ); cond
  1971.       (if booleCur
  1972.   (vla-put-ActiveLayer
  1973.     (vlex-ActiveDocument)
  1974.     (vla-Item (vlex-LayerTable) iloc)
  1975.   )
  1976.       )
  1977.       (setq out strName)
  1978.     )
  1979.     ( T
  1980.      (princ (strcat "\nLayer already exists: " strName))
  1981.     )
  1982.   )
  1983.   out
  1984. )


  1985. ;;; Selection Sets -->>

  1986. ;;;***************************************************************************;;;
  1987. ;;; MODULE: vlex-SSetExists-p (Name)                                          ;;;
  1988. ;;; NOTES: Boolean test if Selection Set <name> exists in drawing session     ;;;
  1989. ;;;***************************************************************************;;;

  1990. (defun vlex-SSetExists-p (Name)
  1991.   (not
  1992.     (vl-Catch-All-Error-p
  1993.       (vl-Catch-All-Apply
  1994.   'vla-Item
  1995.   (list (vla-Get-SelectionSets (vlex-ActiveDocument)) Name)
  1996.       )
  1997.     )
  1998.   )
  1999. )

  2000. ;;;***************************************************************************;;;
  2001. ;;; MODULE: vlex-SelectByType (objtype)                                       ;;;
  2002. ;;; NOTES: Return Selection Set of Objects by type (string value)             ;;;
  2003. ;;; EXAMPLE: (setq myset (vlex-SelectByType "CIRCLE"))            ;;;
  2004. ;;;***************************************************************************;;;

  2005. (defun vlex-SelectByType (objtype / ss)
  2006.   (if (vlex-SSetExists-p "%TEMP_SET")
  2007.     (vla-Delete
  2008.       (vla-Item
  2009.   (vla-get-SelectionSets (vlex-ActiveDocument))
  2010.   "%TEMP_SET"
  2011.       )
  2012.     )
  2013.   )
  2014.   (setq ss
  2015.     (vla-Add
  2016.       (vla-get-SelectionSets (vlex-ActiveDocument))
  2017.       "%TEMP_SET"
  2018.     )
  2019.   )
  2020.   (vla-Select ss
  2021.     ACSelectionSetAll nil nil
  2022.     (vlex-IntList->VarArray (list 0))
  2023.     (vlex-VarList->VarArray (list objtype))
  2024.   )
  2025.   ss
  2026. )

  2027. ;;;***************************************************************************;;;
  2028. ;;; MODULE: vlex-SelectOnScreen-Filter (GroupCodes FilterLists)               ;;;
  2029. ;;; NOTES: Return Selection Set by Filtering During On-Screen Selection       ;;;
  2030. ;;;***************************************************************************;;;

  2031. (defun vlex-SelectOnScreen-Filter (GroupCodes FilterLists / ss)
  2032.   (if (vlex-SSetExists-p "%TEMP_SET")
  2033.     (vla-Delete
  2034.       (vla-Item
  2035.   (vla-get-SelectionSets (vlex-ActiveDocument))
  2036.   "%TEMP_SET"
  2037.       )
  2038.     )
  2039.   )
  2040.   (setq ss
  2041.     (vla-Add
  2042.       (vla-get-SelectionSets (vlex-ActiveDocument))
  2043.       "%TEMP_SET"
  2044.     )
  2045.   )
  2046.   (vla-Select ss
  2047.     ACSelectionSetAll nil nil
  2048.     (vlex-IntList->VarArray GroupCodes)
  2049.     (vlex-VarList->VarArray FilterLists)
  2050.   )
  2051.   ss
  2052. )

  2053. ;;;***************************************************************************;;;
  2054. ;;; MODULE: vlex-PICKCIRCLES                                                  ;;;
  2055. ;;; NOTES: Return Selection Set of CIRCLEs on layer "0" only                ;;;
  2056. ;;;***************************************************************************;;;

  2057. (defun vlex-PICKCIRCLES ()
  2058.   (if
  2059.     (setq ss (vlex-SelectOnScreen-Filter '(0 8) '("CIRCLE" "0")))
  2060.     (vlax-For item ss
  2061.       (princ (vla-get-ObjectName item))
  2062.       (terpri)
  2063.     )
  2064.   ); if
  2065.   (terpri)
  2066.   ss
  2067. )

  2068. ;;;***************************************************************************;;;
  2069. ;;; MODULE: vlex-GETCIRCLES                                                   ;;;
  2070. ;;; NOTES: Return Selection Set of CIRCLE Objects only                        ;;;
  2071. ;;;***************************************************************************;;;

  2072. (defun C:GETCIRCLES ()
  2073.   (if (setq ss (vlex-SelectByType "CIRCLE"))
  2074.     (vlax-For item ss
  2075.       (princ (vla-get-ObjectName item))
  2076.       (terpri)
  2077.     )
  2078.   )
  2079.   ss
  2080. )

  2081. ;;; PROFILES . . . -->>

  2082. ;;;***************************************************************************;;;
  2083. ;;; MODULE: vlex-Profiles ()                                                  ;;;
  2084. ;;; NOTES: Get Profiles collection object                               ;;;
  2085. ;;;***************************************************************************;;;

  2086. (defun vlex-Profiles ()
  2087.   (vla-get-Profiles (vlex-AcadPrefs))
  2088. )

  2089. ;;;***************************************************************************;;;
  2090. ;;; MODULE: vlex-ProfileReLoad (name ARGname)                                 ;;;
  2091. ;;; NOTES: Import profile from ARG to replace existing profile definition     ;;;
  2092. ;;; EXAMPLE: (vlex-ProfileReLoad "profile1" "c:\\profiles\\profile1.arg")     ;;;
  2093. ;;;***************************************************************************;;;

  2094. (defun vlex-ProfileReLoad (name ARGname)
  2095.   (cond
  2096.     ( (= (vlax-get-property (vlex-Profiles) 'ActiveProfile) name)
  2097.       ; or following code.
  2098.       ;(= (vla-get-ActiveProfile (vlex-Profiles)) name)
  2099.       (princ "\nCannot delete a profile that is in use." )
  2100.     );
  2101.     ( (and
  2102.   (vlex-ProfileExists-p name)
  2103.   (findfile ARGname)
  2104.       )
  2105.       (vlex-ProfileDelete name)
  2106.       (vlex-ProfileImport name ARGname)
  2107.       (vla-put-ActiveProfile (vlex-Profiles) name)
  2108.     );
  2109.     ( (and
  2110.   (not (vlex-ProfileExists-p name))
  2111.   (findfile ARGname)
  2112.       )
  2113.       (vlex-ProfileImport name ARGname)
  2114.       (vla-put-ActiveProfile (vlex-Profiles) name)
  2115.     );
  2116.     ( (not (findfile ARGname))
  2117.       (princ (strcat "\nCannot locate ARG source: " ARGname))
  2118.     )
  2119.   ); cond
  2120. )

  2121. ;;;***************************************************************************;;;
  2122. ;;; MODULE: vlex-ProfileExportX (pName ARGfile)                               ;;;
  2123. ;;; NOTES: Export an existing profile to a new external .ARG file             ;;;
  2124. ;;; EXAMPLE: (vlex-ProfileExportX "profile1" "c:/profiles/profile1.arg")      ;;;
  2125. ;;;***************************************************************************;;;

  2126. (defun vlex-ProfileExportX (pName ARGfile)
  2127.   (cond
  2128.     ( (vlex-ProfileExists-p pName)
  2129.       (vlax-invoke-method
  2130.   (vlex-Profiles)
  2131.   'ExportProfile pName ARGfile
  2132.   (vlax-make-variant 1 :vlax-vbBoolean)  ;; == TRUE
  2133.       )
  2134.     );
  2135.     ( T (princ "\nNo such profile exists to export.") )
  2136.   ); cond
  2137. )

  2138. ;;;***************************************************************************;;;
  2139. ;;; MODULE: vlex-ProfileCopy (Name1 Name2)                                    ;;;
  2140. ;;; NOTES: Copies an existing profile to a new profile                        ;;;
  2141. ;;; EXAMPLE: (vlex-ProfileCopy pName newName)                                 ;;;
  2142. ;;;***************************************************************************;;;

  2143. (defun vlex-ProfileCopy (Name1 Name2)
  2144.   (cond
  2145.     ( (and
  2146.   (vlex-ProfileExists-p Name1)
  2147.   (not (vlex-ProfileExists-p Name2))
  2148.       )
  2149.       (vlax-invoke-method
  2150.   (vlex-Profiles)
  2151.   'CopyProfile
  2152.   Name1 Name2
  2153.       )
  2154.     );
  2155.     ( (not (vlex-ProfileExists-p Name1))
  2156.       (princ "\nError: No such profile exists.")
  2157.     );
  2158.     ( (vlex-ProfileExists-p Name2)
  2159.       (princ "\nProfile already exists, copy failed.")
  2160.     )
  2161.   ); cond
  2162. )



发表于 2012-11-8 15:44 | 显示全部楼层
不会啊,明经上本来就有啊!http://bbs.mjtd.com/forum.php?mod=viewthread&tid=15980
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-2 21:06 , Processed in 1.576000 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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