1 [功能] 检查加载vlisp扩展

  1. ;;1 [功能] 检查加载vlisp扩展
  2. (vl-Load-COM)

2 常数(lisp编辑器在输出局部变量时,带*的会排在前面.Caoyin这样写很有道理)

  1. ;;2 常数(lisp编辑器在输出局部变量时,带*的会排在前面.Caoyin这样写很有道理)
  2. (setq *En2Obj* vlax-ename->vla-object
  3. *Obj2En* vlax-vla-object->ename
  4. *2PI* (* PI 2)
  5. *0.5PI* (/ PI 2)
  6. *0.25PI* (/ PI 4)
  7. ;;常用VLA对象、集合
  8. *ACAD* (vlax-get-acad-object)
  9. *DOC* (vla-get-ActiveDocument *ACAD*)
  10. *DOCS* (vla-get-Documents *ACAD*)
  11. *MS* (vla-get-modelSpace *DOC*)
  12. *PS* (vla-get-paperSpace *DOC*)
  13. *BLKS* (vla-get-Blocks *DOC*)
  14. *LAYS* (vla-get-Layers *DOC*)
  15. *LTS* (vla-get-Linetypes *DOC*)
  16. *STS* (vla-get-TextStyles *DOC*)
  17. *GRPS* (vla-get-groups *DOC*)
  18. *DIMS* (vla-get-DimStyles *DOC*)
  19. *LOUTS* (vla-get-Layouts *DOC*)
  20. *VPS* (vla-get-Viewports *DOC*)
  21. *VS* (vla-get-Views *DOC*)
  22. *DICS* (vla-get-Dictionaries *DOC*)
  23. ;;常用的几个外部接口对象
  24. *FSO* (vlax-get-or-create-object "Scripting.FileSystemObject")
  25. *WSH* (vlax-get-or-create-object "wscript.shell")
  26. *SHELL* (vlax-get-or-create-object "Shell.Application")
  27. *SCR* (vlax-get-or-create-object "ScriptControl")
  28. *WBEM* (vlax-get-or-create-object "WbemScripting.SWbemLocator")
  29. )

3 [功能] 返回活动空间vla对象

  1. ;;3 [功能] 返回活动空间vla对象
  2. (defun MJ:ActiveSpace()
  3. (if (= 1 (vlax-get-Property DOC* 'ActiveSpace));模型1,布局0
  4. *MS*
  5. *PS*
  6. )
  7. )

4 [功能] 空间

4.1 [功能] 返回当前活动空间名称(“Model” or “Paper”)

  1. ;;4.1 [功能] 返回当前活动空间名称("Model" or "Paper")
  2. (defun MJ:ActiveSpace-Name ()
  3. (if (= 1 (vla-get-ActiveSpace *DOC*))
  4. "Model"
  5. "Paper"
  6. )
  7. )

4.2 [功能] 返回空间名称,如”Model”或者”Layout1”…

  1. ;;4.2 [功能] 返回空间名称,如"Model"或者"Layout1"...
  2. (defun MJ:ActiveSpace1 ()
  3. (vla-get-Name (vla-get-ActiveLayout *DOC*))
  4. )

5 [功能] 返回Preferences vla对象

  1. ;;5 [功能] 返回Preferences vla对象
  2. (defun MJ:AcadPrefs ()
  3. (vlax-Get-Property *ACAD* 'Preferences)
  4. )

6 [功能] 返回指定引用的属性

  1. ;;6 [功能] 返回指定引用的属性
  2. ;;TabName:Application,Display,Drafting,Files,OpenSave,Output,Profiles,Selection,System,User
  3. ;; 示例 (MJ:GetPrefKey 'Files 'SupportPath) 获取支持文件路径
  4. (defun MJ:GetPrefKey (TabName KeyName)
  5. (vlax-get-property
  6. (vlax-get-property
  7. (MJ:AcadPrefs)
  8. TabName
  9. )
  10. KeyName
  11. )
  12. )

7 [功能] 更改引用设置

  1. ;;7 [功能] 更改引用设置
  2. ;; 示例 (MJ:SetPrefKey "OpenSave" "IncrementalSavePercent" 0)
  3. (defun MJ:SetPrefKey (TabName KeyName NewVal)
  4. (vlax-put-property
  5. (vlax-get-property
  6. (MJ:AcadPrefs)
  7. TabName
  8. )
  9. KeyName
  10. NewVal
  11. )
  12. )

8 [功能] 返回 acad对象的属性

  1. ;;8 [功能] 返回 acad对象的属性
  2. ;;PropName:ActiveDocument,Application,Caption,Documents,FullName,Height,HWND,LocaleId,MenuBar,
  3. ;;MenuGroups,Name,Path,Preferences,StatusId,VBE,Version,Visible,Width,WindowLeft,WindowState,WindowTop
  4. ;; 示例 (MJ:AcadProp 'FullName)
  5. (defun MJ:AcadProp (PropName)
  6. (vlax-get-property *ACAD* PropName)
  7. )

9 [功能] 对象名称

  1. ;;9 [功能] 对象名称
  2. ;; 示例 (MJ:Name *ACAD*) returns "AutoCAD"
  3. ;; 示例 (MJ:Name *MS*)返回"*Model_Space"
  4. (defun MJ:Name (obj)
  5. (if (vlax-property-available-p obj 'Name)
  6. (vlax-get-property obj 'Name)
  7. "<NONE_NAME>"
  8. )
  9. )

10 [功能] 文件

10.1 [功能] 打开文件名列表

  1. ;;10.1 [功能] 打开文件名列表
  2. ;;verbose:T,nil
  3. ;; 示例: (MJ:DocsList T)
  4. ;; NOTES: VerboseTfull path+filename ; nilfilenames
  5. (defun MJ:DocsList (verbose / docname out)
  6. (vlax-for each *DOCS*
  7. (if verbose
  8. (setq docname
  9. (strcat
  10. (vlax-get-property each 'Path)
  11. "\\"
  12. (MJ:Name each)
  13. )
  14. )
  15. (setq docname (MJ:Name each))
  16. )
  17. (setq out (cons docname out))
  18. )
  19. (reverse out)
  20. )

10.2 [功能] (打开文件 未打开文件)列表

  1. ;;10.2 [功能] (打开文件 未打开文件)列表
  2. ;;示例(car (MJ:DocsList1 DwgFileLst))取得列表文件中打开的文件列表
  3. (defun MJ:DocsList1 (DwgFileLst / OPENFILELST)
  4. (setq OpenFileLst (vl-remove-if 'VL-FILE-SYSTIME DwgFileLst)
  5. DwgFileLst (vl-remove-if-not 'VL-FILE-SYSTIME DwgFileLst)
  6. )
  7. (if DwgFileLst
  8. (setq DwgFileLst (vl-sort DwgFileLst '<))
  9. )
  10. (if OpenFileLst
  11. (setq OpenFileLst (vl-sort OpenFileLst '<))
  12. )
  13. (list OpenFileLst DwgFileLst)
  14. )

11 [功能] 查询对象属性和方法

  1. ;;11 [功能] 查询对象属性和方法
  2. (defun C:HHDump (/ ent)
  3. (while (setq ent (entsel))
  4. (vlax-Dump-Object
  5. (vlax-Ename->Vla-Object (car ent))
  6. )
  7. )
  8. (princ)
  9. )

12 [功能] 设置 Qleader 命令“引线设置”对话框的相关参数

  1. ;;12 [功能] 设置 Qleader 命令“引线设置”对话框的相关参数
  2. ;;注:<font color=\"red\">引线的箭头跟DIMSTYLE使用同一设置,可以直接修改DIMLDRBLK系统变量</font>
  3. ;;2011.5.5 by caoyin
  4. (defun QleaderSet (/ DICEN)
  5. (setq DICEN (namedobjdict));(enget DICEN)可查看内容(3 . 词典)
  6. (if (dictsearch DICEN "AcadDim")
  7. (dictremove DICEN "AcadDim")
  8. )
  9. (dictadd DICEN
  10. "AcadDim"
  11. (entmakex '((0 . "XRECORD")
  12. (100 . "AcDbXrecord")
  13. (280 . 1)
  14. (90 . 990106)
  15. (3 . "");;-----引线和箭头-〉箭头[用户箭头的缺省块名,""则表示未设置]
  16. (60 . 0);;-----注释-〉注释类型[0,1,2,3,4]
  17. (61 . 0);;-----注释-〉重复使用注释[0,1,2]
  18. (62 . 1);;-----附着-〉文字在右边[0,1,2,3,4]
  19. (63 . 1);;-----附着-〉文字在左边[0,1,2,3,4]
  20. (64 . 0);;-----附着-〉最后一行加下划线[0,1]
  21. (65 . 0);;-----引线和箭头-〉引线[0,1]
  22. (66 . 0);;-----引线和箭头-〉点数-〉无限制[0,1]
  23. (67 . 3);;-----引线和箭头-〉点数[任意正整数]
  24. (68 . 1);;-----注释-〉多行文字选项-〉提示输入宽度[0,1]
  25. (69 . 0);;-----注释-〉多行文字选项-〉始终左对齐[0,1]
  26. (70 . 0);;-----引线和箭头-〉角度约束->第一段[0,1,2,3,4,5]
  27. (71 . 0);;-----引线和箭头-〉角度约束->第二段[0,1,2,3,4,5]
  28. (72 . 0);;-----注释-〉多行文字选项-〉文字边框[0,1]
  29. (40 . 0.0)
  30. (170 . 2);;----控制“引线设置”对话框的缺省选项卡[0,1,2]
  31. ;; (340 . 图元名)
  32. ;;-----当DXF组码60的值为3,且已经设定了块参照的块名,则340组码才会出现
  33. ;;-----格式为(340 . 上次使用块参照作为注释对象,实际插入的块实例的图元名)
  34. )
  35. )
  36. )
  37. )

13 [功能] 求点集中最远,最近点表 ;By 无痕

  1. ;;13 [功能] 求点集中最远,最近点表 ;By 无痕
  2. ;:(最远两点 最近两点)
  3. ;;示例(MJ:lensort (while (setq pt(getpoint)) (setq plst (cons pt plst)))))
  4. ;;(((14857.8 -599.932 0.0) (26695.2 -3687.68 0.0)) ((15733.8 -3687.68 0.0) (15630.7 -3842.07 0.0)))
  5. (defun MJ:lensort (ptlst / pt d maxd mind maxl minl)
  6. (setq minl (list (car ptlst) (cadr ptlst))
  7. maxd 0
  8. mind (apply 'distance minl)
  9. )
  10. (while (setq pt (car ptlst)
  11. ptlst (cdr ptlst)
  12. )
  13. (foreach n ptlst
  14. (setq d (distance n pt))
  15. (cond ((< maxd d)
  16. (setq maxd d
  17. maxl (list n pt)
  18. )
  19. )
  20. ((> mind d)
  21. (setq mind d
  22. minl (list n pt)
  23. )
  24. )
  25. )
  26. )
  27. )
  28. (list maxl minl)
  29. )

14 [功能] 集合数量

14.1 [功能] 返回指定集合的数量

  1. ;;14.1 [功能] 返回指定集合的数量
  2. ;; 示例: (MJ:CollectionCount (MJ:GetLayers)))
  3. (defun MJ:CollectionCount (Collection)
  4. (vlax-get-property Collection 'Count)
  5. )

14.2 [功能] 返回文档集合的数量

  1. ;;
  2. (defun MJ:DocsCount ()
  3. (vlax-get-property *DOCS* 'Count)
  4. )

15 [功能] 返回文档指定对象的属性

  1. ;;15 [功能] 返回文档指定对象的属性
  2. ;;Cname: Active,ActiveDimStyle,ActiveLayer,ActiveLayout,ActiveLinetype,ActivePViewport,ActiveSelectionSet,
  3. ;;ActiveSpace,ActiveTextStyle,ActiveUCS,ActiveViewport,Application,Blocks,Database,Dictionaries,DimStyles,
  4. ;;ElevationModelSpace,ElevationPaperSpace,FileDependencies,FullName,Groups,Height,HWND,Layers,Layouts,Limits,
  5. ;;Linetypes,ModelSpace,MSpace, Name,ObjectSnapMode,PaperSpace,Path,PickfirstSelectionSet,Plot,PlotConfigurations,
  6. ;;Preferences,ReadOnly,RegisteredApplications,Saved,SelectionSets,SummaryInfo,TextStyles,UserCoordinateSystems,Utility,
  7. ;;Viewports,Views,Width,WindowState,WindowTitle
  8. ;;示例 (MJ:DocCollection "WindowState")
  9. (defun MJ:DocCollection (Cname)
  10. (vlax-Get-Property *DOC* Cname)
  11. )

15.1 [功能] 图层集合

  1. ;;15.1 [功能] 图层集合
  2. (defun MJ:GetLayers () (vlax-Get-Property *DOC* 'Layers))

15.2 [功能] 线型集合

  1. ;;15.2 [功能] 线型集合
  2. (defun MJ:GetLtypes () (vlax-Get-Property *DOC* 'Linetypes))

15.4 [功能] 尺寸样式集合

  1. ;;15.4 [功能] 尺寸样式集合
  2. (defun MJ:GetDimStyles () (vlax-Get-Property *DOC* 'DimStyles))

15.5 [功能] 布局集合

  1. ;;15.5 [功能] 布局集合
  2. (defun MJ:GetLayouts () (vlax-Get-Property *DOC* 'Layouts))

15.6 [功能] 词典集合

  1. ;;15.6 [功能] 词典集合
  2. (defun MJ:GetDictionaries () (vlax-Get-Property *DOC* 'Dictionaries))

15.7 [功能] 块集合(不是我们平时绘图时所说的块)

  1. ;;15.7 [功能] 块集合(不是我们平时绘图时所说的块)
  2. (defun MJ:GetBlocks () (vlax-Get-Property *DOC* 'Blocks))

15.8 [功能] 打印配置集合

  1. ;;15.8 [功能] 打印配置集合
  2. (defun MJ:GetPlotConfigs ()(vlax-Get-Property *DOC* 'PlotConfigurations))

15.9 [功能] 视图集合

  1. ;;15.9 [功能] 视图集合
  2. (defun MJ:GetViews () (vlax-Get-Property *DOC* 'Views))

15.10 [功能] 视口集合

  1. ;;15.10 [功能] 视口集合
  2. (defun MJ:GetViewports () (vlax-Get-Property *DOC* 'Viewports))

15.11 [功能] 组集合

  1. ;;15.11 [功能] 组集合
  2. (defun MJ:GetGroups () (vlax-Get-Property *DOC* 'Groups))

15.12 [功能] 注册程序集合

  1. ;;15.12 [功能] 注册程序集合
  2. (defun MJ:GetRegApps () (vlax-Get-Property *DOC* 'RegisteredApplications))

16 [功能] 返回集合成员名称列表

  1. ;;16 [功能] 返回集合成员名称列表
  2. ;;示例 (MJ:ListCollectionMemberNames (MJ:GetLayers))返回:图层列表("0" "中心线" "文字" "DIM")
  3. (defun MJ:ListCollectionMemberNames (collection / out)
  4. (vlax-for each collection
  5. (setq out (cons (MJ:Name each) out))
  6. )
  7. (reverse out)
  8. )

16.1 [功能] 返回线型集合成员名称列表(常量LTS)

  1. ;;16.1 [功能] 返回线型集合成员名称列表(常量*LTS*)
  2. (defun MJ:ListLtypes ()
  3. (MJ:ListCollectionMemberNames (vlax-Get-Property *DOC* 'Linetypes))
  4. )

16.2 [功能] 图层列表(常量LAYS)

  1. ;;16.2 [功能] 图层列表(常量*LAYS*)
  2. ;;示例("0" "中心线" "文字" "DIM")
  3. (defun MJ:ListLayers ()
  4. (MJ:ListCollectionMemberNames (vlax-Get-Property *DOC* 'Layers))
  5. )

16.3 [功能] 返回文字样式集合成员名称列表(常量STS)

  1. ;;16.3 [功能] 返回文字样式集合成员名称列表(常量*STS*)
  2. (defun MJ:ListTextStyles ()
  3. (MJ:ListCollectionMemberNames (vlax-Get-Property *DOC* 'TextStyles))
  4. )

16.4 [功能] 返回尺寸样式集合成员名称列表

  1. ;;16.4 [功能] 返回尺寸样式集合成员名称列表
  2. (defun MJ:ListDimStyles ()
  3. (MJ:ListCollectionMemberNames *DIMS*)
  4. )

16.5 [功能] 返回布局集合成员名称列表

  1. ;;16.5 [功能] 返回布局集合成员名称列表
  2. (defun MJ:ListLayouts ()
  3. (MJ:ListCollectionMemberNames *LOUTS*)
  4. )

16.6 [功能] 返回词典集合成员名称列表

  1. ;;16.6 [功能] 返回词典集合成员名称列表
  2. (defun MJ:ListDictionaries ()
  3. (MJ:ListCollectionMemberNames *DICS*)
  4. )

16.7 [功能] 返回块集合成员名称列表

  1. ;;16.7 [功能] 返回块集合成员名称列表
  2. (defun MJ:ListBlocks ()
  3. (MJ:ListCollectionMemberNames *BLKS*)
  4. )

16.8 [功能] 返回打印配置集合成员名称列表

  1. ;;16.8 [功能] 返回打印配置集合成员名称列表
  2. (defun MJ:ListPlotConfigs ()
  3. (MJ:ListCollectionMemberNames (MJ:GetPlotConfigs))
  4. )

16.9 [功能] 返回视图集合成员名称列表

  1. ;;16.9 [功能] 返回视图集合成员名称列表
  2. (defun MJ:ListViews ()
  3. (MJ:ListCollectionMemberNames (MJ:GetViews))
  4. )

16.10 [功能] 返回视口集合成员名称列表(同常量VPS)

  1. ;;16.10 [功能] 返回视口集合成员名称列表(同常量*VPS*)
  2. (defun MJ:ListViewPorts ()
  3. (MJ:ListCollectionMemberNames (MJ:GetViewports))
  4. )

16.11 [功能] 返回组集合成员名称列表

  1. ;;16.11 [功能] 返回组集合成员名称列表
  2. (defun MJ:ListGroups ()
  3. (MJ:ListCollectionMemberNames (MJ:GetGroups))
  4. )

16.12 [功能] 返回注册程序集合成员名称列表

  1. ;;16.12 [功能] 返回注册程序集合成员名称列表
  2. (defun MJ:ListRegApps ()
  3. (MJ:ListCollectionMemberNames (MJ:GetRegApps))
  4. )

17 [功能] 点表排序(根据x Y 或者Z坐标排序)

  1. ;;17 [功能] 点表排序(根据x Y 或者Z坐标排序)
  2. ;; 示例: (MJ:SortPoints MJ:Points "Y") Y排序
  3. (defun MJ:SortPoints (points-list xyz)
  4. (setq xyz (strcase xyz))
  5. (cond
  6. ((= xyz "Z")
  7. (vl-sort points-list
  8. (function (lambda (p1 p2) (< (caddr p1) (caddr p2))))
  9. )
  10. ;|; 3-point lists required!
  11. (if
  12. (apply '= (mapcar '(lambda (lst) (length lst)) points-list));如果各点长度同
  13. (vl-sort points-list (function (lambda (p1 p2) (< (caddr p1) (caddr p2)))))
  14. (princ "\nCannot sort on Z-coordinates with 2D points!")
  15. )|;
  16. )
  17. ((= xyz "X")
  18. (vl-sort
  19. points-list
  20. (function (lambda (p1 p2) (< (car p1) (car p2))))
  21. )
  22. )
  23. ((= xyz "Y")
  24. (vl-sort
  25. points-list
  26. (function (lambda (p1 p2) (< (cadr p1) (cadr p2))))
  27. )
  28. )
  29. )
  30. )

18 [功能] 集合->列表

  1. ;;18 [功能] 集合->列表
  2. ;; 示例: (MJ:CollectionList (MJ:GetLtypes)) 返回:线性列表
  3. (defun MJ:CollectionList (Collection / name out)
  4. (vlax-for each Collection
  5. (setq name (MJ:Name each))
  6. (setq out (cons name out))
  7. )
  8. (reverse out)
  9. )

19 [功能] 线型数量

  1. ;;19 [功能] 线型数量
  2. (defun MJ:CountLtypes ()
  3. (MJ:CollectionCount (vlax-Get-Property *DOC* 'Linetypes))
  4. )

20 [功能] 对集合对象的每个成员执行指定函数的操作

  1. ;;20 [功能] 对集合对象的每个成员执行指定函数的操作
  2. ;; 示例: (MJ:MapCollection all-arcs 'MJ:DeleteObject)
  3. (defun MJ:MapCollection (Collection qFunction)
  4. (vlax-map-collection Collection qFunction)
  5. )

20.1 [功能] 显示集合对象每个成员的方法和属性.既然是集合,方法是相同的

  1. ;;20.1 [功能] 显示集合对象每个成员的方法和属性.既然是集合,方法是相同的
  2. ;; 示例: (MJ:DumpCollection (MJ:GetLayers))
  3. (defun MJ:DumpCollection (Collection)
  4. (MJ:MapCollection Collection 'vlax-dump-object)
  5. )

20.2 [功能] 删除对象

  1. ;;20.2 [功能] 删除对象
  2. ;; 示例: (MJ:DeleteObject arc-object1)
  3. (defun MJ:DeleteObject (obj)
  4. (princ "\n ***DeleteObject")
  5. (cond
  6. ((and
  7. (not (vlax-erased-p obj));存在
  8. (vlax-read-enabled-p obj);可读
  9. (vlax-write-enabled-p obj);可写
  10. )
  11. (vlax-invoke-method obj 'Delete)
  12. (if (not (vlax-object-released-p obj))
  13. (vlax-release-object obj);释放
  14. )
  15. )
  16. (T (princ "\nCannot delete object!"))
  17. )
  18. )

21.1 [功能] ename<->vla对象

21.1 [功能] ename->vla对象

  1. ;;21.1 [功能] ename->vla对象
  2. ;; 示例: (MJ:MakeObject (car (entsel)))
  3. (defun MJ:MakeObject (entname)
  4. (cond
  5. ((= (type entname) 'ENAME)
  6. (*En2Obj* entname)
  7. )
  8. ((= (type entname) 'VLA-OBJECT)
  9. entname
  10. )
  11. )
  12. )

21.2 [功能] vla对象->ename

  1. ;;21.2 [功能] vla对象->ename
  2. (defun MJ:MakeEname (object)
  3. (if (equal (type object) 'vla-object)
  4. (*Obj2En* object)
  5. object
  6. )
  7. )

22 [功能] 返回对象名称(见9)

  1. ;;22 [功能] 返回对象名称(见9)
  2. ;; 示例: (= "AcDbArc" (MJ:ObjectType MJ:object))
  3. (defun MJ:ObjectType (obj)
  4. (vlax-get-property obj 'ObjectName)
  5. )

23 编组

23.1 编组开始(command “_.undo” “be”)

  1. ;;23.1 编组开始(command "_.undo" "be")
  2. (defun MJ:UndoBegin ()
  3. (vlax-invoke-method *DOC* 'StartUndoMark)
  4. )

23.2 编组结束(command “_.undo” “END”)

  1. ;;23.2 编组结束(command "_.undo" "END")
  2. (defun MJ:UndoEnd ()
  3. (vlax-invoke-method *DOC* 'EndUndoMark)
  4. )

24 [功能] 用一个对象的属性等修改另一个对象的属性

  1. ;;24 [功能] 用一个对象的属性等修改另一个对象的属性
  2. ;;示例(setq source (MJ:MakeObject(car (entsel))) target (MJ:MakeObject(car (entsel))))
  3. ;; (MJ:CopyProp "Layer" source target)用一个对象的图层等修改另一个对象的图层等
  4. (defun MJ:CopyProp (propName source target)
  5. (cond
  6. ((member (strcase propName)
  7. '("LAYER" "LINETYPE" "COLOR"
  8. "LINETYPESCALE" "LINEWEIGHT" "PLOTSTYLENAME"
  9. "ELEVATION" "THICKNESS"
  10. )
  11. )
  12. (cond
  13. ((and
  14. (not (vlax-erased-p source));存在
  15. (not (vlax-erased-p target));存在
  16. (vlax-read-enabled-p source);可读
  17. (vlax-write-enabled-p target);可写
  18. )
  19. (vlax-put-property
  20. target
  21. propName
  22. (vlax-get-property source propName);修改
  23. )
  24. )
  25. (T (princ "\n One or more objects inaccessible!"))
  26. )
  27. )
  28. (T (princ "\n Invalid property-key request!"))
  29. )
  30. )

24.1 [功能] 用一个对象的’(图层 线型…)修改另一个对象的图层 线型…等

  1. ;;24.1 [功能] 用一个对象的'(图层 线型...)修改另一个对象的图层 线型...等
  2. ;; 示例: (MJ:MapPropertyList '("Layer" "Color") arc-object1 arc-object2
  3. (defun MJ:MapPropertyList (propList source target)
  4. (foreach prop propList
  5. (MJ:CopyProp prop source target)
  6. )
  7. )

25 [功能] 配置文件

25.1 [功能] 配置文件集合

  1. ;;25.1 [功能] 配置文件集合
  2. (defun MJ:Profiles ()
  3. (vla-get-Profiles (MJ:AcadPrefs))
  4. )

25.2 [功能] 设置配置文件

  1. ;;25.2 [功能] 设置配置文件
  2. ;; 示例: (MJ:SetProfile "MJ:Profile")
  3. (defun MJ:SetProfile (pname)
  4. (vl-load-com)
  5. (vla-put-ActiveProfile
  6. (vla-get-Profiles
  7. (vla-get-Preferences
  8. *ACAD*
  9. )
  10. )
  11. pname
  12. )
  13. )

25.3 [功能] 重新装载配置文件

  1. ;;25.3 [功能] 重新装载配置文件
  2. ;; 示例: (MJ:ProfileReLoad "profile1" "c:\\profiles\\profile1.arg")
  3. (defun MJ:ProfileReLoad (name ARGname)
  4. (cond
  5. ((= (vlax-get-property (MJ:Profiles) 'ActiveProfile) name)
  6. ;; or following code.
  7. ;;(= (vla-get-ActiveProfile (MJ:Profiles)) name)
  8. (princ "\nCannot delete a profile that is in use.")
  9. )
  10. ((and
  11. (MJ:ProfileExists-p name)
  12. (findfile ARGname)
  13. )
  14. (MJ:ProfileDelete name)
  15. (MJ:ProfileImport name ARGname)
  16. (vla-put-ActiveProfile (MJ:Profiles) name)
  17. )
  18. ((and
  19. (not (MJ:ProfileExists-p name))
  20. (findfile ARGname)
  21. )
  22. (MJ:ProfileImport name ARGname)
  23. (vla-put-ActiveProfile (MJ:Profiles) name)
  24. )
  25. ((not (findfile ARGname))
  26. (princ (strcat "\nCannot locate ARG source: " ARGname))
  27. )
  28. )
  29. )

25.4 [功能] 重启默认配置文件

  1. ;;25.4 [功能] 重启默认配置文件
  2. ;; 示例: (MJ:ProfileReset "profile1")
  3. (defun MJ:ProfileReset (strName)
  4. (if (MJ:ProfileExists-p strName)
  5. (vlax-Invoke-Method
  6. (MJ:Profiles)
  7. 'ResetProfile
  8. strName
  9. )
  10. (princ (strcat "\nProfile [" strName "] does not exist."))
  11. )
  12. )

25.5 [功能] 输出配置文件

  1. ;;25.5 [功能] 输出配置文件
  2. ;; ARGS: arg-file(string), profile-name(string), T(Boolean)
  3. ;; 示例: (MJ:ProfileExport "<<Unnamed Profile>>" "D:/test.arg" T)
  4. (defun MJ:ProfileExport (strName strFilename BooleReplace)
  5. (if (MJ:ProfileExists-p strName)
  6. (if (not (findfile strFilename))
  7. (progn
  8. (vlax-Invoke-Method
  9. (vlax-Get-Property (MJ:AcadPrefs) "Profiles")
  10. 'ExportProfile
  11. strName
  12. strFilename
  13. )
  14. T
  15. )
  16. (if BooleReplace
  17. (progn
  18. (vl-file-delete (findfile strFilename))
  19. (if (not (findfile strFilename))
  20. (progn
  21. (vlax-Invoke-Method
  22. (vlax-Get-Property (MJ:AcadPrefs) "Profiles")
  23. 'ExportProfile
  24. strName
  25. strFilename
  26. )
  27. T
  28. )
  29. (princ "\nCannot replace ARG file, aborted.")
  30. )
  31. )
  32. (princ (strcat "\n" strFilename " already exists, aborted.")
  33. )
  34. )
  35. )
  36. )
  37. )

25.6 [功能] 输出配置文件

  1. ;;25.6 [功能] 输出配置文件
  2. ;; NOTES: Export an existing profile to a new external .ARG file
  3. ;; 示例: (MJ:ProfileExportX "<<Unnamed Profile>>" "D:/test1.arg")
  4. (defun MJ:ProfileExportX (pName ARGfile)
  5. (cond
  6. ((MJ:ProfileExists-p pName)
  7. (vlax-invoke-method
  8. (MJ:Profiles)
  9. 'ExportProfile
  10. pName
  11. ARGfile
  12. (vlax-make-variant 1 :vlax-vbBoolean)
  13. ;; == TRUE
  14. )
  15. )
  16. (T (princ "\nNo such profile exists to export."))
  17. )
  18. )

25.7 [功能] 输入配置文件

  1. ;;25.7 [功能] 输入配置文件
  2. ;; ARGS: profile-name(string), arg-file(string)
  3. ;; 示例: (MJ:ProfileImport "MJ:Profile" "c:/test.arg")
  4. ;; VBA equivalent: ;;
  5. ;; ThisDrawing.Application.preferences._ ;;
  6. ;; Profiles.ImportProfile _ ;;
  7. ;; strProfileToImport, strARGFileSource, True ;;
  8. (defun MJ:ProfileImport (pName ARGfile)
  9. (cond
  10. ((findfile ARGfile)
  11. (vlax-invoke-method
  12. (vlax-get-property (MJ:AcadPrefs) "Profiles")
  13. 'ImportProfile
  14. pName
  15. ARGfile
  16. (vlax-make-variant 1 :vlax-vbBoolean)
  17. ;; == TRUE
  18. )
  19. ) ;
  20. (T (princ "\nARG file not found to import!"))
  21. )
  22. )

25.8 [功能] 复制配置文件

  1. ;;25.8 [功能] 复制配置文件
  2. ;; 示例: (MJ:ProfileCopy pName newName)
  3. (defun MJ:ProfileCopy (Name1 Name2)
  4. (cond
  5. ((and
  6. (MJ:ProfileExists-p Name1)
  7. (not (MJ:ProfileExists-p Name2))
  8. )
  9. (vlax-invoke-method
  10. (MJ:Profiles)
  11. 'CopyProfile
  12. Name1
  13. Name2
  14. )
  15. ) ;
  16. ((not (MJ:ProfileExists-p Name1))
  17. (princ "\nError: No such profile exists.")
  18. ) ;
  19. ((MJ:ProfileExists-p Name2)
  20. (princ "\nProfile already exists, copy failed.")
  21. )
  22. )
  23. )

25.9 [功能] 重命名配置文件

  1. ;;25.9 [功能] 重命名配置文件
  2. ;; 示例: (MJ:ProfileRename oldName newName)
  3. (defun MJ:ProfileRename (oldName newName)
  4. (cond
  5. ((and
  6. (MJ:ProfileExists-p oldName)
  7. (not (MJ:ProfileExists-p newName))
  8. )
  9. (vlax-invoke-method
  10. (MJ:Profiles)
  11. 'RenameProfile
  12. oldName
  13. newName
  14. )
  15. )
  16. (T (princ))
  17. ;; add your error handling here?
  18. )
  19. )

25.10 [功能] 删除配置文件

  1. ;;25.10 [功能] 删除配置文件
  2. ;; 示例: (MJ:ProfileDelete "MJ:Profile")
  3. (defun MJ:ProfileDelete (pName)
  4. (vlax-invoke-method
  5. (vlax-get-property (MJ:AcadPrefs) "Profiles")
  6. 'DeleteProfile
  7. pName
  8. )
  9. )

25.11 [功能] 配置文件是否存在

  1. ;;25.11 [功能] 配置文件是否存在
  2. ;; 示例: (if (MJ:ProfileExists-p "<<Unnamed Profile>>") ...)
  3. (defun MJ:ProfileExists-p (pName)
  4. (member (strcase pName) (mapcar 'strcase (MJ:ProfileList)))
  5. )

25.12 [功能] 配置文件列表

  1. ;;25.12 [功能] 配置文件列表
  2. ;;返回示例("<<Unnamed Profile>>" "yky_m2006")
  3. (defun MJ:ProfileList (/ hold)
  4. (vlax-invoke-method
  5. (vlax-get-property (MJ:AcadPrefs) "Profiles")
  6. 'GetAllProfileNames
  7. 'hold
  8. )
  9. (if hold
  10. (vlax-safearray->list hold)
  11. )
  12. )

26-161

  1. ;;26.1 [功能] 非当前文档,关闭(不保存)
  2. ;; Author: Frank Whaley
  3. (defun MJ:CloseAll (/ item cur)
  4. (vl-load-com)
  5. (vlax-for item *DOCS*
  6. (if (= (vla-get-active item) :vlax-false)
  7. (vla-close item :vlax-false)
  8. (setq cur item)
  9. )
  10. )
  11. ;;(vla-sendcommand cur "_.CLOSE")
  12. (command "vbastmt" "AcadApplication.activeDocument.close false ");关闭当前文档
  13. )
  14. ;;27.1 [功能] 保存所有文档
  15. (defun MJ:SaveAllDocs (/ item)
  16. (vlax-for item *DOCS*
  17. (vla-save item)
  18. )
  19. )
  20. ;;27.2 [功能] 活动文档是否已经保存?
  21. (defun MJ:Saved-p ()
  22. (= (vla-get-saved *DOC*) :vlax-True)
  23. )
  24. ;;acR12_DXF,AutoCAD Release12/LT2 DXF (*.dxf)
  25. ;;ac2000_dwg,AutoCAD 2000 DWG (*.dwg)
  26. ;;ac2000_dxf,AutoCAD 2000 DXF (*.dxf)
  27. ;;ac2000_Template,AutoCAD 2000 Drawing Template File (*.dwt)
  28. ;;ac2004_dwg,AutoCAD 2004 DWG (*.dwg)
  29. ;;ac2004_dxf,AutoCAD 2004 DXF (*.dxf)
  30. ;;ac2004_Template,AutoCAD 2004 Drawing Template File (*.dwt)
  31. ;;acNative,A synonym for the current drawing release format
  32. ;;AcUnknown,Read-only. The drawing type is unknown or invalid.
  33. ;;27.3 [功能] 另存为2K格式
  34. (defun MJ:SaveAs2000 (name)
  35. (vla-saveas *DOC* name acR15_DWG)
  36. )
  37. ;;27.4 [功能] 另存为R14格式
  38. (defun MJ:SaveAsR14 (name)
  39. (vla-saveas *DOC* name acR14_DWG)
  40. )
  41. ;;28.1 [功能] 清理打开文档
  42. (defun MJ:PurgeAllDocs (/ item cur)
  43. (vlax-for item *DOCS*
  44. (vla-PurgeAll item)
  45. )
  46. )
  47. ;;28.2 [功能] 删除未使用的图层,比purge彻底
  48. (defun MJ:LayerDelete ()
  49. (vl-Load-Com)
  50. (vl-Catch-All-Apply
  51. '(lambda ()
  52. (vla-Remove
  53. (vla-GetExtensionDictionary
  54. (vla-Get-Layers
  55. *DOC*
  56. )
  57. )
  58. "ACAD_LAYERFILTERS"
  59. )
  60. )
  61. )
  62. (princ)
  63. )
  64. ;;29.1 [功能] 取得选定块的指定属性
  65. ;; (MJ:GetTagTextStringByRef (*En2Obj* (car (entsel))) "设计")
  66. (defun MJ:GetTagTextStringByRef (br tagname / atts tag str)
  67. (if (and
  68. (= (vla-get-hasattributes br) :vlax-true)
  69. (safearray-value
  70. (setq atts
  71. (vlax-variant-value
  72. (vla-getattributes br)
  73. )
  74. )
  75. )
  76. )
  77. (foreach tag (vlax-safearray->list atts)
  78. (if (= (strcase tagname) (strcase (vla-get-tagstring tag)))
  79. (setq str (vla-get-TextString tag))
  80. )
  81. )
  82. )
  83. str
  84. )
  85. ;;29.2 [功能] 取得块属性列表
  86. ;(MJ:GetAttributes (car (entsel)))取得属性列表(("比例" . "") ("材料" . "Q235"))
  87. (defun MJ:GetAttributes (ent / blkref lst)
  88. (if (= (vla-Get-ObjectName
  89. (setq blkref (vlax-Ename->vla-Object ent))
  90. )
  91. "AcDbBlockReference"
  92. )
  93. (if (vla-Get-HasAttributes blkref)
  94. (mapcar
  95. '(lambda (x)
  96. (setq
  97. lst (cons
  98. (cons (vla-Get-TagString x) (vla-Get-TextString x))
  99. lst
  100. )
  101. )
  102. )
  103. (vlax-safearray->list
  104. (vlax-variant-value (vla-GetAttributes blkref))
  105. )
  106. )
  107. )
  108. )
  109. (reverse lst)
  110. )
  111. ;;29.3 [功能] [功能] 取得块属性列表
  112. ;; 示例: (MJ:GetAttributes (car (entsel))返回(("比例" "" <Entity name: 7efd2ad0>)(...))
  113. (defun MJ:GetAttributes (ent / lst)
  114. (if (safearray-value
  115. (setq lst
  116. (vlax-variant-value
  117. (vla-getattributes
  118. (vlax-ename->vla-object ent)
  119. )
  120. )
  121. )
  122. )
  123. (mapcar
  124. '(lambda (x)
  125. (list
  126. (vla-get-tagstring x)
  127. (vla-get-textstring x)
  128. (*Obj2En* x)
  129. )
  130. )
  131. (vlax-safearray->list lst)
  132. )
  133. )
  134. )
  135. ;;29.4 [功能] Returns a list of constant attributes tags and their values
  136. ;; 示例: (MJ:GetConstantAttributes (car (entsel)))
  137. (defun MJ:GetConstantAttributes (ent / atts)
  138. (vl-load-com)
  139. (cond
  140. ((and (safearray-value
  141. (setq atts
  142. (vlax-variant-value
  143. (vla-getconstantattributes
  144. (vlax-ename->vla-object ent)
  145. )
  146. )
  147. )
  148. )
  149. )
  150. (mapcar
  151. '(lambda (x)
  152. (cons (vla-get-tagstring x) (vla-get-textstring x))
  153. )
  154. (vlax-safearray->list atts)
  155. )
  156. ) ;
  157. (T
  158. (princ
  159. (strcat
  160. "\nThe block reference \""
  161. (vla-get-Name (vlax-ename->vla-object ent))
  162. "\" doesn't include constant attributes tags and their values"
  163. )
  164. )
  165. )
  166. )
  167. )
  168. ;;30.1 [功能] 更改块指定属性
  169. ;; (MJ:PutTagTextString "块名" tagname "new value")
  170. (defun MJ:PutTagTextString
  171. (bn tagname textstring / layout i atts tag)
  172. (vlax-for layout *LOUTS*
  173. (vlax-for i (vla-get-block layout)
  174. (if (and
  175. (= (vla-get-objectname i) "AcDbBlockReference")
  176. (= (strcase (vla-get-name i)) (strcase bn))
  177. )
  178. (if (and
  179. (= (vla-get-hasattributes i) :vlax-true)
  180. (safearray-value
  181. (setq atts
  182. (vlax-variant-value
  183. (vla-getattributes i)
  184. )
  185. )
  186. )
  187. )
  188. (foreach tag (vlax-safearray->list atts)
  189. (if (= (strcase tagname) (strcase (vla-get-tagstring tag)))
  190. (vla-put-TextString tag textstring)
  191. )
  192. )
  193. (vla-update i)
  194. )
  195. )
  196. )
  197. )
  198. )
  199. ;;30.2 [功能] 块的属性值改为新值---纯lisp by 自贡黄明儒
  200. ;;示例(attchg (car (entsel)) "设计" "aaa")
  201. (defun attchg (ent attname new / EN ENTLIST)
  202. (defun MJ:DXF (IT LST)
  203. (cdr (assoc IT LST))
  204. )
  205. (if (and (setq en ent)
  206. (setq entlist (entget en))
  207. (equal (MJ:DXF 0 entlist) "INSERT")
  208. (equal (MJ:DXF 66 entlist) 1) ;=1则块有属性值
  209. )
  210. (while (and en
  211. (setq en (entnext en))
  212. (setq entlist (entget en))
  213. (equal (MJ:DXF 0 entlist) "ATTRIB")
  214. )
  215. (if (= (strcase (MJ:DXF 2 entlist)) (strcase attname))
  216. (progn (entmod (subst (cons 1 new) (assoc 1 entlist) entlist))
  217. (entupd ent)
  218. (setq en nil)
  219. )
  220. )
  221. )
  222. )
  223. (princ)
  224. )
  225. ;;30.3 [功能] 更改选定块的指定属性
  226. ;; (MJ:PutTagTextStringByRef (*En2Obj* (car (entsel))) "设计" "new value")
  227. (defun MJ:PutTagTextStringByRef (br tagname textstring / atts tag)
  228. (if (and
  229. (= (vla-get-hasattributes br) :vlax-true)
  230. (safearray-value
  231. (setq atts
  232. (vlax-variant-value
  233. (vla-getattributes br)
  234. )
  235. )
  236. )
  237. )
  238. (foreach tag (vlax-safearray->list atts)
  239. (if (= (strcase tagname) (strcase (vla-get-tagstring tag)))
  240. (vla-put-TextString tag textstring)
  241. )
  242. )
  243. (vla-update br)
  244. )
  245. )
  246. ;;30.4 [功能] 更改块多个属性
  247. ;;(setq blk (car (entsel)))
  248. ;;(MJ:ChangeAttributes (list blk (cons "设计" "AA")(cons "名称" "BB")))
  249. (defun MJ:ChangeAttributes (lst / blk itm atts)
  250. (setq blk (vlax-Ename->vla-Object (car lst))
  251. lst (cdr lst)
  252. )
  253. (if (= (vla-Get-HasAttributes blk) :vlax-true) ;如果有属性
  254. (progn
  255. (setq atts (vlax-SafeArray->list
  256. (vlax-Variant-Value (vla-GetAttributes blk))
  257. )
  258. )
  259. (foreach item lst
  260. (mapcar
  261. '(lambda (x)
  262. (if
  263. (= (strcase (car item)) (strcase (vla-Get-TagString x)))
  264. (vla-Put-TextString x (cdr item))
  265. )
  266. )
  267. atts
  268. )
  269. )
  270. (vla-Update blk)
  271. )
  272. )
  273. )
  274. ;;30.5 [功能] 更改块多个属性
  275. ;; 示例: (MJ:ChangeAttribute (list ename '("MJ:Attribute" . "NewValue")))
  276. ;; 示例 (MJ:ChangeAttribute (list (car (entsel)) '("设计" . "NewValue")))
  277. (defun MJ:ChangeAttribute (lst / item atts)
  278. (vl-load-com)
  279. (if (safearray-value
  280. (setq atts
  281. (vlax-variant-value
  282. (vla-getattributes (vlax-ename->vla-object (car lst)))
  283. )
  284. )
  285. )
  286. (progn
  287. (foreach item (cdr lst)
  288. (mapcar
  289. '(lambda (x)
  290. (if
  291. (= (strcase (car item)) (strcase (vla-get-tagstring x)))
  292. (vla-put-textstring x (cdr item))
  293. )
  294. )
  295. (vlax-safearray->list atts)
  296. )
  297. )
  298. (vla-update (vlax-ename->vla-object (car lst)))
  299. )
  300. )
  301. )
  302. ;;31.1 [功能] 返回指定(块名 标记 属性值)的块 选择集
  303. ;; 示例: (MJ:SelectAttributedBlocks '("块名" "Tag" "value"))
  304. (defun MJ:SelectAttributedBlocks (lst / ss ss2 c ent att)
  305. (if (setq ss (ssget "X" (list (cons 0 "INSERT") (cons 2 (car lst)))))
  306. (progn
  307. (setq c 0)
  308. (repeat (sslength ss)
  309. (setq ent (vlax-ename->vla-object (ssname ss c)))
  310. (if (vla-get-hasattributes ent)
  311. (foreach att (vlax-safearray->list
  312. (vlax-variant-value (vla-getattributes ent))
  313. )
  314. (if
  315. (= (strcase (vla-get-tagstring att)) (strcase (cadr lst)))
  316. (if (= (strcase (vla-get-textstring att))
  317. (strcase (caddr lst))
  318. )
  319. (progn
  320. (vla-highlight ent :vlax-true)
  321. (if (not ss2)
  322. (setq ss2 (ssadd (ssname ss c)))
  323. (ssadd (ssname ss c) ss2)
  324. )
  325. )
  326. )
  327. )
  328. )
  329. )
  330. (setq c (1+ c))
  331. )
  332. )
  333. )
  334. ss2
  335. )
  336. ;;31.2 [功能] 返回指定(块名 标记 属性值)的块 选择集
  337. ;; (MJ:FindBlockTagValue "blockname" "tagname" "tagvalue")
  338. (defun MJ:FindBlockTagValue
  339. (bn tagname value / layout i atts tag sset c)
  340. (vlax-for layout *LOUTS*
  341. (vlax-for i (vla-get-block layout)
  342. (if (and
  343. (= (vla-get-objectname i) "AcDbBlockReference")
  344. (= (strcase (vla-get-name i)) (strcase bn))
  345. )
  346. (if (and
  347. (= (vla-get-hasattributes i) :vlax-true)
  348. (safearray-value
  349. (setq atts
  350. (vlax-variant-value
  351. (vla-getattributes i)
  352. )
  353. )
  354. )
  355. )
  356. (progn
  357. (foreach tag (vlax-safearray->list atts)
  358. (if (and
  359. (= (strcase tagname)
  360. (strcase (vla-get-TagString tag))
  361. )
  362. (= value (vla-get-TextString tag))
  363. )
  364. (progn
  365. (if (not sset)
  366. (setq sset (ssadd (*Obj2En* i)))
  367. (ssadd (*Obj2En* i) sset)
  368. )
  369. )
  370. )
  371. )
  372. )
  373. )
  374. )
  375. )
  376. )
  377. (sssetfirst nil sset)
  378. )
  379. ;;32.1 [功能] 更改属性位置
  380. ;; (MJ:ChangeTagIns "sheet-text" "a3-scale" '(703.4722 17.8350 0))
  381. (defun MJ:ChangeTagIns (bn tagname ins / layout i atts tag)
  382. (defun list->variantArray (ptsList / arraySpace sArray)
  383. (setq arraySpace
  384. (vlax-make-safearray
  385. vlax-vbdouble
  386. (cons 0 (- (length ptsList) 1))
  387. )
  388. )
  389. (setq sArray (vlax-safearray-fill arraySpace ptsList))
  390. (vlax-make-variant sArray)
  391. )
  392. (vlax-for layout *LOUTS*
  393. (vlax-for i (vla-get-block layout)
  394. (if (and
  395. (= (vla-get-objectname i) "AcDbBlockReference")
  396. (= (strcase (vla-get-name i)) (strcase bn))
  397. )
  398. (if (and
  399. (= (vla-get-hasattributes i) :vlax-true)
  400. (safearray-value
  401. (setq atts
  402. (vlax-variant-value
  403. (vla-getattributes i)
  404. )
  405. )
  406. )
  407. )
  408. (foreach tag (vlax-safearray->list atts)
  409. (if (= (strcase tagname) (strcase (vla-get-tagstring tag)))
  410. (vla-put-InsertionPoint tag (list->variantArray ins))
  411. )
  412. )
  413. (vla-update i)
  414. )
  415. )
  416. )
  417. )
  418. )
  419. ;;32.2 [功能] 更改块属性宽度
  420. ;; (MJ:ChangeTagWidth <block name> <tag name> <tag height>)
  421. ;; (MJ:ChangeTagWidth "panel1" "drw-no" 0.97)
  422. (defun MJ:ChangeTagWidth (bn tagname tagwidth / layout i atts tag)
  423. (vlax-for layout *LOUTS*
  424. (vlax-for i (vla-get-block layout)
  425. (if (and
  426. (= (vla-get-objectname i) "AcDbBlockReference")
  427. (= (strcase (vla-get-name i)) (strcase bn))
  428. )
  429. (if (and
  430. (= (vla-get-hasattributes i) :vlax-true)
  431. (safearray-value
  432. (setq atts
  433. (vlax-variant-value
  434. (vla-getattributes i)
  435. )
  436. )
  437. )
  438. )
  439. (foreach tag (vlax-safearray->list atts)
  440. (if (= (strcase tagname) (strcase (vla-get-tagstring tag)))
  441. (vla-put-scalefactor tag tagwidth)
  442. )
  443. )
  444. (vla-update i)
  445. )
  446. )
  447. )
  448. )
  449. )
  450. ;;32.3 [功能] 更改块属性高度
  451. ;; (MJ:ChangeTagHeight <block name> <tag name> <tag height>)
  452. ;; (MJ:ChangeTagHeight "sheet-text" "client-drw" 0.97)
  453. (defun MJ:ChangeTagHeight
  454. (bn tagname tagheight / layout i atts tag)
  455. (vlax-for layout *LOUTS*
  456. (vlax-for i (vla-get-block layout)
  457. (if (and
  458. (= (vla-get-objectname i) "AcDbBlockReference")
  459. (= (strcase (vla-get-name i)) (strcase bn))
  460. )
  461. (if (and
  462. (= (vla-get-hasattributes i) :vlax-true)
  463. (safearray-value
  464. (setq atts
  465. (vlax-variant-value
  466. (vla-getattributes i)
  467. )
  468. )
  469. )
  470. )
  471. (foreach tag (vlax-safearray->list atts)
  472. (if (= (strcase tagname) (strcase (vla-get-tagstring tag)))
  473. (vla-put-height tag tagheight)
  474. )
  475. )
  476. (vla-update i)
  477. )
  478. )
  479. )
  480. )
  481. )
  482. ;;33 [功能] 列表块插入点(Y排序)
  483. ;; (MJ:ListBlockIns "BTL")
  484. ;; return value example:
  485. ;; ((341.385 29.2937 0.0 #<VLA-OBJECT IAcadBlockReference 071b9e24>)
  486. ;; (341.385 34.2937 0.0 #<VLA-OBJECT IAcadBlockReference 071b9e74>)
  487. ;; (341.385 39.2937 0.0 #<VLA-OBJECT IAcadBlockReference 071bd184>))
  488. (defun MJ:ListBlockIns (bn / layout i pl)
  489. (vlax-for layout *LOUTS*
  490. (vlax-for i (vla-get-block layout)
  491. (if (and
  492. (= (vla-get-objectname i) "AcDbBlockReference")
  493. (= (strcase (vla-get-name i)) (strcase bn))
  494. )
  495. (setq pl
  496. (cons
  497. (append (safearray-value
  498. (vlax-variant-value (vla-get-InsertionPoint i))
  499. )
  500. (list i)
  501. )
  502. pl
  503. )
  504. )
  505. )
  506. )
  507. )
  508. ; sort by y-value
  509. (vl-sort pl
  510. (function (lambda (e1 e2)
  511. (< (cadr e1) (cadr e2))
  512. )
  513. )
  514. )
  515. )
  516. ;;34 [功能] 块集的某一属性,显示块的x(or y z)值
  517. ;; Arguments: ss块集 attname属性 ordinate(0=X, 1=Y, 2=Z)
  518. ;; 示例: (MJ:LabelOrdinate ss "设计" 0)
  519. (defun MJ:LabelOrdinate (ss attname ordinate / c block atts val att)
  520. (vl-load-com)
  521. (setq c -1)
  522. (repeat (sslength ss)
  523. (setq block (vlax-ename->vla-object
  524. (ssname ss (setq c (1+ c)))
  525. )
  526. atts (vlax-safearray->list
  527. (vlax-variant-value
  528. (vla-getattributes block)
  529. )
  530. )
  531. val (rtos
  532. (nth ordinate
  533. (vlax-safearray->list
  534. (vlax-variant-value
  535. (vla-get-insertionpoint block)
  536. )
  537. )
  538. )
  539. 2
  540. 0
  541. )
  542. )
  543. (foreach att atts
  544. (if (= (strcase attname) (strcase (vla-get-tagstring att)))
  545. (vla-put-textstring att val)
  546. )
  547. )
  548. (vla-update block)
  549. )
  550. (princ)
  551. )
  552. ;;35.1 [功能] 块中删除对象
  553. ;; 示例: (MJ:DeleteObjectFromBlock (car (nentsel)))
  554. ;; Notes: 1. As shown, you can use the NENTSEL function to obtain the name of an entity within a block.
  555. ;; 2. Existing block reference will not show a change until you regen the drawing.
  556. (defun MJ:DeleteObjectFromBlock (ent / doc blk)
  557. (setq ent (vlax-ename->vla-object ent)
  558. blk (vla-ObjectIdToObject *DOC* (vla-get-OwnerID ent))
  559. )
  560. (vla-Delete ent)
  561. (vla-get-Count blk)
  562. )
  563. ;;35.2 [功能] 块增加对象
  564. ;; 示例: (MJ:AddObjectsToBlock (car (entsel)) (ssget))
  565. ;; Notes: Existing block references will not show a change until you
  566. ;; regen the drawing
  567. (defun MJ:AddObjectsToBlock (blk ss / doc blkref blkdef inspt refpt)
  568. (vl-load-com)
  569. (setq blkref (vlax-ename->vla-object blk)
  570. blkdef (vla-Item (vla-get-Blocks *DOC*) (vla-get-Name blkref))
  571. inspt (vlax-variant-value (vla-get-InsertionPoint blkref))
  572. ssarray (SS->Array ss)
  573. refpt (vlax-3d-point '(0 0 0))
  574. )
  575. (foreach ent (vlax-safearray->list ssarray)
  576. (vla-Move ent inspt refpt)
  577. )
  578. (vla-CopyObjects *DOC* ssarray blkdef)
  579. (foreach ent (vlax-safearray->list ssarray)
  580. (vla-Delete ent)
  581. )
  582. (princ)
  583. )
  584. ;;35.3 [功能] 返回指定块每一个引用实体名列表
  585. ;; 注:未能验证是否正确?(MJ:ListBLockRefs "BTL")
  586. (defun MJ:ListBLockRefs (blkName / lst)
  587. (setq lst (entget
  588. (cdr
  589. (assoc 330 (entget (tblobjname "block" blkName)))
  590. )
  591. )
  592. )
  593. (apply
  594. 'append
  595. (mapcar '(lambda (x)
  596. (if (entget (cdr x))
  597. (list (cdr x))
  598. )
  599. )
  600. (repeat 2
  601. (setq lst (reverse (cdr (member (assoc 102 lst) lst))))
  602. )
  603. )
  604. )
  605. )
  606. ;;35.4 [功能] 块引用名列表Returns a list conaining the entity names of any block definitions that
  607. ;; reference the specified block
  608. ;; 示例: (MJ:GetParentBlocks "BTL")
  609. (defun MJ:GetParentBlocks (blkName / doc)
  610. (apply
  611. 'append
  612. (mapcar
  613. '(lambda (x)
  614. (if (= :vlax-false
  615. (vla-get-IsLayout
  616. (vla-ObjectIdToObject
  617. *DOC*
  618. (vla-get-OwnerId (vlax-ename->vla-object x))
  619. )
  620. )
  621. )
  622. (list x)
  623. )
  624. )
  625. (MJ:ListBLockRefs blkName)
  626. )
  627. )
  628. )
  629. ;;36 [功能] 删除指定名的所有块
  630. ;; (MJ:EraseBlock "BTL");删除名叫"BTL"的所有块
  631. (defun MJ:EraseBlock (bn / layout i)
  632. (vlax-for layout *LOUTS*
  633. (vlax-for i (vla-get-block layout)
  634. (if (and
  635. (= (vla-get-objectname i) "AcDbBlockReference")
  636. (= (strcase (vla-get-name i)) (strcase bn))
  637. )
  638. (vla-Delete i)
  639. )
  640. )
  641. )
  642. )
  643. ;;37 [功能] 块名"BTL"是否存在
  644. ;; (MJ:ExistBlock "BTL"是)
  645. (defun MJ:ExistBlock (bn / layout i exist)
  646. (vlax-for layout *LOUTS*
  647. (vlax-for i *BLKS*
  648. (if (and
  649. (= (vla-get-objectname i) "AcDbBlockReference")
  650. (= (strcase (vla-get-name i)) (strcase bn))
  651. )
  652. (setq exist T)
  653. )
  654. )
  655. )
  656. exist
  657. )
  658. ;;38.1 [功能] 块更名(块bn nn必须存在)
  659. ;; (MJ:RenameBlock "b1" "b2")块"b1"更名为"b2"
  660. (defun MJ:RenameBlock (bn nn / layout i)
  661. (vlax-for layout *LOUTS*
  662. (vlax-for i (vla-get-block layout)
  663. (if (and
  664. (= (vla-get-objectname i) "AcDbBlockReference")
  665. (= (strcase (vla-get-name i)) (strcase bn))
  666. )
  667. (vla-put-name i nn)
  668. )
  669. )
  670. )
  671. )
  672. ;;38.2 [功能] 块更名
  673. ;;名为bn的块存在,名为nn的块不存在
  674. ;;(MJ:RenameBlock1 "ccd1" "ccd2")
  675. (defun MJ:RenameBlock1 (bn nn / BLOCK)
  676. (vla-put-name (vla-item (vla-get-blocks *DOC*) bn) nn)
  677. )
  678. ;;39 [功能] 块名例表
  679. ;; 返回示例("*D5" "A$C263E5435" "b2" "b1")
  680. (defun MJ:blocks (/ b bn tl)
  681. (vlax-for b (vla-get-blocks *DOC*)
  682. (if (= (vla-get-islayout b) :vlax-false)
  683. (setq tl (cons (vla-get-name b) tl))
  684. )
  685. )
  686. (reverse tl)
  687. )
  688. ;;40 [功能] XRef图块列表 a list of all xref names
  689. ;;返回示例 ("xref1" "x2")
  690. (defun MJ:xrefs (/ b bn tl)
  691. (vlax-for b (vla-get-blocks *DOC*)
  692. (if (= (vla-get-isxref b) :vlax-true)
  693. (setq tl (cons (vla-get-name b) tl))
  694. )
  695. )
  696. (reverse tl)
  697. )
  698. ;;41 [功能] 返回名为"bn"的XRef图块实体列表
  699. ;; 返回示例 (<Entity name: 2ea6290> <Entity name: 2ea6288>)
  700. (defun blockrefs (bn / lst ed)
  701. (if (setq ed (tblobjname "block" bn))
  702. (setq
  703. lst (entget
  704. (cdr (assoc 330 (entget ed)))
  705. )
  706. )
  707. )
  708. (apply
  709. 'append
  710. (mapcar '(lambda (x)
  711. (list (cdr x))
  712. )
  713. (cdr (reverse (cdr (member (assoc 102 lst) lst))))
  714. )
  715. )
  716. )
  717. ;;42 [功能] 返回包容点集的最小点最大点列表
  718. ;; (MJ:Extents '((1 0 0) (2 2 0) (1 2 0)))
  719. (defun MJ:Extents (plist /)
  720. (list
  721. (apply 'mapcar (cons 'min plist))
  722. (apply 'mapcar (cons 'max plist))
  723. )
  724. )
  725. ;;43.1 [功能] 两点中点
  726. (defun MJ:Mid (pts / P1 P2 X Y)
  727. (setq p1 (car pts) p2 (cadr pts))
  728. (if (= (length p1) (length p2))
  729. nil
  730. (setq p1 (list (car p1) (cadr p1))
  731. p2 (list (car p2) (cadr p2))
  732. )
  733. )
  734. (mapcar '(lambda (X Y) (/ (+ X Y) 2.0)) P1 P2)
  735. )
  736. ;;43.2 [功能] <起点>,<中点>,<终点>列表 ;By 无痕
  737. (DEFUN xl-3p (e / ps pe pm)
  738. (setq ps (vlax-curve-getstartparam e)
  739. pe (vlax-curve-getendparam e)
  740. pm (/ (- pe ps) 2)
  741. )
  742. (mapcar 'vlax-curve-getpointatparam
  743. (list e e e)
  744. (list ps pm pe)
  745. )
  746. )
  747. ;;44 [功能] 求矩形中心
  748. ;;示例 (MJ:RectCenter (car (entsel)))
  749. (defun MJ:RectCenter (rec)
  750. (MJ:Mid (MJ:Extents (MJ:Massoc 10 (entget rec))))
  751. )
  752. ;;45 [功能] 返回封闭曲线质心二维坐标
  753. ;; 示例: (MJ:Centroid (car (entsel)))
  754. (defun MJ:Centroid (poly / pl ms va reg cen)
  755. (vl-load-com)
  756. (setq pl (vlax-ename->vla-object poly)
  757. ms (vla-get-modelspace
  758. *DOC*
  759. )
  760. va (vlax-make-safearray vlax-vbObject '(0 . 0))
  761. )
  762. (vlax-safearray-put-element va 0 pl)
  763. (setq reg (car (vlax-safearray->list
  764. (vlax-variant-value (vla-addregion ms va))
  765. )
  766. )
  767. cen (vla-get-centroid reg)
  768. )
  769. (vla-delete reg)
  770. (vlax-safearray->list (vlax-variant-value cen))
  771. )
  772. ;;46.1 [功能] 多段线各顶点(见99.3)
  773. ;;示例 (MJ:Massoc 10 (entget (car (entsel))))
  774. ;; Notes:特别适合多段线各顶点
  775. (defun MJ:Massoc (key alist)
  776. (apply
  777. 'append
  778. (mapcar '(lambda (x)
  779. (if (eq (car x) key)
  780. (list (cdr x))
  781. )
  782. )
  783. alist
  784. )
  785. )
  786. )
  787. ;;46.2 [功能] pline,lwpline点坐标表 By 无痕
  788. ;;示例(vxs (car (entsel))),返回三维点坐标
  789. (defun vxs (e / i v lst)
  790. (setq i -1)
  791. (while
  792. (setq v (vlax-curve-getpointatparam e (setq i (1+ i))))
  793. (setq lst (cons v lst))
  794. )
  795. (reverse lst)
  796. )
  797. ;;46.3 [功能] 返回包含每一出现在列表中的指定键的cdr(点对的后部分)的列表。
  798. ;;;示例 (MJ:massoc 10 (entget (car (entsel))))
  799. ;;注意 该函数特别适合用于找到细多义线上的所有顶点。
  800. (defun MJ:massoc (key alist)
  801. (mapcar 'cdr
  802. (vl-remove-if-not '(lambda (x) (equal key (car x))) alist)
  803. )
  804. )
  805. ;;47 [功能] 曲线是否封闭
  806. ;;(MJ:IsClosed (car (entsel)))封闭返回T,圆返回nil
  807. (defun MJ:IsClosed (epl / vpl)
  808. (setq vpl (MJ:MakeObject epl));转换成Vla
  809. (if (vlax-property-available-p vpl 'Closed)
  810. (= (vlax-get-property vpl 'Closed) :vlax-true)
  811. )
  812. )
  813. ;;48 [功能] 返回一个包涵经过pt点的多段线端点的列表
  814. ;; Returns a list containing the endpoints of the selected lwpoly segment
  815. ;; 示例: (apply 'MJ:GetPolySegment (list (car (entsel)) (getpoint)))返回((-1600.24 2403.92) (-1524.08 2403.92))
  816. (defun MJ:GetPolySegment (poly pt / pts i)
  817. (setq pts (MJ:Massoc 10 (entget poly))
  818. i (caddar (ssnamex (ssget pt)))
  819. )
  820. (list
  821. (nth (1- i) pts)
  822. (if
  823. (and
  824. (MJ:IsClosed poly)
  825. (= i (length pts))
  826. )
  827. (car pts)
  828. (nth i pts)
  829. )
  830. )
  831. )
  832. ;;49 [功能] 把弧变成圆
  833. (defun MJ:CloseArc (/ arcent arcobj trapobj circ)
  834. (while (setq arcent (entsel "\nSelect ARC object: "))
  835. (setq arcobj (MJ:MakeObject (car arcent)))
  836. (cond
  837. ((= "AcDbArc" (MJ:ObjectType arcobj))
  838. (MJ:UndoBegin)
  839. (setq circ
  840. (vla-addCircle
  841. *MS*
  842. (vla-Get-center arcobj)
  843. (vla-Get-radius arcobj)
  844. )
  845. )
  846. (MJ:MapPropertyList
  847. '("Layer" "Color" "Thickness" "Linetype" "LinetypeScale")
  848. arcobj
  849. circ
  850. )
  851. (MJ:DeleteObject arcobj)
  852. (vlax-Release-Object circ)
  853. (MJ:UndoEnd)
  854. ) ;
  855. (T (princ "\nNot an ARC object, try again..."))
  856. ) ; cond
  857. ) ; endwhile
  858. (princ)
  859. )
  860. ;;50.1 [功能] 线型是否存在?
  861. ;;示例: (MJ:Ltype-Exists-p "DASHED") (MJ:Ltype-Exists-p "continuous")
  862. (defun MJ:Ltype-Exists-p (strLtype)
  863. (member
  864. (strcase strLtype)
  865. (mapcar 'strcase (MJ:ListLtypes))
  866. )
  867. )
  868. ;;50.2 [功能] 改变vla对象线型
  869. ;; 示例: (MJ:Apply-Ltype cirobj "DASHED")改变对象线型
  870. (defun MJ:Apply-Ltype (obj strLtype / entlist)
  871. (cond
  872. ((MJ:Ltype-Exists-p strLtype)
  873. (cond
  874. ((and
  875. (vlax-Read-Enabled-p obj)
  876. (vlax-Write-Enabled-p obj)
  877. )
  878. (vla-Put-Linetype obj strLtype)
  879. T
  880. )
  881. (T (princ "\n Unable to modify object!"))
  882. )
  883. )
  884. (T
  885. (princ (strcat "\n Linetype ["
  886. strLtype
  887. "] not loaded."
  888. )
  889. )
  890. )
  891. )
  892. )
  893. ;;51.1 [功能] 角度->弧度
  894. (defun MJ:D2R (a) (* pi (/ a 180.0)))
  895. ;;51.2 [功能] 弧度->角度
  896. (defun MJ:R2D (a) (/ (* a 180.0) pi))
  897. ;;52.1 [功能] 3D点->2D By Caoyin
  898. (defun 3dpoint->2dpoint (3dpt)
  899. (if (apply 'and (mapcar 'numberp 3dpt))
  900. (mapcar '+ 3dpt '(0. 0.))
  901. )
  902. )
  903. ;;52.2 [功能] 3D点->2D
  904. (defun 3d->2d (3dpt / 2dpt)
  905. (setq 2dpt (list (car 3dpt) (cadr 3dpt)))
  906. )
  907. ;;52.3 [功能] 3D点列表->2D点列表
  908. (defun 3dpoint-list->2dpoint-list (3dplist / 2dplist)
  909. (cond
  910. ((and 3dplist (listp 3dplist) (listp (car 3dplist)))
  911. (setq 2dplist
  912. (mapcar '(lambda (pt) (list (car pt) (cadr pt))) 3dplist)
  913. )
  914. )
  915. (T
  916. (princ
  917. "\n3dpoint-list->2dpoint-list: Invalid parameter list..."
  918. )
  919. )
  920. )
  921. )
  922. ;;52.4 [功能] 3D点列表->2D点列表
  923. (defun 3dlist->2dlist (3dplist)
  924. (mapcar '3d->2d 3dplist)
  925. )
  926. ;;52.5 [功能] 对表分段
  927. ;;(xl_div lst nom)表分段. -> 返回 分段的表. ------by 无痕.2004.1
  928. ; lst 表,nom = 分段的子表元素个数(从1开始计).
  929. ;;示例 (xl_div '(1 2 3 4 5 6 7 8 9) 3) -> ((1 2 3) (4 5 6) (7 8 9))
  930. (defun xl-div (lst x / lst2)
  931. (foreach n lst
  932. (if (and lst2 (/= x (length (car lst2))))
  933. (setq lst2 (cons (append (car lst2) (list n)) (cdr lst2)))
  934. (setq lst2 (cons (list n) lst2))
  935. )
  936. )
  937. (reverse lst2)
  938. )
  939. ;;53.1 [功能] 画线
  940. ;; 示例:(MJ:AddLine (getpoint) (getpoint) nil nil nil)
  941. (defun MJ:AddLine (StartPt EndPt strLayer intColor strLtype / obj)
  942. (cond
  943. ((and StartPt (listp StartPt) EndPt (listp EndPt))
  944. (setq obj (vla-addLine
  945. (vla-Get-ModelSpace
  946. *DOC*
  947. )
  948. (vlax-3D-Point StartPt)
  949. (vlax-3D-Point EndPt)
  950. )
  951. )
  952. (cond
  953. ((vlax-Write-Enabled-p obj)
  954. (if strLayer
  955. (vla-Put-Layer obj strLayer)
  956. )
  957. (if intColor
  958. (vla-Put-Color obj intColor)
  959. )
  960. (if strLtype
  961. (MJ:Apply-Ltype obj strLtype)
  962. )
  963. (vla-Update obj)
  964. (vlax-Release-Object obj)
  965. (entlast)
  966. )
  967. (T (princ "\nUnable to modify object properties..."))
  968. )
  969. )
  970. (T (princ "\nMJ:AddLine: Invalid parameter list..."))
  971. )
  972. )
  973. ;;53.2 [功能] 根据点表画线
  974. (defun MJ:AddLineC (ptlist Bclosed strLayer intColor strLtype / *MJ:MODELSPACE* PT1 PTZ)
  975. (setq *MJ:ModelSpace* *MS*)
  976. (cond
  977. ((and ptlist (listp ptlist) (listp (car ptlist)))
  978. (setq pt1 (car ptlist)
  979. ;; save first point
  980. ptz (last ptlist)
  981. ;; save last point
  982. )
  983. (while (and ptlist (>= (length ptlist) 2))
  984. (MJ:AddLine
  985. *MJ:ModelSpace*
  986. (car ptlist)
  987. (cadr ptlist)
  988. strLayer
  989. intColor
  990. strLtype
  991. )
  992. (setq ptlist (cdr ptlist))
  993. )
  994. (if (= Bclosed T)
  995. (MJ:AddLine
  996. *MJ:ModelSpace* pt1 ptz strLayer intColor strLtype)
  997. )
  998. )
  999. (T (princ "\nMakeLineC: Invalid parameter list..."))
  1000. )
  1001. )
  1002. ;;54 [功能] 画弧
  1003. ;; 示例: (MJ:AddArc pt1 0.5 0 90 "0" 3 "DASHED")
  1004. (defun MJ:AddArc
  1005. (CenterPt Radius StartAng EndAng
  1006. strLayer intColor strLtype /
  1007. obj
  1008. )
  1009. (cond
  1010. ((and CenterPt (listp CenterPt) Radius StartAng EndAng)
  1011. (setq obj
  1012. (vla-addArc
  1013. (vla-Get-ModelSpace
  1014. *DOC*
  1015. )
  1016. (vlax-3D-Point CenterPt)
  1017. Radius
  1018. (MJ:D2R StartAng)
  1019. (MJ:D2R EndAng)
  1020. )
  1021. )
  1022. (cond
  1023. ((vlax-Write-Enabled-p obj)
  1024. (if strLayer
  1025. (vla-Put-Layer obj strLayer)
  1026. )
  1027. (if intColor
  1028. (vla-Put-Color obj intColor)
  1029. )
  1030. (if strLtype
  1031. (MJ:Apply-Ltype obj strLtype)
  1032. )
  1033. (vla-Update obj)
  1034. (vlax-Release-Object obj)
  1035. (entlast)
  1036. ) ;
  1037. (T (princ "\nUnable to modify object properties..."))
  1038. )
  1039. ) ;
  1040. (T (princ "\nMJ:AddArc: Invalid parameter list..."))
  1041. )
  1042. )
  1043. ;;55 [功能] 画圆
  1044. ;; 示例: (MJ:AddCircle pt1 0.5 "0" 3 "DASHED")
  1045. (defun MJ:AddCircle
  1046. (CenterPt Radius strLayer intColor strLtype / obj)
  1047. (cond
  1048. ((and CenterPt (listp CenterPt) Radius)
  1049. (setq obj (vla-addCircle
  1050. (vla-Get-ModelSpace
  1051. *DOC*
  1052. )
  1053. (vlax-3D-Point CenterPt)
  1054. Radius
  1055. )
  1056. )
  1057. (cond
  1058. ((vlax-Write-Enabled-p obj)
  1059. (if strLayer
  1060. (vla-Put-Layer obj strLayer)
  1061. )
  1062. (if intColor
  1063. (vla-Put-Color obj intColor)
  1064. )
  1065. (if strLtype
  1066. (MJ:Apply-Ltype obj strLtype)
  1067. )
  1068. (vla-Update obj)
  1069. (vlax-Release-Object obj)
  1070. (entlast)
  1071. )
  1072. (T (princ "\nUnable to modify object properties..."))
  1073. )
  1074. )
  1075. (T (princ "\nMJ:AddCircle: Invalid parameter list..."))
  1076. )
  1077. )
  1078. ;;56 [功能] 画多段线
  1079. ;; EXMAPLE: (MJ:AddPline ptlist "0" T 3 "DASHED" 0.125) ;;
  1080. (defun MJ:AddPline
  1081. (ptlist strLayer Bclosed intColor strLtype
  1082. dblWidth / vrtcs lst plgen
  1083. plist plpoints obj
  1084. )
  1085. (cond
  1086. ((and ptlist (listp ptlist) (listp (car ptlist)))
  1087. (setq plist (apply 'append (mapcar '3dpoint->2dpoint ptlist))
  1088. plpoints (MJ:List->VariantArray plist)
  1089. obj (vla-AddLightWeightPolyline
  1090. (vla-Get-ModelSpace
  1091. *DOC*
  1092. )
  1093. plpoints
  1094. )
  1095. )
  1096. (cond
  1097. ((and
  1098. (vlax-Read-Enabled-p obj)
  1099. (vlax-Write-Enabled-p obj)
  1100. )
  1101. (if Bclosed
  1102. (vla-Put-Closed obj :vlax-True)
  1103. )
  1104. (if strLayer
  1105. (vla-Put-Layer obj strLayer)
  1106. )
  1107. (if intColor
  1108. (vla-Put-Color obj intColor)
  1109. )
  1110. (if dblWidth
  1111. (vla-Put-ConstantWidth obj dblWidth)
  1112. )
  1113. (if strLtype
  1114. (progn
  1115. (MJ:Apply-Ltype obj strLtype)
  1116. (vla-Put-LinetypeGeneration obj :vlax-True)
  1117. )
  1118. )
  1119. (vla-Update obj)
  1120. (vlax-Release-Object obj)
  1121. (entlast)
  1122. )
  1123. (T (princ "\n Unable to modify object!"))
  1124. )
  1125. )
  1126. (T (princ "\n Invalid parameter list...."))
  1127. )
  1128. )
  1129. ;;56.1 [功能] 画椭圆
  1130. ;; 示例: (MJ:AddEllipse l1 p2 45 "PARTS" nil nil) ;;
  1131. (defun MJ:AddEllipse
  1132. (ctr hmpt roll strLayer intColor strLtype / lst obj)
  1133. (cond
  1134. ((and ctr (listp ctr) hmpt (listp hmpt) roll)
  1135. (setq hmpt (list
  1136. (- (car hmpt) (car ctr))
  1137. (- (cadr hmpt) (cadr ctr))
  1138. )
  1139. obj (vla-addEllipse
  1140. *MS*
  1141. (vlax-3D-Point ctr)
  1142. (vlax-3D-Point hmpt)
  1143. (cos (MJ:D2R roll))
  1144. )
  1145. )
  1146. (cond
  1147. ((vlax-Write-Enabled-p obj)
  1148. (if strLayer
  1149. (vla-Put-Layer obj strLayer)
  1150. )
  1151. (if intColor
  1152. (vla-Put-Color obj intColor)
  1153. )
  1154. (if strLtype
  1155. (MJ:Apply-Ltype obj strLtype)
  1156. )
  1157. (vla-Update obj)
  1158. )
  1159. (T (princ "\nUnable to modify object properties..."))
  1160. )
  1161. (vlax-Release-Object obj)
  1162. (entlast)
  1163. )
  1164. (T (princ "\nInvalid paprameter list..."))
  1165. )
  1166. )
  1167. ;;56.2 [功能] 画椭圆弧
  1168. (defun MJ:AddEllipseArc1
  1169. (ctr hmpt roll StartAng
  1170. EndAng strLayer intColor strLtype
  1171. / obj rang
  1172. )
  1173. (cond
  1174. ((and ctr (listp ctr) hmpt roll)
  1175. (setq hmpt (list
  1176. (- (car hmpt) (car ctr))
  1177. (- (cadr hmhp) (cadr ctr))
  1178. )
  1179. obj (vla-addEllipse
  1180. *MS*
  1181. (vlax-3D-Point ctr)
  1182. (vlax-3D-Point hmpt)
  1183. (MJ:Roll->Ratio roll)
  1184. )
  1185. )
  1186. (cond
  1187. ((vlax-Write-Enabled-p obj)
  1188. (vla-Put-StartAngle obj (MJ:D2R StartAng))
  1189. (vla-Put-EndAngle obj (MJ:D2R EndAng))
  1190. (if strLayer
  1191. (vla-Put-Layer obj strLayer)
  1192. )
  1193. (if intColor
  1194. (vla-Put-Color obj intColor)
  1195. )
  1196. (if strLtype
  1197. (MJ:Apply-Ltype obj strLtype)
  1198. )
  1199. (vla-Update obj)
  1200. (vlax-Release-Object obj)
  1201. (entlast)
  1202. )
  1203. (T (princ "\nUnable to modify object properties..."))
  1204. )
  1205. )
  1206. (T (princ "\nMakeArcEllipse1: Invalid parameter list..."))
  1207. )
  1208. )
  1209. ;;56.3 [功能] 画椭圆弧
  1210. (defun MJ:AddEllipseArc2
  1211. (ctr hmpt hmin StartAng
  1212. EndAng strLayer intColor strLtype
  1213. / obj rang
  1214. )
  1215. (cond
  1216. ((and ctr (listp ctr) hmpt (listp hmpt) hmin)
  1217. (setq hmpt (list
  1218. (- (car hmpt) (car ctr))
  1219. (- (cadr hmpt) (cadr ctr))
  1220. )
  1221. obj (vla-addEllipse
  1222. *MS*
  1223. (vlax-3D-Point ctr)
  1224. (vlax-3D-Point hmpt)
  1225. hmin
  1226. )
  1227. )
  1228. (cond
  1229. ((vlax-Write-Enabled-p obj)
  1230. (vla-Put-StartAngle obj (MJ:D2R StartAng))
  1231. (vla-Put-EndAngle obj (MJ:D2R EndAng))
  1232. (if strLayer
  1233. (vla-Put-Layer obj strLayer)
  1234. )
  1235. (if intColor
  1236. (vla-Put-Color obj intColor)
  1237. )
  1238. (if strLtype
  1239. (MJ:Apply-Ltype obj strLtype)
  1240. )
  1241. (vla-Update obj)
  1242. (vlax-Release-Object obj)
  1243. (entlast)
  1244. )
  1245. (T (princ "\nUnable to modify object properties..."))
  1246. )
  1247. )
  1248. (T (princ "\nMakeArcEllipse2: Invalid parameter list..."))
  1249. )
  1250. )
  1251. ;;57 [功能] 生成一个点
  1252. ;; 示例: (MJ:AddPoint p1 nil)
  1253. (defun MJ:AddPoint (pt strLayer / obj)
  1254. (cond
  1255. ((and pt (listp pt))
  1256. (setq obj (vla-addPoint *MS* (vlax-3D-Point pt)))
  1257. (if (vlax-Write-Enabled-p obj)
  1258. (progn
  1259. (if strLayer
  1260. (vla-Put-Layer obj strLayer)
  1261. )
  1262. (vla-Update obj)
  1263. (vlax-Release-Object obj)
  1264. (entlast)
  1265. )
  1266. (princ "\nMJ:AddPoint: Unable to modify object!")
  1267. )
  1268. )
  1269. (T (princ "\nMJ:AddPoint: Invalid parameter list..."))
  1270. )
  1271. )
  1272. ;;58 [功能] 单行文字
  1273. ;; 示例: (MJ:AddText "ABC" p1 "MC" "STANDARD" 0.25 1.0 0 "TEXT" nil)
  1274. (defun MJ:AddText
  1275. (strTxt pt Just strStyle dblHgt
  1276. dblWid dblRot strLay intCol /
  1277. txtobj
  1278. )
  1279. (cond
  1280. ((setq txtobj
  1281. (vla-AddText
  1282. (MJ:ActiveSpace)
  1283. strTxt
  1284. (if (not (member (strcase Just) '("A" "F")))
  1285. (vlax-3d-Point pt)
  1286. (vlax-3d-Point (car pt))
  1287. ) ; endif
  1288. dblHgt
  1289. ;; ignored if Just = "A" (aligned)
  1290. )
  1291. )
  1292. (vla-put-StyleName txtobj strStyle)
  1293. (vla-put-Layer txtobj strLay)
  1294. (if intCol
  1295. (vla-put-Color txtobj intCol)
  1296. )
  1297. (setq Just (strcase Just))
  1298. ;; force to upper case for comparisons...
  1299. ;; Left/Align/Fit/Center/Middle/Right/BL/BC/BR/ML/MC/MR/TL/TC/TR
  1300. ;; Note that "Left" is not a normal default.
  1301. ;;
  1302. ;; ALIGNMENT TYPES...
  1303. ;; AcAlignmentLeft=0
  1304. ;; AcAlignmentCenter=1
  1305. ;; AcAlignmentRight=2
  1306. ;; AcAlignmentAligned=3
  1307. ;; AcAlignmentMiddle=4
  1308. ;; AcAlignmentFit=5
  1309. ;; AcAlignmentTopLeft=6
  1310. ;; AcAlignmentTopCenter=7
  1311. ;; AcAlignmentTopRight=8
  1312. ;; AcAlignmentMiddleLeft=9
  1313. ;; AcAlignmentMiddleCenter=10
  1314. ;; AcAlignmentMiddleRight=11
  1315. ;; AcAlignmentBottomLeft=12
  1316. ;; AcAlignmentBottomCenter=13
  1317. ;; AcAlignmentBottomRight=14
  1318. ;;
  1319. ;; HORIZONTAL JUSTIFICATIONS...
  1320. ;; AcHorizontalAlignmentLeft=0
  1321. ;; AcHorizontalAlignmentCenter=1
  1322. ;; AcHorizontalAlignmentRight=2
  1323. ;; AcHorizontalAlignmentAligned=3
  1324. ;; AcHorizontalAlignmentMiddle=4
  1325. ;; AcHorizontalAlignmentFit=5
  1326. ;;
  1327. ;; VERTICAL JUSTIFICATIONS...
  1328. ;; AcVerticalAlignmentBaseline=0
  1329. ;; AcVerticalAlignmentBottom=1
  1330. ;; AcVerticalAlignmentMiddle=2
  1331. ;; AcVerticalAlignmentTop=3
  1332. (cond
  1333. ((= Just "L")
  1334. ;; Left
  1335. (vla-put-ScaleFactor txtobj dblWid)
  1336. (vla-put-Rotation txtobj (DTR dblRot))
  1337. )
  1338. ((= Just "C")
  1339. ;; Center
  1340. (vla-put-Alignment txtobj 1)
  1341. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1342. (vla-put-ScaleFactor txtobj dblWid)
  1343. (vla-put-Rotation txtobj (DTR dblRot))
  1344. )
  1345. ((= Just "R")
  1346. ;; Right
  1347. (vla-put-Alignment txtobj 2)
  1348. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1349. (vla-put-ScaleFactor txtobj dblWid)
  1350. (vla-put-Rotation txtobj (DTR dblRot))
  1351. )
  1352. ((= Just "A")
  1353. ;; Alignment
  1354. (vla-put-Alignment txtobj 3)
  1355. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1356. )
  1357. ((= Just "M")
  1358. ;; Middle
  1359. (vla-put-Alignment txtobj 4)
  1360. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1361. (vla-put-ScaleFactor txtobj dblWid)
  1362. (vla-put-Rotation txtobj (DTR dblRot))
  1363. )
  1364. ((= Just "F")
  1365. ;; Fit
  1366. (vla-put-Alignment txtobj 5)
  1367. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1368. )
  1369. ((= Just "TL")
  1370. ;; Top-Left
  1371. (vla-put-Alignment txtobj 6)
  1372. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1373. (vla-put-ScaleFactor txtobj dblWid)
  1374. (vla-put-Rotation txtobj (DTR dblRot))
  1375. )
  1376. ((= Just "TC")
  1377. ;; Top-Center
  1378. (vla-put-Alignment txtobj 7)
  1379. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1380. (vla-put-ScaleFactor txtobj dblWid)
  1381. (vla-put-Rotation txtobj (DTR dblRot))
  1382. )
  1383. ((= Just "TR")
  1384. ;; Top-Right
  1385. (vla-put-Alignment txtobj 8)
  1386. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1387. (vla-put-ScaleFactor txtobj dblWid)
  1388. (vla-put-Rotation txtobj (DTR dblRot))
  1389. )
  1390. ((= Just "ML")
  1391. ;; Middle-Left
  1392. (vla-put-Alignment txtobj 9)
  1393. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1394. (vla-put-ScaleFactor txtobj dblWid)
  1395. (vla-put-Rotation txtobj (DTR dblRot))
  1396. )
  1397. ((= Just "MC")
  1398. ;; Middle-Center
  1399. (vla-put-Alignment txtobj 10)
  1400. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1401. (vla-put-ScaleFactor txtobj dblWid)
  1402. (vla-put-Rotation txtobj (DTR dblRot))
  1403. )
  1404. ((= Just "MR")
  1405. ;; Middle-Right
  1406. (vla-put-Alignment txtobj 11)
  1407. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1408. (vla-put-ScaleFactor txtobj dblWid)
  1409. (vla-put-Rotation txtobj (DTR dblRot))
  1410. )
  1411. ((= Just "BL")
  1412. ;; Bottom-Left
  1413. (vla-put-Alignment txtobj 12)
  1414. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1415. (vla-put-ScaleFactor txtobj dblWid)
  1416. (vla-put-Rotation txtobj (DTR dblRot))
  1417. )
  1418. ((= Just "BC")
  1419. ;; Bottom-Center
  1420. (vla-put-Alignment txtobj 13)
  1421. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1422. (vla-put-ScaleFactor txtobj dblWid)
  1423. (vla-put-Rotation txtobj (DTR dblRot))
  1424. )
  1425. ((= Just "BR")
  1426. ;; Bottom-Right
  1427. (vla-put-Alignment txtobj 14)
  1428. (vla-put-TextAlignmentPoint txtobj (vlax-3d-point pt))
  1429. (vla-put-ScaleFactor txtobj dblWid)
  1430. (vla-put-Rotation txtobj (DTR dblRot))
  1431. )
  1432. )
  1433. (vla-Update txtobj)
  1434. (vlax-Release-Object txtobj)
  1435. (entlast)
  1436. )
  1437. )
  1438. )
  1439. ;;59 [功能] 画多边形
  1440. ;; (MJ:AddPolygon center, radius, sides, flag, width, layer, color, ltype)
  1441. ;; 示例: (MJ:AddPolygon pt1 1.0 6 nil 0 "0" nil "DASHED")
  1442. (defun MJ:AddPolygon
  1443. (ctrpt dblRad intSides strType dblWid
  1444. strLay intCol strLtype / pa
  1445. dg ptlist deg
  1446. )
  1447. (setq pa (polar ctrpt 0 dblRad)
  1448. dg (/ 360.0 intSides)
  1449. ;; get angles between faces
  1450. deg dg
  1451. )
  1452. (repeat intSides
  1453. (setq ptlist
  1454. (if ptlist
  1455. (append ptlist (list (polar ctrpt (MJ:D2R deg) dblRad)))
  1456. (list (polar ctrpt (MJ:D2R deg) dblRad))
  1457. )
  1458. )
  1459. (setq deg (+ dg deg))
  1460. ) ; repeat
  1461. (MJ:AddPline ptlist strLay T intCol strLtype dblWid)
  1462. )
  1463. ;;60 [功能] 画矩形
  1464. ;; (MJ:AddRectangle p1(lower left), p3(upper right), layer, color, linetype, width)
  1465. ;; 示例: (MJ:AddRectangle p1 p3 "0" nil "DASHED" 0.25)
  1466. (defun MJ:AddRectangle
  1467. (p1 p3 strLayer intColor strLtype dblWid / p2 p4 obj)
  1468. (setq p2 (list (car p1) (cadr p3))
  1469. p4 (list (car p3) (cadr p1))
  1470. )
  1471. (cond
  1472. ((setq obj (MJ:AddPline
  1473. (list p1 p2 p3 p4)
  1474. strLayer
  1475. T
  1476. intColor
  1477. strLtype
  1478. dblWidth
  1479. )
  1480. )
  1481. obj
  1482. ;; raise object (entity name)
  1483. )
  1484. )
  1485. )
  1486. ;;61 [功能] 画长方体
  1487. ;; (MJ:AddSolid points-list, layer(string), color(integer))
  1488. ;; 示例: (MJ:AddSolid ptlist "0" nil)
  1489. (defun MJ:AddSolid (ptlist strLayer intColor / plist obj)
  1490. (cond
  1491. ((and ptlist (listp ptlist) (listp (car ptlist)))
  1492. (if (= (length ptlist) 3)
  1493. (setq plist (append ptlist (list (last ptlist))))
  1494. (setq plist ptlist)
  1495. )
  1496. (cond
  1497. ((setq obj (vla-addSolid
  1498. (MJ:ActiveSpace)
  1499. (vlax-3D-Point (car plist))
  1500. (vlax-3D-Point (cadr plist))
  1501. (vlax-3D-Point (caddr plist))
  1502. (vlax-3D-Point (cadddr plist))
  1503. )
  1504. )
  1505. (if strLayer
  1506. (vla-Put-Layer obj strLayer)
  1507. )
  1508. (if intColor
  1509. (vla-Put-Color obj intColor)
  1510. )
  1511. (vla-Update obj)
  1512. (vlax-release-object obj)
  1513. (entlast)
  1514. ) ;
  1515. (T (princ "\nUnable to create object..."))
  1516. ) ; cond
  1517. ) ;
  1518. (T (princ "\nMJ:AddSolid: Invalid parameter list..."))
  1519. )
  1520. )
  1521. ;;62 [功能] 多行文字MText
  1522. (defun myMText (txtString coner Width)
  1523. (vla-addText *MS* (vlax-3d-point pt) Width txtString)
  1524. )
  1525. ;;63 [功能] 面域Region
  1526. (defun myRegion (curveObjList nColor / CN CURVES REGIONOBJ)
  1527. (setq cn (length curveObjList))
  1528. (setq curves (vlax-make-safearray vlax-vbObject (cons 0 (1- cn))))
  1529. (vlax-safearray-fill curves curveObjList)
  1530. (setq RegionObj (vla-AddRegion *MS* curves))
  1531. (vla-put-color
  1532. (vla-safearray-get-element (vla-Variant-value RegionObj) 0)
  1533. nColor
  1534. )
  1535. )
  1536. ;;64 [功能] 对象外画一矩形
  1537. ;; 示例: (MJ:DrawVpBorder (car (entsel))) ;;
  1538. ;; Notes: 1. The return value is the entity name of the newly created lwpolyline ;;
  1539. ;; 2. The layout containing the viewport to be drawn must be active ;;
  1540. (defun MJ:DrawVpBorder (vp / ll ur coords pl)
  1541. (vl-load-com)
  1542. (setq vp (vlax-ename->vla-object vp))
  1543. (vla-GetBoundingBox vp 'll 'ur)
  1544. (setq ll (vlax-safearray->list ll)
  1545. ur (vlax-safearray->list ur)
  1546. )
  1547. (setq coords (vlax-safearray-fill
  1548. (vlax-make-safearray vlax-vbDouble (cons 0 7))
  1549. (list (nth 0 ll);x
  1550. (nth 1 ll);y
  1551. (nth 0 ur);x
  1552. (nth 1 ll);y
  1553. (nth 0 ur)
  1554. (nth 1 ur)
  1555. (nth 0 ll)
  1556. (nth 1 ur)
  1557. )
  1558. )
  1559. )
  1560. (vla-put-closed
  1561. (setq pl (vla-AddLightWeightPolyline
  1562. (vla-get-ModelSpace (vla-get-Document vp))
  1563. coords
  1564. )
  1565. )
  1566. :vlax-true
  1567. )
  1568. (*Obj2En* pl)
  1569. )
  1570. ;;65.1 [功能] 创建图层(成功返回层名)
  1571. ;;(MJ:DefineLayer strName intColor strLtype booleCur)
  1572. ;; 示例: (MJ:DefineLayer "MJ:Layer1" 3 "DASHED" T)
  1573. (defun MJ:DefineLayer
  1574. (strName intColor strLtype booleCur / iloc obj out)
  1575. (cond
  1576. ((not (tblsearch "layer" strName))
  1577. (setq obj (vla-add (*LAYS*) strName))
  1578. (setq iloc (vl-position strName (MJ:ListLayers)))
  1579. (cond
  1580. ((vlax-Write-Enabled-p obj)
  1581. (if intColor
  1582. (vla-put-Color obj intColor)
  1583. )
  1584. (if strLtype
  1585. (MJ:Apply-Ltype obj strLtype)
  1586. )
  1587. )
  1588. (T (princ "\nUnable to modify object properties..."))
  1589. )
  1590. (if booleCur
  1591. (vla-put-ActiveLayer
  1592. *DOC*
  1593. (vla-Item (*LAYS*) iloc)
  1594. )
  1595. )
  1596. (setq out strName)
  1597. )
  1598. (T
  1599. (princ (strcat "\nLayer already exists: " strName))
  1600. )
  1601. )
  1602. out
  1603. )
  1604. ;;65.2 [功能] 创建一个图层(新建层不为当前层)
  1605. ;; 示例: (MJ:MakeLayer "A-Wall")
  1606. (defun MJ:MakeLayer (lName / oLayer)
  1607. (if
  1608. (vl-catch-all-error-p
  1609. (setq oLayer
  1610. (vl-catch-all-apply
  1611. 'vla-add
  1612. (list
  1613. *LAYS*
  1614. lName
  1615. )
  1616. )
  1617. )
  1618. )
  1619. nil
  1620. oLayer
  1621. )
  1622. )
  1623. ;;66.1 [功能] 表->变体数组类型
  1624. (defun MJ:DblList->VariantArray (nList / ArraySpace sArray)
  1625. ;; allocate space for an array of 2d points stored as doubles
  1626. (setq ArraySpace
  1627. (vlax-Make-SafeArray
  1628. vlax-vbDouble
  1629. (cons 0
  1630. (- (length nList) 1)
  1631. )
  1632. )
  1633. )
  1634. (setq sArray (vlax-SafeArray-Fill ArraySpace nList))
  1635. (vlax-Make-Variant sArray)
  1636. )
  1637. ;;66.2 [功能] 表->整数数组
  1638. (defun MJ:IntList->VarArray (aList)
  1639. (vlax-SafeArray-Fill
  1640. (vlax-Make-SafeArray
  1641. vlax-vbInteger ; (2) Integer
  1642. (cons 0 (- (length aList) 1))
  1643. )
  1644. aList
  1645. )
  1646. )
  1647. ;;66.3 [功能] 表->变体数组
  1648. (defun MJ:VarList->VarArray (aList)
  1649. (vlax-SafeArray-Fill
  1650. (vlax-Make-SafeArray
  1651. vlax-vbVariant ;(12) Variant
  1652. (cons 0 (- (length aList) 1))
  1653. )
  1654. aList
  1655. )
  1656. )
  1657. ;;66.4 [功能] 选择集->数组
  1658. (defun SS->Array (ss / c r)
  1659. (vl-load-com)
  1660. (setq c -1)
  1661. (repeat (sslength ss)
  1662. (setq r (cons (ssname ss (setq c (1+ c))) r))
  1663. )
  1664. (setq r (reverse r))
  1665. (vlax-safearray-fill
  1666. (vlax-make-safearray
  1667. vlax-vbObject;根据需要使用其类型
  1668. (cons 0 (1- (length r)))
  1669. )
  1670. (mapcar 'vlax-ename->vla-object r)
  1671. )
  1672. )
  1673. ;;66.5 [功能] 列表->变体数组
  1674. ;; 示例: (setq ptlist (list "1" 2 (list 1.0 2.0 3.0)))
  1675. ;;(MJ:list->VariantArray (apply 'append ptlist) vlax-vbDouble)
  1676. ;; Notes: 1. If your list includes various data types, pass vlax-vbVariant for the
  1677. ;; varType argument
  1678. ;; 2. Entity names are converted to ObjectIDs
  1679. ;; 3. To convert a point list to ActiveX coordinates:
  1680. (defun MJ:list->VariantArray (lst varType)
  1681. (vlax-make-variant
  1682. (vlax-safearray-fill
  1683. (vlax-make-safearray
  1684. varType
  1685. (cons 0 (1- (length lst)))
  1686. )
  1687. (mapcar
  1688. '(lambda (x)
  1689. (cond
  1690. ((= (type x) 'list)
  1691. (vlax-safearray-fill
  1692. (vlax-make-safearray
  1693. (if (apply '= (mapcar 'type x))
  1694. (cond
  1695. ((= (type (car x)) 'REAL) vlax-vbDouble)
  1696. ((= (type (car x)) 'INT) vlax-vbInteger)
  1697. ((= (type (car x)) 'STR) vlax-vbString)
  1698. )
  1699. vlax-vbVariant
  1700. )
  1701. (cons 0 (1- (length x)))
  1702. )
  1703. x
  1704. )
  1705. )
  1706. ((= (type x) 'ename)
  1707. (vla-get-objectid (*En2Obj* x))
  1708. )
  1709. (t x)
  1710. )
  1711. )
  1712. lst
  1713. )
  1714. )
  1715. )
  1716. )
  1717. ;;67 [功能] 对象端点列表
  1718. ;; 示例:(MJ:GetEllipseArcPoints (car (entsel)))返回两端点
  1719. (defun MJ:GetEllipseArcPoints
  1720. (ellent / OUT P-END P-START VLAOBJECT-ELLIPSE)
  1721. (setq vlaObject-Ellipse (MJ:MakeObject ellent)
  1722. ;; convert ename to object
  1723. p-start (vla-Get-StartPoint vlaObject-Ellipse)
  1724. p-end (vla-Get-EndPoint vlaObject-Ellipse)
  1725. out (list
  1726. (vlax-SafeArray->List (vlax-Variant-Value p-start))
  1727. (vlax-SafeArray->List (vlax-Variant-Value p-end))
  1728. )
  1729. )
  1730. out
  1731. )
  1732. ;;68 [功能] 更改Vla对象线型比例
  1733. ;; 示例: (MJ:Apply-LtScale objLine 24.0)
  1734. (defun MJ:Apply-LtScale (obj dblLtScale)
  1735. (cond
  1736. ((and
  1737. (vlax-Read-Enabled-p obj)
  1738. (vlax-Write-Enabled-p obj)
  1739. )
  1740. (vla-Put-Linetype dblLtScale)
  1741. T
  1742. )
  1743. (T (princ "\n Unable to modify object!"))
  1744. )
  1745. )
  1746. ;;69 [功能] 将图层集合中的第一个图层设置为当前层
  1747. (defun MJ:LayZero ()
  1748. (vla-put-ActiveLayer
  1749. *DOC*
  1750. (vla-Item (*LAYS*) 0)
  1751. )
  1752. )
  1753. ;;70 [功能] 设置指定层为当前层
  1754. ;; (MJ:LayActive "DIM")相当于(command "clayer" "DIM")
  1755. (defun MJ:LayActive (name / iloc out)
  1756. (cond
  1757. ((and
  1758. (tblsearch "layer" name)
  1759. (setq iloc (vl-Position name (MJ:ListLayers)))
  1760. )
  1761. (vla-put-ActiveLayer
  1762. *DOC*
  1763. (vla-Item (*LAYS*) iloc)
  1764. )
  1765. (setq out name)
  1766. )
  1767. (T (princ (strcat "\n Layer not defined: " name)))
  1768. )
  1769. out
  1770. )
  1771. ;;71.1图层列表 开
  1772. (defun MJ:LayerOn (LayList)
  1773. (vlax-for each (vla-get-layers *DOC*)
  1774. (if (member (strcase (vla-get-name each)) LayList)
  1775. (if (vlax-write-enabled-p each)
  1776. (vla-put-LayerOn each :vlax-True)
  1777. )
  1778. )
  1779. (vlax-release-object each)
  1780. )
  1781. )
  1782. ;;71.2 [功能] 图层列表 关
  1783. (defun MJ:LayerOff (LayList)
  1784. (vlax-for each (*LAYS*)
  1785. (if (member (strcase (vla-get-name each)) LayList)
  1786. (if (vlax-write-enabled-p each)
  1787. (vla-put-LayerOn each :vlax-False)
  1788. )
  1789. )
  1790. (vlax-release-object each)
  1791. )
  1792. )
  1793. ;;71.3 [功能] 图层列表 冻结
  1794. (defun MJ:LayerFreeze (LayList)
  1795. (vlax-for each (*LAYS*)
  1796. (if (member (strcase (vla-get-name each)) LayList)
  1797. (if (vlax-write-enabled-p each)
  1798. (vla-put-Freeze each :vlax-True)
  1799. )
  1800. )
  1801. (vlax-release-object each)
  1802. )
  1803. )
  1804. ;;71.4 [功能] 图层列表 解冻
  1805. (defun MJ:LayerThaw (LayList)
  1806. (vlax-for each (*LAYS*)
  1807. (if (member (strcase (vla-get-name each)) LayList)
  1808. (if (vlax-write-enabled-p each)
  1809. (vla-put-Freeze each :vlax-False)
  1810. )
  1811. )
  1812. (vlax-release-object each)
  1813. )
  1814. )
  1815. ;;71.5 [功能] 图层列表[打印/不打印]
  1816. ;; 示例: (MJ:LayerNoPlot '("DOORS" "WINDOWS") T)设置图层不打印
  1817. ;; 示例: (MJ:LayerNoPlot '("DOORS" "WINDOWS") nil) 设置图层打印
  1818. (defun MJ:LayerNoPlot (LayList On-Off)
  1819. (vlax-for each (*LAYS*)
  1820. (if (member (strcase (vla-get-name each)) LayList)
  1821. (if (vlax-write-enabled-p each)
  1822. (if On-Off
  1823. (vla-put-Plottable each :vlax-True)
  1824. (vla-put-Plottable each :vlax-False)
  1825. )
  1826. )
  1827. )
  1828. (vlax-release-object each)
  1829. )
  1830. )
  1831. ;;71.6 [功能] 图层列表 锁
  1832. (defun MJ:LayerLock (LayList)
  1833. (vlax-for each (*LAYS*)
  1834. (if (member (strcase (vla-get-name each)) LayList)
  1835. (if (vlax-write-enabled-p each)
  1836. (vla-put-Lock each :vlax-True)
  1837. )
  1838. )
  1839. (vlax-release-object each)
  1840. )
  1841. )
  1842. ;;71.7 [功能] 图层列表 解锁
  1843. (defun MJ:LayerUnLock (LayList)
  1844. (vlax-for each (*LAYS*)
  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. ;;71.8 [功能] 锁定图层列表
  1854. (defun MJ:ListLayers-Locked (/ each out)
  1855. (vlax-for each (*LAYS*)
  1856. (if (= (vlax-get-property each "Lock") :vlax-true)
  1857. (setq out (cons (vla-get-name each) out))
  1858. )
  1859. )
  1860. out
  1861. )
  1862. ;;71.9 [功能] 返回冻结图层列表
  1863. (defun MJ:ListLayers-Frozen (/ each out)
  1864. (vlax-for each (*LAYS*)
  1865. (if (= (vlax-get-property each "Freeze") :vlax-true)
  1866. (setq out (cons (vla-get-name each) out))
  1867. )
  1868. )
  1869. out
  1870. )
  1871. ;;71.10 [功能] 返回关闭图层列表
  1872. (defun MJ:ListLayers-Off (/ each out)
  1873. (vlax-for each (*LAYS*)
  1874. (if (= (vlax-get-property each "LayerOn") :vlax-false)
  1875. (setq out (cons (vla-get-name each) out))
  1876. )
  1877. )
  1878. out
  1879. )
  1880. ;;71.11 [功能] 可打印图层列表
  1881. (defun MJ:ListLayers-Plottable (/ each out)
  1882. (vlax-for each (*LAYS*)
  1883. (if (= (vlax-get-property each "Plottable") :vlax-true)
  1884. (setq out (cons (vla-get-name each) out))
  1885. )
  1886. )
  1887. out
  1888. )
  1889. ;;71.12 [功能] 非打印图层列表
  1890. (defun MJ:ListLayers-Plottalbe-Not (/ each out)
  1891. (vlax-for each (*LAYS*)
  1892. (if (= (vlax-get-property each "Plottable") :vlax-false)
  1893. (setq out (cons (vla-get-name each) out))
  1894. )
  1895. )
  1896. out
  1897. )
  1898. ;;71.13 [功能] 层是否冻结?
  1899. ;;(MJ:Layer-Frozen-p "DIM")
  1900. (defun MJ:Layer-Frozen-p (lname / each)
  1901. (if
  1902. (and
  1903. (setq fl (MJ:ListLayers-Frozen))
  1904. ;; any frozen layers?
  1905. (member (strcase lname) (mapcar 'strcase fl))
  1906. )
  1907. T
  1908. )
  1909. )
  1910. ;;71.14 [功能] 解冻 解锁 所有图层
  1911. (defun MJ:Mylayer ()
  1912. (acet-layerp-mode T)
  1913. (acet-layerp-mark T)
  1914. (command "_.Layer" "Thaw" "*" "U" "*" "ON" "*" "")
  1915. )
  1916. ;;71.15 [功能] 恢复图层状态 By coaying
  1917. (defun MJ:layer-restore ()
  1918. (acet-layerp-mark nil)
  1919. (command "_.layerp")
  1920. )
  1921. ;;71.16 [功能] 得到图层状态highflybird
  1922. (defun Get_Layer_Status (/ V_LIST L_LIST C_LIST T_LIST W_LIST *DOC)
  1923. (setq *Doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  1924. (vlax-for n (vla-get-layers *DOC)
  1925. (setq V_List (cons (cons n (vla-get-LayerOn n)) V_List)
  1926. L_List (cons (cons n (vla-get-Lock n)) L_List)
  1927. C_List (cons (cons n (vla-get-TrueColor n)) C_List)
  1928. T_List (cons (cons n (vla-get-Linetype n)) T_List)
  1929. W_List (cons (cons n (vla-get-LineWeight n)) W_List)
  1930. F_List (cons (cons n (vla-get-Freeze n)) F_List)
  1931. )
  1932. )
  1933. (List V_List L_List C_List T_List W_List F_List)
  1934. )
  1935. ;;71.17 [功能] 恢复图层状态highflybird
  1936. (defun Restore_Layer_status (LayLst)
  1937. (mapcar (function
  1938. (lambda (x y)
  1939. (foreach n X
  1940. (if (/= (strcase (setq name (vla-get-name (car n))))
  1941. (strcase (getvar "clayer"))
  1942. ) ; 非当前层
  1943. (vlax-put-property (car n) y (cdr n))
  1944. ;;对于当前层
  1945. (if (/= y "Freeze") ; 排除冻结操作,以防出错
  1946. (vlax-put-property (car n) y (cdr n))
  1947. )
  1948. )
  1949. )
  1950. )
  1951. )
  1952. LayLst
  1953. (list "Layeron" "Lock" "TrueColor"
  1954. "LineType" "LineWeight" "Freeze"
  1955. )
  1956. )
  1957. ;;(vl-cmdf "regen")
  1958. )
  1959. ;;71.18 [功能] 图层是否锁定?
  1960. ;;(b_layer_locked "0"),0层锁后返回T
  1961. (defun b_layer_locked (la / na e1)
  1962. (setq na (tblobjname "layer" la)
  1963. e1 (entget na)
  1964. )
  1965. (equal 4 (logand 4 (cdr (assoc 70 e1))))
  1966. )
  1967. ;;72 [功能] 设置vla对象线宽
  1968. ;; NOTES:
  1969. ;; "ByLwDefault" = -3
  1970. ;; "ByBlock" = -2
  1971. ;; "ByLayer" = -1
  1972. ;; Other values are 0, 5, 9, 13, 15, 18, 20, 25, 30, 35, 40, 50, 53, 60,
  1973. ;; 70, 80, 90, 100, 106, 120, 140, 158, 200, 211
  1974. (defun MJ:SetLweight (obj intLwt)
  1975. (cond
  1976. ((member intLwt
  1977. '(0 5 9 13 15 18 20 25 30 35 40
  1978. 50 60 70 80 90 100 106 120 140 158 200
  1979. 211
  1980. )
  1981. )
  1982. (vla-put-LineWeight obj ineLwt)
  1983. T
  1984. )
  1985. )
  1986. )
  1987. ;;73 [功能] vla选择集是否存在
  1988. (defun MJ:SSetExists-p (Name)
  1989. (not
  1990. (vl-Catch-All-Error-p
  1991. (vl-Catch-All-Apply
  1992. 'vla-Item
  1993. (list (vla-Get-SelectionSets *DOC*) Name)
  1994. )
  1995. )
  1996. )
  1997. )
  1998. ;;74.1 [功能] 返回指定类型的选择集
  1999. ;; 示例: (setq MJ:set (MJ:SelectByType "CIRCLE"))
  2000. ;;(MJ:MapCollection MJ:set 'MJ:DeleteObject)圆全部删除
  2001. (defun MJ:SelectByType (objtype / ss)
  2002. (if (MJ:SSetExists-p "%TEMP_SET")
  2003. (vla-Delete
  2004. (vla-Item
  2005. (vla-get-SelectionSets *DOC*)
  2006. "%TEMP_SET"
  2007. )
  2008. )
  2009. )
  2010. (setq ss
  2011. (vla-Add
  2012. (vla-get-SelectionSets *DOC*)
  2013. "%TEMP_SET"
  2014. )
  2015. )
  2016. (vla-Select
  2017. ss
  2018. ACSelectionSetAll
  2019. nil
  2020. nil
  2021. (MJ:IntList->VarArray (list 0))
  2022. (MJ:VarList->VarArray (list objtype))
  2023. )
  2024. ss
  2025. )
  2026. ;;74.2 [功能] 返回指定类型的选择集
  2027. ;; MODULE: (MJ:SelectOnScreen-Filter GroupCodes FilterLists)
  2028. ;;示例见下
  2029. (defun MJ:SelectOnScreen-Filter (GroupCodes FilterLists / ss)
  2030. (if (MJ:SSetExists-p "%TEMP_SET")
  2031. (vla-Delete
  2032. (vla-Item
  2033. (vla-get-SelectionSets *DOC*)
  2034. "%TEMP_SET"
  2035. )
  2036. )
  2037. )
  2038. (setq ss
  2039. (vla-Add
  2040. (vla-get-SelectionSets *DOC*)
  2041. "%TEMP_SET"
  2042. )
  2043. )
  2044. (vla-Select
  2045. ss
  2046. ACSelectionSetAll
  2047. nil
  2048. nil
  2049. (MJ:IntList->VarArray GroupCodes)
  2050. (MJ:VarList->VarArray FilterLists)
  2051. )
  2052. ss
  2053. )
  2054. ;;74.3 [功能] 返回0层上的圆选择集
  2055. (defun MJ:PICKCIRCLES (/ SS)
  2056. (if
  2057. (setq ss (MJ:SelectOnScreen-Filter '(0 8) '("CIRCLE" "0")))
  2058. (vlax-For item ss
  2059. (princ (vla-get-ObjectName item))
  2060. (terpri)
  2061. )
  2062. )
  2063. (terpri)
  2064. ss
  2065. )
  2066. ;;74.4 [功能] 返回圆选择集(并打印名称)
  2067. (defun C:GETCIRCLES ()
  2068. (if (setq ss (MJ:SelectByType "CIRCLE"))
  2069. (vlax-For item ss
  2070. (princ (vla-get-ObjectName item))
  2071. (terpri)
  2072. )
  2073. )
  2074. ss
  2075. )
  2076. ;;75.1 [功能] 返回CAD窗口状态
  2077. ;; acEnum 1=Min 2=Normal 3=Max
  2078. ;; 示例: (MJ:GetWindowState) return 1, 2 or 3
  2079. (defun MJ:GetWindowState ()
  2080. (vla-get-WindowState *ACAD*)
  2081. )
  2082. ;;75.2 [功能] 设置CAD窗口状态
  2083. ;; 示例: (MJ:SetWindowState 3) maximizes the window display
  2084. (defun MJ:SetWindowState (acEnum)
  2085. (vla-put-WindowState *ACAD* acEnum)
  2086. )
  2087. ;;76.1 [功能] 隐藏CAD
  2088. ;; 示例: (MJ:HideAutoCAD)
  2089. (defun MJ:HideAutoCAD ()
  2090. (vla-put-Visible *ACAD* :vlax-False)
  2091. )
  2092. ;;76.2 [功能] 显示CAD
  2093. ;; 示例: (MJ:ShowAutoCAD)
  2094. (defun MJ:ShowAutoCAD ()
  2095. (vla-put-Visible *ACAD* :vlax-True)
  2096. )
  2097. ;;76.3 [功能] 隐藏CAD一段时间
  2098. ;; 示例: (MJ:HideShowTest 500) 隐藏CAD,时间500毫秒
  2099. (defun MJ:HideShowTest (delay-time)
  2100. (MJ:HideAutoCAD)
  2101. (vl-cmdf "delay" delay-time)
  2102. (MJ:ShowAutoCAD)
  2103. )
  2104. ;;77.1 [功能] CAD参数选择
  2105. (defun MJ:DocPrefs ()
  2106. (vla-get-Preferences *DOC*)
  2107. )
  2108. ;;77.2 [功能] 线宽显示
  2109. (defun MJ:LWdisplayON ()
  2110. (vla-put-LineWeightDisplay (MJ:DocPrefs) :vlax-True)
  2111. )
  2112. ;;77.3 [功能] 隐藏线宽
  2113. (defun MJ:LWdisplayOFF ()
  2114. (vla-put-LineWeightDisplay (MJ:DocPrefs) :vlax-False)
  2115. )
  2116. ;;77.4 [功能] 对象捕捉开
  2117. (defun MJ:ObjectSortBySnapON ()
  2118. (vla-put-ObjectSortBySnap (MJ:DocPrefs) :vlax-True)
  2119. )
  2120. ;;77.5 [功能] 对象捕捉关闭
  2121. (defun MJ:ObjectSortBySnapOFF ()
  2122. (vla-put-ObjectSortBySnap (MJ:DocPrefs) :vlax-False)
  2123. )
  2124. ;;77.6[功能] 图形被其它用户参照时仍可以立即编辑
  2125. (defun MJ:XrefEditON ()
  2126. (vla-put-XrefEdit (MJ:DocPrefs) :vlax-True)
  2127. )
  2128. ;;77.7[功能] 图形被其它用户参照时不可以立即编辑
  2129. (defun MJ:XrefEditOFF ()
  2130. (vla-put-XrefEdit (MJ:DocPrefs) :vlax-False)
  2131. )
  2132. ;;78.1 [功能] CAD菜单集合
  2133. (defun MJ:MenuGroups ()
  2134. (vla-get-menugroups *ACAD*)
  2135. )
  2136. ;;78.2 [功能] 菜单列表
  2137. ;;示例("ACAD" "CXinZhi")
  2138. (defun MJ:MenuGroups-ListAll (/ out)
  2139. (vlax-for each (MJ:MenuGroups)
  2140. (setq out (cons (vla-get-name each) out))
  2141. )
  2142. (reverse out)
  2143. )
  2144. ;;78.3 [功能] 菜单是否存在
  2145. ;;示例(MJ:MenuGroup-Exists-p "CXinZhi")返回 1
  2146. (defun MJ:MenuGroup-Exists-p (name)
  2147. (if
  2148. (member
  2149. (strcase name)
  2150. (mapcar 'strcase (MJ:MenuGroups-ListAll))
  2151. )
  2152. (vl-position name (MJ:MenuGroups-ListAll))
  2153. )
  2154. )
  2155. ;;78.4 [功能] 工具条Vla集合
  2156. (defun MJ:Toolbars (mgroup)
  2157. (if (MJ:MenuGroup-Exists-p mgroup)
  2158. (vla-get-toolbars
  2159. (vla-item
  2160. (MJ:MenuGroups)
  2161. (vl-position
  2162. (strcase mgroup)
  2163. (mapcar 'strcase (MJ:MenuGroups-ListAll))
  2164. )
  2165. )
  2166. )
  2167. )
  2168. )
  2169. ;;78.5 [功能] 工具条列表
  2170. ;;(MJ:ToolbarsList "CXinZhi")返回("附加图层工具" "附加文字工具" "附加标准工具")
  2171. (defun MJ:ToolbarsList (mgroup / tb out)
  2172. (if (setq tb (MJ:Toolbars mgroup))
  2173. (vlax-for each tb
  2174. (setq out (cons (vla-get-name each) out))
  2175. )
  2176. )
  2177. (reverse out)
  2178. )
  2179. ;;78.6 [功能] 工具条列表
  2180. ;; Arguments: 菜单名称
  2181. ;; 示例: (ListToolbars "acad")(ListToolbars "CXinZhi")
  2182. (defun MJ:ListToolbars (groupName / mGroups mGroup lst)
  2183. (if (not
  2184. (vl-catch-all-error-p
  2185. (setq
  2186. mGroup (vl-catch-all-apply
  2187. 'vla-item
  2188. (list (vla-get-menugroups *ACAD*)
  2189. groupName
  2190. )
  2191. )
  2192. )
  2193. )
  2194. )
  2195. (vlax-for tBar (vla-get-toolbars mGroup)
  2196. (setq lst (cons (vla-get-name tBar) lst))
  2197. )
  2198. )
  2199. )
  2200. ;;78.7 [功能] 工具条是否存在
  2201. ;;(MJ:Toolbar-Exists-p "CXinZhi" "附加图层工具");返回0
  2202. (defun MJ:Toolbar-Exists-p (mgroup tbname)
  2203. (if
  2204. (and
  2205. (MJ:MenuGroup-Exists-p mgroup)
  2206. (member
  2207. (strcase tbname)
  2208. (mapcar 'strcase (MJ:Toolbars-ListAll mgroup))
  2209. )
  2210. )
  2211. (vl-position tbname (MJ:Toolbars-ListAll mgroup))
  2212. )
  2213. )
  2214. ;;78.8 [功能] 指定工具条(Vla)
  2215. (defun MJ:Toolbar (mgroup tbname / loc)
  2216. (if (setq loc (MJ:Toolbar-Exists-p mgroup tbname))
  2217. (vla-item (MJ:Toolbars mgroup) loc)
  2218. )
  2219. )
  2220. ;;78.9 [功能] 显示指定工具条
  2221. ;;(MJ:Toolbar-Show "ACAD" "UCS")将显示UCS工具条
  2222. ;;(MJ:Toolbar-Show "CXinZhi" "附加图层工具")
  2223. (defun MJ:Toolbar-Show (mgroup tbname / tb)
  2224. (if (setq tb (MJ:Toolbar mgroup tbname))
  2225. (if (= (vla-get-visible tb) :vlax-false)
  2226. (progn
  2227. (vla-put-visible tb :vlax-true)
  2228. T
  2229. )
  2230. )
  2231. )
  2232. )
  2233. ;;78.10 [功能] 隐藏工具条
  2234. (defun MJ:Toolbar-Hide (mgroup tbname / tb)
  2235. (if (setq tb (MJ:Toolbar mgroup tbname))
  2236. (if (= (vla-get-visible tb) :vlax-true)
  2237. (progn
  2238. (vla-put-visible tb :vlax-false)
  2239. T
  2240. )
  2241. )
  2242. )
  2243. )
  2244. ;;78.11 [功能] 工具条放置位置
  2245. ;; NOTES: Allowable <dock> values are 0(top), 1(bottom), 2(left), ;;
  2246. ;; and 3(right). Returns 1 if successful, -1 if toolbar is not ;;
  2247. ;; visible, -2 if parameter is invalid, or 0 if toolbar not found. ;;
  2248. (defun MJ:Toolbar-Dock (mgroup tbname dock / tb)
  2249. (if (setq tb (MJ:Toolbar mgroup tbname))
  2250. (if (= (vla-get-visible tb) :vlax-true)
  2251. (if (member dock '(0 1 2 3))
  2252. (progn
  2253. (vlax-invoke-method tb 'Dock dock)
  2254. 1
  2255. )
  2256. -2
  2257. ;; invalid dockstatus parameter
  2258. )
  2259. -1
  2260. ;; toolbar not visible
  2261. )
  2262. 0
  2263. ;; toolbar not found
  2264. )
  2265. )
  2266. ;;78.12 [功能] Float a given toolbar at specified position(top and left)
  2267. ;; and display with specified number of rows. Returns 1 if successful,
  2268. ;; -1 if toolbar is not visible, 0 if toolbar is not found.
  2269. (defun MJ:Toolbar-Folat (mgroup tbname top left rows)
  2270. (if (setq tb (MJ:Toolbar mgroup tbname))
  2271. (if (= (vla-get-visible tb) :vlax-true)
  2272. (progn
  2273. (vlax-invoke-method tb 'Float top left rows)
  2274. 1
  2275. )
  2276. -1
  2277. ;; toolbar not visible
  2278. )
  2279. 0
  2280. ;; toolbar not found
  2281. )
  2282. )
  2283. ;;78.13 [功能] 改变工具条按钮位图
  2284. ;; 示例: (MJ:ChangeBitmap "acad" "dimension" "linear dimension" "test.bmp")
  2285. ;; Notes: 1. If the bitmap is not in the AutoCAD search path, you must specify ;;
  2286. ;; the full path to file ;;
  2287. (defun MJ:ChangeBitmap (mnuGroup tbrName btnName bitmap)
  2288. (vl-load-com)
  2289. (vla-setbitmaps
  2290. (vla-item
  2291. (vla-item
  2292. (vla-get-toolbars
  2293. (vla-item (vla-get-menugroups *ACAD*)
  2294. mnuGroup
  2295. )
  2296. )
  2297. tbrName
  2298. )
  2299. btnName
  2300. )
  2301. bitmap
  2302. bitmap
  2303. )
  2304. (princ)
  2305. )
  2306. ;;79 [功能] 2D点转成vla 2D
  2307. (defun MJ:2DPoint (pt)
  2308. (vl-load-com)
  2309. (vlax-make-variant
  2310. (vlax-safearray-fill
  2311. (vlax-make-safearray vlax-vbdouble '(0 . 1))
  2312. (list (car pt) (cadr pt))
  2313. )
  2314. )
  2315. )
  2316. ;;80.1 [功能] 激活最左边一个布局
  2317. ;;下面程序使用vla-activate有问题,看起来没有错误
  2318. ;;模型和布局之间自由切换(setvar "CTAB" "layout2")
  2319. (defun MJ:ActivateLastLayout (/ CNT I)
  2320. (vlax-for layout *LOUTS*
  2321. (if (= (vla-get-taborder layout) 1);取得布局的tab顺序,图纸空间的标签(tab)顺序必须是1或大于1
  2322. (vla-put-ActiveLayout *DOC* layout) ; (vla-activate layout)运行有问题
  2323. )
  2324. )
  2325. )
  2326. ;;80.2 [功能] 激活第二个图形[Ctrl+Tab] 见10
  2327. (defun MJ:ActivateDrawing ()
  2328. (vla-activate (vla-item *docs* 1))
  2329. )
  2330. ;;81 [功能] VLA选择集过滤条件Returns a list containing a pair of variants for use as
  2331. ;; ActiveX selection set filters
  2332. ;; 示例: (MJ:BuildFilter '((0 . "LWPOLYLINE") (8 . "WALLS")))
  2333. (defun MJ:BuildFilter (filter)
  2334. (vl-load-com)
  2335. (mapcar '(lambda (lst typ)
  2336. (vlax-make-variant
  2337. (vlax-safearray-fill
  2338. (vlax-make-safearray
  2339. typ
  2340. (cons 0
  2341. (1- (length lst))
  2342. )
  2343. )
  2344. lst
  2345. )
  2346. )
  2347. )
  2348. (list (mapcar 'car filter) (mapcar 'cdr filter))
  2349. (list vlax-vbInteger vlax-vbVariant)
  2350. )
  2351. )
  2352. ;;81 [功能] 类型库智能化加载
  2353. ;;用法: (vlax-load-type-libeary ProgID[STRING] UniquePrefix[STR] )
  2354. ;; (vlax-load-type-libeary ProgID[STRING] PrefixList[STR] )
  2355. ;; 参数1: 与vlax-get-create-object 函数相同的ProgID 字符串
  2356. ;; 参数2: 前缀,可以是字符串或表
  2357. ;; 表的顺序 (:methods-prefix :properties-prefix :constants-prefix)
  2358. ;;说明: 此函数读取 Windows REGISTRY 并且侦测合适的 DLL/OCX/EXE 类型库并自动加载
  2359. ;;返回值: T 或者 nil
  2360. (Defun vlax-load-type-library
  2361. (File Prefix / FileX Host N KeyX Val OSVar rtn)
  2362. (setq Host "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\CLSID"
  2363. N -1
  2364. KeyX (vl-registry-descendents Host)
  2365. )
  2366. (while (< (setq N (1+ N))
  2367. (length KeyX)
  2368. )
  2369. (if (and (setq Val (vl-registry-read
  2370. (strcat Host "\\" (nth N KeyX) "\\ProgID")
  2371. )
  2372. )
  2373. (vl-string-search (strcase File) (strcase Val))
  2374. )
  2375. (setq FileX (vl-registry-read
  2376. (strcat Host "\\" (nth N KeyX) "\\InProcServer32")
  2377. )
  2378. N (length KeyX)
  2379. )
  2380. )
  2381. )
  2382. (if (= (type Prefix) 'STR)
  2383. (setq Prefix (list Prefix Prefix (strcat ":" Prefix)))
  2384. )
  2385. (if (= (type FileX) 'LIST)
  2386. (setq FileX (cdr FileX))
  2387. )
  2388. (if (= (type FileX) 'STR)
  2389. (progn
  2390. (setq FileX (strcase FileX))
  2391. (foreach OSVar (list "SYSTEMROOT" "WINDIR"
  2392. "WINBOOTDIR" "SYSTEMDRIVE"
  2393. "USERNAME" "COMPUTERNAME"
  2394. "HOMEDRIVE" "HOMEPATH"
  2395. "PROGRAMFILES"
  2396. )
  2397. (if (vl-string-search (strcat "%" OSVar "%") FileX)
  2398. (setq FileX (vl-string-subst
  2399. (strcase (getenv OSVar))
  2400. (strcat "%" OSVar "%")
  2401. FileX
  2402. )
  2403. )
  2404. )
  2405. )
  2406. (if (setq rtn (findfile FileX))
  2407. (setq rtn
  2408. (vlax-import-type-library
  2409. :tlb-filename
  2410. FileX
  2411. :methods-prefix
  2412. (nth 0 Prefix)
  2413. :properties-prefix
  2414. (nth 1 Prefix)
  2415. :constants-prefix
  2416. (nth 2 Prefix)
  2417. )
  2418. )
  2419. )
  2420. )
  2421. )
  2422. rtn
  2423. )
  2424. ;;82 [功能] 转换路径中字符 "/" "\\" 并返回大写值
  2425. ;;用法: (vldos-formatpath PathStringToFormat[STRING] )
  2426. ;;参数1: 路径字符串
  2427. ;;返回值:转换后的字符串 或者 None
  2428. (Defun vldos-formatpath (string)
  2429. (while (vl-string-search "/" string)
  2430. (setq string (vl-string-subst "\\" "/" string))
  2431. )
  2432. (while (vl-string-search "\\\\" string)
  2433. (setq string (vl-string-subst "\\" "\\\\" string))
  2434. )
  2435. (strcase string)
  2436. )
  2437. ;;83 [功能] 通过IE 显示一个 HTML 字符串
  2438. ;;用法: (vldos-text->ie ContentString[STRING] )
  2439. ;; 参数1: 要显示的字符串或字符串表
  2440. ;;说明: 传送数据至新打开的IE窗口
  2441. ;;返回值: 包括字符串的新打开的IE窗口 OR NIL
  2442. (Defun vldos-text->ie (TXT / list->string ie ln doc)
  2443. (if (= (type TXT) 'STR)
  2444. (setq TXT (list TXT))
  2445. )
  2446. (if (setq ie (vlax-create-object "InternetExplorer.Application"))
  2447. (progn
  2448. (vlax-put-property ie 'menubar 0)
  2449. (vlax-put-property ie 'toolbar 0)
  2450. (vla-put-visible ie t)
  2451. (vlax-invoke-method ie 'navigate "about :blank")
  2452. (setq doc (vlax-get-property ie 'document))
  2453. (foreach ln TXT
  2454. (vlax-invoke-method doc 'writeln ln "")
  2455. )
  2456. (vlax-invoke-method doc 'close)
  2457. (vlax-release-object doc)
  2458. (vlax-release-object ie)
  2459. )
  2460. )
  2461. )
  2462. ;;84.1 [功能] 显示时间/日期对话框
  2463. ;;用法: (vldos-time)
  2464. ;;返回值: 显示时间/日期对话框 OR NIL
  2465. (Defun vldos-time (/ sys)
  2466. (if (setq sys (vlax-create-object "Shell.Application"))
  2467. (progn
  2468. (vlax-invoke-method sys 'settime)
  2469. (vlax-release-object sys)
  2470. )
  2471. )
  2472. )
  2473. ;;84.2 [功能] Returns the logical drive letter to which a network share is mapped
  2474. ;; Arguments: A UNC path
  2475. ;; 示例: (MJ:MappedShare "\\\\MJ:Server\\MJ:Share")
  2476. ;; Notes: 1. Be sure to substitute two backslashes for every one in the UNC path
  2477. ;; 2. This routine requires the use SCRRUN.DLL. Visite the
  2478. ;; Microsoft scripting web site if you do not have it.
  2479. (defun MJ:MappedShare (share / drives drive letter)
  2480. (vlax-for drive (setq drives (vlax-get-property *FSO* 'Drives))
  2481. (if (= (strcase (vlax-get-property drive 'ShareName))
  2482. (strcase share)
  2483. )
  2484. (setq letter (vlax-get-property drive 'DriveLetter))
  2485. )
  2486. )
  2487. (vlax-release-object drives)
  2488. letter
  2489. )
  2490. ;;84.3 [功能] 返回驱动器类型
  2491. ;; 示例: (mapcar 'MJ:DriveType (MJ:ListDrives))
  2492. ;; Notes: 1. This routine requires the use SCRRUN.DLL.
  2493. ;; Visit the Microsoft scripting web site if you do not have it.
  2494. ;;方法: BuildPath (2),CopyFile (3),CopyFolder (3),CreateFolder (1),CreateTextFile (3),DeleteFile (2),DeleteFolder (2)
  2495. ;;DriveExists (1),FileExists (1),FolderExists (1),GetAbsolutePathName (1),GetBaseName (1),GetDrive (1),GetDriveName (1)
  2496. ;;GetExtensionName (1),GetFile (1),GetFileName (1),GetFileVersion (1),GetFolder (1),GetParentFolderName (1)
  2497. ;;GetSpecialFolder (1),GetStandardStream (2),GetTempName (),MoveFile (2),MoveFolder (2),penTextFile (4)
  2498. (defun MJ:DriveType (drv / drives drive typ)
  2499. (if (vlax-invoke-method *FSO* 'DriveExists drv)
  2500. (progn
  2501. (setq drives (vlax-get-property *FSO* 'Drives)
  2502. drive (vlax-get-property drives 'Item drv)
  2503. typ (vlax-get-property drive 'DriveType)
  2504. )
  2505. (vlax-release-object drive)
  2506. (vlax-release-object drives)
  2507. (nth typ
  2508. '("UNKNOWN" "REMOVABLE" "FIXED" "REMODTE" "CDROM" "RAMDISK")
  2509. )
  2510. )
  2511. )
  2512. )
  2513. ;;84.4 [功能] 返回驱动器列表
  2514. (defun MJ:ListDrives (/ drive drives lst)
  2515. (vlax-for drive (setq drives (vlax-get-property*FSO* 'Drives))
  2516. (setq lst (cons (vlax-get-property drive 'DriveLetter) lst))
  2517. )
  2518. (vlax-release-object drives)
  2519. (reverse lst)
  2520. )
  2521. ;;84.5 [功能] 修改本地磁盘的卷标
  2522. ;;用法: (vldos-label DriveLetter[STRING] NewVolumnName[STRING] )
  2523. ;; 参数1: 盘符 例如: "C" 或 "C:"
  2524. ;; 参数2: 新卷标, 如果长度超过11个字符, 自动裁掉
  2525. ;; <<< 本函数不检查字符串是否符合命名规则 >>>
  2526. ;;返回值: 新卷标 or NIL
  2527. (Defun vldos-Label (DRV NEW / Fil DDD ERR)
  2528. (if (> (strlen NEW) 11)
  2529. (setq NEW (substr New 1 11))
  2530. )
  2531. (if (setq Fil (vlax-get-or-create-object "Scripting.FileSystemObject"))
  2532. (progn
  2533. (setq DDD (vlax-invoke-method Fil 'GetDrive DRV))
  2534. (vlax-put-property DDD "VolumeName" NEW)
  2535. (if (not (eq (setq NEW (strcase NEW))
  2536. (strcase (vlax-get-property DDD "VolumeName"))
  2537. )
  2538. )
  2539. (setq NEW nil)
  2540. )
  2541. (vlax-release-object DDD)
  2542. (vlax-release-object FIL)
  2543. )
  2544. (setq New nil)
  2545. )
  2546. NEW
  2547. )
  2548. ;;84.6 [功能] 执行 DOS DELTREE 命令
  2549. ;;用法: (vldos-deltree DirectoryToDelete[STRING] )
  2550. ;; 参数1: 要被删除的目录名称. 此函数不显示确认过程,删除文件夹和所有的子文件夹
  2551. ;; 如果参数是根目录,江删除所有的子目录.
  2552. ;;返回值: T or NIL
  2553. (Defun vldos-Deltree (Folder / sf subf FIL Rtn)
  2554. (cond ((vl-file-directory-p Folder)
  2555. (if (null (setq Fil
  2556. (vlax-get-or-create-object "Scripting.FileSystemObject")
  2557. )
  2558. )
  2559. (setq Rtn nil)
  2560. (progn
  2561. (cond
  2562. ((<= (strlen Folder) 3)
  2563. (if (= (strlen folder) 2)
  2564. (setq folder (strcat folder "\\"))
  2565. )
  2566. (setq subf (vl-directory-files Folder nil -1)
  2567. subf (vl-remove "." subf)
  2568. subf (vl-remove ".." subf)
  2569. subf (vl-remove "Recycled" subf)
  2570. )
  2571. (foreach sf subf
  2572. (vlax-invoke-method
  2573. Fil
  2574. 'DeleteFolder
  2575. (strcat folder sf)
  2576. T
  2577. )
  2578. )
  2579. )
  2580. (t (vlax-invoke-method Fil 'DeleteFolder Folder T))
  2581. )
  2582. (vlax-release-object FIL)
  2583. (setq Rtn (not (vl-file-directory-p Folder)))
  2584. )
  2585. )
  2586. )
  2587. ((findfile Folder)
  2588. (vl-file-delete folder)
  2589. (setq Rtn (not (findfile Folder)))
  2590. )
  2591. )
  2592. Rtn
  2593. )
  2594. ;;84.7 [功能] 创建目录
  2595. ;;用法: (vldos-mkdir DirectoryToCreate[STRING] )
  2596. ;;参数1: 目录的全路径名. 此函数会自动创建参数中所有不存在的目录.
  2597. ;;返回值: 创建目录的全路径名 or NIL
  2598. (Defun vldos-MkDir (Folder / FolderX Fil FFF Pos DIR DRV)
  2599. (if (null
  2600. (setq
  2601. Fil (vlax-get-or-create-object "Scripting.FileSystemObject")
  2602. )
  2603. )
  2604. (setq Folder nil)
  2605. (progn
  2606. (while (vl-string-search "/" Folder)
  2607. (setq Folder (vl-string-subst "\\" "/" Folder))
  2608. )
  2609. (if (wcmatch Folder "*\\")
  2610. (setq Folder (substr Folder 1 (1- (strlen Folder))))
  2611. )
  2612. (setq FolderX Folder)
  2613. (while (setq Pos (vl-string-search "\\" Folder))
  2614. (setq FFF (cons (substr Folder 1 Pos) FFF)
  2615. Folder (substr Folder (+ Pos 2))
  2616. )
  2617. )
  2618. (setq FFF (reverse (cons Folder FFF))
  2619. DRV (car FFF)
  2620. FFF (cdr FFF)
  2621. )
  2622. (foreach DIR FFF
  2623. (if
  2624. (null (vl-file-directory-p (setq DRV (strcat DRV "\\" DIR)))
  2625. )
  2626. (vlax-invoke-method
  2627. Fil
  2628. 'createfolder
  2629. DRV
  2630. )
  2631. )
  2632. )
  2633. (vlax-release-object Fil)
  2634. (if (setq Folder (vl-file-directory-p FolderX))
  2635. (setq Folder (vldos-formatpath FolderX))
  2636. )
  2637. )
  2638. )
  2639. Folder
  2640. )
  2641. ;;84.8 [功能] 复制文件或目录
  2642. ;;用法: (vldos-copy SourceFile/Directory[STRING] TargetFile/Directory[STRING] )
  2643. ;; 参数1: 源文件或目录
  2644. ;; 参数2: 目标目录. 如果包含 "*\\" or "*/", 此函数将在此路径下创建相同的子目录.
  2645. ;; 返回值: 复制的文件或目录字符串 or NIL
  2646. (Defun vldos-copy (from to / sys folder)
  2647. (setq from (vldos-formatpath from)
  2648. to (vldos-formatpath to)
  2649. )
  2650. (if (null (vl-file-directory-p to))
  2651. (setq to (vldos-mkdir to))
  2652. )
  2653. (if (setq sys (vlax-get-or-create-object "Shell.Application"))
  2654. (progn
  2655. (if (setq folder (vlax-invoke-method sys 'namespace to))
  2656. (progn
  2657. (princ
  2658. (strcat "\n Copying file(s) from \042"
  2659. FROM "\042 to \042"
  2660. to "\042..."
  2661. )
  2662. )
  2663. (vlax-invoke-method folder 'copyhere from (+ 4 16))
  2664. (vlax-release-object folder)
  2665. (princ "...Done!")
  2666. )
  2667. )
  2668. (vlax-release-object sys)
  2669. )
  2670. )
  2671. (princ)
  2672. )
  2673. ;;84.9 [功能] 复制目录下所有文件和目录
  2674. ;;示例 (vldos-copy2 (getvar "dwgprefix") "C:\\mtool\\SUPPORT")
  2675. (Defun vldos-copy2 (From to / rtn)
  2676. (cond
  2677. ((vl-file-directory-p From)
  2678. (if (< (strlen to) 3)
  2679. (setq to (strcat to "\\"))
  2680. (if (not (vl-file-directory-p to))
  2681. (vldos-mkdir to)
  2682. )
  2683. )
  2684. (if (setq
  2685. Rtn (vlax-get-or-create-object "Scripting.FileSystemObject")
  2686. )
  2687. (progn
  2688. (vlax-invoke-method Rtn 'CopyFolder From to T)
  2689. (vlax-release-object Rtn)
  2690. (if (vl-file-directory-p to)
  2691. (setq Rtn (vldos-formatpath to))
  2692. )
  2693. )
  2694. )
  2695. )
  2696. ((findfile From)
  2697. (vl-file-copy From to)
  2698. (if (setq rtn (findfile to))
  2699. (setq rtn (vldos-formatpath rtn))
  2700. )
  2701. )
  2702. )
  2703. rtn
  2704. )
  2705. ;;84.10 [功能] 移动文件或目录
  2706. ;;用法: (vldos-move SourceFile/Directory[STRING] TargetFile/Directory[STRING] )
  2707. ;; 参数1: 源文件或目录.
  2708. ;; 参数2: 目标目录. 如果包含 "*\\" or "*/", 此函数将在此路径下创建相同的子目录.
  2709. ;;返回值: 移动后的文件或目录字符串 or NIL
  2710. (Defun vldos-move (from to / sys folder)
  2711. (if (setq sys (vlax-get-or-create-object "Shell.Application"))
  2712. (progn
  2713. (setq from (vldos-formatpath from)
  2714. to (vldos-formatpath to)
  2715. folder (vlax-invoke-method sys 'namespace to)
  2716. )
  2717. (if folder
  2718. (progn
  2719. (princ
  2720. (strcat "\n Moving file(s) from \042"
  2721. FROM "\042 to \042"
  2722. to "\042..."
  2723. )
  2724. )
  2725. (vlax-invoke-method folder 'movehere from (+ 4 16))
  2726. (vlax-release-object folder)
  2727. (princ "...Done!")
  2728. )
  2729. )
  2730. (vlax-release-object sys)
  2731. )
  2732. )
  2733. (princ)
  2734. )
  2735. ;;84.11 [功能] 重命名文件或目录
  2736. ;;用法: (vldos-rename SourceFile/Directory[STRING] NewName[STRING] )
  2737. ;; 参数1: 源文件或目录.
  2738. ;; 参数2: 新名称.
  2739. ;;返回值: 重命名后的文件或目录 or NIL
  2740. (Defun vldos-rename (From to / Fil folder new parent rtn)
  2741. (cond
  2742. ((vl-file-directory-p From)
  2743. (setq parent (vl-filename-directory From)
  2744. new (strcat parent to)
  2745. )
  2746. (if (and (setq
  2747. Fil
  2748. (vlax-get-or-create-object "Scripting.FileSystemObject")
  2749. )
  2750. (> (strlen From) 3)
  2751. ;; Can not rename root folder
  2752. (null (vl-file-directory-p new))
  2753. ;; not an existing folder name
  2754. )
  2755. (progn
  2756. (setq folder (vlax-invoke-method Fil 'GetFolder From))
  2757. (vlax-put-property folder "Name" To)
  2758. (vlax-release-object folder)
  2759. (vlax-release-object Fil)
  2760. )
  2761. (setq parent nil)
  2762. )
  2763. )
  2764. ((findfile From)
  2765. (setq parent (vl-filename-directory from))
  2766. (vl-file-rename From to)
  2767. )
  2768. )
  2769. (if (and parent
  2770. (vl-file-directory-p
  2771. (setq to (strcat parent to))
  2772. )
  2773. )
  2774. (setq rtn (vldos-formatpath to))
  2775. )
  2776. rtn
  2777. )
  2778. ;;84.12 [功能] 返回磁盘的类型
  2779. ;;用法: (vldos-drivetype DriveLetter[STRING] )
  2780. ;; 参数1: 盘符 例如: "C:"
  2781. ;;返回值: 磁盘的类型 or NIL
  2782. (Defun vldos-drivetype (drv / Fil drives drive typ rtn)
  2783. (setq rtn "INVALID")
  2784. (if
  2785. (and (setq
  2786. Fil (vlax-get-or-create-object "Scripting.FileSystemObject")
  2787. )
  2788. (equal :vlax-true (vlax-invoke-method Fil 'DriveExists drv))
  2789. )
  2790. (progn
  2791. (setq drives (vlax-get-property Fil 'Drives)
  2792. drive (vlax-get-property drives 'Item drv)
  2793. typ (vlax-get-property drive 'DriveType)
  2794. rtn (nth typ
  2795. (list "UNKNOWN" "REMOVABLE"
  2796. "FIXED" "REMOTE"
  2797. "CDROM" "RAMDISK"
  2798. )
  2799. )
  2800. )
  2801. (vlax-release-object drive)
  2802. (vlax-release-object drives)
  2803. (vlax-release-object Fil)
  2804. )
  2805. )
  2806. rtn
  2807. )
  2808. ;;84.13 [功能] 返回当前的磁盘表
  2809. ;;用法: (vldos-alldrive)
  2810. ;;返回值: 返回当前的磁盘表 or NIL
  2811. (Defun vldos-alldrive (/ fil drive drives lst)
  2812. (if (setq Fil (vlax-get-or-create-object "Scripting.FileSystemObject"))
  2813. (progn
  2814. (vlax-for drive (setq drives (vlax-get-property Fil 'Drives))
  2815. (setq lst (cons (vlax-get-property drive 'DriveLetter) lst))
  2816. )
  2817. (vlax-release-object drives)
  2818. (vlax-release-object Fil)
  2819. (setq lst (reverse lst))
  2820. )
  2821. )
  2822. lst
  2823. )
  2824. ;;[功能] 返回磁盘的特定信息
  2825. ;;用法: (vldos-driveinfo DriveLetter[STRING] key[STRING] )
  2826. ;; 参数1: 盘符 例如: "C:"
  2827. ;; 参数2: 所需磁盘信息的字符串
  2828. ;;返回值: 磁盘的特定信息 or NIL
  2829. ;|
  2830. "TOTALSIZE" 磁盘总空间
  2831. "FREESPACE" 磁盘可用空间
  2832. "DRIVETYPE" 磁盘类型
  2833. "FILESYSTEM" 文件系统类型
  2834. "SERIALNUMBER" 磁盘序列号
  2835. "SHARENAME" 共享名称
  2836. "VOLUMENAME" 磁盘卷标
  2837. |;
  2838. (Defun vldos-driveinfo (Drv Key / pos rtn)
  2839. (if (/= (type key) 'STR)
  2840. (setq rtn (vldos-alldriveinfo drv))
  2841. (if (setq pos (vl-position
  2842. (setq key (strcase key))
  2843. (list "TOTALSIZE" "FREESPACE"
  2844. "DRIVETYPE" "FILESYSTEM"
  2845. "SERIALNUMBER" "SHARENAME"
  2846. "VOLUMENAME"
  2847. )
  2848. )
  2849. )
  2850. (setq rtn (nth pos (vldos-alldriveinfo drv)))
  2851. )
  2852. )
  2853. rtn
  2854. )
  2855. ;;84.14 [功能] 返回磁盘的所有信息
  2856. ;;用法: (vldos-alldriveinfo DriveLetter[STRING] )
  2857. ;; 参数1: 盘符 例如: "C:"
  2858. ;;返回值 磁盘的所有信息 or NIL
  2859. (Defun vldos-alldriveinfo (Drv / DrvObj FilSys RetVal)
  2860. (if (setq
  2861. FilSys (vlax-get-or-create-object "Scripting.FileSystemObject")
  2862. )
  2863. (progn
  2864. (setq RetVal
  2865. (cond
  2866. ((= (vlax-invoke FilSys "DriveExists" Drv) 0) 0)
  2867. ((setq DrvObj (vlax-invoke FilSys "GetDrive" Drv))
  2868. (cond
  2869. ((= (vlax-get DrvObj "IsReady") 0) -1)
  2870. ((list
  2871. (/ (vlax-get-property DrvObj "TotalSize") 1000.0)
  2872. (/ (vlax-get-property DrvObj "FreeSpace") 1000.0)
  2873. (vlax-get-property DrvObj "DriveType")
  2874. (vlax-get-property DrvObj "FileSystem")
  2875. (vlax-get-property DrvObj "SerialNumber")
  2876. (vlax-get-property DrvObj "ShareName")
  2877. (vlax-get-property DrvObj "VolumeName")
  2878. )
  2879. )
  2880. )
  2881. )
  2882. )
  2883. )
  2884. (if (EQUAL (TYPE DrvObj) 'vla-object)
  2885. (vlax-release-object DrvObj)
  2886. )
  2887. (vlax-release-object FilSys)
  2888. )
  2889. )
  2890. RetVal
  2891. )
  2892. ;;84.15 [功能] 返回文件的特定信息
  2893. ;;用法: (vldos-fileinfo Filename[STRING] key[STRING] )
  2894. ;; 参数1: 文件全路径名
  2895. ;; 参数2: 所需文件信息的字符串
  2896. ;;返回值: 文件的特定信息 or NIL
  2897. ;|
  2898. "DATECREATED" 创建日期
  2899. "DATELASTMODIFIED" 修改日期
  2900. "DATELASTACCESSED" 最后一次访问时间
  2901. "TYPE" 文件类型
  2902. "SIZE" 文件大小
  2903. "ATTRIBUTES" 文件属性
  2904. |;
  2905. (Defun vldos-fileinfo (Drv Key / pos rtn)
  2906. (if (/= (type key) 'STR)
  2907. (setq rtn (vldos-allfileinfo drv))
  2908. (if (setq pos (vl-position
  2909. (setq key (strcase key))
  2910. (list "DATECREATED" "DATELASTMODIFIED"
  2911. "DATELASTACCESSED" "TYPE"
  2912. "SIZE" "ATTRIBUTES"
  2913. )
  2914. )
  2915. )
  2916. (setq rtn (nth pos (vldos-allfileinfo drv)))
  2917. )
  2918. )
  2919. rtn
  2920. )
  2921. ;;84.16 [功能] 返回磁盤的所有信息
  2922. ;;用法: (vldos-alldriveinfo DriveLetter[STRING] )
  2923. ;; 參數1: 盤符 例如: "C:"
  2924. ;;返回值: 磁盤的所有信息 or NIL
  2925. (defun VLDOS-ALLDRIVEINFO (DRV / DRVOBJ FILSYS RETVAL)
  2926. (if (setq
  2927. FILSYS (vlax-get-or-create-object "Scripting.FileSystemObject")
  2928. )
  2929. (progn
  2930. (setq RETVAL
  2931. (cond
  2932. ((= (vlax-invoke FILSYS "DriveExists" DRV) 0) 0)
  2933. ((setq DRVOBJ (vlax-invoke FILSYS "GetDrive" DRV))
  2934. (cond
  2935. ((= (vlax-get DRVOBJ "IsReady") 0) -1)
  2936. ((list
  2937. (/ (vlax-get DRVOBJ "TotalSize") 1000.0)
  2938. (/ (vlax-get DRVOBJ "FreeSpace") 1000.0)
  2939. (vlax-get DRVOBJ "DriveType")
  2940. (vlax-get DRVOBJ "FileSystem")
  2941. (vlax-get DRVOBJ "SerialNumber")
  2942. (vlax-get DRVOBJ "ShareName")
  2943. (vlax-get DRVOBJ "VolumeName")
  2944. )
  2945. )
  2946. )
  2947. )
  2948. )
  2949. )
  2950. (if (equal (type DRVOBJ) 'VLA-OBJECT)
  2951. (vlax-release-object DRVOBJ)
  2952. )
  2953. (vlax-release-object FILSYS)
  2954. )
  2955. )
  2956. RETVAL
  2957. )
  2958. ;;84.17 [功能] 读文本文件到表 (快于 AutoLISP read-line函数)
  2959. ;;用法: (vldos-readfile FilenameToRead[STRING] )
  2960. ;; 参数1: 文本文件全路径名. (包括后缀名)
  2961. ;; 只有文本文件才能返回正确结果.
  2962. ;;返回值: 返回包括文件内容的表 or NIL
  2963. (Defun vldos-readfile
  2964. (Fil / string->list FilObj FilPth FilSys OpnFil All)
  2965. (Defun string->list (String / ID Rtn)
  2966. (if (null (setq ID (vl-string-search "\r\n" String)))
  2967. (setq Rtn (list String))
  2968. (progn
  2969. (while ID
  2970. (setq Rtn (cons (substr String 1 ID) Rtn)
  2971. String (substr String (+ 3 ID))
  2972. ID (vl-string-search "\r\n" String)
  2973. )
  2974. )
  2975. (setq Rtn (reverse (cons String Rtn)))
  2976. )
  2977. )
  2978. Rtn
  2979. )
  2980. (if (AND (setq FilPth (findfile Fil))
  2981. (setq FilSys (vlax-create-object "Scripting.FileSystemObject"))
  2982. )
  2983. (progn
  2984. (setq FilObj (vlax-invoke FilSys "GetFile" FilPth)
  2985. OpnFil (vlax-invoke FilObj "OpenAsTextStream" 1 0)
  2986. All (string->list (vlax-invoke OpnFil "readall"))
  2987. )
  2988. (vlax-invoke OpnFil "Close")
  2989. (vlax-release-object OpnFil)
  2990. (vlax-release-object FilObj)
  2991. (vlax-release-object FilSys)
  2992. )
  2993. )
  2994. All
  2995. )
  2996. ;;84.18 [功能] 将字符串或表写入文件 (快于 AutoLISP write-line函数)
  2997. ;;用法: (vldos-writefile FileNameString[STRING] ContentStringList[LIST] ModeFlag[BOOLEAN] )
  2998. ;; (vldos-writefile FileNameString[STRING] ContentString[STRING] ModeFlag[BOOLEAN] )
  2999. ;; 参数1: 文本文件全路径名. (包括后缀名)
  3000. ;; 参数2: 要写入文件的字符串或表
  3001. ;; 参数3: 最加或覆盖标志. nil 最加, T 覆盖
  3002. ;;返回值: 文本文件全路径名 or NIL
  3003. (Defun vldos-writefile
  3004. (Fil TXT Mode /
  3005. list->string FilObj FilPth
  3006. FilSys OpnFil Line
  3007. )
  3008. (Defun list->string (slist / line rtn)
  3009. (if (= (type slist) 'str)
  3010. (setq rtn slist)
  3011. (progn
  3012. (setq rtn "")
  3013. (foreach line slist
  3014. (if (= rtn "")
  3015. (setq rtn line)
  3016. (setq rtn (strcat rtn "\r\n" line))
  3017. )
  3018. )
  3019. )
  3020. )
  3021. rtn
  3022. )
  3023. (if TXT
  3024. (progn
  3025. (if (and Mode (findfile Fil))
  3026. (vl-file-delete Fil)
  3027. )
  3028. (if (setq FilSys (vlax-create-object "Scripting.FileSystemObject"))
  3029. (progn
  3030. (if (null (setq FilPth (findfile Fil)))
  3031. (setq OpnFil (vlax-invoke-method
  3032. FilSys "CreateTextFile" Fil 0 0)
  3033. )
  3034. (setq FilObj (vlax-invoke FilSys "GetFile" FilPth)
  3035. OpnFil (vlax-invoke FilObj "OpenAsTextStream" 8 0)
  3036. )
  3037. )
  3038. (if OpnFil
  3039. (progn
  3040. ;; VBA WinScript data forReading = 1, forWriting = 2, forAppending = 8;
  3041. ;; TristateUseDefault, TristateTrue, TristateFalse (-2, -1, 0)
  3042. ;;TristateUseDefault (-2) Opens the file using the system default.
  3043. ;;TristateTrue (-1) Open the file as Unicode.
  3044. ;;TristateFalse (0) Open the file as ASCII.
  3045. (vlax-invoke OpnFil "Write" (list->string TXT))
  3046. (vlax-invoke OpnFil "Close")
  3047. (vlax-release-object OpnFil)
  3048. (if (= (type FilObj) 'vla-object)
  3049. (vlax-release-object FilObj)
  3050. )
  3051. (vlax-release-object FilSys)
  3052. )
  3053. )
  3054. )
  3055. )
  3056. (if (setq Filpth (findfile Fil))
  3057. (setq FilPth (vldos-formatpath filpth))
  3058. )
  3059. )
  3060. )
  3061. filpth
  3062. )
  3063. ;;84.19 [功能] 目录浏览对话框
  3064. ;;用法: (vldos-browsedir PromptString[STRING] )
  3065. ;; (vldos-writefile NIL)
  3066. ;; 参数1: 提示字符串, 如果是 nil, 缺省为 "Select Folder"
  3067. ;;返回值: 返回所选目录路径 OR NIL
  3068. (Defun vldos-browsedir (msg / WinShell shFolder path catchit rtn)
  3069. (if (null MSG)
  3070. (setq MSG "Select folder")
  3071. )
  3072. (if (setq winshell (vlax-create-object "Shell.Application"))
  3073. (progn
  3074. (setq shFolder
  3075. (vlax-invoke-method WinShell 'BrowseForFolder 0 msg 1)
  3076. catchit
  3077. (vl-catch-all-apply
  3078. '(lambda ()
  3079. (setq shFolder (vlax-get-property shFolder 'self))
  3080. (setq path (vlax-get-property shFolder 'path))
  3081. )
  3082. )
  3083. )
  3084. (vlax-release-object shFolder)
  3085. (vlax-release-object winshell)
  3086. (if (vl-catch-all-error-p catchit)
  3087. (setq rtn nil)
  3088. (setq rtn (vldos-formatpath path))
  3089. )
  3090. )
  3091. )
  3092. rtn
  3093. )
  3094. ;;84.20 [功能] 显示 windows 的确认对话框包括图标和可选按钮
  3095. ;;用法: (vldos-msgbox TitleString[STRING] IconType[STRING/REAL] MessageString[STRING] ButtonType[INT] )
  3096. ;; 参数1: 标题字符串, 如果是 nil, 缺省为 "Message"
  3097. ;; 参数2: 图标类型字符串或整数值. 如果是字符串, 只有第一个字符串有效.
  3098. ;; 参数3: 消息字符串, 如果是 nil, 缺省为 "Message HERE"
  3099. ;; 参数4: 按钮类型整数值.
  3100. ;;返回值: 所选按钮的值 OR NIL
  3101. ;|;;按钮
  3102. ;;0 OK
  3103. ;;1 OK and Cancel
  3104. ;;2 Abort, Retry, and Ignore
  3105. ;;3 Yes, No, Cancel
  3106. ;;4 Yes and No
  3107. ;;5 Retry and Cancel
  3108. ;;图标类型
  3109. ;;16 [X] Stop Mark icon
  3110. ;;32 [?] Question Mark icon
  3111. ;;48 [!] Exclamation Mark icon
  3112. ;;64 [i] Information Mark icon
  3113. ;; 返回值所代表的按钮
  3114. ;;1 OK button
  3115. ;;2 Cancel button
  3116. ;;3 Abort button
  3117. ;;4 Retry button
  3118. ;;5 Ignore button
  3119. ;;6 Yes button
  3120. ;;7 No button
  3121. |;
  3122. (Defun vldos-msgbox (TITLE ICON MSG BTNS / IDT sys BTN)
  3123. (if (setq sys (vlax-get-or-create-object "WScript.Shell"))
  3124. (progn
  3125. (if (not (equal (type TITLE) 'STR))
  3126. (setq TITLE "Message")
  3127. )
  3128. (cond ((null ICON) (setq ICON 64))
  3129. ((= (type ICON) 'STR)
  3130. (setq ICON (substr (strcase ICON) 1 1)
  3131. IDT (list (cons "X" 16)
  3132. (cons "?" 32)
  3133. (cons "!" 48)
  3134. (cons "i" 64)
  3135. )
  3136. ICON (cdr (assoc ICON IDT))
  3137. )
  3138. (if (null ICON)
  3139. (setq ICON 64)
  3140. )
  3141. )
  3142. ((= (type ICON) 'INT)
  3143. (if (null (member ICON (list 16 32 48 64)))
  3144. (setq ICON 64)
  3145. )
  3146. (t (setq ICON 64))
  3147. )
  3148. )
  3149. (if (not (equal (type MSG) 'STR))
  3150. (setq MSG "Message HERE")
  3151. )
  3152. (cond ((null BTNS) (setq BTNS 0))
  3153. ((= (type BTNS) 'INT)
  3154. (if (or (< BTNS 0) (> BTNS 5))
  3155. (setq BTNS 0)
  3156. )
  3157. )
  3158. (t (setq BTNS 0))
  3159. )
  3160. (setq
  3161. BTN (vlax-invoke-method sys 'popup MSG 0 TITLE (+ ICON BTNS))
  3162. )
  3163. (vlax-release-object sys)
  3164. )
  3165. )
  3166. BTN
  3167. )
  3168. ;;84.21 [功能] 当前目录文件搜索. 类似于 DIR /S 命令.
  3169. ;;用法: (vldos-findfile FilenameFullPathString[STRING] )
  3170. ;; (vldos-writefile NIL)
  3171. ;; 参数1: 文件名. 可以包括扩展符 ("*" and "?").
  3172. ;; 如果文件名描述符为 nil ,返回所有的文件包括子目录。
  3173. ;;返回值: 包括所有符合条件的文件名 OR NIL
  3174. (Defun vldos-findfile (Filename / string->list
  3175. getallfiles allfiles path
  3176. )
  3177. (Defun string->list (String / ID Rtn)
  3178. (if (null (setq ID (vl-string-search ";" String)))
  3179. (setq Rtn (list String))
  3180. (progn
  3181. (while ID
  3182. (setq Rtn (cons (substr String 1 ID) Rtn)
  3183. String (substr String (+ 2 ID))
  3184. ID (vl-string-search ";" String)
  3185. )
  3186. )
  3187. (setq Rtn (reverse (cons String Rtn)))
  3188. )
  3189. )
  3190. Rtn
  3191. )
  3192. (Defun getallfiles (loc ext / path files rtn)
  3193. (cond
  3194. ((= loc "")
  3195. (foreach path (string->list (getvar "acadprefix"))
  3196. (setq rtn (append rtn (getallfiles path ext)))
  3197. )
  3198. )
  3199. ((vl-file-directory-p loc)
  3200. (if (null (wcmatch loc "*\\"))
  3201. (setq loc (strcat loc "\\"))
  3202. )
  3203. (foreach files (vl-directory-files loc ext)
  3204. (setq rtn (cons (vldos-formatpath (strcat loc files)) rtn))
  3205. )
  3206. (foreach path (vl-directory-files loc nil -1)
  3207. (if (and (/= path ".")
  3208. (/= path "..")
  3209. )
  3210. (setq rtn (append rtn (getallfiles (strcat loc path) ext)))
  3211. )
  3212. )
  3213. )
  3214. )
  3215. rtn
  3216. )
  3217. (setq path (vldos-formatpath (vl-filename-directory Filename))
  3218. Filename (substr Filename (1+ (strlen path)))
  3219. allfiles (acad_strlsort (getallfiles path filename))
  3220. )
  3221. allfiles
  3222. )
  3223. ;;84.22 [功能] 合并两个文本文件
  3224. ;;用法: (vldos-merge MergeBaseFilenameString[STRING] MergeFilenameString[STRING] EraseMergefileFlag[BOOLEAN] )
  3225. ;; 参数1: 基文件名
  3226. ;; 参数2: 将被合并的文件名
  3227. ;; 参数3: 是否删除被合并文件的标志.
  3228. ;;返回值: 合并后的文件名 OR NIL
  3229. (Defun vldos-merge (file1 File2 Erase / rtn)
  3230. (if (and (setq file1 (findfile file1))
  3231. (setq file2 (findfile file2))
  3232. )
  3233. (progn
  3234. (vldos-writefile file1 (vldos-readfile file2) nil)
  3235. (if Erase
  3236. (vl-file-delete File2)
  3237. )
  3238. (setq rtn (findfile file1))
  3239. )
  3240. )
  3241. rtn
  3242. )
  3243. ;;85.1 [功能] 字符串分割为表 By 无痕
  3244. ;;(str2lst1 str) 将输入的数据转换为字符串列表.-----------------------------梁雄啸.2004.3
  3245. ;;测试: (str2lst1 "Hello 2World 12 5456.1568") = ("Hello" "2World" "12" "5456.1568")
  3246. (defun str2lst1 (str / i)
  3247. (while (setq i (vl-string-search
  3248. " "
  3249. str
  3250. (if i
  3251. (+ 2 i)
  3252. 0
  3253. )
  3254. )
  3255. )
  3256. (setq str (vl-string-subst "\"\"" " " str i))
  3257. )
  3258. (read (strcat "(\"" str "\")"))
  3259. )
  3260. ;;85.2 [功能] 字符串分割为表 -------梁雄啸.2004.3
  3261. ;;测试: (str2lst2 "Hello 2World 12 5456.1568") -> ("Hello" "2World" "12" "5456.1568")
  3262. (defun str2lst2 (str /)
  3263. (read
  3264. (vl-list->string
  3265. (apply
  3266. 'append
  3267. (mapcar '(lambda (x)
  3268. (if (= 32 x)
  3269. (list 34 32 34)
  3270. (list x)
  3271. )
  3272. )
  3273. (append (list 40 34) (vl-string->list str) (list 34 41))
  3274. )
  3275. )
  3276. )
  3277. )
  3278. )
  3279. ;;85.3 [功能] 字符串分割为表 (纯autolspl的写法)-----梁雄啸.2004.3
  3280. ;;测试: (str2lst3 "Hello 2World 12 5456.1568") = ("Hello" "2World" "12" "5456.1568")
  3281. (defun str2lst3 (str / i strlst str1)
  3282. (setq i 0
  3283. str1 ""
  3284. )
  3285. (while (/= "" (setq s (substr str (setq i (1+ i)) 1)))
  3286. (cond ((/= " " s) (setq str1 (strcat str1 s)))
  3287. (T
  3288. (setq strlst (append strlst (list str1))
  3289. str1 ""
  3290. )
  3291. )
  3292. )
  3293. )
  3294. (if (/= str1 "")
  3295. (append strlst (list str1))
  3296. strlst
  3297. )
  3298. )
  3299. ;;85.4 [功能] 字符串分割为表
  3300. (defun str2lst (str / i str1)
  3301. (setq i 0
  3302. str1 ""
  3303. )
  3304. (while (/= "" (setq s (substr str (setq i (1+ i)) 1)))
  3305. (setq str1 (strcat str1
  3306. (if (= " " s)
  3307. "\" \""
  3308. s
  3309. )
  3310. )
  3311. )
  3312. )
  3313. (read (strcat "(\"" str1 "\")"))
  3314. )
  3315. ;;85.5 [功能] 字符串分割成表
  3316. ;; 示例: (MJ:Parse (getenv "ACAD") ";") ;;
  3317. ;; Notes: 1. AutoLISP does not correctly interpret any character code outside the ;;
  3318. ;; range of 1 to 255, so you cannot parse a null delimited string. ;;
  3319. (defun MJ:Parse (str delim / lst pos token)
  3320. (setq pos (vl-string-search delim str))
  3321. (while pos
  3322. (setq lst (cons
  3323. (if (= (setq token (substr str 1 pos)) delim)
  3324. nil
  3325. token
  3326. )
  3327. lst
  3328. )
  3329. str (substr str (+ pos 2))
  3330. pos (vl-string-search delim str)
  3331. )
  3332. )
  3333. (if (> (strlen str) 0)
  3334. (setq lst (cons str lst))
  3335. )
  3336. (reverse lst)
  3337. )
  3338. ;;85.6 [功能] 字符串函数 by qjchen@gmail.com
  3339. ;;str是准备被处理的字符串,delim是一个字符串集合,其中的每一个字符都会被当作是分割符号
  3340. ;;如 (MJ:delim "25 35 45 ; 55, 66 " " ;")=> ("25" "35" "45" "55," "66")
  3341. ;;(MJ:delim "aa 10 b10x20.2" "")返回("aa 10 b10x20.2")
  3342. (defun MJ:delim (str delim / l1 l2)
  3343. (setq str (vl-string->list str) delim (vl-string->list delim))
  3344. (while str
  3345. (if (not (member (car str) delim))
  3346. (setq l1 (cons (car str) l1))
  3347. (if l1 (setq l2 (cons (vl-list->string (reverse l1)) l2) l1 nil))
  3348. )
  3349. (setq str (cdr str))
  3350. )
  3351. (if l1 (setq l2 (cons (vl-list->string (reverse l1)) l2)))
  3352. (reverse l2)
  3353. )
  3354. ;;85.7 [功能] 用分隔符解释字符串成表 ;by fsxm
  3355. ;;空格" ",不能用"" ,一个空格就转成一个字符
  3356. ;;(fsxm-Split "aa 10 b10x20.2" " ")返回("aa" "10" "b10x20.2")
  3357. ;;(fsxm-Split "aa 10 b10x20.2" "")死循环
  3358. (defun fsxm-Split (string strkey / po strlst xlen)
  3359. (setq xlen (1+ (strlen strkey)))
  3360. (while (setq po (vl-string-search strkey string))
  3361. (setq strlst (cons (substr string 1 po) strlst))
  3362. (setq string (substr string (+ po xlen)))
  3363. )
  3364. (reverse (cons string strlst))
  3365. )
  3366. ;;85.8 [功能] 字符串分割(这是highflybird问答我的求助)
  3367. ;;(Split "aa 10 b10x20.2" "")返回("AA" "10" "B10X20")
  3368. ;;(Split "aa 10 b10x20.2" ".")返回("AA" "10" "B10X20" "2")
  3369. (defun Split (String Delimiter / str lst)
  3370. (setq str (VL-STRING-TRANSLATE Delimiter " " String)) ;首先替换
  3371. (setq str (strcat "(" str ")")) ;然后加括号
  3372. (setq lst (read str)) ;读
  3373. (setq lst (mapcar 'VL-PRINC-TO-STRING lst)) ;转化
  3374. )
  3375. ;;86.1 [功能] Exports the specified project to disk ;;
  3376. ;; Arguments: The name of a project and the full path to a file ;;
  3377. ;; 示例: (MJ:ExportProject "Johnson" "c:\\temp\\project.txt") ;;
  3378. (defun MJ:ExportProject (pName fName / fh prj)
  3379. (vl-load-com)
  3380. (setq fh (open fName "w"))
  3381. (if (setq prj (vl-registry-read
  3382. (strcat "HKEY_CURRENT_USER\\"
  3383. (vlax-product-key)
  3384. "\\Profiles\\"
  3385. (getvar "CPROFILE")
  3386. "\\Project Settings\\"
  3387. pName
  3388. )
  3389. "RefSearchPath"
  3390. )
  3391. )
  3392. (progn
  3393. (write-line (strcat "[" pName "] ") fh)
  3394. (foreach folder
  3395. (MJ:Parse prj ";")
  3396. (write-line folder fh)
  3397. )
  3398. )
  3399. (princ "\nThe specified windows registry key is not exists."
  3400. )
  3401. )
  3402. (close fh)
  3403. (princ)
  3404. )
  3405. ;;86.2 [功能] Imports a project exported by MJ:ExportProject ;;
  3406. ;; Arguments: The full path to a file containing an exported project ;;
  3407. ;; 示例: (MJ:ImportProject "c:\\temp\\project.txt") ;;
  3408. (defun MJ:ImportProject (fName / pName fh l lst)
  3409. (vl-load-com)
  3410. (if (setq fh (open fName "r"))
  3411. (progn
  3412. (setq pName (read-line fh)
  3413. pName (substr pName 2 (- (strlen pName) 2))
  3414. lst ""
  3415. )
  3416. (while (setq l (read-line fh))
  3417. (setq lst (strcat lst l ";"))
  3418. )
  3419. (vl-registry-write
  3420. (strcat "HKEY_CURRENT_USER\\"
  3421. (vlax-product-key)
  3422. "\\Profiles\\"
  3423. (getvar "CPROFILE")
  3424. "\\Project Settings\\"
  3425. pName
  3426. )
  3427. "RefSearchPath"
  3428. (substr lst 1 (1- (strlen lst)))
  3429. )
  3430. (close fh)
  3431. )
  3432. )
  3433. (princ)
  3434. )
  3435. ;;87.1 [功能] 包围对象最小最大点列表
  3436. ;; 示例: (MJ:GetBoundingBox (car (entsel)))返回 ((左下角点)(右上角点))
  3437. (defun MJ:GetBoundingBox (ent / ll ur)
  3438. (vla-getboundingbox (vlax-ename->vla-object ent) 'll 'ur)
  3439. (mapcar 'vlax-safearray->list (list ll ur))
  3440. )
  3441. ;;87.2 [功能] 选择集的实体外矩形框 by gxl
  3442. (defun MJ:GetssBox (ss / i l1 l2 ll ur)
  3443. (repeat (setq i (sslength ss))
  3444. (vla-getboundingbox
  3445. (vlax-ename->vla-object (ssname ss (setq i (1- i))))
  3446. 'll
  3447. 'ur
  3448. )
  3449. (setq l1 (cons (vlax-safearray->list ll) l1)
  3450. l2 (cons (vlax-safearray->list ur) l2)
  3451. )
  3452. )
  3453. (mapcar '(lambda (a b) (apply 'mapcar (cons a b)))
  3454. '(min max)
  3455. (list l1 l2)
  3456. )
  3457. )
  3458. ;;88.1 [功能] 返回曲线长度(不能返回块中曲线长度)
  3459. ;; Arguments: The entity name of a line, arc, circle, polyline (heavy or lightweight). ;;
  3460. ;; 示例: (MJ:GetCurveLength (car (entsel))) ;;
  3461. (defun MJ:GetCurveLength (curve /)
  3462. (vl-load-com)
  3463. (setq curve (vlax-ename->vla-object curve))
  3464. (vlax-curve-getDistAtParam
  3465. curve
  3466. (vlax-curve-getEndParam curve)
  3467. )
  3468. )
  3469. ;;88.2 [功能] 返回曲线长度(包括块内曲线)
  3470. (defun CurveLen (/ CURVE-OBJ EN ENT)
  3471. (if (setq ent (entsel "\n 点击曲线"))
  3472. (progn
  3473. (setq en (entget (car ent)))
  3474. (if (= (cdr (assoc 0 en)) "INSERT")
  3475. (setq ent (nentselp "" (cadr ent)))
  3476. )
  3477. (setq curve-obj (vlax-ename->vla-object (car ent)))
  3478. (vlax-curve-getDistAtParam
  3479. curve-obj
  3480. (vlax-curve-getEndParam curve-obj)
  3481. )
  3482. )
  3483. )
  3484. )
  3485. ;;89 [功能] Returns the size of the specified file in bytes
  3486. ;; 示例: (MJ:GetFileSize "c:\\autoexec.bat")
  3487. ;; Notes: 1. There are reports of VL-FILE-SIZE and ACET-FILE-SIZE malfunction on
  3488. ;; Win2K systems. Use this as a substitute. It requires SCRRUN.DLL.
  3489. ;; Visit the Microsoft scripting web site if you do not have it.
  3490. (defun MJ:GetFileSize (fileName / fso file size)
  3491. (vl-load-com)
  3492. (if (findfile fileName)
  3493. (progn
  3494. (setq file (vlax-invoke-method *FSO* 'GetFile fileName)
  3495. size (vlax-variant-value (vlax-get-property file 'Size))
  3496. )
  3497. (vlax-release-object file)
  3498. )
  3499. )
  3500. size
  3501. )
  3502. ;;90.1 [功能] 返回文字样式字体高度
  3503. ;; 示例: (MJ:GetLastHeight "standard")
  3504. (defun MJ:GetLastHeight (style)
  3505. (vl-load-com)
  3506. (vla-get-LastHeight
  3507. (vla-Item
  3508. (vla-get-TextStyles
  3509. *DOC*
  3510. )
  3511. style
  3512. )
  3513. )
  3514. )
  3515. ;;90.2 [功能] 设置文字样式字体高度
  3516. ;; 示例: (MJ:SetLastHeight "standard" 2.5)
  3517. (defun MJ:SetLastHeight (style height)
  3518. (vl-load-com)
  3519. (vla-put-LastHeight
  3520. (vla-Item
  3521. (vla-get-TextStyles
  3522. *DOC*
  3523. )
  3524. style
  3525. )
  3526. height
  3527. )
  3528. )
  3529. ;;91 [功能] Returns the LISP value of an ActiveX variant. ;;
  3530. ;; Arguments: An ActiveX variant or safearray. ;;
  3531. ;; 示例: (MJ:lisp-value MJ:Variant) ;;
  3532. ;; Notes: This function will recursively dig into a safearray and convert all ;;
  3533. ;; values, including nested safearray's, into a LISP value. ;;
  3534. (defun MJ:lisp-value (v)
  3535. (cond
  3536. ((= (type v) 'variant)
  3537. (MJ:lisp-value (variant-value v))
  3538. )
  3539. ((= (type v) 'safearray)
  3540. (mapcar 'MJ:lisp-value (safearray-value v))
  3541. )
  3542. (T v)
  3543. )
  3544. )
  3545. ;;92.1 [功能] Attach Extended Entity Data to an AutoCAD object. ;;
  3546. ;; Arguments: An ActiveX object and an Extended Entity Data list in the same format as ;;
  3547. ;; returned by GetXData. ;;
  3548. ;; 示例: (MJ:PutXData MJ:VlaObj '((1001 . "ACADX") (1000 . "MJ:StringData"))) ;;
  3549. ;; Notes: The Extended Entity Data application names as noted in the 1001 group ;;
  3550. ;; code must be registered with the AutoLISP function REGAPP prior to ;;
  3551. ;; attaching data to an object. See the AutoCAD help files for valid Extended;;
  3552. ;; Entity Data codes and values. ;;
  3553. (defun MJ:PutXData (vlaObj XData)
  3554. (setq XData
  3555. (MJ:BuildFilter
  3556. (mapcar
  3557. '(lambda (item / key)
  3558. (setq key (car item))
  3559. (if (<= 1010 key 1033)
  3560. (cons key
  3561. (vlax-variant-value
  3562. (vlax-3d-point
  3563. (cdr item)
  3564. )
  3565. )
  3566. )
  3567. item
  3568. )
  3569. )
  3570. XData
  3571. )
  3572. )
  3573. )
  3574. (vla-setXData vlaObj (car XData) (cadr XData))
  3575. )
  3576. ;;92.2 [功能] Get Extended Entity Data attached to an AutoCAD object.
  3577. ;; Arguments: An ActiveX object and an application name that has been registed with ;;
  3578. ;; the AutoLISP function REGAPP. ;;
  3579. ;; 示例: (MJ:GetXData MJ:VlaObj "ACADX") ;;
  3580. ;; Notes: Returns a list of Extended Entity Data attached to the object. ;;
  3581. (defun MJ:GetXData (vlaObj AppID / xType XData)
  3582. (vla-getxdata vlaObj AppID 'xType 'xData)
  3583. (mapcar '(lambda (key val) (cons key (MJ:lisp-value val)))
  3584. (vlax-safearray->list xType)
  3585. (vlax-safearray->list xData)
  3586. )
  3587. )
  3588. ;;93.1 [功能] 面积标注 ;;
  3589. ;; Arguments: The entity name of any object that supports the Area property ;;
  3590. ;; (Arc, Circle, Ellipse, LWPolyline, Polyline, Region or Spline) ;;
  3591. ;; 示例: (MJ:LabelArea (car (entsel))) ;;
  3592. ;; Notes: 1. The first time an entity is labeled, the text will appear at the ;;
  3593. ;; entity's start point or center point ;;
  3594. ;; 2. Call MJ:LabelArea again to update a label. The label will update ;;
  3595. ;; regardless of its current position ;;
  3596. ;; 3. The are is formatted in the current units ;;
  3597. (defun MJ:LabelArea (ent / elist xdata text start area)
  3598. (regapp "LABELAREA")
  3599. (setq elist (entget ent '("LABELAREA"))
  3600. xdata (assoc -3 elist)
  3601. text (if xdata
  3602. (entget (handent (cdr (cadadr xdata))))
  3603. )
  3604. start (if (not text)
  3605. (cdr (assoc 10 elist))
  3606. )
  3607. area (vla-get-area (setq ent (*En2Obj* ent)))
  3608. )
  3609. (if (not text)
  3610. (progn
  3611. (setq
  3612. text (vla-addtext
  3613. (vla-get-block
  3614. (vla-item
  3615. *LOUTS*
  3616. (cdr (assoc 410 elist))
  3617. )
  3618. )
  3619. (rtos area)
  3620. (vlax-3d-point start)
  3621. 0.25
  3622. )
  3623. )
  3624. )
  3625. (vla-put-textstring
  3626. (setq text (*En2Obj* (cdr (assoc -1 text))))
  3627. (rtos area)
  3628. )
  3629. )
  3630. (vla-setxdata
  3631. ent
  3632. (vlax-make-variant
  3633. (vlax-safearray-fill
  3634. (vlax-make-safearray vlax-vbInteger '(0 . 1))
  3635. '(1001 1005)
  3636. )
  3637. )
  3638. (vlax-make-variant
  3639. (vlax-safearray-fill
  3640. (vlax-make-safearray vlax-vbVariant '(0 . 1))
  3641. (list "LABELAREA" (vla-get-handle text))
  3642. )
  3643. )
  3644. )
  3645. (princ)
  3646. )
  3647. ;;93.2 [功能] 面积求和
  3648. ;;highflybird写的那个程序,长度、面积、惯性矩...什么都能
  3649. (defun ToTAreah (/ EN N SS TOT_AREA)
  3650. (if (setq ss (ssget '((-4 . "<OR")
  3651. (0 . "POLYLINE")
  3652. (0 . "LWPOLYLINE")
  3653. (0 . "CIRCLE")
  3654. (0 . "ELLIPSE")
  3655. (0 . "SPLINE")
  3656. (0 . "REGION")
  3657. (-4 . "OR>")
  3658. )
  3659. )
  3660. )
  3661. (progn
  3662. (setq n -1)
  3663. (setq tot_area 0)
  3664. (repeat (sslength ss)
  3665. (setq en (ssname ss (setq n (1+ n))))
  3666. (command "._area" "_O" en)
  3667. (setq tot_area (+ tot_area (getvar "area")))
  3668. )
  3669. )
  3670. )
  3671. tot_area
  3672. )
  3673. ;;94 [功能] 重命名布局
  3674. ;; 示例: (MJ:RenameLayout "Layout1" "MJ:Layout")
  3675. (defun MJ:RenameLayout (oldName newName)
  3676. (vla-put-name (vla-item *LOUTS* oldName) newName)
  3677. )
  3678. ;;95 [功能] 返回打开文件列表
  3679. ;; 示例: (MJ:ListDocuments)返回 ("Drawing1.dwg" "Drawing2.dwg")
  3680. (defun MJ:ListDocuments (/ fname lst)
  3681. (vl-load-com)
  3682. (vlax-for doc *DOCS*
  3683. (setq
  3684. lst (cons (if (/= (setq fname (vla-get-fullname doc)) "")
  3685. fname
  3686. (vla-get-name doc)
  3687. )
  3688. lst
  3689. )
  3690. )
  3691. )
  3692. (reverse lst)
  3693. )
  3694. ;;96 [功能] 返回布局列表
  3695. ;; 示例:(MJ:ListLayouts)返回 ("Model" "MJ:Layout" "Layout2")
  3696. (defun MJ:ListLayouts (/ layouts c lst lay)
  3697. (vl-load-com)
  3698. (setq layouts (vla-get-layouts
  3699. *DOC*
  3700. )
  3701. c -1
  3702. )
  3703. ;;(vlax-for lay layouts (setq lst (cons (vla-get-name lay) lst)))
  3704. (repeat (vla-get-count layouts)
  3705. (setq lst (cons (setq c (1+ c)) lst))
  3706. );(2 1 0)
  3707. (vlax-for lay layouts
  3708. (setq lst
  3709. (subst
  3710. (vla-get-name lay)
  3711. (vla-get-taborder lay)
  3712. lst
  3713. )
  3714. )
  3715. )
  3716. (reverse lst)
  3717. )
  3718. ;;97 [功能] 窗口左下角空间切换是否显示
  3719. (defun MJ:ToggleLayouts (/ prefDisplay)
  3720. (vl-load-com)
  3721. (setq prefDisplay
  3722. (vla-get-Display
  3723. (vla-get-Preferences
  3724. *ACAD*
  3725. )
  3726. )
  3727. )
  3728. (vla-put-DisplayLayoutTabs
  3729. prefDisplay
  3730. (if (= (vla-get-DisplayLayoutTabs prefDisplay) :vlax-true)
  3731. :vlax-false
  3732. :vlax-true
  3733. )
  3734. )
  3735. (princ)
  3736. )
  3737. ;;98.1 [功能] 模型空间背景色在空白之间切换
  3738. (defun MJ:ToggleMSBackground (/ prefDisplay)
  3739. (vl-load-com)
  3740. (setq prefDisplay (vla-get-Display
  3741. (vla-get-Preferences *ACAD*)
  3742. )
  3743. color (vlax-variant-value
  3744. (vlax-variant-change-type
  3745. (vla-get-GraphicsWinModelBackgrndColor prefDisplay)
  3746. vlax-vbLong
  3747. )
  3748. )
  3749. )
  3750. (vla-put-GraphicsWinModelBackgrndColor
  3751. prefDisplay
  3752. (vlax-make-variant
  3753. (if (= color 0)
  3754. 16777215
  3755. 0
  3756. )
  3757. vlax-vbLong
  3758. )
  3759. )
  3760. (princ)
  3761. )
  3762. ;;98.2[功能] 布局空间背景色在空白之间切换
  3763. (defun MJ:TogglePSBackground (/ prefDisplay)
  3764. (vl-load-com)
  3765. (setq prefDisplay (vla-get-Display
  3766. (vla-get-Preferences *ACAD*)
  3767. )
  3768. color (vlax-variant-value
  3769. (vlax-variant-change-type
  3770. (vla-get-GraphicsWinLayoutBackgrndColor prefDisplay)
  3771. vlax-vbLong
  3772. )
  3773. )
  3774. )
  3775. (vla-put-GraphicsWinLayoutBackgrndColor
  3776. prefDisplay
  3777. (vlax-make-variant
  3778. (if (= color 0)
  3779. 16777215
  3780. 0
  3781. )
  3782. vlax-vbLong
  3783. )
  3784. )
  3785. (princ)
  3786. )
  3787. ;;99.1 [功能] 表->二维表
  3788. ;;示例(list->2pair (list (getpoint)(getpoint)(getpoint)(getpoint)))
  3789. ;;示例(list->2pair '(1 2 3 4 5 6)),返回((1 2) (3 4) (5 6))
  3790. (defun list->2pair (old / new)
  3791. (while (setq new (cons (list (car old) (cadr old)) new)
  3792. old (cddr old)
  3793. )
  3794. )
  3795. (reverse new)
  3796. )
  3797. ;;99.2 [功能] 表->三维表
  3798. ;;示例(list->3pair '(1 2 3 4 5 6)),返回((1 2 3) (4 5 6))
  3799. (defun list->3pair (old / new)
  3800. (while (setq new (cons (list (car old) (cadr old) (caddr old)) new)
  3801. old (cdddr old)
  3802. )
  3803. )
  3804. (reverse new)
  3805. )
  3806. ;;99.3 [功能] 获取多段线顶点列表(见46)
  3807. ;;多段线顶点((-1736.57 2913.7) (-1618.83 2795.96) (-1413.66 2795.96))
  3808. ;;vla-Get-Coordinates不能取得高程
  3809. (defun LwpolinePoints (/ temp)
  3810. (setq temp (vla-Get-Coordinates (*En2Obj* (car (entsel)))))
  3811. (list->2pair (vlax-safearray->list (vlax-variant-value temp)))
  3812. )
  3813. ;;99.4 [功能] 两对象交点
  3814. ;; mode:acExtendNone,acExtendThisEntity,acExtendOtherEntity,acExtendBoth
  3815. (defun All-intersectwith (obj1 obj2 mode / INT IPLIST)
  3816. (defun list->3pair (old / new)
  3817. (while (setq new (cons (list (car old) (cadr old) (caddr old)) new)
  3818. old (cdddr old)
  3819. )
  3820. )
  3821. (reverse new)
  3822. )
  3823. (setq int (vla-IntersectWith obj1 obj2 mode))
  3824. (setq iplist (vl-catch-all-apply
  3825. 'vlax-safearray->list
  3826. (list (vlax-variant-value int))
  3827. )
  3828. )
  3829. (if (vl-catch-all-error-p iplist)
  3830. nil
  3831. (list->3pair iplist)
  3832. )
  3833. )
  3834. ;;100.1 [功能] 判断是否val对象?
  3835. (defun Is-Vla-Object (obj) (equal (type obj) 'vla-object))
  3836. ;;100.2 [功能] 判断是否字符串
  3837. (defun Is-String (arg) (equal (type arg) 'str))
  3838. ;;100.3 [功能] 判断是否实数?
  3839. (defun Is-Real (arg) (equal (type arg) 'real))
  3840. ;;100.4 [功能] 判断是否ename对象?
  3841. (defun Is-Ename (arg) (equal (type arg) 'ename))
  3842. ;;100.5 [功能] 判断是否变体?
  3843. (defun Is-Variant (arg) (equal (type arg) 'variant))
  3844. ;;100.6 [功能] 判断 X 是否是选择集且长度不为 0
  3845. (defun MJ:ssP (x)
  3846. (and (= (type X) 'PICKSET) (> (sslength X) 0))
  3847. )
  3848. ;;100.7 [功能] 是否为点对表
  3849. ;;示例(MJ:ConsP lst)
  3850. (defun MJ:ConsP (lst)
  3851. (and (vl-consp lst)
  3852. (not (vl-list-length lst))
  3853. )
  3854. )
  3855. ;;101 [功能] 多段线顶点的连续样式产生线型
  3856. ;;示例 (MJ:ApplyLtypeGen (car (entsel)))
  3857. (defun MJ:ApplyLtypeGen (object / obj)
  3858. (setq object (MJ:MakeObject object)) ;不是Vla对象,则转换成vla对象
  3859. (vla-put-LinetypeGeneration object :vlax-True)
  3860. )
  3861. ;;示例 (MJ:Put-ByLayer (vlax-ename->vla-object (car (entsel))))
  3862. ;;102.1 [功能] 使对象颜色随层
  3863. (defun MJ:Put-ByLayer (obj)
  3864. (if (vlax-write-enabled-p obj)
  3865. (progn
  3866. (vla-put-Color obj 255)
  3867. ;(vla-put-Linetype obj ...);; <-- I need to figure this out!!!
  3868. )
  3869. ); endif
  3870. )
  3871. ;;102.2 [功能] 设置当前颜色
  3872. ;;acColor 颜色值字符串:"1" "2" "3" ... "bylayer"
  3873. (defun MJ:myColor (acColor)
  3874. (vla-setVariable *DOC* "cecolor" acColor)
  3875. )
  3876. ;;103 [功能] 打印配置
  3877. (defun MJ:PlotConfigs (/ ITEMNAME OUT)
  3878. (defun MJ:Name (obj)
  3879. (if (vlax-property-available-p obj 'Name)
  3880. (vlax-get-property obj 'Name)
  3881. "<NONE_NAME>"
  3882. )
  3883. )
  3884. (vlax-for each (vlax-get-property
  3885. *DOC*
  3886. 'PlotConfigurations
  3887. )
  3888. (if (vlax-property-available-p each 'GetPlotDeviceNames)
  3889. (setq out (cons (vlax-get-property each 'GetPlotDeviceNames) out))
  3890. )
  3891. (setq itemname (MJ:Name each)
  3892. out (cons itemname out)
  3893. )
  3894. )
  3895. out
  3896. )
  3897. ;;104 [功能] 打印设备列表
  3898. (defun MJ:GetPlotDevices ()
  3899. (vl-load-com)
  3900. (vlax-safearray->list
  3901. (vlax-variant-value
  3902. (vla-getplotdevicenames
  3903. (vla-item (vla-get-layouts
  3904. *DOC*
  3905. )
  3906. "Model"
  3907. )
  3908. )
  3909. )
  3910. )
  3911. )
  3912. ;;105.1 [功能] 清除所有捕捉,与按F3有不同处(参见77.4)
  3913. (defun MJ:SnapOff ()
  3914. (vla-put-ObjectSnapMode *DOC* :vlax-false)
  3915. )
  3916. ;;105.2 [功能] MJ:SnapOn之后下面函数只启用端点捕捉
  3917. (defun MJ:SnapOn ()
  3918. (vla-put-ObjectSnapMode *DOC* :vlax-true)
  3919. )
  3920. ;;106.1 [功能] 打开一个文件
  3921. ;;示例: (MJ:OpenDwg "D:\\紫金防雨.dwg")(MJ:OpenDwg "D:\\DrawingA.dxf")
  3922. (defun MJ:OpenDwg (fullname)
  3923. (command "vbastmt"
  3924. (strcat "AcadApplication.Documents.Open "
  3925. (chr 34) fullname (chr 34)
  3926. )
  3927. )
  3928. )
  3929. ;;106.2 [功能] 打开一个文件
  3930. ;;示例(MJ:OpenDwg1 "D:\\紫金防雨.dwg")(MJ:OpenDwg1 "D:\\DrawingA.dxf")
  3931. (defun MJ:OpenDwg1 (fullname / *DOC*)
  3932. (setq *DOCS* (vla-get-Documents (vlax-get-acad-object)))
  3933. (vla-open *DOCS* fullname)
  3934. )
  3935. ;;106.3 [功能] 将一文件输入到当前文件中
  3936. ;;示例(MJ:OpenDwg2 "D:\\DrawingA.dxf")
  3937. (defun MJ:OpenDwg2 (fullname / *DOC*)
  3938. (setq *DOC* (vla-get-ActiveDocument (vlax-get-acad-object)))
  3939. (vla-import *DOC* fullname (vlax-3d-point (list 0 0 0)) 1)
  3940. )
  3941. ;;107.1 [功能] 原位复制Vla
  3942. ;;obj 图元对象,或图元名
  3943. (defun myCopy (obj)
  3944. (if (= (type obj) 'ENAME)
  3945. (setq obj (*En2Obj* obj))
  3946. )
  3947. (vla-copy obj)
  3948. )
  3949. ;;107.2 [功能] 原位复制ename
  3950. (entmake (entget ename))
  3951. ;;107.3 [功能] 原位置复制VLA选集
  3952. (vlax-map-collection SS 'vla-copy)
  3953. ;;107.4 [功能] 删除VLA选择集
  3954. (vlax-map-collection SS 'vla-delete)
  3955. ;;107.5 [功能] 块内原地复制 By xshrimp
  3956. (defun MJ:BlockNentselX (/ BLOCKREFOBJ I NENT OBJ OBJENT)
  3957. ;;生成无名块
  3958. (defun make*ublock (obj / blockobj)
  3959. (setq blockObj (vla-add (vla-get-Blocks *DOC*)
  3960. (vlax-3d-point (list 0 0 0))
  3961. "*U"
  3962. )
  3963. )
  3964. (vla-CopyObjects
  3965. *DOC*
  3966. (vlax-safearray-fill
  3967. (vlax-make-safearray vlax-vbObject (cons 0 0))
  3968. (list obj)
  3969. )
  3970. blockObj
  3971. )
  3972. (vla-delete obj)
  3973. (vla-get-name blockObj)
  3974. )
  3975. ;; 主程序
  3976. (if (= (length (setq nent (nentsel))) 4)
  3977. (progn (entmake (entget (car nent)))
  3978. (setq objent (*En2Obj* (entlast))
  3979. i 0
  3980. )
  3981. (foreach n (last nent)
  3982. (setq obj (*En2Obj* n))
  3983. (setq blockRefObj
  3984. (vla-InsertBlock
  3985. *MS*
  3986. (vla-get-InsertionPoint obj)
  3987. (make*ublock objent)
  3988. (vla-get-xScaleFactor obj)
  3989. (vla-get-yScaleFactor obj)
  3990. (vla-get-zScaleFactor obj)
  3991. (vla-get-Rotation obj)
  3992. )
  3993. )
  3994. (setq i (1+ i))
  3995. (if (> i 1)
  3996. (command "_.explode" (entlast))
  3997. )
  3998. (setq objent (*En2Obj* (entlast)))
  3999. )
  4000. (command "_.explode" (entlast))
  4001. (sssetfirst nil (ssget "p"))
  4002. )
  4003. )
  4004. (prin1)
  4005. )
  4006. ;;107.6 [功能] 块内原地复制 by highflybird
  4007. (defun MJ:BlockNentselH (/ *SPACE BLK ENT LX LY LZ MAT NEW OBJ Q REF RET SCLMAT SX SY SZ TRSMAT V VV VX VY VZ)
  4008. ;; 匿名块程序
  4009. (defun make-anonymous-block (obj / BLKOBJ origin bkName *space)
  4010. (setq origin (vlax-3d-point '(0.0 0.0 0.0)))
  4011. (setq blkobj (vla-add (vla-get-blocks *doc*) origin "*U"))
  4012. (setq bkName (vla-get-name blkobj))
  4013. (vlax-invoke *doc* 'copyobjects (list obj) blkobj)
  4014. (if (zerop (vla-get-ActiveSpace *DOC*))
  4015. (setq *space (vla-get-PaperSpace *doc*))
  4016. (setq *space (vla-get-modelspace *doc*))
  4017. )
  4018. (vla-insertblock *space origin bkName 1 1 1 0)
  4019. (vla-put-Explodable blkobj :vlax-true)
  4020. blkobj
  4021. )
  4022. ;; 矩阵转置
  4023. ;; MAT:trp Transpose a matrix -Doug Wilson-
  4024. (defun MAT:trp (m)
  4025. (apply 'mapcar (cons 'list m))
  4026. )
  4027. ;; 向量的矩阵变换(向量乘矩阵)
  4028. ;; Matrix x Vector - Vladimir Nesterovsky
  4029. ;; Args: m - nxn matrix, v - vector in R^n
  4030. (defun MAT:mxv (m v)
  4031. (mapcar (function (lambda (r) (apply '+ (mapcar '* r v))))
  4032. m
  4033. )
  4034. )
  4035. ;; 矩阵相乘
  4036. ;; MAT:mxm Multiply two matrices -Vladimir Nesterovsky-
  4037. (defun MAT:mxm (m q)
  4038. (mapcar (function (lambda (r) (MAT:mxv (MAT:trp q) r))) m)
  4039. )
  4040. ;; 主程序
  4041. (setq ret (nentselp))
  4042. (if (null ret)
  4043. (exit)
  4044. )
  4045. (setq mat (caddr ret)) ;这个是变换矩阵
  4046. (setq vv (reverse (cdr (reverse mat)))) ;去掉第四行(0 0 0 1)
  4047. (setq vX (mapcar 'car vv)) ;X 向量
  4048. (setq vY (mapcar 'cadr vv)) ;Y 向量
  4049. (setq vZ (mapcar 'caddr vv)) ;Z 向量
  4050. (setq lX (distance vX '(0 0 0))) ;X 比例因子
  4051. (setq lY (distance vY '(0 0 0))) ;Y 比例因子
  4052. (setq lZ (distance vZ '(0 0 0))) ;Z 比例因子
  4053. (setq ent (car ret))
  4054. (setq obj (*En2Obj* ent))
  4055. (if (and (equal lX lY 1e-8) (equal lY lZ 1e-8)) ;如果是均匀缩放
  4056. (progn
  4057. (if (zerop (vla-get-ActiveSpace *DOC*))
  4058. (setq *space (vla-get-PaperSpace *doc*))
  4059. (setq *space (vla-get-modelspace *doc*))
  4060. )
  4061. (vlax-invoke *doc* 'copyobjects (list obj) *space)
  4062. ;则仅仅是copyObjects方式添加到空间中
  4063. (setq new (*En2Obj* (entlast)))
  4064. (vla-transformby new (vlax-tmatrix mat)) ;然后再矩阵变换
  4065. )
  4066. (progn
  4067. (setq blk (make-anonymous-block obj)) ;先做一个匿名图块
  4068. (setq ref (*En2Obj* (entlast))) ;插入块参照
  4069. (setq sX (/ 1 lx)) ;非均匀缩放则要取得各个比例值
  4070. (setq sY (/ 1 lY))
  4071. (setq sZ (/ 1 lZ))
  4072. (setq sclMat (list (list sX 0 0 1);乘以一个比例缩放矩阵使得比例均匀
  4073. (list 0 sY 0 1)
  4074. (list 0 0 sZ 1)
  4075. (list 0 0 0 1)
  4076. )
  4077. )
  4078. (setq trsmat (MAT:mxm mat sclMat)) ;得到一个均匀缩放的变换矩阵
  4079. (vla-transformby ref (vlax-tmatrix trsmat)) ;变换参照
  4080. ;;最后需要变换回去
  4081. (vla-put-xscalefactor ref (* (vla-get-xscalefactor ref) lX))
  4082. (vla-put-yscalefactor ref (* (vla-get-yscalefactor ref) lY))
  4083. (vla-put-zscalefactor ref (* (vla-get-zscalefactor ref) lZ))
  4084. (vlax-put ref 'insertionpoint (mapcar 'last vv))
  4085. ;;(vla-Explode ref)
  4086. (command "explode" "L") ;炸开匿名块参照
  4087. ;;(vla-delete ref)
  4088. (vla-delete blk) ;删除匿名块定义
  4089. )
  4090. )
  4091. (princ)
  4092. )
  4093. ;;107.7 [功能] 块内原地复制 by GSLS(SS)
  4094. ;; 示例 : (MJ:BlockNentsel "My God:")
  4095. (defun MJ:BlockNentsel (msg / EN EN1 ENT INS MAT OBJ PT X Y)
  4096. (setq en (Nentsel msg))
  4097. (if (= (length en) 4)
  4098. (progn
  4099. (setq en1 (car en)
  4100. pt (cadr en)
  4101. mat (caddr en)
  4102. ins (last mat)
  4103. mat (reverse (cdr (reverse mat)))
  4104. mat (append
  4105. (mapcar '(lambda (x y)
  4106. (append x (list y))
  4107. )
  4108. mat
  4109. ins
  4110. )
  4111. '((0. 0. 0. 1.))
  4112. )
  4113. ent (entget en1 '("*"))
  4114. ent (vl-remove (assoc -1 ent) ent)
  4115. en1 (entmakex ent)
  4116. )
  4117. (if en1
  4118. (progn
  4119. (setq obj (*En2Obj* en1))
  4120. (vla-TransformBy obj (vlax-tmatrix mat))
  4121. (setq en1 (*Obj2En* obj))
  4122. )
  4123. )
  4124. (list en1 pt T)
  4125. )
  4126. (append en (list nil))
  4127. )
  4128. )
  4129. ;;108 [功能] 输出 WMF SAT EPS DXF BMP格式文件
  4130. ;;fileName 输出文件名
  4131. ;;Extension 输出文件格式:WMF SAT EPS DXF BMP 之一
  4132. ;;SelectonSet 选择集对象,如果Extension=EPS/DXF,则忽略(但必须有效!),而输出整个图形
  4133. (defun myExport (fileName Extension SelectonSet /)
  4134. (vla-export *DOC* fileName Extension SelectonSet)
  4135. )
  4136. ;;109 [功能] 移动Move
  4137. (defun myMove (moveEnt fromPt toPt / moveType point1 point2)
  4138. (setq point1 (vlax-3d-point fromPt)
  4139. point2 (vlax-3d-point toPt)
  4140. )
  4141. (setq moveType (type moveEnt))
  4142. (cond
  4143. ((= moveType 'ENAME)
  4144. (setq obj (*En2Obj* moveEnt))
  4145. (vla-move obj point1 point2)
  4146. 1
  4147. )
  4148. ((= moveType 'PICKSET)
  4149. (setq sn (sslength moveEnt)
  4150. i 0
  4151. )
  4152. (while (< i sn)
  4153. (setq si (ssname moveEnt i))
  4154. (setq obj (*En2Obj* si))
  4155. (vla-move obj point1 point2)
  4156. (setq i (1+ i))
  4157. )
  4158. )
  4159. )
  4160. )
  4161. ;;110 [功能] 偏移
  4162. ;;对逆时针方向的图形 dis >0 向外偏移,<0 为向内偏移
  4163. (defun myOffset (obj dis / wObj offsetObj)
  4164. (setq wObj obj)
  4165. (if (= (type obj) 'ENAME)
  4166. (setq wObj (*En2Obj* obj))
  4167. )
  4168. (setq offsetObj (vla-Offset wObj dis))
  4169. )
  4170. ;;111 [功能] 退出Acad
  4171. (defun myQuit ()
  4172. (vla-Quit *ACAD*)
  4173. )
  4174. ;;112 [功能] 重生成
  4175. (defun myRegen ()
  4176. (vla-Regen *ACAD* :vlax-true)
  4177. )
  4178. ;;113 [功能] 旋转(见133.1)
  4179. (defun myRotate (obj basePoint RotateAngle / wObj bPoint rAngle)
  4180. (setq wObj obj)
  4181. (if (= (type obj) 'ENAME)
  4182. (setq wObj (*En2Obj* obj))
  4183. )
  4184. (setq bPoint (vlax-3d-point basePoint))
  4185. (setq rAngle (/ (* RotateAngle pi) 180.0))
  4186. (vla-Rotate wObj bPoint rAngle)
  4187. )
  4188. ;;114.1 [功能] 多段线添加节点Vertex
  4189. ;;pt节点;index序号
  4190. (defun MJ:AddVertex (PLineObj index pt / newVertex)
  4191. (setq newVertex (vlax-make-safearray vlax-vbDouble (cons 0 1)))
  4192. (vlax-safearray-fill newVertex pt)
  4193. (vla-AddVertex PLineObj index newVertex)
  4194. )
  4195. ;;114.2 [功能] 多段线修改节点Vertex
  4196. ;;示例 (MJ:ChangeVertex (car(entsel)) (trans (getpoint) 0 1) 1)
  4197. (defun MJ:ChangeVertex (pl pt index)
  4198. (if (= 'ename (type pl))
  4199. (setq pl (*En2Obj* pl))
  4200. )
  4201. (if (= "AcDbPolyline" (vla-get-ObjectName pl))
  4202. (setq pt (list (car pt) (cadr pt)))
  4203. )
  4204. (VL-CATCH-ALL-APPLY
  4205. 'vla-put-coordinate
  4206. (list
  4207. pl
  4208. index
  4209. (vlax-make-variant
  4210. (vlax-safearray-fill
  4211. (vlax-make-safearray
  4212. vlax-vbdouble
  4213. (cons 0 (1- (length pt)))
  4214. )
  4215. pt
  4216. )
  4217. )
  4218. )
  4219. )
  4220. )
  4221. ;;114.3 [功能] 多段线除重点
  4222. (defun c:DESP (/ DATA ENP L N NEWDATA SEL)
  4223. (princ "\n ★☆★选择需要除重点的多段线:")
  4224. (if (SetQ Sel (SsGet (list (cons 0 "lwpolyline"))))
  4225. (Repeat (setq L (SsLength Sel))
  4226. (SetQ data (entget (SsName Sel (setq L (1- L)))))
  4227. (setq n -1 newdata nil)
  4228. (while (setq enp (nth (setq n (1+ n)) data))
  4229. (if (and (member enp newdata) (= 10 (car enp)))
  4230. (setq n (+ n 3))
  4231. (setq newdata (cons enp newdata))
  4232. )
  4233. )
  4234. (entmod (reverse newdata))
  4235. )
  4236. )
  4237. (princ)
  4238. )
  4239. ;;114.4 [功能] 动态绘制指引标注框符号 By Gu_xl 2012.07.17
  4240. (defun c:zybz (/ P1 P2 EN OBJ EL GR PT PA NEW FILLETFlag R kd *error*)
  4241. (defun *error* (s)
  4242. (princ s)
  4243. (if obj
  4244. (vla-delete obj)
  4245. )
  4246. (if new
  4247. (vla-delete new)
  4248. )
  4249. (princ)
  4250. )
  4251. (if (and (setq p1 (getpoint "\n左下角点: "))
  4252. (setq p2 (GETCORNER p1 "\n右上角点: "))
  4253. )
  4254. (progn
  4255. (command "_.rectang" p1 p2)
  4256. (setq en (entlast)
  4257. obj (vlax-ename->vla-object en)
  4258. )
  4259. (setq r (getvar 'FILLETRAD))
  4260. (initget "Yes No Set")
  4261. (setq kd
  4262. (cond
  4263. ((setq kd
  4264. (getkword
  4265. (strcat
  4266. "\n矩形是否圆角(R="
  4267. (rtos r 2 3)
  4268. ")[圆角Yes/不圆角No/设置圆角半径Set]<No>"
  4269. )
  4270. )
  4271. )
  4272. )
  4273. ("No")
  4274. )
  4275. )
  4276. (if (= kd "Set")
  4277. (setq r (getdist (strcat "\n输入圆角半径<" (rtos r 2 3) ">")))
  4278. )
  4279. (if (null r)
  4280. (setq r (getvar 'FILLETRAD))
  4281. )
  4282. (if (and (or (= kd "Set") (= kd "Yes")) (not (equal r 0 1e-6)))
  4283. (progn (setvar 'FILLETRAD r)
  4284. (command "_.FILLET" "p" en)
  4285. (setq FILLETFlag t)
  4286. )
  4287. )
  4288. (while (= 5 (car (setq gr (grread t 15))))
  4289. (redraw en 2)
  4290. (if new
  4291. (vla-delete new)
  4292. )
  4293. (setq pt (cadr gr))
  4294. (setq pa (vlax-curve-getParamAtPoint
  4295. en
  4296. (vlax-curve-getclosestpointto en pt)
  4297. )
  4298. )
  4299. (cond
  4300. ((equal pa (fix pa) 1e-6) (setq pa (1- (fix pa))))
  4301. (t (setq pa (fix pa)))
  4302. )
  4303. (if (MINUSP pa)
  4304. (setq pa 0)
  4305. )
  4306. (if (and FILLETFlag (member pa '(1 3 5 7)))
  4307. (setq pa (1- pa))
  4308. )
  4309. (setq p1 (vlax-curve-getPointAtParam en (+ pa 0.35))
  4310. p2 (vlax-curve-getPointAtParam en (+ pa 0.65))
  4311. )
  4312. (vla-copy obj)
  4313. (setq new (vlax-ename->vla-object (entlast)))
  4314. (vla-AddVertex
  4315. new
  4316. (+ 1 pa)
  4317. (vlax-make-variant
  4318. (vlax-safearray-fill
  4319. (vlax-make-safearray
  4320. vlax-vbdouble
  4321. '(0 . 1)
  4322. )
  4323. (list (car p1) (cadr p1))
  4324. )
  4325. )
  4326. )
  4327. (vla-AddVertex
  4328. new
  4329. (+ 2 pa)
  4330. (vlax-make-variant
  4331. (vlax-safearray-fill
  4332. (vlax-make-safearray
  4333. vlax-vbdouble
  4334. '(0 . 1)
  4335. )
  4336. (list (car
  4337. (trans pt 1 0)
  4338. )
  4339. (cadr
  4340. (trans pt 1 0)
  4341. )
  4342. )
  4343. )
  4344. )
  4345. )
  4346. (vla-AddVertex
  4347. new
  4348. (+ 3 pa)
  4349. (vlax-make-variant
  4350. (vlax-safearray-fill
  4351. (vlax-make-safearray
  4352. vlax-vbdouble
  4353. '(0 . 1)
  4354. )
  4355. (list (car p2) (cadr p2))
  4356. )
  4357. )
  4358. )
  4359. )
  4360. (entdel en)
  4361. )
  4362. )
  4363. (princ)
  4364. )
  4365. ;;115 [功能] 文件名已经保存,返回T;新建一文件,未命名保存过,返回 nil
  4366. (defun MJ:DwgNamed-p ()
  4367. (= 1 (getvar "dwgtitled"))
  4368. )
  4369. ;;116.1 [功能] 缩放整个图形
  4370. (defun MJ:ZoomAll()
  4371. (vla-ZoomAll *ACAD*)
  4372. )
  4373. ;;116.2 [功能] 缩放到实际范围
  4374. (defun MJ:ZoomExtents()
  4375. (vla-ZoomExtents *ACAD*)
  4376. )
  4377. ;;116.3 [功能] pt中心点缩放1
  4378. (defun MJ:ZoomCenter1 (pt)
  4379. (vla-ZoomCenter *ACAD* (vlax-3d-point pt) 1.0)
  4380. )
  4381. ;;116.4 [功能] pt中心点缩放2
  4382. (defun MJ:ZoomCenter2 (centerPoint zoomHeight)
  4383. (vla-ZoomCenter
  4384. *ACAD*
  4385. (vlax-3d-point centerPoint)
  4386. zoomHeight
  4387. )
  4388. )
  4389. ;;116.5 [功能] 两点窗口缩放
  4390. (defun MJ:ZoomWindow (p1 p2)
  4391. (vla-ZoomWindow *ACAD*
  4392. (vlax-3d-point p1) (vlax-3d-point p2)
  4393. )
  4394. )
  4395. ;;116.6 [功能] 视口比例缩放-放大2倍
  4396. (defun MJ:ZoomScale ()
  4397. (vla-ZoomScaled *ACAD* 2.0 1)
  4398. )
  4399. ;;116.7 [功能] 视口比例缩放
  4400. (defun MJ:ZoomScaled (scaleFactor scaleType / AcadObject sType)
  4401. (setq sType scaleType)
  4402. (if (or (not scaleType) (= scaleType ""))
  4403. (setq sType acZoomScaledRelative) ;和视图相关,或acZoomScaledAbsolute与图形范围
  4404. )
  4405. (vla-ZoomScaled
  4406. *ACAD*
  4407. scaleFactor
  4408. scaleType
  4409. )
  4410. )
  4411. ;;116.8 [功能] 返回上一视图
  4412. (defun MJ:ZoomPrevious ()
  4413. (vla-ZoomPrevious *ACAD*)
  4414. )
  4415. ;;117.1 [功能] 在当前视图状况下将图形单位转换为像素
  4416. (defun MJ:U2P (UN)
  4417. (* UN (/ (cadr (getvar 'SCREENSIZE)) (getvar 'VIEWSIZE)))
  4418. )
  4419. ;;117.2 [功能] 在当前视图状况下将像素转换为图形单位
  4420. (defun PIX2UNITS (pix)
  4421. (* pix (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE"))))
  4422. )
  4423. ;;117.3 [功能] 返回当前视窗左下角和右上角 坐标
  4424. (defun viewpnts (/ a b c d x)
  4425. (setq b (getvar "viewsize")
  4426. c (car (getvar "screensize"))
  4427. d (cadr (getvar "screensize"))
  4428. a (* b (/ c d))
  4429. x (setq x (getvar "viewctr"))
  4430. x (trans x 1 2)
  4431. c (list (- (car x) (/ a 2.0)) (- (cadr x) (/ b 2.0)) 0.0)
  4432. d (list (+ (car x) (/ a 2.0)) (+ (cadr x) (/ b 2.0)) 0.0)
  4433. c (trans c 2 1)
  4434. d (trans d 2 1)
  4435. )
  4436. (list c d)
  4437. )
  4438. ;;117.4 [功能] pickbox大小
  4439. (defun MJ:pickboxsize ()
  4440. (* (/ (getvar "pickbox") (cadr (getvar "screensize")))
  4441. (getvar "viewsize")
  4442. )
  4443. )
  4444. ;;118.1 [功能] 获取 0~1 之间的随机数 (by zml84)
  4445. (defun MJ:RAD ()
  4446. (/ (rem (getvar "CPUTICKS") 1984) 1983)
  4447. )
  4448. ;;118.2 [功能] 获取 0~7 之间的随机数
  4449. (defun ZL-RAND ()
  4450. (fix (* 7 (/ (rem (getvar "CPUTICKS") 1984) 1983)))
  4451. )
  4452. ;;119.1 [功能] 将 ACI 索引颜色转换成 RGB 配色系统
  4453. (defun MJ:ACI->RGB (ACI / COL)
  4454. (setq COL (vla-get-truecolor (vla-get-ActiveLayer *DOC*)))
  4455. (if (not (vl-catch-all-apply 'vla-put-ColorIndex (list COL ACI))
  4456. )
  4457. (list (vla-get-red COL)
  4458. (vla-get-green COL)
  4459. (vla-get-blue COL)
  4460. )
  4461. )
  4462. )
  4463. ;;119.2 [功能] RGB 配色系统转换成 ACI 索引颜色
  4464. (defun MJ:RGB->ACI (R G B / COL ACI)
  4465. (setq COL (vla-get-truecolor (vla-get-ActiveLayer *DOC*)))
  4466. (vl-catch-all-apply
  4467. '(lambda ()
  4468. (vla-SetRGB COL R G B)
  4469. (setq ACI (vla-get-ColorIndex COL))
  4470. )
  4471. )
  4472. ACI
  4473. )
  4474. ;;120.1 [功能] 选择集->图元列表
  4475. (defun MJ:SS->LIST (SS)
  4476. (vl-remove-if-not 'Is-Ename (mapcar 'cadr (ssnamex SS)))
  4477. )
  4478. ;;120.2 [功能] 选择集->图元列表 By caiqs
  4479. (defun ss->lst (ss / retu)
  4480. (setq retu (apply 'append (ssnamex ss)))
  4481. (setq retu (vl-remove-if-not '(lambda (x) (= (type x) 'ENAME)) retu))
  4482. )
  4483. ;;120.3 [功能] Vla集合->图元列表
  4484. (defun VlaSS (VlaSS / lst)
  4485. (vlax-for x VlaSS
  4486. (setq lst (cons (vlax-vla-object->ename x) lst))
  4487. )
  4488. )
  4489. ;;120.4 [功能] 图元列表->选择集
  4490. (defun MJ:Sel-List->SS (Lst / en ss kk)
  4491. (setq ss (ssadd)
  4492. kk 0
  4493. )
  4494. (foreach en Lst
  4495. (ssadd en ss)
  4496. (setq kk (1+ kk))
  4497. )
  4498. ss
  4499. )
  4500. ;;120.5 [功能] 图元列表->选择集 By caiqs
  4501. (defun lst->ss (lst / ss)
  4502. (setq ss (ssadd))
  4503. (last (mapcar '(lambda (x) (ssadd x ss)) lst))
  4504. )
  4505. ;;121 [功能] 根据当前文档的图形单位精度将实数转换为字符串
  4506. ;; [参数] REL----实数
  4507. (defun MJ:RTOS (REL / DZIN)
  4508. (setq DZIN (getvar 'DIMZIN))
  4509. (setvar 'DIMZIN 0)
  4510. (setq REL (rtos REL 2 (getvar 'LUPREC)))
  4511. (setvar 'DIMZIN DZIN)
  4512. REL
  4513. )
  4514. ;;122.1 [功能] 遍历选择集对所包含的图元进行指定函数操作
  4515. ;; [参数] SS----选择集
  4516. ;; FUN---函数名
  4517. ;; [返回] 包含每个图元的操作结果的表
  4518. (defun MJ:SS-MAP (SS FUN / N LST)
  4519. (repeat (setq N (sslength SS))
  4520. (setq LST (cons (apply FUN (list (ssname SS (setq N (1- N))))) LST))
  4521. )
  4522. LST
  4523. )
  4524. ;;122.2 [功能] 遍历选择集对所包含的图元进行指定函数操作
  4525. ;; [参数] SS----选择集
  4526. ;; FUN---函数名
  4527. ;; [返回] 最后一个图元的操作结果
  4528. (defun MJ:SS-FOR (SS FUN / N)
  4529. (repeat (setq N (sslength SS))
  4530. (apply FUN (list (ssname SS (setq N (1- N)))))
  4531. )
  4532. )
  4533. ;;123 [功能] 获取当前 AutoCAD 的版本
  4534. (defun MJ:ACAD-VAR () (atof (getvar "ACADVER")))
  4535. ;;124 [功能] 获取 DXF 组码值
  4536. (defun MJ:DXF (IT LST)
  4537. (cdr (assoc IT LST))
  4538. )
  4539. ;;125.1 [功能] 获取在图元 en 之后产生的图元列表
  4540. (defun MJ:EntNextAll (EN / LST)
  4541. (if EN
  4542. (while (setq EN (entnext EN))
  4543. (if (not (member (cdr (assoc 0 (entget EN)))
  4544. '("ATTRIB" "VERTEX" "SEQEND")
  4545. )
  4546. )
  4547. (setq LST (cons EN LST))
  4548. )
  4549. )
  4550. )
  4551. (reverse LST)
  4552. )
  4553. ;;125.2 [功能] 获取在图元 en 之后产生的图元的选择集
  4554. (defun MJ:ss-entnext (en / ss)
  4555. (if en
  4556. (progn
  4557. (setq ss (ssadd))
  4558. (while (setq en (entnext en))
  4559. (if (not (member (cdr (assoc 0 (entget en)))
  4560. '("ATTRIB"
  4561. "VERTEX"
  4562. "SEQEND"
  4563. )
  4564. )
  4565. )
  4566. (ssadd en ss)
  4567. )
  4568. )
  4569. (if (zerop (sslength ss))
  4570. (setq ss nil)
  4571. )
  4572. ss
  4573. )
  4574. (ssget "_x")
  4575. )
  4576. )
  4577. ;;126 [功能] 打印列表中的数据
  4578. (defun MJ:Print-List (LST) (mapcar 'princ LST))
  4579. ;;127 [功能] 更新组码
  4580. ;; (entmodEnt 图元 组码 组码新值 TF) TFnil时不更新图元
  4581. (defun MJ:entmodEnt (ent a vale TF / ENTLIST)
  4582. (setq entlist (entget ent))
  4583. (entmod (subst (cons a vale) (assoc a entlist) entlist))
  4584. (if TF
  4585. (entupd ent)
  4586. )
  4587. ent
  4588. )
  4589. ;;128.1 [功能] 选择集->无名块
  4590. ;;示例(MJ:BLK-MakeUnNameBlock (ssget))
  4591. ;;注意 函数对选择集中存在具有属性的图块及复杂多义线无效
  4592. (defun MJ:BLK-MakeUnNameBlock (ss / count entlist ent blk pt)
  4593. (setq pt (car (MJ:GetssBox ss)))
  4594. (entmake (list '(0 . "BLOCK")
  4595. '(2 . "*U")
  4596. '(70 . 1)
  4597. (cons 10 pt)
  4598. )
  4599. )
  4600. (setq count 0)
  4601. (repeat (sslength ss)
  4602. (setq entlist (entget (setq ent (ssname ss count))))
  4603. (setq count (1+ count))
  4604. (entmake entlist)
  4605. )
  4606. (setq count 0)
  4607. (repeat (sslength ss)
  4608. (setq ent (ssname ss count))
  4609. (setq count (1+ count))
  4610. (entdel ent)
  4611. )
  4612. (setq blk (entmake '((0 . "ENDBLK"))))
  4613. (if (princ blk)
  4614. (entmake (list (cons 0 "INSERT")
  4615. (cons 2 blk)
  4616. (cons 10 pt)
  4617. )
  4618. )
  4619. )
  4620. blk
  4621. )
  4622. ;;128.2 [功能] [选择集/obj表] 做成一个块
  4623. (defun MJ:add-Block (ss/objlst name InsertionPoint / block blocks)
  4624. (if (atom ss/objlst)
  4625. (setq ss/objlst (mapcar 'vlax-ename->vla-object
  4626. (MJ:SS->LIST ss/objlst)
  4627. )
  4628. )
  4629. )
  4630. (setq blocks (vla-get-Blocks *doc*))
  4631. (setq block (vla-add Blocks (vlax-3d-point InsertionPoint) name))
  4632. (vlax-invoke *doc* 'CopyObjects ss/objlst block) block
  4633. )
  4634. ;;128.3 [功能] 选择集做成一个块
  4635. (defun MJ:MakeBlock (ss / A)
  4636. (setq A (rtos (* (getvar "CDATE") 1E8)))
  4637. (if ss
  4638. (command "_.BLOCK" A "0,0" ss "")
  4639. )
  4640. ;;(command "_.INSERT" A "@" "" "" "")
  4641. )
  4642. ;;129.1 [功能] 删除表中相同图元
  4643. (defun MJ:delsame (l)
  4644. (if L
  4645. (cons (car L) (MJ:delsame (vl-remove (car L) (cdr L))))
  4646. )
  4647. )
  4648. ;;129.2 [功能] 深入递归删除重复出现的原子,每个嵌套的表也要除重
  4649. (defun gxl-ListDumpAtomAll (Lst / tmp)
  4650. (if Lst
  4651. (cons (if (= 'list (type (setq tmp (car Lst))))
  4652. (gxl-ListDumpAtomAll tmp)
  4653. tmp
  4654. )
  4655. (gxl-ListDumpAtomAll
  4656. (vl-remove
  4657. (car Lst)
  4658. (cdr Lst)
  4659. )
  4660. )
  4661. )
  4662. )
  4663. )
  4664. ;;129.3 [功能] 剔除表元素 By 无痕
  4665. ;;提示; 等同于: (vl-remove at list)
  4666. ;;(MJ:removeat "a" '(58 3 (a . 8) "a" 4.5)) -> (58 3 (A . 8) 4.5)
  4667. (defun MJ:removeat (at lst) ;at=atom
  4668. (apply 'append (subst nil (list at) (mapcar 'list lst)))
  4669. )
  4670. ;;130 [功能] 获得特定符号表的列表。
  4671. ;; 有效符号表名称为Layer,Ltype,Viewx,Style,Block,Appid,Ucs,DimstyleVport
  4672. (defun MJ:get-tblnext (table-name / lst d)
  4673. (while (setq d (tblnext table-name (null d)))
  4674. (setq lst (cons (cdr (assoc 2 d)) lst))
  4675. )
  4676. (reverse lst)
  4677. )
  4678. ;;131.1 [功能] 返回a在表lst中的位置 or nil
  4679. (defun MJ:position (a lst / b)
  4680. (if (setq b (member a lst))
  4681. (progn (setq b (- (length lst) (length b))))
  4682. )
  4683. b
  4684. )
  4685. ;;131.2 [功能] 返回a在表lst中的位置 or nil
  4686. ;; 示例(position x '(a b c)) -> nil, (position 'b '(a b c d)) -> 1
  4687. (defun position (x lst / ret)
  4688. (if (not (zerop (setq ret (length (member x lst)))));x不在表中返回nil
  4689. (- (length lst) ret)
  4690. )
  4691. )
  4692. ;;131.3 [功能] 从列表中删除指定的元素
  4693. (defun MJ:removeNth (index lst / c)
  4694. (setq c -1)
  4695. (apply 'append
  4696. (mapcar '(lambda (x)
  4697. (if (/= (setq c (1+ c)) index)
  4698. (list x)
  4699. )
  4700. )
  4701. lst
  4702. )
  4703. )
  4704. )
  4705. ;;131.4 [功能] 从列表中删除指定的元素 By xianaihua
  4706. (defun RemoveNth6 (index lst / i)
  4707. (setq i -1)
  4708. (vl-remove-if '(lambda (x) (= (setq i (1+ i)) index)) lst)
  4709. )
  4710. ;;131.5 [功能] 元素不在列表中,则加入之
  4711. ;;(adjoin 0 '(1 2 3))->(0 1 2 3)
  4712. (defun adjoin (ele lst / tmp)
  4713. (if (= (type lst) 'SYM)
  4714. (setq tmp lst
  4715. lst (eval tmp)
  4716. )
  4717. )
  4718. (setq lst (cond ((member ele lst) lst)
  4719. (t (cons ele lst))
  4720. )
  4721. )
  4722. (if tmp
  4723. (set tmp lst)
  4724. lst
  4725. )
  4726. )
  4727. ;;132 [功能] 关键字a的列表框增加内容
  4728. (defun MJ:mpoplst (a lst / n)
  4729. (start_list a 3)
  4730. (setq n 0)
  4731. (repeat (length lst)
  4732. (add_list (nth n lst))
  4733. (setq n (+ n 1))
  4734. )
  4735. (end_list)
  4736. )
  4737. ;;133.1 [功能] 旋转一个点(见113)
  4738. ;;Rotate 'pnt' from a base point of 'p1' and through an angle
  4739. ;;of 'ang' (in radians)
  4740. (defun MJ:rotate_pnt (pnt p1 ang /)
  4741. (polar p1 (+ (angle p1 pnt) ang) (distance p1 pnt))
  4742. )
  4743. ;;133.2 [功能] 缩放一个点
  4744. ;;scale 'pnt' from a base point of 'p1' by a factor of fact
  4745. (defun MJ:scale_pnt (pnt p1 fact /)
  4746. (polar p1 (angle p1 pnt) (* fact (distance p1 pnt)))
  4747. )
  4748. ;;134.1 [功能] 返回文件名(带扩展名) (反findfile)
  4749. ;;如a"C:\\Program Files\\AutoCAD 2005\\support\\AlignObject.VLX",返回"AlignObject.VLX"
  4750. (defun MJ:pstrip (a / b)
  4751. (cond ((setq b (strsea "\\" a)) (setq b b))
  4752. ((setq b (strsea "/" a)) (setq b b))
  4753. (T (setq b (list 0)))
  4754. )
  4755. (setq a (substr a (+ (last b) 1) (strlen a)))
  4756. )
  4757. ;;134.2 [功能] 去文件名扩展,比如去掉.exe
  4758. (defun MJ:xstrip (fna / st)
  4759. (if (and (setq st (strsea "." fna))
  4760. (<= (- (strlen fna) 3) (last st))
  4761. )
  4762. (setq fna (substr fna 1 (- (last st) 1)))
  4763. )
  4764. fna
  4765. )
  4766. (defun strsea (a b / c n)
  4767. (cond ((equal "" a) (setq c nil))
  4768. ((not (equal (type b) (type "1")))
  4769. (progn (print "!!!!不是字符串!!!!")
  4770. (print b)
  4771. (setq c nil)
  4772. )
  4773. )
  4774. (T
  4775. (progn (setq n 1)
  4776. (while (>= (+ (- (strlen b) n) 1) (strlen a))
  4777. (if (equal (substr b n (strlen a)) a)
  4778. (setq c (append c (list n))
  4779. n (- (+ n (strlen a)) 1)
  4780. )
  4781. )
  4782. (setq n (+ n 1))
  4783. )
  4784. )
  4785. )
  4786. )
  4787. c
  4788. )
  4789. ;;134.3 [功能] 分割文件名为三部分
  4790. ;;(fnsplitl "C:\\Program Files\\AutoCAD 2004\\acad.exe")
  4791. ;;返回("C:\\Program Files\\AutoCAD 2004\\" "acad" ".exe")
  4792. ;;135 [功能] p1是否在p2 p3线上
  4793. (defun what_side (p1 p2 p3 / a dx dx1 dy dy1)
  4794. (setq dx (- (car p3) (car p2))
  4795. dy (- (cadr p3) (cadr p2))
  4796. dx1 (- (car p1) (car p2))
  4797. dy1 (- (cadr p1) (cadr p2))
  4798. )
  4799. (setq a (- (* dx dy1) (* dy dx1))
  4800. a (rtos a 2 6)
  4801. a (atof a)
  4802. )
  4803. (if (not (equal 0.0 a))
  4804. (setq a (/ a (abs a)))
  4805. )
  4806. a
  4807. )
  4808. ;;136 [功能] 亮显选择集或对象(夹点不显示) 函数
  4809. (defun MJ:ayEntSSHighLight (SSorEntName / oldGrips)
  4810. (setq oldGrips (getvar "Grips"))
  4811. (setvar "Grips" 0)
  4812. (cond
  4813. ((= (type SSorEntName) 'PICKSET)
  4814. (sssetfirst nil SSorEntName)
  4815. )
  4816. ((= (type SSorEntName) 'ENAME)
  4817. (sssetfirst nil (ssadd SSorEntName (ssadd)))
  4818. )
  4819. )
  4820. (setvar "Grips" oldGrips)
  4821. )
  4822. ;;137.1 [功能] 获得图形中倒数第二个图元的函数
  4823. (defun MJ:EntSecLast (/ e sle)
  4824. (entdel (setq e (entlast)))
  4825. (setq sle (entlast))
  4826. (entdel e)
  4827. sle
  4828. )
  4829. ;;137.2 [功能] 图中最后图元Find True last entity
  4830. (Defun MJ:LASTENT (/ E0 EN)
  4831. (Setq E0 (EntLast))
  4832. (While (Setq EN (EntNext E0)) (Setq E0 EN))
  4833. E0
  4834. )
  4835. ;;138.1 [功能] 读取指定文件中指定行的内容
  4836. ;;(MJ:getfile_text "test1.txt" 5)
  4837. (defun MJ:getfile_text (files line / fn text)
  4838. (setq line(+ 1 line));本程序假定第一行为表头
  4839. (setq files (findfile files))
  4840. (if files
  4841. (progn
  4842. (setq fn(open files "r"))
  4843. (if (<= line (MJ:getfile_line files))
  4844. (progn
  4845. (repeat line
  4846. (setq text(read-line fn))
  4847. )
  4848. (close fn)
  4849. text
  4850. )
  4851. nil
  4852. )
  4853. )
  4854. nil
  4855. )
  4856. )
  4857. ;;138.2 [功能] 返回文件行数量
  4858. (defun MJ:getfile_line (files / tmplst x fn)
  4859. (setq files (findfile files))
  4860. (if files
  4861. (progn
  4862. (setq tmplst 0)
  4863. (setq fn (open files "r"))
  4864. (while (read-line fn)
  4865. (setq tmplst (+ 1 tmplst))
  4866. )
  4867. (close fn)
  4868. tmplst
  4869. )
  4870. nil
  4871. )
  4872. )
  4873. ;;138.3 [功能] 读取文件并按行将文件转换为表
  4874. ;; 示例:(MJ:getfile "tyl.ini")
  4875. (defun MJ:getfile(files / tmplst x fn)
  4876. (setq files(findfile files))
  4877. (if files
  4878. (progn
  4879. (setq fn (open files "r"))
  4880. (while (setq x (read-line fn))
  4881. (setq tmplst(append tmplst(list x)))
  4882. )
  4883. (close fn)
  4884. tmplst
  4885. )
  4886. nil
  4887. )
  4888. )
  4889. ;;139 [功能] [选择集/obj表] 做成一个组
  4890. (defun MJ:add-group (ss/objlst group_name / Group groups)
  4891. (if (atom ss/objlst)
  4892. (setq ss/objlst (mapcar 'vlax-ename->vla-object
  4893. (MJ:SS->LIST ss/objlst)
  4894. )
  4895. )
  4896. )
  4897. (setq group (vla-add (vla-get-groups *doc*) group_name))
  4898. (vlax-invoke group 'AppendItems ss/objlst) group
  4899. )
  4900. ;;140 [功能] 加载幻灯片
  4901. (defun MJ:loadsld (key sld / x y)
  4902. (setq x (dimx_tile key)
  4903. y (dimy_tile key)
  4904. )
  4905. (start_image key)
  4906. (fill_image 0 0 x y -2)
  4907. (slide_image 0 0 x y sld)
  4908. (end_image)
  4909. )
  4910. ;;141 [功能] 点表排序
  4911. (defun Sort_XYZ_pList (PLIST / p1 p2)
  4912. (setq plist (vl-sort plist
  4913. '(lambda (p1 p2)
  4914. (cond ((< (car p1) (car p2)) T)
  4915. ((and (= (car p1) (car p2))
  4916. (< (cadr p1) (cadr p2))
  4917. )
  4918. T
  4919. )
  4920. ((and (= (car p1) (car p2))
  4921. (= (cadr p1) (cadr p2))
  4922. (< (caddr p1) (caddr p2))
  4923. )
  4924. T
  4925. )
  4926. (T nil)
  4927. )
  4928. )
  4929. )
  4930. )
  4931. )
  4932. ;;142 [功能] 选择集相减 By 自贡黄明儒2012.8.23
  4933. ;;返回 选择集 or nil
  4934. ;;(setq ss1 (ssget)) (setq ss2 (ssget))
  4935. (defun SS_Sub (SS1 SS2 / ENAME SS SSTEMP)
  4936. (cond ((and (equal (type ss1) 'PICKSET)
  4937. (equal (type ss1) 'PICKSET)
  4938. )
  4939. (cond ((equal (sslength ss1) (sslength ss2))
  4940. (vl-cmdf "_.select" ss1 "")
  4941. (setq ss (ssget "p"))
  4942. (vl-cmdf "_.select" ss2 "")
  4943. (setq ssTemp (ssget "p"))
  4944. (repeat (sslength ssTemp)
  4945. (Setq ENAME (SsName ssTemp 0))
  4946. (SsDel ENAME ssTemp)
  4947. (if (ssmemb ENAME ss)
  4948. (SsDel ENAME SS)
  4949. )
  4950. )
  4951. (if (equal (sslength ss) 0)
  4952. nil
  4953. ss
  4954. )
  4955. )
  4956. (T
  4957. (command "._Select" ss1 "_Remove" ss2 "")
  4958. (ssget "_P")
  4959. )
  4960. )
  4961. )
  4962. ((and (equal (type ss1) 'PICKSET)
  4963. (not (equal (type ss2) 'PICKSET))
  4964. )
  4965. ss1
  4966. )
  4967. (T nil)
  4968. )
  4969. )
  4970. ;;143.1 [功能]选择集SS排序->图元列表 By 自贡黄明儒 2012.8.28
  4971. ;;注:选择集是按选择顺序排序,多选时按生成顺序排序,下面是按坐标排序
  4972. ;;"D->U"从下到上;"U->D"从上到下;"L->R"从左到右;"R->L"从右到左
  4973. ;;示例(setq ss (ssget)) (SS_Sort ss "D->U" "L->R")下到上,左到右
  4974. (defun SS_Sort_list (SS Sort1 Sort2 / E LST N PT10)
  4975. ;;2.1 表 排序
  4976. (defun Sort_pList (PLIST Sort1 Sort2 / SYMBOL1 SYMBOL2)
  4977. (cond
  4978. ((member Sort1 (list "L->R" "R->L"))
  4979. (cond ((equal Sort1 "L->R") (setq Symbol1 '>))
  4980. (T (setq Symbol1 '<))
  4981. )
  4982. (cond ((equal Sort2 "D->U") (setq Symbol2 '>))
  4983. (T (setq Symbol2 '<))
  4984. )
  4985. (vl-sort
  4986. PLIST
  4987. '(lambda (p1 p2)
  4988. (cond (((eval Symbol1) (car (car p1)) (car (car p2))) T)
  4989. ((and (= (car (car p1)) (car (car p2)))
  4990. ((eval Symbol2) (cadr (car p1)) (cadr (car p2)))
  4991. )
  4992. T
  4993. )
  4994. )
  4995. )
  4996. )
  4997. )
  4998. (T
  4999. (cond ((equal Sort1 "D->U") (setq Symbol1 '>))
  5000. (T (setq Symbol1 '<))
  5001. )
  5002. (cond ((equal Sort2 "L->R") (setq Symbol2 '>))
  5003. (T (setq Symbol2 '<))
  5004. )
  5005. (vl-sort
  5006. PLIST
  5007. '(lambda (p1 p2)
  5008. (cond (((eval Symbol1) (cadr (car p1)) (cadr (car p2))) T)
  5009. ((and (= (cadr (car p1)) (cadr (car p2)))
  5010. ((eval Symbol2) (car (car p1)) (car (car p2)))
  5011. )
  5012. T
  5013. )
  5014. )
  5015. )
  5016. )
  5017. )
  5018. )
  5019. )
  5020. ;;2.2 选择集SS排序 主程序
  5021. (repeat (setq n (sslength ss))
  5022. (setq e (ssname ss (setq n (1- n))))
  5023. (setq pt10 (cdr (assoc 10 (entget e))))
  5024. (setq lst (cons (cons pt10 e) lst))
  5025. )
  5026. (mapcar 'cdr (Sort_pList lst Sort1 Sort2))
  5027. )
  5028. ;;143.2 [功能]选择集排序->选择集 By 自贡黄明儒 2012.8.28
  5029. (defun SS_Sort (SS Sort1 Sort2)
  5030. (lst->ss (SS_Sort_list SS Sort1 Sort2))
  5031. )
  5032. ;;144.1 [功能] 读取系统剪贴板中字符串
  5033. (defun GET-CLIP-STRING (/ HTML RESULT)
  5034. (and (setq HTML (vlax-create-object "htmlfile"))
  5035. (setq RESULT (vlax-invoke
  5036. (vlax-get (vlax-get HTML 'PARENTWINDOW)
  5037. 'CLIPBOARDDATA
  5038. )
  5039. 'GETDATA
  5040. "Text"
  5041. )
  5042. )
  5043. (vlax-release-object HTML)
  5044. )
  5045. RESULT
  5046. )
  5047. ;;144.2 [功能] 向系统剪贴板写入文字
  5048. (defun SET-CLIP-STRING (STR / HTML RESULT)
  5049. (and (= (type STR) 'STR)
  5050. (setq HTML (vlax-create-object "htmlfile"))
  5051. (setq RESULT (vlax-invoke
  5052. (vlax-get (vlax-get HTML 'PARENTWINDOW)
  5053. 'CLIPBOARDDATA
  5054. )
  5055. 'SETDATA
  5056. "Text"
  5057. STR
  5058. )
  5059. )
  5060. (vlax-release-object HTML)
  5061. )
  5062. )
  5063. ;;144.3 [功能] 清空剪贴板内文字
  5064. (defun xdl-clscliptext (/ ieobj)
  5065. (setq
  5066. ieobj (vlax-get-or-create-object "Internetexplorer.application")
  5067. )
  5068. (vlax-invoke ieobj 'navigate "about :blank") ;about与:blank间无空格
  5069. (vlax-invoke
  5070. (vlax-get (vlax-get (vlax-get ieobj 'document) 'parentwindow)
  5071. 'clipboarddata
  5072. )
  5073. 'clearData
  5074. "text"
  5075. )
  5076. (vlax-release-object ieobj)
  5077. )
  5078. ;;145 [功能] 求多段线上的弧段(圆或圆弧也有效)的圆心
  5079. ;;(getCenter (entsel "\n选择多段线弧段: "))
  5080. (defun getCenter (EP / E P)
  5081. (mapcar 'set '(E P) EP)
  5082. (setq P (apply 'vlax-curve-getClosestPointTo EP))
  5083. (mapcar '+ P
  5084. (vlax-curve-getsecondderiv
  5085. E
  5086. (vlax-curve-getParamAtPoint E P)
  5087. )
  5088. )
  5089. )
  5090. ;;146 [功能] 质心
  5091. ;;示例 (GetCentroid (car(entsel)))
  5092. (defun GetCentroid (poly / AXERR CEN PL REG VA)
  5093. (setq pl (*En2Obj* poly)
  5094. va (vlax-make-safearray vlax-vbObject '(0 . 0))
  5095. )
  5096. (vlax-safearray-put-element va 0 pl)
  5097. (setq axErr (VL-CATCH-ALL-APPLY 'vla-addregion (list *MS* va)))
  5098. (if (VL-CATCH-ALL-ERROR-P axErr)
  5099. nil
  5100. (progn
  5101. (setq reg (car (vlax-safearray->list (vlax-variant-value axErr)))
  5102. cen (vla-get-centroid reg)
  5103. )
  5104. (vla-delete reg)
  5105. (vlax-safearray->list (vlax-variant-value cen))
  5106. )
  5107. )
  5108. )
  5109. ;;147.1 [功能] 自定义max
  5110. ;;示例(max1 '("asd" "dfd" "hgrt"))返回"hgrt"
  5111. (defun max1 (lst)
  5112. (if lst
  5113. (if (> (car lst) (max1 (cdr lst)))
  5114. (car lst)
  5115. (max1 (cdr lst)
  5116. )
  5117. )
  5118. )
  5119. )
  5120. ;;147.2 [功能] 自定义max
  5121. ;;示例(max2 '("asd" "dfd" "hgrt"))返回"hgrt"
  5122. (defun max2 (l)
  5123. (car (vl-sort l '>))
  5124. )
  5125. ;;147.3 [功能] 自定义vl-remove-if
  5126. ;; (remove-if 'numberp '(0 (0 1) "")) -> ((0 1) "")
  5127. (defun remove-if (pred from)
  5128. (cond
  5129. ((atom from) from) ;nil or symbol (return that)
  5130. ((apply pred (list (car from))) (remove-if pred (cdr from)))
  5131. (t (cons (car from) (remove-if pred (cdr from))))
  5132. )
  5133. )
  5134. ;;147.4 [功能] 自定义remove-if-not
  5135. (defun remove-if-not (pred lst) ; by Vladimir Nesterowsky
  5136. (apply 'append
  5137. (mapcar '(lambda (e)
  5138. (if (apply pred (list e))
  5139. (list e)
  5140. )
  5141. )
  5142. lst
  5143. )
  5144. )
  5145. )
  5146. ;;147.5 [功能] 自定义vl-prin1-to-string
  5147. ;; 1示例(symbol-name 'a) -> "a";(symbol-name a) -> nil
  5148. ;; 2示例(symbol-name '(0 1 2 a)) -> "(0 1 2 A)"
  5149. (defun symbol-name (sym / f str tmp)
  5150. ;; 执行完毕,搜索电脑,没有发现*sym.tmp
  5151. ;; 下句产生临时文件的方法是不是与vl-filename-mktemp相同呢?
  5152. (setq tmp "$sym.tmp");temp. filename, should be deleted原来创建txt文件如此简单!
  5153. (setq f (open tmp "w"))
  5154. (princ sym f)
  5155. (close f)
  5156. (setq f (open tmp "r")
  5157. str (read-line f)
  5158. f (close f)
  5159. )
  5160. ;; (startapp "notepad" tmp);显示给使用者看
  5161. str
  5162. )
  5163. ;;148.1 [功能] 根据点表画多段线
  5164. (defun draw-pline1 (pts)
  5165. (command "_PLINE")
  5166. (mapcar 'command pts)
  5167. (command "")
  5168. )
  5169. ;;148.2 [功能] 根据点表画多段线
  5170. ;; TF:T封闭,NIL不封闭
  5171. (defun draw-pline2 (pts tf)
  5172. (apply 'command (cons "pline" pts))
  5173. (if tf
  5174. (command "c")
  5175. (command "")
  5176. )
  5177. )
  5178. ;;148.3 [功能] 根据点表画多段线---xyp1964
  5179. (defun Entmake-Spline (ptn / a)
  5180. (entmake (append (list '(0 . "SPLINE")
  5181. '(100 . "AcDbEntity")
  5182. '(100 . "AcDbSpline")
  5183. '(71 . 3)
  5184. )
  5185. (mapcar '(lambda (pt) (cons 11 pt)) ptn)
  5186. )
  5187. )
  5188. (entlast)
  5189. )
  5190. ;;148.4 [功能] 根据点表画样条曲线
  5191. (defun draw-spline (pts)
  5192. (command "_SPLINE")
  5193. (mapcar 'command pts)
  5194. (command "" "" "")
  5195. )
  5196. ;;149.1 [功能] 进程显示
  5197. (defun spinner ()
  5198. (if (not #spin)
  5199. (setq #spin "-")
  5200. )
  5201. (cond
  5202. ((equal #spin "-") (setq #spin "\\"))
  5203. ((equal #spin "\\") (setq #spin "|"))
  5204. ((equal #spin "|") (setq #spin "/"))
  5205. (T (setq #spin "-"))
  5206. )
  5207. (princ (strcat (chr 8) #spin))
  5208. (princ) ;这句很重要
  5209. )
  5210. ;;149.2 [功能] 进程显示
  5211. (defun HH:WORKING ()
  5212. (if (= WRKCNT NIL)
  5213. (setq WRKCNT 0)
  5214. )
  5215. (setq WRKCNT (1+ WRKCNT))
  5216. (cond ((= WRKCNT 1) (setq WRK "-"))
  5217. ((= WRKCNT 2) (setq WRK "\\"))
  5218. ((= WRKCNT 3) (setq WRK "|"))
  5219. ((= WRKCNT 4) (progn (setq WRK "/") (setq WRKCNT 0)))
  5220. )
  5221. (princ (strcat "\n* " WRK " 请稍候...... ! " WRK " *"))
  5222. (princ)
  5223. )
  5224. ;;149.3 [功能] 进程显示
  5225. (defun spin (wh)
  5226. (princ (strcat "\r "
  5227. wh
  5228. (cond ((= #spin "|") (setq #spin "/"))
  5229. ((= #spin "/") (setq #spin "-"))
  5230. ((= #spin "-") (setq #spin "\\"))
  5231. (T (setq #spin "|"))
  5232. )
  5233. )
  5234. )
  5235. (princ)
  5236. )
  5237. ;;150 [功能] 生成无名组
  5238. ;;示例(bns_makgrp (MJ:SS->LIST (ssget)) "描述")
  5239. (defun bns_makgrp (LST DESC / EN)
  5240. (command "_.-group" "_create" "*" DESC)
  5241. (foreach EN LST (command EN))
  5242. (command "")
  5243. )
  5244. ;;151 [功能] 曲线选集长度求和--陌生人.2004.1
  5245. ;;示例(MJ:lens nil)
  5246. (defun MJ:lens (ss / ss ssv lens)
  5247. (if (= nil ss)
  5248. (setq ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE"))))
  5249. )
  5250. (setq ssv (vla-get-activeselectionset
  5251. (vla-get-activedocument (vlax-get-acad-object))
  5252. )
  5253. lens 0
  5254. )
  5255. (vlax-for obj ssv
  5256. (setq lens (+ lens
  5257. (vlax-curve-getdistatparam obj (vlax-curve-getendparam obj))
  5258. )
  5259. )
  5260. )
  5261. )
  5262. ;;152.1 [功能] 局部重生 by Lee Mac
  5263. ;;示例 (MJ:Update (entget (car (entsel))))
  5264. (defun MJ:Update (enlist)
  5265. (entupd (cdr (assoc -1 enlist)))
  5266. )
  5267. ;;152.2 [功能] 局部重生
  5268. ;;示例(MJ:RedrawSS (ssget))
  5269. (defun MJ:RedrawSS (ss)
  5270. (
  5271. (lambda (i)
  5272. (while (setq e (ssname ss (setq i (1+ i))))
  5273. (entupd e)
  5274. )
  5275. )
  5276. -1
  5277. )
  5278. )
  5279. ;;153.1 [功能] 注册应用程序名的选择集
  5280. (defun ssget-app (rname)
  5281. (ssget "X" (list (list -3 (list rname))))
  5282. )
  5283. ;;153.2 [功能] 一个图元的扩展数据列表
  5284. ;;示例 (get-eedlist-all (car (entsel)))
  5285. (defun get-eedlist-all (ent)
  5286. (cdadr (assoc -3 (entget ent) '("*"))))
  5287. )
  5288. ;;153.3 [功能] 一个图元的扩展数据列表(无注册应用程序名)
  5289. (defun getxdata-all (e apnlst)
  5290. (apply 'append (mapcar 'cdr (getxdata e apnlst)))
  5291. )
  5292. ;;153.4 [功能] 一个图元的扩展数据列表
  5293. (defun getxdata (e apnlst)
  5294. (cdr (assoc -3 (entget e apnlst)))
  5295. )
  5296. ;;153.5 [功能] 删除扩展数据
  5297. (defun DelXdata (eName )
  5298. (entmod
  5299. (list
  5300. (cons -1 eName)
  5301. (cons -3
  5302. (mapcar 'list
  5303. (mapcar 'car (cdr (assoc -3 (entget eName '("*")))))
  5304. )
  5305. )
  5306. )
  5307. )
  5308. )
  5309. ;;153.6 [功能] 附着扩展图元数据到AutoCAD对象上
  5310. ;; 示例(ax:PutXData myVlaObj '((1001 . "ACADX") (1000 . "myStringData")))
  5311. (defun ax:PutXData (vlaObj XData)
  5312. (setq XData
  5313. (ax:BuildFilter
  5314. (mapcar
  5315. '(lambda (item / key)
  5316. (setq key (car item))
  5317. (if (<= 1010 key 1033)
  5318. (cons key
  5319. (vlax-variant-value
  5320. (vlax-3d-point
  5321. (cdr item)
  5322. )
  5323. )
  5324. )
  5325. item
  5326. )
  5327. )
  5328. XData
  5329. )
  5330. )
  5331. )
  5332. (vla-setXData vlaObj (car XData) (cadr XData))
  5333. )
  5334. ;;153.7 [功能] 设置链接在一个实体上,或者获取链接(geturl)--Highflybird
  5335. (defun c:PutHyperlink1 (/ e)
  5336. (if (setq e (car (entsel "\nSelect Object to Add Hyperlink to: ")))
  5337. (seturl e "http://www.google.co.uk")
  5338. )
  5339. (princ)
  5340. )
  5341. (defun c:PutHyperlink2 (/ e)
  5342. (if (setq e (car (entsel "\nSelect Object to Add Hyperlink to: ")))
  5343. (vla-add (vla-get-hyperlinks (vlax-ename->vla-object e))
  5344. "http://www.google.co.uk"
  5345. )
  5346. )
  5347. (princ)
  5348. )
  5349. ;;154.1 [功能] 获取ObjectDBX版本字符串
  5350. ;;用于操作非打开文件
  5351. (defun GetObjectDBXVer (/ VERSION)
  5352. (if (>= (setq VERSION (atoi (getvar "acadver"))) 16)
  5353. (strcat "ObjectDBX.AxDbDocument." (itoa VERSION))
  5354. )
  5355. )
  5356. ;;154.2 [功能] dwgdxf文件函数
  5357. ;;非打开文件
  5358. (defun Dwg2Dxf (DwgName dxfName / dbxDoc)
  5359. (setq dbxDoc (vla-GetInterfaceObject
  5360. (vlax-get-acad-object)
  5361. (GetObjectDBXVer)
  5362. )
  5363. )
  5364. (vla-open dbxDoc DwgName) ;不能打开.dxf文件
  5365. ;;(vla-import dbxDoc DwgName InsertPoint scalefactor);是不行的.
  5366. (vlax-invoke dbxDoc "dxfout" dxfName)
  5367. (if dbxDoc
  5368. (vlax-release-object dbxDoc)
  5369. ) ;关闭文档,用(vla-close dbxDoc :vlax-false)行不通?
  5370. )
  5371. ;;154.3 [功能] 将文件存为2K格式,并去教育版(文件名不变)
  5372. ;;非打开的文件
  5373. ;;(DwgOut "D:\\Drawing1.dwg")
  5374. (defun DwgOut (DwgName / BACKUPFILE BASENAME DOCOBJ DXFFILE FILEPATH)
  5375. ;;1 获取全路径,即路径后有
  5376. (defun GetFullPath (path)
  5377. (if (wcmatch path "*\\")
  5378. path
  5379. (strcat path "\\")
  5380. )
  5381. )
  5382. ;;2 能删除所有文件,不管只读、隐藏与否,都能删除
  5383. (defun DeleteFile (FIL / FILSYS FILDIR SS ENT)
  5384. (setq FILSYS (vlax-create-object "Scripting.FileSystemObject"))
  5385. (setq FILDIR (vl-filename-directory FIL))
  5386. (setq
  5387. SS (vl-directory-files
  5388. FILDIR
  5389. (strcat (vl-filename-base FIL) (vl-filename-extension FIL))
  5390. 1
  5391. )
  5392. )
  5393. (foreach ENT SS
  5394. (vlax-invoke
  5395. FILSYS
  5396. "deletefile"
  5397. (strcat FILDIR "\\" ENT)
  5398. :vlax-false
  5399. )
  5400. )
  5401. (vlax-release-object FILSYS)
  5402. )
  5403. ;;3 本程序主程序:1转成dxf 2原文件改名为备份 3打开另存为2K 4删除dxf
  5404. (setq BaseName (vl-filename-base DwgName)
  5405. filepath (vl-filename-directory DwgName)
  5406. dxfFile (vl-string-subst ".dxf" ".dwg" DwgName)
  5407. BackupFile (strcat (getfullpath filepath)
  5408. BaseName
  5409. "_Backup"
  5410. (vl-filename-extension DwgName)
  5411. )
  5412. )
  5413. (Dwg2Dxf DwgName dxfFile) ;利用objectdbx转存文件,目的是去教育版印戳
  5414. (if (findfile BackupFile)
  5415. (deletefile BackupFile)
  5416. ) ;检查原dwg文件的备份文件名是否存在,如果存在,则删除
  5417. (if (vl-file-rename DwgName BackupFile) ;修改原dwg文件名
  5418. (progn
  5419. (setq
  5420. DocObj (vla-open (vla-get-documents (vlax-get-acad-object))
  5421. dxfFile
  5422. )
  5423. ) ;打开dxf文件
  5424. (vla-saveas DocObj DwgName acR15_DWG) ;再存为2kdwg文件
  5425. (vla-close DocObj :vlax-false)
  5426. (deletefile dxfFile) ;删除dxf文件
  5427. )
  5428. )
  5429. (princ)
  5430. )
  5431. ;;154.4 [功能] 将文件以Wblock输出,并去教育版(文件名不变)
  5432. ;;非打开的文件
  5433. ;;示例 (DwgOutWblock "D:\\Drawing1.dwg")
  5434. (defun DwgOutWblock
  5435. (DwgName / BACKUPFILE BASENAME
  5436. DOCOBJ DXFFILE FILEPATH NEWSET
  5437. SSETS
  5438. )
  5439. ;;1 获取全路径,即路径后有
  5440. (defun GetFullPath (path)
  5441. (if (wcmatch path "*\\")
  5442. path
  5443. (strcat path "\\")
  5444. )
  5445. )
  5446. ;;2 能删除所有文件,不管只读、隐藏与否,都能删除
  5447. (defun DeleteFile (FIL / FILSYS FILDIR SS ENT)
  5448. (setq FILSYS (vlax-create-object "Scripting.FileSystemObject"))
  5449. (setq FILDIR (vl-filename-directory FIL))
  5450. (setq
  5451. SS (vl-directory-files
  5452. FILDIR
  5453. (strcat (vl-filename-base FIL) (vl-filename-extension FIL))
  5454. 1
  5455. )
  5456. )
  5457. (foreach ENT SS
  5458. (vlax-invoke
  5459. FILSYS
  5460. "deletefile"
  5461. (strcat FILDIR "\\" ENT)
  5462. :vlax-false
  5463. )
  5464. )
  5465. (vlax-release-object FILSYS)
  5466. )
  5467. ;;3 本程序主程序:1转成dxf 2原文件改名为备份 3打开并以wblock输出 4删除dxf
  5468. (setq BaseName (vl-filename-base DwgName)
  5469. filepath (vl-filename-directory DwgName)
  5470. dxfFile (vl-string-subst ".dxf" ".dwg" DwgName)
  5471. BackupFile (strcat (getfullpath filepath)
  5472. BaseName
  5473. "_Backup"
  5474. (vl-filename-extension DwgName)
  5475. )
  5476. )
  5477. (Dwg2Dxf DwgName dxfFile) ;利用objectdbx转存文件,目的是去教育版印戳
  5478. (if (findfile BackupFile)
  5479. (deletefile BackupFile)
  5480. ) ;检查原dwg文件的备份文件名是否存在,如果存在,则删除
  5481. (if (vl-file-rename DwgName BackupFile) ;修改原dwg文件名
  5482. (progn
  5483. (setq
  5484. DocObj (vla-open (vla-get-documents (vlax-get-acad-object))
  5485. dxfFile
  5486. )
  5487. ) ;打开dxf文件
  5488. (setq ssets (vla-get-selectionsets DocObj))
  5489. (if (vl-catch-all-error-p
  5490. (vl-catch-all-apply 'vla-item (list ssets "$Set"))
  5491. )
  5492. (setq newSet (vla-add ssets "$Set"))
  5493. (progn
  5494. (vla-delete (vla-item ssets "$Set"))
  5495. (setq newSet (vla-add ssets "$Set"))
  5496. )
  5497. )
  5498. ;;select all objects in the drawing
  5499. (vla-Select newSet acSelectionSetAll)
  5500. (vla-WBlock DocObj DwgName newSet)
  5501. (vla-close DocObj :vlax-false)
  5502. (deletefile dxfFile) ;删除dxf文件
  5503. )
  5504. )
  5505. (princ)
  5506. )
  5507. ;;154.5 [功能] 打开的文件以Wblock输出,并去教育版(除激活的文档外,文件名不变)
  5508. (defun DwgOutWblockOpen (/ *ACAD* *DOCS* BASENAME CUR DWGNAME DWGNAMEEXT DWGNAMELIST FILEPATH N NEWDWGNAME SSOBJ)
  5509. ;;1 获取全路径,即路径后有
  5510. (defun GetFullPath (path)
  5511. (if (wcmatch path "*\\")
  5512. path
  5513. (strcat path "\\")
  5514. )
  5515. )
  5516. (setq *ACAD* (vlax-get-acad-object)
  5517. *DOCS* (vla-get-Documents *ACAD*)
  5518. )
  5519. ;;2 打开的文件(除激活的文档外),全关闭,按非打开处理,再打开
  5520. ;;DwgNameList除激活的文档外的打开文件列表,并关闭
  5521. (vlax-for item *DOCS*
  5522. (if (= (vla-get-active item) :vlax-false)
  5523. (progn (setq DwgName (vlax-get-property item 'FullName))
  5524. (setq DwgNameList (cons DwgName DwgNameList))
  5525. (vla-close item :vlax-false)
  5526. )
  5527. (setq cur item)
  5528. )
  5529. )
  5530. (setq n -1)
  5531. (repeat (length DwgNameList)
  5532. (setq DwgName (nth (setq n (1+ n)) DwgNameList))
  5533. (DwgOutWblock DwgName)
  5534. (vla-open (vla-get-documents (vlax-get-acad-object)) DwgName) ;再打开
  5535. )
  5536. ;;3 激活的文档须更名输出
  5537. (setq DwgName (vlax-get-property cur 'FullName))
  5538. (setq BaseName (vl-filename-base DwgName))
  5539. (setq filepath (vl-filename-directory DwgName))
  5540. (setq DwgNameExt (vl-filename-extension DwgName))
  5541. (setq n -1)
  5542. (while (findfile (setq NewDwgName
  5543. (strcat (getfullpath filepath)
  5544. BaseName
  5545. (itoa (setq n (1+ n)))
  5546. DwgNameExt
  5547. )
  5548. )
  5549. )
  5550. )
  5551. (ssget "x" (list (cons 410 (getvar "ctab"))))
  5552. (setq SSOBJ (vla-get-activeselectionset cur))
  5553. (vla-wblock cur NewDwgName SSOBJ)
  5554. (DwgOutWblock NewDwgName)
  5555. (vla-open (vla-get-documents (vlax-get-acad-object)) NewDwgName)
  5556. (alert (strcat "\n 当前文档已经更名为" BaseName (itoa n)))
  5557. (command "vbastmt" "AcadApplication.activeDocument.close false ")
  5558. )
  5559. ;;154.6 [功能] 打开的文件全部Wblock输出
  5560. (defun OpenFileWblock (/ *ACAD* *DOCS* BASENAME DWGNAME DWGNAMEEXT EACH FILEPATH N NEWDWGNAME NEWSET SSETS J)
  5561. ;;1 获取全路径,即路径后有
  5562. (defun GetFullPath (path)
  5563. (if (wcmatch path "*\\")
  5564. path
  5565. (strcat path "\\")
  5566. )
  5567. )
  5568. ;;2 打开的文件更名输出
  5569. (setq *acad* (vlax-get-acad-object))
  5570. (setq *DOCS* (vla-get-Documents *ACAD*))
  5571. (setq n -1)
  5572. (repeat (vlax-get-Property *DOCS* 'count)
  5573. (setq each (vla-item *docs* (setq n (1+ n))))
  5574. (setq DwgName (vlax-get-Property each 'fullname))
  5575. (setq BaseName (vl-filename-base DwgName)
  5576. filepath (vl-filename-directory DwgName)
  5577. DwgNameExt (vl-filename-extension DwgName)
  5578. )
  5579. (setq J -1)
  5580. (while (findfile (setq NewDwgName
  5581. (strcat (getfullpath filepath)
  5582. BaseName
  5583. (itoa (setq J (1+ J)))
  5584. DwgNameExt
  5585. )
  5586. )
  5587. )
  5588. )
  5589. (setq ssets (vla-get-selectionsets each))
  5590. (if (vl-catch-all-error-p
  5591. (vl-catch-all-apply 'vla-item (list ssets "$Set"))
  5592. )
  5593. (setq newSet (vla-add ssets "$Set"))
  5594. (progn
  5595. (vla-delete (vla-item ssets "$Set"))
  5596. (setq newSet (vla-add ssets "$Set"))
  5597. )
  5598. )
  5599. ;;select all objects in the drawing
  5600. (vla-Select newSet acSelectionSetAll)
  5601. (vla-WBlock each NewDwgName newSet)
  5602. )
  5603. (princ)
  5604. )
  5605. ;;154.7 [功能] 复制非打开文件的块至本图
  5606. ;;(Odbx-copyblocks 文件名)
  5607. ;;(Odbx-copyblocks "D:\\DrawingA.dwg"),之后输入命令i,就可以看到DrawingA的块均在本图中了
  5608. (defun Odbx-copyblocks (DwgName / DBXBLOCKS DBXDOC NUM)
  5609. (setq dbxDoc (vla-GetInterfaceObject
  5610. (vlax-get-acad-object)
  5611. (GetObjectDBXVer)
  5612. )
  5613. )
  5614. (vla-open dbxDoc DwgName) ;不能打开.dxf文件,返回nil
  5615. (setq DBXBLOCKS (vla-get-blocks dbxDoc))
  5616. (vlax-for BLK DBXBLOCKS
  5617. (if (and (not (wcmatch (substr (vla-get-name BLK) 1 1) "`*"))
  5618. (= (vla-get-isxref BLK) :vlax-false)
  5619. ) ;去除系统块、匿名块和参照类对象
  5620. (setq namelst (append namelst (list (vla-get-name BLK))))
  5621. )
  5622. )
  5623. (foreach name namelst
  5624. (setq num (vla-item DBXBLOCKS name))
  5625. (vla-copyobjects
  5626. dbxDoc
  5627. (vlax-safearray-fill
  5628. (vlax-make-safearray vlax-vbobject '(0 . 0))
  5629. (list num)
  5630. )
  5631. (vla-get-modelspace
  5632. (vla-get-activedocument (vlax-get-acad-object))
  5633. )
  5634. )
  5635. )
  5636. (if dbxDoc
  5637. (vlax-release-object dbxDoc)
  5638. )
  5639. )
  5640. ;;154.8 [功能] 复制非打开文件的特定块至本图
  5641. ;;示例(CopyBlock "D:\\DrawingA.dwg" "ccd1"),之后输入命令i,就可以看到DrawingA的"ccd1"块在本图中了
  5642. ;; COPYBLOCK.LSP Copyright ?999 Tony Tanzillo
  5643. ;; http://www.caddzone.com
  5644. ;; tony.tanzillo@caddzone.com
  5645. (defun CopyBlock (DwgName BlkName / *ACAD* BLOCKS DBXDOC NUM)
  5646. (setq *acad* (vlax-get-acad-object))
  5647. (setq blocks (vla-get-blocks (vla-get-ActiveDocument *acad*)))
  5648. (setq dbxDoc (vla-GetInterfaceObject *acad* (GetObjectDBXVer)))
  5649. (vla-open dbxDoc DwgName)
  5650. (setq num (vla-item (vla-get-blocks dbxDoc) BlkName))
  5651. (vla-CopyObjects
  5652. dbxDoc
  5653. (vlax-safearray-fill
  5654. (vlax-make-safearray
  5655. vlax-vbObject
  5656. '(0 . 0)
  5657. )
  5658. (list num)
  5659. )
  5660. blocks
  5661. )
  5662. (vlax-release-object dbxDoc)
  5663. (vla-item blocks BlkName)
  5664. )
  5665. ;;154.9 [功能] 复制特定文件的块至本图(不论打开或者非打开)
  5666. ;;本程序将选择一个文件,然后将其下的块均拷贝到本图中,用命令i就可以插入这些块了
  5667. (defun B2CurDrawing (/ *ACAD* *DOC* *DOCS* FNAME FULLNAME LST)
  5668. (defun Open-copyblocks (fname / BLOCKS DOC DOCBLOCKS NAMELST NUM)
  5669. (setq blocks (vla-get-blocks *DOC*))
  5670. (setq Doc (vla-item *DOCS*
  5671. (strcat (vl-filename-base fname)
  5672. (vl-filename-extension fname)
  5673. )
  5674. )
  5675. )
  5676. (setq DocBLOCKS (vla-get-blocks Doc))
  5677. (vlax-for BLK DocBLOCKS
  5678. (if (and (not (wcmatch (substr (vla-get-name BLK) 1 1) "`*"))
  5679. (= (vla-get-isxref BLK) :vlax-false)
  5680. ) ;去除系统块、匿名块和参照类对象
  5681. (setq namelst (append namelst (list (vla-get-name BLK))))
  5682. )
  5683. )
  5684. (foreach name namelst
  5685. (setq num (vla-item DocBLOCKS name))
  5686. (vla-CopyObjects
  5687. Doc
  5688. (vlax-safearray-fill
  5689. (vlax-make-safearray
  5690. vlax-vbObject
  5691. '(0 . 0)
  5692. )
  5693. (list num)
  5694. )
  5695. blocks
  5696. )
  5697. )
  5698. (vlax-release-object doc)
  5699. )
  5700. (setq *ACAD* (vlax-get-acad-object)
  5701. *DOC* (vla-get-ActiveDocument *acad*)
  5702. *DOCS* (vla-get-Documents *ACAD*)
  5703. )
  5704. ;;(setq fullname (vla-get-fullname *DOC*))
  5705. ;;打开文件列表
  5706. (vlax-for doc *DOCS*
  5707. (setq
  5708. lst (cons (if (/= (setq fname (vla-get-fullname doc)) "")
  5709. fname
  5710. (vla-get-name doc)
  5711. )
  5712. lst
  5713. )
  5714. )
  5715. )
  5716. (setq fname (getfiled "选择DWG文件"
  5717. (getvar "DWGPREFIX")
  5718. "DWG"
  5719. 0
  5720. )
  5721. )
  5722. ;;(VL-FILE-SYSTIME fname);打开的文件返回nil,这个方法太好了
  5723. ;;(vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list *DOCS* fname)))
  5724. (cond ((and fname (member fname lst) (not (equal fullname fname)))
  5725. (Open-copyblocks fname)
  5726. )
  5727. ((and fname (not (member fname lst)))
  5728. (Odbx-copyblocks fname)
  5729. )
  5730. (T nil)
  5731. )
  5732. (princ)
  5733. )
  5734. ;;155 [功能] 统计组定义个数--lxx.2004.2
  5735. (defun c:countgp ()
  5736. (vla-get-count (vla-get-groups (vla-get-activedocument(vlax-get-acad-object))))
  5737. )
  5738. ;;155.1.1 [功能] 炸开所有组
  5739. (defun c:delgps ()
  5740. (vlax-for obj (vla-get-groups (vla-get-activedocument(vlax-get-acad-object)))
  5741. (vla-delete obj)
  5742. )
  5743. )
  5744. ;;155.1.2 [功能] 分解组
  5745. (defun bns_groups_unsel (/ na e1 a n lst lst2 lst3)
  5746. (defun m_assoc (a lst / b lst2)
  5747. (while (setq b (assoc a lst))
  5748. (setq lst (cdr (member b lst))
  5749. lst2 (append lst2 (list b))
  5750. )
  5751. )
  5752. lst2
  5753. )
  5754. (setq lst (dictsearch (namedobjdict) "ACAD_GROUP"))
  5755. (setq lst2 (m_assoc 3 lst))
  5756. (repeat (setq n (length lst2))
  5757. (setq a (nth (setq n (1- n )) lst2))
  5758. (setq na (cdr (car (cdr (member a lst)))))
  5759. (setq e1 (entget na))
  5760. (if (member '(71 . 1) e1)
  5761. (progn
  5762. ;;(command "_.-group" "_sel" (cdr a) "_y")
  5763. (setq e1 (subst '(71 . 0) '(71 . 1) e1))
  5764. (entmod e1)
  5765. (setq lst3 (append lst3 (list na)))
  5766. )
  5767. )
  5768. )
  5769. lst3
  5770. )
  5771. ;;155.1.3 [功能] 重组分解组
  5772. ;;(setq lst (bns_groups_unsel))(bns_groups_sel lst)
  5773. (defun bns_groups_sel (lst / n na e1)
  5774. (repeat (setq n (length lst))
  5775. (setq na (nth (setq n (1- n)) lst)
  5776. e1 (entget na)
  5777. )
  5778. (setq e1 (subst '(71 . 1) '(71 . 0) e1))
  5779. (entmod e1)
  5780. )
  5781. )
  5782. ;;155.1.4 删除匿名组(并不删除组对象) lxx.2005.10.
  5783. (defun c:del*gp ()
  5784. (vlax-for obj (vla-get-groups (vla-get-activedocument(vlax-get-acad-object)))
  5785. (if (wcmatch (vla-get-name obj)"'**")(vla-delete obj))
  5786. )
  5787. )
  5788. ;;155.1.5 [功能] 删除空组及数量为1的组定义(并不删除组对象) By lxx.2005.10改.
  5789. (defun c:delgp0 ()
  5790. (vlax-for obj (vla-get-groups (vla-get-activedocument(vlax-get-acad-object)))
  5791. (if (< (vla-get-count obj)2)(vla-delete obj))
  5792. )
  5793. )
  5794. ;;155.2 [功能] 组定义添加实体.
  5795. (defun GroupAdd (/ B G)
  5796. (if (and (setq g (car (entsel "\n 击要添加对象的组:")))
  5797. (setq b (cons 340 (car (entsel "\n 添加到组的对象:"))))
  5798. )
  5799. (progn (setq g (gpdef1 G))
  5800. (entmod (append g (list b)))
  5801. )
  5802. )
  5803. (princ)
  5804. )
  5805. ;;155.3.1 [功能] 所有组列表
  5806. (defun c:listgps ()
  5807. (vlax-for obj (vla-get-groups
  5808. (vla-get-activedocument (vlax-get-acad-object))
  5809. )
  5810. ;;(setq gphd (append gphd (list (vla-get-handle obj))))
  5811. (print (entget (handent (vla-get-handle obj))))
  5812. )
  5813. ;;(mapcar '(lambda (x) (print (entget (handent x))) (print)) gphd)
  5814. (princ)
  5815. )
  5816. ;;155.3.2 [功能] 所有可选择的组名列表
  5817. ;;组可选标志: dxf70 =3?
  5818. (defun c:gpsel1 (/ gps)
  5819. (vlax-for obj (vla-get-groups
  5820. (vla-get-activedocument (vlax-get-acad-object))
  5821. )
  5822. (if ;;(/= 3 (cdr (assoc 70 (entget (vlax-vla-object->ename obj)))))
  5823. (/= 3
  5824. (cdr (assoc 70 (entget (handent (vla-get-handle obj)))))
  5825. )
  5826. (setq gps (append gps (list (vla-get-name obj))))
  5827. )
  5828. )
  5829. gps
  5830. )
  5831. ;;155.3.3 [功能] 求所有组名列表
  5832. (defun c:gpsel2 (/ LST)
  5833. (setq lst (dictsearch (namedobjdict) "ACAD_GROUP"))
  5834. (mapcar 'cdr
  5835. (vl-remove-if '(lambda (x) (/= 3 (car x))) lst)
  5836. )
  5837. )
  5838. ;;155.4.1 [功能] 求组定义(一重的组)
  5839. ;;测试: (gpdef1 (car(entsel)))
  5840. (defun gpdef1 (gpe)
  5841. (entget(cdr(assoc 330 (entget gpe))))
  5842. )
  5843. ;;155.4.2 [功能] 求组内实体(一重的组)
  5844. ;;测试:返回-> (<图元名: 7ef7ceb0> <图元名: 7ef7ceb8> <图元名: 7ef7cea8>)
  5845. (defun C:GetGroupEntity ()
  5846. (mapcar 'cdr
  5847. (vl-remove-if
  5848. '(lambda (x) (/= 340 (car x)))
  5849. (gpdef1 (car (entsel)))
  5850. )
  5851. )
  5852. )
  5853. ;;155.4.3 [功能] 求组名(一重的组)
  5854. (defun C:GroupName1 (/ GPDEFL GPDICT GPNAME)
  5855. (setq gpdefl (gpdef1 (car (entsel))))
  5856. (setq gpdict (entget (cdr (assoc 330 gpdefl))))
  5857. (setq gpname (cdadr (member (cons 350 (cdr (assoc -1 gpdefl)))
  5858. (reverse gpdict)
  5859. )
  5860. )
  5861. )
  5862. )
  5863. ;;155.5.1 [功能] 求组定义列表 -> (组定义1 组定义2 ...):
  5864. ;;测试: (gpdef (car(entsel)))
  5865. (defun gpdef (gpe / el lst a gpdf gplst)
  5866. (setq el (entget gpe))
  5867. (if (setq lst (member '(102 . "{ACAD_REACTORS") el))
  5868. (while (and (setq lst (cdr lst)) (= 330 (car (setq a (car lst)))))
  5869. (if (= "GROUP" (cdr (assoc 0 (setq gpdf (entget (cdr a))))))
  5870. (setq gplst (cons gpdf gplst))
  5871. )
  5872. )
  5873. )
  5874. (reverse gplst)
  5875. )
  5876. ;;155.5.2 [功能] 求组内实体: 求组信息-----lxx.2004.5
  5877. ;;示例:(getgp (car(entsel)))=>(("G3" <Entity name: 7ef7bd90> (<Entity name: 7ef7b500> <Entity name: 7ef7b378>)) ("G4" <Entity name: 7ef7bd98> (<Entity name: 7ef7b500><Entity name: 7ef7b378> <Entity name: 7ef7acd0>)))
  5878. (defun getgp (gpe / GPDICT GPELST GPENT GPNAME X)
  5879. (mapcar '(lambda (x)
  5880. (setq gpent (cdr (assoc -1 x))
  5881. gpelst (mapcar 'cdr
  5882. (vl-remove-if '(lambda (x) (/= 340 (car x))) x)
  5883. )
  5884. gpdict (entget (cdr (assoc 330 x)))
  5885. gpname (cdadr (member (cons 350 gpent) (reverse gpdict)))
  5886. )
  5887. (list gpname gpent gpelst)
  5888. )
  5889. (gpdef gpe)
  5890. )
  5891. )
  5892. ;;155.5.3 [功能] 取得组名列表:
  5893. ;; (gpn1 (car(entsel))) -> ("X1" "X2" "TT")
  5894. (defun gpn1 (gpe / el lst a gpdf gps gpname gpnlst)
  5895. (setq el (entget gpe))
  5896. (if (setq lst (member '(102 . "{ACAD_REACTORS") el))
  5897. (while (and (setq lst (cdr lst)) (= 330 (car (setq a (car lst)))))
  5898. (if (= "GROUP" (cdr (assoc 0 (setq gpdf (entget (cdr a))))))
  5899. (setq gps (if gps
  5900. gps
  5901. (entget (cdr (assoc 330 gpdf)))
  5902. )
  5903. gpname (cdadr (member (cons 350 (cdr (assoc -1 gpdf)))
  5904. (reverse gps)
  5905. )
  5906. )
  5907. gpnlst (cons gpname gpnlst)
  5908. )
  5909. )
  5910. )
  5911. )
  5912. (reverse gpnlst)
  5913. )
  5914. ;;155.5.4 [功能] 取得组名列表:
  5915. ;; (gpn2 (car(entsel))) -> ("X1" "X2" "TT")
  5916. (defun gpn2 (gpe / el lst a g gpnlst)
  5917. (setq el (entget gpe))
  5918. (if (setq lst (member '(102 . "{ACAD_REACTORS") el))
  5919. (while (and (setq lst (cdr lst)) (= 330 (car (setq a (car lst)))))
  5920. (if (= "GROUP" (cdr (assoc 0 (entget (setq g (cdr a))))))
  5921. ;;(= "AcDbGroup" (vla-get-objectName (setq gobj (vlax-ename->vla-object (cdr a)))))
  5922. (setq gpnlst (cons (vla-get-Name (vlax-ename->vla-object g)) gpnlst))
  5923. )
  5924. )
  5925. )
  5926. (reverse gpnlst)
  5927. )
  5928. ;;155.5.5 [功能] 取得组名列表:
  5929. (defun gpn3 (/ doc theobj grp obj kj ip)
  5930. (setq doc (vla-get-Activedocument (vlax-get-acad-object)))
  5931. (vla-getentity
  5932. (vla-get-utility doc)
  5933. 'theobj
  5934. 'ip
  5935. "\nSelect Object: "
  5936. )
  5937. (vlax-for grp (vla-get-groups doc)
  5938. (vlax-for obj grp
  5939. (if (equal (vla-get-objectid obj) (vla-get-objectid theobj))
  5940. (setq kj (cons (vla-get-name grp) kj))
  5941. )
  5942. )
  5943. )
  5944. kj
  5945. )
  5946. ;;155.5.6 [功能] 取得组名列表:
  5947. ;;(gpn4 (car(entsel)))
  5948. (defun gpn4 (e / g)
  5949. ;;获取实体的永久反应器 --- by eachy
  5950. ;;(get_object_reactor (car(entsel))),同(acet-acadreactor-ids-get (car (entsel)))-by lucas
  5951. (defun get_object_reactor (e / elst lst etlst)
  5952. (setq elst (entget e))
  5953. (if (and (assoc 102 elst)
  5954. (= (cdr (assoc 102 elst)) "{ACAD_REACTORS")
  5955. )
  5956. (progn
  5957. (setq lst (cdr (member '(102 . "{ACAD_REACTORS") elst)))
  5958. (while (= (caar lst) 330)
  5959. (setq etlst (cons (cdar lst) etlst))
  5960. (setq lst (cdr lst))
  5961. )
  5962. )
  5963. )
  5964. etlst
  5965. )
  5966. (setq lst (get_object_reactor e))
  5967. (foreach item (mapcar 'vlax-ename->vla-object lst)
  5968. (if (= (vla-get-objectname item) "AcDbGroup")
  5969. (setq g (cons (vla-get-name item) g))
  5970. )
  5971. )
  5972. g
  5973. )
  5974. ;;155.5.7 [功能] 取得组名列表: --by 灯火
  5975. ;;(gpn5 (car(entsel)))
  5976. (defun gpn5 (eName / DXF102 ELIST EN ET GPNAME OBJGROPU)
  5977. (setq dxf102 (assoc 102 (entget eName)))
  5978. (if (and dxf102 (= (cdr dxf102) "{ACAD_REACTORS"))
  5979. (progn
  5980. (setq
  5981. eList (cdr (member '(102 . "{ACAD_REACTORS") (entget eName)))
  5982. )
  5983. (while (= (caar eList) 330)
  5984. (setq en (cdar eList))
  5985. (setq et (cdr (assoc 0 (entget en))))
  5986. (if (= et "GROUP")
  5987. (progn
  5988. (setq objGropu (vlax-ename->vla-object en))
  5989. (setq gpName (cons (vla-get-Name objGropu) gpName))
  5990. )
  5991. )
  5992. (setq eList (cdr eList))
  5993. )
  5994. )
  5995. )
  5996. gpName
  5997. )
  5998. ;;155.5.8 [功能] 取得组名列表: --by 灯火
  5999. ;;(gpn6 (car(entsel)))
  6000. (defun gpn6 (ename / key dct rtn)
  6001. (setq key (cons 340 ename)
  6002. dct (dictsearch (namedobjdict) "acad_group")
  6003. )
  6004. (while (setq dct (member (assoc 3 dct) dct))
  6005. (if (member key (entget (cdadr dct)))
  6006. (setq rtn (cons (cdar dct) rtn))
  6007. )
  6008. (setq dct (cddr dct))
  6009. )
  6010. (reverse rtn)
  6011. )
  6012. ;;155.5.9 [功能] 取得组名列表: --by 灯火
  6013. ;;(gpn7 (car(entsel)))
  6014. (defun gpn7 (Obj / Cur_ID NmeLst)
  6015. (setq Gb:AcO (cond (Gb:AcO)
  6016. (T (vlax-get-acad-object))
  6017. )
  6018. Gb:AcD (cond (Gb:AcD)
  6019. (T (vla-get-activedocument Gb:AcO))
  6020. )
  6021. Cur_ID (vla-get-ObjectID (vlax-ename->vla-object Obj))
  6022. )
  6023. (vlax-for Grp (vla-get-Groups Gb:AcD)
  6024. (vlax-for Ent Grp
  6025. (if (equal (vla-get-ObjectID Ent) Cur_ID)
  6026. (setq NmeLst (cons (vla-get-Name Grp) NmeLst))
  6027. )
  6028. )
  6029. )
  6030. (reverse NmeLst)
  6031. )
  6032. ;;155.6. [功能] 生成无名组
  6033. ;;示例(acet-group-make-anon (list WIPOUT TXT) "In use by TEXTMASK")
  6034. (defun acet-group-make-anon (LST DESC / EN)
  6035. (command "_.-group" "_create" "*" DESC)
  6036. (foreach EN LST (command EN))
  6037. (command "")
  6038. )
  6039. ;;156.1 [功能] 删除重叠对象(overkill)
  6040. ;;不知谁写的,太好了.
  6041. (DEFUN HH:delBLOCKs (ss / E EN K LIST1 S9 XY)
  6042. (repeat (setq k (sslength ss))
  6043. (if (and (setq e (ssname ss (setq k (1- k))))
  6044. (setq en (entget e))
  6045. )
  6046. (progn
  6047. (setq xy (cdr en))
  6048. (IF (SETQ S9 (ASSOC 5 XY))
  6049. (SETQ XY (subst '(5 . "ASD") S9 XY))
  6050. )
  6051. (if (member xy list1)
  6052. (entdel e)
  6053. (setq list1 (cons xy list1))
  6054. )
  6055. )
  6056. )
  6057. )
  6058. )
  6059. ;;156.2 [功能] 删除重叠数字,保留较大的数或保留较小的数---Gu_xl
  6060. (defun c:delWords (/ kd e ll ur n s1 L SS)
  6061. (initget "Big Small")
  6062. (setq kd (getkword "\n[留大数Big/留小数Small]<Big>:"))
  6063. (if (= "Small" kd)
  6064. (setq kd <)
  6065. (setq kd >)
  6066. )
  6067. (while (setq ss (ssget ":S" '((0 . "*text"))))
  6068. (while (> (sslength ss) 0)
  6069. (setq e (ssname ss 0))
  6070. (vla-GetBoundingBox (vlax-ename->vla-object e) 'll 'ur)
  6071. (setq ll (vlax-safearray->list ll)
  6072. ur (vlax-safearray->list ur)
  6073. )
  6074. (setq s1 (ssget "c"
  6075. (trans ll 0 1)
  6076. (trans ur 0 1)
  6077. '((0 . "*text"))
  6078. )
  6079. l nil
  6080. )
  6081. (repeat (setq n (sslength s1))
  6082. (setq l (cons (ssname s1 (setq n (1- n))) l))
  6083. )
  6084. (setq l (vl-sort l
  6085. '(lambda (a b)
  6086. (kd (atof (cdr (assoc 1 (entget a))))
  6087. (atof (cdr (assoc 1 (entget b))))
  6088. )
  6089. )
  6090. )
  6091. )
  6092. (ssdel (car l) ss)
  6093. (foreach a (cdr l)
  6094. (ssdel a ss)
  6095. (entdel a)
  6096. )
  6097. )
  6098. )
  6099. (princ)
  6100. )
  6101. ;;157 [功能] 曲线取点函数(用于封闭曲线内局部放大或者删除其内图元时)
  6102. ;;示例(ssget "WP" (Object-Plst (car (entsel))) '((0 . "*TEXT,DIMENSION")))
  6103. (defun Object-Plst (EntCicl / END I LEN LINEOBJ NUM PLST PT START)
  6104. (setq lineObj (vlax-ename->vla-object EntCicl)
  6105. start (vlax-curve-getStartParam lineObj)
  6106. end (vlax-curve-getEndParam lineObj)
  6107. )
  6108. (setq num 100 ;取100点
  6109. i -1
  6110. )
  6111. (setq len (/ (- end start) num))
  6112. (while (< i num)
  6113. (setq i (1+ i))
  6114. (setq pt (vlax-curve-getPointAtParam lineObj (* i len)))
  6115. (setq plst (append plst (list pt)))
  6116. )
  6117. plst
  6118. )
  6119. ;;158 [功能] ENTSEL函数功能扩展 caoyin
  6120. ;; MSG:和ENTSEL一样,为用于提示用户的字符串,当该参数为nil时,缺省提示信息为“选择对象: ”。
  6121. ;; FIL:图元dxf特性过滤器,和ssget函数相同。
  6122. ;; ERRMAG:出错提示信息,在选择目标不符合条件时在命令行打印。当该参数为nil时,缺省提示信息为"无效的对象。"。
  6123. (defun MC:ENTSEL1 (MSG FIL ERRMSG / E PF SS RT ERR)
  6124. (setq E T
  6125. PF (getvar 'PICKFIRST)
  6126. )
  6127. (or ERRMSG (setq ERRMSG "无效的对象。"))
  6128. (setvar 'PICKFIRST 1)
  6129. (while E
  6130. ;;用apply的目的在于当entsel后面的参数为nil时不会出错。
  6131. (if (setq E (apply 'entsel (cond (MSG (list MSG)))))
  6132. (cond
  6133. ((vl-consp E)
  6134. ;;后面的ssadd是建立一个空选择集,前面的ssadd是向该空选择集中添加entsel所拾取的图元。
  6135. (setq SS (ssadd (car E) (ssadd)))
  6136. ;;将选择集SS设为已选择状态
  6137. (sssetfirst nil SS)
  6138. (setvar "nomutt" 1)
  6139. ;;获取当前激活的选择集,而过滤器则保证从中筛选出符合条件的对象。
  6140. (if (setq SS (ssget "_I" FIL))
  6141. ;;当SS返回为真,则将变量E设为nil以结束while,反之则打印出错提示信息,并将变量E设为T以确保while继续执行。
  6142. (setq RT E
  6143. E nil
  6144. )
  6145. (progn (princ ERRMSG) (setq E T))
  6146. )
  6147. (setvar "nomutt" 0)
  6148. )
  6149. (T
  6150. (setq RT E
  6151. E nil
  6152. )
  6153. )
  6154. )
  6155. ;;当ERRNO返回7,表明用户鼠标的拾取点上没有对象,变量E设为T确保while继续。若ERRNO返回52则表明用户右击鼠标放弃选择。
  6156. (cond ((= (setq ERR (getvar 'ERRNO)) 7)
  6157. (setq E T)
  6158. (princ "未选择对象。")
  6159. )
  6160. ((= ERR 52) (setq E nil))
  6161. )
  6162. )
  6163. )
  6164. (setvar 'PICKFIRST PF)
  6165. RT
  6166. )
  6167. ;;159 [功能] 块爆破(属性转成文字)burst
  6168. (Defun C:HH:BURST2 (/ ENAME SS1)
  6169. ;;1 Item from association list
  6170. (Defun ITEM (N E) (CDR (Assoc N E)))
  6171. ;;2 Convert Attribute Entity to Text Entity
  6172. (Defun ATT-TEXT (AENT / TENT ILIST INUM)
  6173. (Setq TENT '((0 . "TEXT")))
  6174. (ForEach INUM
  6175. '(8 6 38 39 62 67 210 10 40 1 50 41 51 7 71 72 73 11 74)
  6176. (If (Setq ILIST (Assoc INUM AENT))
  6177. (Setq TENT (Cons ILIST TENT))
  6178. )
  6179. )
  6180. (Setq tent (Subst (Cons 73 (item 74 aent)) (Assoc 74 tent) tent))
  6181. (EntMake (Reverse TENT))
  6182. )
  6183. ;;3 BURST-ONE
  6184. (Defun BURST-ONE1
  6185. (BNAME / AENT AGAIN ANAME ATYPE BENT ENAME SS SS1 SS2)
  6186. (Setq BENT (EntGet BNAME))
  6187. (If (= 1 (ITEM 66 BENT)) ;如果是属性块
  6188. (Progn (Setq ANAME BNAME)
  6189. (While (Setq ANAME (EntNext ANAME)
  6190. AENT (EntGet ANAME)
  6191. ATYPE (ITEM 0 AENT)
  6192. AGAIN (= "ATTRIB" ATYPE)
  6193. )
  6194. (ATT-TEXT AENT)
  6195. )
  6196. )
  6197. )
  6198. (command "_.explode" bname)
  6199. (setq ss (ssget "_p"))
  6200. (setq ss2 (ssget "_p" '((0 . "ATTDEF"))))
  6201. (command "._Select" ss "")
  6202. (setq ss1 (ssget "_p" '((0 . "INSERT"))))
  6203. (if ss2
  6204. (command "_.erase" ss2 "")
  6205. )
  6206. (If SS1
  6207. (Progn
  6208. (Repeat (SsLength SS1)
  6209. (Setq ENAME (SsName SS1 0))
  6210. (SsDel ENAME SS1)
  6211. (BURST-ONE1 ENAME) ;递归
  6212. )
  6213. )
  6214. )
  6215. )
  6216. ;;4 主程序
  6217. (Setq SS1 (SsGet (list (cons 0 "INSERT"))))
  6218. (If SS1
  6219. (Progn (Setvar "highlight" 0)
  6220. (terpri)
  6221. (Repeat (SsLength SS1)
  6222. (Setq ENAME (SsName SS1 0))
  6223. (SsDel ENAME SS1)
  6224. (BURST-ONE1 ENAME)
  6225. )
  6226. (princ "\n ")
  6227. )
  6228. )
  6229. (princ)
  6230. )
  6231. ;;160.1 [功能] 获取指定文件夹(不包括子文件夹)下所有满足扩展名的文件
  6232. (defun GetFullPath (path)
  6233. (if (wcmatch path "*\\")
  6234. path
  6235. (strcat path "\\")
  6236. )
  6237. )
  6238. ;;返回列表文件表元素全为小写
  6239. ;;示例(GetAllSpecFilesInFolder "D:\\TEMP\\" "*.dwg")
  6240. (defun GetAllSpecFilesInFolder (dir filter)
  6241. (mapcar
  6242. (function
  6243. (lambda (file)
  6244. (strcase (strcat (getfullpath dir) file) T)
  6245. )
  6246. )
  6247. (vl-directory-files dir filter 1)
  6248. )
  6249. )
  6250. ;;160.2 [功能] 获取指定文件夹(包括子文件夹)下所有满足扩展名的文件
  6251. ;; 示例(GetAllSpecFilesInFolders "D:\\TEMP\\" "*.dwg")
  6252. (defun GetAllSpecFilesInFolders (dir filter / filenames)
  6253. (setq filenames (mapcar
  6254. (function
  6255. (lambda (file)
  6256. (strcase (strcat (getfullpath dir) file) T)
  6257. ;;递归出口
  6258. )
  6259. )
  6260. (vl-directory-files dir filter 1)
  6261. )
  6262. )
  6263. (mapcar
  6264. (function
  6265. (lambda (subdir)
  6266. ;; 此处递归
  6267. (setq filenames (append filenames
  6268. (GetAllSpecFilesInFolders
  6269. (strcat (getfullpath dir) subdir)
  6270. filter
  6271. )
  6272. )
  6273. )
  6274. )
  6275. )
  6276. (vl-remove-if
  6277. (function (lambda (subdir)
  6278. (member subdir '("." ".."))
  6279. )
  6280. )
  6281. (vl-directory-files dir nil -1)
  6282. )
  6283. )
  6284. filenames
  6285. )
  6286. ;;161.1 [功能] 选择集->VlaSS集合
  6287. ;;(vlax-map-Collection (ss->vlass ss) 'vla-delete)
  6288. (defun ss->vlass (ss)
  6289. (command "_.select" ss "")
  6290. (vla-get-activeselectionset
  6291. (vla-get-ActiveDocument (vlax-get-acad-object))
  6292. )
  6293. )
  6294. ;; 161.2 [功能]将一个选择集转化为VLA集合 by裸奔的花猫
  6295. (defun ss->vlass (ss / DOC I KJ SSET NSET VLA)
  6296. (setq doc (vla-get-activedocument (vlax-get-acad-object))
  6297. sset (vla-get-selectionsets doc)
  6298. )
  6299. ;;有选择集$Set,则先删除,或者(vla-Clear $Set);清空$Set
  6300. (if (vl-catch-all-error-p
  6301. (vl-catch-all-apply 'vla-item (list sset "$Set"))
  6302. )
  6303. nil
  6304. (vla-delete (vla-item sset "$Set"))
  6305. )
  6306. (setq nset (vla-add sset "$Set")) ;新建一个VLA选择集
  6307. ;;得到VLA物体列表
  6308. (repeat (setq i (sslength ss))
  6309. (setq vla (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
  6310. (setq kj (cons vla kj))
  6311. )
  6312. (vlax-invoke nset 'additems kj)
  6313. nset
  6314. )

164 [功能] 关于多段线-自贡黄明儒

164.1 [功能] 曲线是否封闭

;;164.1 [功能] 曲线是否封闭
;;示例(HH:isClosed (car (entsel)))
(defun HH:isClosed (obj)
  (or (vlax-curve-isclosed e)
      (equal (vlax-curve-getstartpoint e)
         (vlax-curve-getendpoint e)
         1e-5
      )
  )
)

164.2 [功能]使多段线封闭

;;164.2 [功能]使多段线封闭
(defun HH:MakeClosed (en / OBJ)
  (cond    ((equal (type en) 'ENAME) (setq obj (vlax-ename->vla-object en)))
    (T (setq obj en))
  )
  ;;(if (equal (vlax-get obj 'Closed) 0) (vlax-put obj 'Closed -1))
  (if (not (vlax-curve-isclosed obj))                ;(equal (vlax-get-property obj 'closed) :vlax-false)
    (vla-put-closed obj :vlax-true)
  )
)

164.3 [功能] 多段线端点列表

;;164.3 [功能] 多段线端点列表
;;示例(HH:PtLists (car (entsel)))
(defun HH:PtLists (en)
  (mapcar 'cdr
      (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget en))
  )
)

164.4 [功能] 矩形中点坐标

;;164.4 [功能] 矩形中点坐标
;;示例(HH:RectangCen (car (entsel)))
(defun HH:RectangCen (en / PL X Y)
  (setq pl (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget en)))
  (setq pl (mapcar 'cdr pl))
  (mapcar '(lambda (X Y) (* (+ X Y) 0.5)) (car pl) (caddr pl))
)
;;示例(HH:RectangCen1 (car (entsel)))
(defun HH:RectangCen1 (en / OBJ PL PL1 X Y)
  (setq obj (vlax-ename->vla-object en))
  (setq pl (vlax-safearray->list (vlax-variant-value (vla-get-coordinates obj))))
  (setq pl1 (cddddr pl))
  (mapcar '(lambda (X Y) (/ (+ X Y) 2.0))
      (list (car pl) (cadr pl))
      (list (car pl1) (cadr pl1))
  )
)

164.5 [功能] 参数param处的切线方向的角度

;;164.5 [功能] 参数param处的切线方向的角度
;;示例(HH:ParamFirstAngle (car (entsel)) 1)
;;注1 (vlax-curve-getFirstDeriv obj param) 函数计算的值是曲线上在参数值为param点处的切线方向
;;注2 param起始值为0
(defun HH:ParamFirstAngle (obj param)
  (setq pt (vlax-curve-getpointatparam obj param))
  (angle pt (mapcar '+ pt (vlax-curve-getFirstDeriv obj param)))
)

164.6 [功能] 参数param处的法线方向的角度

;;164.6 [功能] 参数param处的法线方向的角度
;;示例(HH:ParamSecondAngle (car (entsel)) 1)
;;注:param处是直线,则返回0.0
(defun HH:ParamSecondAngle (obj param)
  (setq pt (vlax-curve-getpointatparam obj param))
  (angle pt (mapcar '+ pt (vlax-curve-getSecondDeriv obj param)))
)

164.7 [功能] 曲线一点的切线方向的角度

;;164.7 [功能] 曲线一点的切线方向的角度
;;示例(HH:PtFirstAngle (car (entsel)) (getpoint))
(defun HH:PtFirstAngle (obj pt)
  (setq param (vlax-curve-getParamAtPoint obj pt))
  (angle pt (mapcar '+ pt (vlax-curve-getFirstDeriv obj param)))
)

164.8 [功能] 曲线一点的法线方向的角度

;;164.8 [功能] 曲线一点的法线方向的角度
;;示例(HH:PtSecondAngle (car (entsel)) (getpoint))
(defun HH:PtSecondAngle    (obj pt)
  (setq param (vlax-curve-getParamAtPoint obj pt))
  (angle pt (mapcar '+ pt (vlax-curve-getSecondDeriv obj param)))
)

164.9 [功能] 去除多段线重点

;;164.9 [功能] 去除多段线重点
;;示例(HH:Remove (car (entsel)))
(defun HH:Remove (en / NEWDATA)
  (foreach e (entget en)
    (if    (and (member e newdata) (= 10 (car e)))
      nil
      (setq newdata (cons e newdata))
    )
  )
  (entmod (reverse newdata))
)

164.10 [功能] 判断点是否在曲线上

;;164.10 [功能] 判断点是否在曲线上
;;示例(HH:PtOnCurve (getpoint) (car (entsel)))
(defun HH:PtOnCurve (pt curve)
  (equal pt (vlax-curve-getClosestPointTo curve pt) 0.00001)
)

164.11 [功能] 曲线长度

;;164.11 [功能] 曲线长度
;;直线、圆弧、圆、多段线、优化多段线、样条曲线等图元
;;示例 (HH:GetCurveLength (car (entsel)))
(defun HH:GetCurveLength (curve)
  (vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve))
)

164.12 [功能] 多段线子段数量

;;164.12 [功能] 多段线子段数量
;;相当于组码90
;;示例 (HH:GetCurveNum (car (entsel)))
(defun HH:GetCurveNum (obj)
  (if (vlax-curve-isClosed obj)
    (fix (1- (vlax-curve-getendParam obj)))
    (fix (vlax-curve-getendParam obj))
  )
)

164.13 [功能] 曲线中点

;;164.13 [功能] 曲线中点
;;示例 (HH:GetMidpointCurve (car (entsel)))
(defun HH:GetMidpointCurve (curve / d)
  (setq d (vlax-curve-getEndParam curve));终点参数
  (setq d (* (vlax-curve-getDistAtParam curve d) 0.5))
  (vlax-curve-getPointAtDist curve d)
)

164.14 [功能] 曲线一点的参数param

;;164.14 [功能] 曲线一点的参数param
;;(HH:PtToParam (car (entsel)) (getpoint))
(defun HH:PtToParam (obj pt)
  (vlax-curve-getParamAtPoint obj pt)
)

164.15 [功能] 参数param处的坐标

;;164.15 [功能] 参数param处的坐标
;;(HH:ParamTopt (car (entsel)) 0)
(defun HH:ParamTopt (obj param)
  (vlax-curve-getPointAtParam obj param)
)

164.16 [功能] 多段线第n子段的起点坐标

;;164.16 [功能] 多段线第n子段的起点坐标
;;示例 (HH:GetSegStratPt (car (entsel)) 0)
(defun HH:GetSegStratPt    (curve n)
  (vlax-curve-getPointAtParam curve (fix n))
)

164.17 [功能] 多段线第n子段的终点坐标

;;164.17 [功能] 多段线第n子段的终点坐标
;;示例 (HH:GetSegEndPt (car (entsel)) 0)
(defun HH:GetSegEndPt (curve n)
  (vlax-curve-getPointAtParam curve (1+ (fix n)))
)

164.18 [功能] 多段线所点击子段的两端点列表

;;164.18 [功能] 多段线所点击子段的两端点列表
;;示例(HH:PickSegEndPt (car(setq en(entsel))) (cadr en))
(defun HH:PickSegEndPt (obj p / pp n)
  (setq    pp (vlax-curve-getclosestpointto obj (trans p 1 0))
    n  (fix (vlax-curve-getparamatpoint obj pp))
  )
  (list    (vlax-curve-getPointAtParam obj n)
    (vlax-curve-getPointAtParam obj (1+ n))
  )
)

164.19 [功能] 多段线所点击点最近的一个顶点

;;164.19 [功能] 多段线所点击点最近的一个顶点
;;示例(HH:PickClosePt (car(setq en(entsel))) (cadr en))
(defun HH:PickClosePt (obj p / N P1 P2 PP)
  (setq    pp (vlax-curve-getclosestpointto obj (trans p 1 0))
    n  (fix (vlax-curve-getparamatpoint obj pp))
  )
  (setq p1 (vlax-curve-getPointAtParam obj n))
  (setq p2 (vlax-curve-getPointAtParam obj (1+ n)))
  (if (< (distance pp p1) (distance pp p2))
    p1
    p2
  )
)

164.20 [功能] 多段线所点击子段param(索引)

;;164.20 [功能] 多段线所点击子段param(索引)
;;示例(HH:PickSegIndex (car(setq en(entsel))) (cadr en))
(defun HH:PickSegIndex (obj p / PP)
  (setq pp (vlax-curve-getclosestpointto obj (trans p 1 0)))
  (fix (vlax-curve-getparamatpoint obj pp))
)

164.21 [功能] 多段线所点击子段的起点坐标

;;164.21 [功能] 多段线所点击子段的起点坐标
;;示例(HH:PickSegStratPt (car(setq en(entsel))) (cadr en))
(defun HH:PickSegStratPt (obj p / pp n)
  (setq    pp (vlax-curve-getclosestpointto obj (trans p 1 0))
    n  (fix (vlax-curve-getparamatpoint obj pp))
  )
  (vlax-curve-getPointAtParam obj n)
)

164.22 [功能] 多段线所点击子段的终点坐标

;;164.22 [功能] 多段线所点击子段的终点坐标
;;示例(HH:PickSegEndPt (car(setq en(entsel))) (cadr en))
(defun HH:PickSegEndPt (obj p / pp n)
  (setq    pp (vlax-curve-getclosestpointto obj (trans p 1 0))
    n  (fix (vlax-curve-getparamatpoint obj pp))
  )
  (vlax-curve-getPointAtParam obj (1+ n))
)

164.23 [功能] 多段线所击点离起点近

;;164.23 [功能] 多段线所击点离起点近
;;示例(HH:PickToStart (car(setq en(entsel))) (cadr en))
(defun HH:PickToStart (curve p / L1 L2 PP)
  (setq pp (vlax-curve-getclosestpointto curve (trans p 1 0)))
  (setq L2 (vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve)))
  (setq L1 (vlax-curve-getDistAtPoint curve pp))
  (> (- L2 L1) L1)
)

164.24 [功能] 多段线所击子段是否是直线(返回nil是弧)

;;164.24 [功能] 多段线所击子段是否是直线(返回nil是弧)
;;示例(HH:PickArc (car(setq en(entsel))) (cadr en))
(defun HH:PickArc (curve p / PP)
  (setq pp (vlax-curve-getclosestpointto curve (trans p 1 0)))
  (setq    pp (vlax-curve-getSecondDeriv
         curve
         (fix (vlax-curve-getparamatpoint curve pp))
       )
  )
  (equal pp '(0.0 0.0 0.0))
)

164.25 [功能] 求多段线上的弧段(圆或圆弧也有效)的圆心 by caoyin

;;164.25 [功能] 求多段线上的弧段(圆或圆弧也有效)的圆心 by caoyin
;;(HH:GetCenter1 (entsel "\n选择多段线弧段: "))
(defun HH:GetCenter1 (EP / E P)
  (mapcar 'set '(E P) EP)
  (setq P (apply 'vlax-curve-getClosestPointTo EP))
  (mapcar '+
      P
      (vlax-curve-getsecondderiv
        E
        (vlax-curve-getParamAtPoint E P)
      )
  )
)

164.26 [功能] 求多段线上的弧段(圆或圆弧也有效)的圆心

;;164.26 [功能] 求多段线上的弧段(圆或圆弧也有效)的圆心
;;(HH:GetCenter2 (car(setq en(entsel))) (cadr en))
(defun HH:GetCenter2 (curve P / EP N PARAM PP SP)
  (setq pp (vlax-curve-getclosestpointto curve (trans p 1 0)))
  (setq Param (vlax-curve-getParamAtPoint curve pp))
  (setq n (fix Param))
  (setq sp (vlax-curve-getPointAtParam curve n))
  (setq Ep (vlax-curve-getPointAtParam curve (1+ n)))  
  (if (minusp (car (trans (mapcar '- pp Ep) 0 (mapcar '- Ep sp))))
   (mapcar '+ pp (vlax-curve-getsecondderiv curve Param))
   (mapcar '- pp (vlax-curve-getsecondderiv curve Param))
  )  
)

164.27 [功能] 判断多段线是否有圆弧(凸度/=0)的子段

;;164.27 [功能] 判断多段线是否有圆弧(凸度/=0)的子段
;;(HH:checkarc1 (car (entsel)))
(defun HH:checkarc1 (en / BU N OBJ PLIST)
  (setq obj (vlax-ename->vla-object en))
  (setq plist (vlax-safearray->list (vlax-variant-value (vla-get-coordinates obj))))
  (setq n 0)
  (repeat (/ (length plist) 2)
    (if    (/= (vla-getbulge obj n) 0)
      (setq bu T)
    )
    (setq n (+ n 1))
  )
  bu
)

164.28 [功能] 判断多段线是否有圆弧(凸度/=0)的子段

;;164.28 [功能] 判断多段线是否有圆弧(凸度/=0)的子段
;;(HH:checkarc2 (car (entsel)))
(defun HH:checkarc2 (en / G)
  (setq G (vl-remove-if-not '(lambda (x) (= (car x) 42)) (entget en)))
  (not (vl-every 'zerop (mapcar 'cdr G)))            ;(vl-remove 0.0 (mapcar 'cdr G))
)

164.29 [功能] 连接线、弧成多段线

;;164.29 [功能] 连接线、弧成多段线
;;(HH:JionToPolyline)
(defun HH:JionToPolyline (/ PET SS)
  (setq pet (getvar "PEDITACCEPT"))
  (setvar "PEDITACCEPT" 1)
  (while (setq ss (ssget '((0 . "ARC,*LINE"))))
    (command "_.pedit" (ssname ss 0) "j" ss "" "")
  )
  (setvar "PEDITACCEPT" pet)
  (princ)
)

164.30 [功能] 构造矩形 by highflybird

;;164.30 [功能] 构造矩形 by highflybird
(defun Make-Rectange (pt1 pt2)
  (entmake
    (list
      '(0 . "LWPOLYLINE")                    ;轻多段线
      '(100 . "AcDbEntity")
      '(100 . "AcDbPolyline")
      '(90 . 4)                            ;四个顶点
      '(70 . 1)                            ;闭合
      (cons 38 (caddr pt1))                    ;高程
      (cons 10 (list (car pt1) (cadr pt1)))            ;左下角
      (cons 10 (list (car pt2) (cadr pt1)))            ;右下角
      (cons 10 (list (car pt2) (cadr pt2)))            ;右上角
      (cons 10 (list (car pt1) (cadr pt2)))            ;左上角
      (cons 210 '(0 0 1))                    ;法线方向
    )
  )
)

164.31 [功能] 点表生成多段线

;;164.31 [功能] 点表生成多段线
(defun Make-LWPOLYLINE (lst / PT)
  (entmake (append (list '(0 . "LWPOLYLINE")
             '(100 . "AcDbEntity")
             '(100 . "AcDbPolyline")
             (cons 90 (length lst))
           )
           (mapcar '(lambda (pt) (cons 10 pt)) lst)
       )
  )
)

164.32 [功能] 画3d多段线 by highflybird

;;164.32 [功能] 画3d多段线 by highflybird
;; draw a closed 3d Polyline
(defun Make3dPoly (pts / e)
  (setq e (Entmake (list '(0 . "POLYLINE")'(70 . 9))))
  (foreach p Pts
    (entmake (list '(0 . "VERTEX") '(70 . 32) (cons 10 p)))
  )
  (entmake '((0 . "SEQEND")))
  (entlast)
)

164.33 [功能] 多段线反向(起点反成终点) byzml84

;;164.33 [功能] 多段线反向(起点反成终点) byzml84
;;(HH:LWPOLYLINEFX (car (entsel)))
(defun HH:LWPOLYLINEFX (EN / A B C D ENT LST LST1 TMP)
  (setq ENT (entget EN))
  (setq tmp ent)
  (while (setq tmp (member (assoc 10 tmp) tmp))
    (setq a   (assoc 10 tmp)
      b   (cons 40 (cdr (assoc 41 tmp)))
      c   (cons 41 (cdr (assoc 40 tmp)))
      d   (cons 42 (- (cdr (assoc 42 tmp))))
      LST (append (list b c d a) LST)
    )
    (setq tmp (cddddr tmp))
  )
  (repeat 3 (setq LST (append (cdr lst) (list (car lst)))))
  (setq lst1 (reverse (cdr (member (assoc 10 ent) (reverse ent)))))
  (entmod (append lst1 lst '((210 0 0 1))))
)

164.34 [功能] 多段线删除顶点

;;164.34 [功能] 多段线删除顶点
(defun HH:delLwpolyPt (/ EN ENT L1 L2 P P1 P2 P90 SS X Y)
  (setq p1 (getpoint))
  (setq p2 (getcorner p1))
  (if (setq ss (ssget "C" p1 p2 '((0 . "LWPOLYLINE"))))
    (progn
      (setq en (ssname ss 0))
      (setq ENT (entget EN))
      (if (> (setq P90 (cdr (assoc 90 ent))) 2)
    (progn
      (setq p (mapcar '(lambda (X Y) (/ (+ X Y) 2.0)) p1 p2))
      (setq p (vlax-curve-getclosestpointto en (trans p 1 0)))
      (setq p1 (HH:PickClosePt en p))
      (setq p1 (list 10 (car p1) (cadr p1)))
      (setq L2 (cddddr (member p1 ent)))            ;后段
      (setq L1 (reverse (cdr (member p1 (reverse ent))))) ;前段
      (setq ent (append L1 L2))
      (entmod (subst (cons 90 (1- P90)) (assoc 90 ent) ent))
    )
      )
    )
  )
)
;;示例(HH:delLwpolyPt1 (car(setq en(entsel))) (cadr en))
(defun HH:delLwpolyPt1 (en p / ENT L1 L2 P1)
  (setq ENT (entget en))
  (setq p (vlax-curve-getclosestpointto en (trans p 1 0)))
  (setq p1 (HH:PickClosePt en p))                ;离p最近的顶点
  (setq p1 (list 10 (car p1) (cadr p1)))
  (setq L2 (cdr (member p1 ent)))                ;后段
  (setq L1 (reverse (cdr (member p1 (reverse ent)))))        ;前段
  (entmod (append L1 L2))
)

164.35 [功能] 多段线增加顶点

;;164.35 [功能] 多段线增加顶点
;;示例(HH:LwAddVertex (car(setq en(entsel))) (cadr en))
(defun HH:LwAddVertex (en pt / EN GR N PP)
  ;;增加一个顶点
  (defun LwAddVertex (obj index pt bugle sw ew)
    (vlax-invoke obj 'addvertex index pt)
    (vla-setbulge obj index bugle)
    (vla-setwidth obj index sw ew)
  )
  (setq pp (vlax-curve-getClosestPointTo en (trans pt 1 0)))
  (setq n (fix (vlax-curve-getParamAtPoint en pp)))
  (setq obj (vlax-ename->vla-object en))
  (vla-GetWidth obj n 'sw 'ew)
  (setq pp (getpoint "\n 新增点 "))
  (setq pp (mapcar '+ '(0 0) pp))
  (vl-catch-all-apply 'LwAddVertex (list obj (1+ n) pp 0 sw sw))
)

164.36 [功能] 多段线修改顶点

;;164.36 [功能] 多段线修改顶点
;;示例(HH:ModifyVertex (car(setq en(entsel))) (cadr en) (getpoint))
(defun HH:ModifyVertex (en pt newPt / ENT L1 L2 NPT P P10)
  (setq p (HH:PickClosePt en pt))
  (setq p10 (list 10 (car p) (cadr p)))
  (setq ent (entget en))
  (setq L2 (cdr (member p10 ent)))
  (setq L1 (reverse (cdr (member p10 (reverse ent)))))
  (setq Npt (list (list 10 (car newPt) (cadr newPt))))
  (entmod (append L1 Npt L2))
)
;;(HH:ModifyVertex1 (car(setq en(entsel))) (cadr en))
(defun HH:ModifyVertex1    (en p / ENT GR L1 L2 NPT P10)
  (setq ent (entget en))
  (setq pt (HH:PickClosePt en p))
  (setq p10 (list 10 (car pt) (cadr pt)))
  (setq L2 (cdr (member p10 ent)))
  (setq L1 (reverse (cdr (member p10 (reverse ent)))))
  (while (and (setq gr (grread 5)) (= (car gr) 5))
    (setq Npt (list (list 10 (car (cadr gr)) (cadr (cadr gr)))))
    (entmod (append L1 Npt L2))
  )
)

164.37 [功能] 多段线拷贝子段

;;164.37 [功能] 多段线拷贝子段
;;(HH:CopyLwSeg (car(setq en(entsel))) (cadr en))
(defun HH:CopyLwSeg (en p / ENT L0 L1 L2 LASTENT N P1 PP TEM)
  (setq pp (vlax-curve-getClosestPointTo en p))
  (setq n (fix (vlax-curve-getParamAtPoint en pp)))
  (setq p1 (vlax-curve-getPointAtParam en n))
  (setq p1 (list 10 (car p1) (cadr p1)))
  (setq ent (entget en))
  (setq tem (member p1 ent))
  (repeat 8 (setq L0 (cons (car tem) L0)) (setq tem (cdr tem)))
  (setq L0 (reverse L0))
  (setq L2 (list (last tem)))
  (setq    L1 (list
         '(0 . "LWPOLYLINE")
         '(100 . "AcDbEntity")
         '(100 . "AcDbPolyline")
         '(90 . 2)
       )
  )
  (entmake (append L1 l0 L2))
  (setq Lastent (entlast))
  (command "_.move" Lastent "" pp pause)
)

164.38 [功能] 修改多段线子段

;;164.38 [功能] 修改多段线子段
;;示例(HH:ModifySeg (car(setq en(entsel))) (cadr en))
(defun HH:ModifySeg (en p / ENT GR I L1 L2 N P1 P2 P42 PP X Y)
  ;;133.1 [功能] 旋转一个点(见113)
  ;;Rotate 'pnt'点 from a base point of 'p1' and through an angle of 'ang' (in radians)
  (defun MJ:rotate_pnt (pnt p1 ang)
    (polar p1 (+ (angle p1 pnt) ang) (distance p1 pnt))
  )
  ;;两点之中点
  (defun mid (p1 p2 / X Y)
    (mapcar '(lambda (X Y) (/ (+ X Y) 2.0)) p1 p2)
  )
  ;;已知三点p1 p2 p,求组码42
  (defun my42 (p1 p2 pt / CEN D H P1P2 P1T P2P1 PT1 R)
    (setq d (/ (distance p1 p2) 2.0))
    (setq p1p2 (mid p1 p2))
    (setq p2p1 (MJ:rotate_pnt p1 p1p2 (/ pi 2)))
    (setq pt1 (mid p1 pt))
    (setq p1t (MJ:rotate_pnt p1 pt1 (/ pi 2)))
    (setq cen (inters p1p2 p2p1 pt1 p1t nil))
    (setq h (car (trans (mapcar '- cen p1) 0 (mapcar '- p1 p2))))
    (setq r (distance cen p1))
    (if    (MINUSP h)
      (setq r (+ r h))
      (setq r (- h r))
    )
    (/ r d)
  )

  (setq pp (vlax-curve-getClosestPointTo en p))
  (setq n (fix (vlax-curve-getParamAtPoint en pp)))
  (setq p1 (vlax-curve-getPointAtParam en n))
  (setq p2 (vlax-curve-getPointAtParam en (1+ n)))
  (setq ent (entget en))
  (setq i 0)
  (while (or (/= (caar ent) 42)
         (if (< i n)
           (setq i (1+ i))
         )
     )
    (setq L1  (cons (car ent) L1)
      ent (cdr ent)
    )
  )
  (setq L1 (REVERSE L1))
  (setq L2 (cdr ent))
  (while (and (setq gr (grread 5)) (= (car gr) 5))
    (setq p42 (cons 42 (my42 p1 p2 (cadr gr))))
    (entmod (append L1 (list p42) L2))
  )
  (princ)
)

164.39 [功能] 修改多段线子段为直线

;;164.39 [功能] 修改多段线子段为直线
;;(HH:ModifySegLine (car(setq en(entsel))) (cadr en))
(defun HH:ModifySegLine    (en p / ENT I L1 L2 N P1 P2 PP)
  (setq pp (vlax-curve-getClosestPointTo en p))
  (setq n (fix (vlax-curve-getParamAtPoint en pp)))
  (setq p1 (vlax-curve-getPointAtParam en n))
  (setq p2 (vlax-curve-getPointAtParam en (1+ n)))
  (setq ent (entget en))
  (setq i 0)
  (while (or (/= (caar ent) 42)
         (if (< i n)
           (setq i (1+ i))
         )
     )
    (setq L1  (cons (car ent) L1)
      ent (cdr ent)
    )
  )
  (setq L1 (REVERSE L1))
  (setq L2 (cdr ent))
  (entmod (append L1 (list (cons 42 0)) L2))
  (princ)
)

164.40 [功能] 点在封闭多段线内返回T,其余nil By 狂刀

;;164.40 [功能] 点在封闭多段线内返回T,其余nil  By 狂刀
;;本程序为狂刀思想,并非源程序
;;(PtInorOut1 (car (entsel)) (getpoint))
(defun PtInorOut1 (en pt / P1 P2 PTS)
  (setq pts (HH:PtLists en))
  (setq    pts (MAPCAR '(LAMBDA (p1 p2) (REM (- (ANGLE pt p1) (ANGLE pt p2)) PI))
            (CONS (LAST pts) pts)
            pts
        )
  )
  (equal (ABS (APPLY '+ pts)) PI)
)

164.41 [功能] 点在封闭多段线内返回T,其余nil By SmcTools

;;164.41 [功能] 点在封闭多段线内返回T,其余nil  By SmcTools
;;(PtInorOut2 (car(entsel))(getpoint))
(defun PtInorOut2 (en pt / I N PT_LIST VA VA_COUNT)
  (setq pt_list (HH:PtLists en))
  (setq    i     0
    va_count 0
    n     (length pt_list)
    pt_list     (append pt_list (list (car pt_list)))
  )
  (repeat n
    (setq va (-    (angle pt (nth i pt_list))
        (angle pt (nth (1+ i) pt_list))
         )
    )
    (cond ((> va pi) (setq va (- va pi)))
      ((< va (* -1 pi)) (setq va (+ va pi)))
    )
    (setq va_count (+ va_count va)
      i       (1+ i)
    )
  )
  (equal (abs va_count) pi)
)

164.42 [功能] 判断点在封闭曲线内外,自交曲线不适用 By Gu_xl 2012.07.31

;;164.42 [功能] 判断点在封闭曲线内外,自交曲线不适用 By Gu_xl 2012.07.31
;;返回: 点在封闭曲线上或曲线内,返回T,否则返回nil
;;测试: (gxl-PtInCurveP  (car(entsel "\n选择曲线:")) (getpoint))
(defun gxl-PtInCurveP (POLY    PT      /       CP      LW      MINP    MAXP    MINX
               MINY    MAXX    MAXY    X       Y       LST     CLOCKWISEP
               ENDPARAM           CURVELENGTH     PARAM   DIST    D1      D2
               DEV
              )
  (cond
    ((equal pt
        (setq cp (vlax-curve-getclosestpointto poly pt))
        1e-8
     )
    ) ;_ 点在曲线上 T
    ((progn
       (vla-GetBoundingBox
     (setq lw (vlax-ename->vla-object POLY))
     'MinP
     'MaxP
       )
       (setq MinP (vlax-safearray->list MinP))
       (setq MaxP (vlax-safearray->list MaxP))
       (setq minx (car MinP)
         miny (cadr MinP)
         maxx (car MaxP)
         maxy (cadr MaxP)
         x      (car pt)
         y      (cadr pt)
       )
       (or (< x minx)
       (> x maxx)
       (< y miny)
       (> y maxy)
       )
     )
     NIL ;_ 点在曲线最小包围盒外 nil
    )
    (t
     (setq
       lst (mapcar
         (function
           (lambda (x)
         (vlax-curve-getParamAtPoint
           lw
           (vlax-curve-getClosestPointTo lw x)
         )
           )
         )
         (list minp
           (list minx maxy)
           MaxP
           (list maxx miny)
         )
       )
     ) ;_ 最小包围盒点在曲线上的投影点的参数表
     (setq ClockwiseP
        (if    (or
          (<= (car lst) (cadr lst) (caddr lst) (cadddr lst))
          (<= (cadr lst) (caddr lst) (cadddr lst) (car lst))
          (<= (caddr lst) (cadddr lst) (car lst) (cadr lst))
          (<= (cadddr lst) (car lst) (cadr lst) (caddr lst))
        ) ;_  or
          t
        ) ;_  if
     ) ;_ 判断曲线是否为顺时针,顺时针 = T
     (setq endparam    (vlax-curve-getendparam poly)
       curvelength (vlax-curve-getDistAtParam poly endparam) ;_ 曲线长度
     )
     (setq param (vlax-curve-getparamatpoint poly cp)
       dist     (vlax-curve-getDistAtParam poly param)
     )
     (if (equal param (fix param) 1e-8)
       (progn
     (setq d1 (- dist 1e-8))
     (if (minusp d1)
       (setq d1 (+ curvelength d1))
     )
     (setq d2 (+ dist 1e-8))
     (if (> d2 curvelength)
       (setq d2 (- d2 curvelength))
     )
     (if (<    (distance pt (vlax-curve-getpointatdist poly d1))
        (distance pt (vlax-curve-getpointatdist poly d2))
         )
       (setq param (vlax-curve-getparamatdist poly d1))
       (setq param (vlax-curve-getparamatdist poly d2))
     )
       )
     )
     (setq dev (vlax-curve-getFirstDeriv poly param)
       cp  (vlax-curve-getpointatparam poly param)
     )
     (=    ClockwiseP
    (
     (lambda (p1 p2 p3)
       (<
         (* (- (car p2) (car p1)) (- (cadr p3) (cadr p1)))
         (* (- (cadr p2) (cadr p1)) (- (car p3) (car p1)))
       )
     )
      pt
      cp
      (mapcar '+ cp dev)
    )
     )
    )
  )
)

164.43 [功能] 点在封闭多段线内返回T;线上0;外nil

;;164.43 [功能] 点在封闭多段线内返回T;线上0;外nil
;;这只是我的一点想法,未必正确
;;(PtInorOut (car(entsel))(getpoint))
(defun PtInorOut (en p / AREA AREA1 EN1 PP)
  (setq pp (vlax-curve-getclosestpointto en (trans p 1 0)))
  (if (equal pp p 1e-8)
    0
    (progn
      (setq area (vlax-get (vlax-ename->vla-object en) 'area))
      (command "_.offset" "" en p "")
      (setq area1 (vlax-get (vlax-ename->vla-object en1) 'area))
      (entdel en1)
      (> area1 area)
    )
  )
)

164.44 [功能] 多段线弧段全改为直线段

;;164.44 [功能] 多段线弧段全改为直线段
;;(HH:ModifySegLine1 (car(setq en(entsel))))
(defun HH:ModifySegLine1 (en / X)
  (entmod
    (mapcar '(lambda (x)
           (if (equal (car x) 42)
         (cons 42 0)
         x
           )
         )
        (entget en)
    )
  )
)

164.45 [功能] 沿多段线取点,弧处按角度加密取点

;;164.45 [功能] 沿多段线取点,弧处按角度加密取点
;;示例(LP:getpts (car (entsel)))
(defun LP:getpts (E / EN I II J L42 N PT PTLST X)
  (defun get42 (en)
    (mapcar 'cdr
        (vl-remove-if-not '(lambda (x) (= (car x) 42)) en)
    )
  )
  (setq en (enget e))
  (setq l42 (get42 en))
  (setq j 0)
  (repeat (length l42)
    (setq x (car l42))
    (setq l42 (cdr l42))
    (cond
      ((and (/= x 0)
        (setq i (fix (/ (* (atan (abs x)) 180) pi)))    ;弧取点密度
        (> i 0)
       )
       (setq ii (/ 1.0 i))
       (repeat i
     (setq pt (vlax-curve-getPointAtParam e j))
     (setq ptlst (cons pt ptlst))
     (setq j (+ ii j))
       )
       (setq j (fix (+ 0.5 j)))
      )
      (T
       (setq pt (vlax-curve-getPointAtParam e j))
       (setq ptlst (cons pt ptlst))
       (setq j (1+ j))
      )
    )
  )
  ptlst
)

164.46 [功能] 多段线自相交 by st788796

;;164.46 [功能] 多段线自相交 by st788796
(defun rrr (e / getlst ep obj pts ptl pams il)
  (defun Getlst    (n / i il)
    (setq i (fix n))
    (repeat i (setq il (cons (setq n (1- n)) il)))
    il
  )
  (setq    obj (vlax-ename->vla-object e)
    ep  (vlax-curve-getendparam e)
  )
  (if (setq pts (vlax-invoke obj 'IntersectWith obj 0))
    (progn
      (while pts
    (setq ptl (cons (list (car pts) (cadr pts) (caddr pts)) ptl)
          pts (cdddr pts)
    )
      )
      (setq il     (cdr (getlst ep))
        pams (mapcar '(lambda (x)
                (vlax-curve-getparamatpoint e x)
              )
             ptl
         )
      )
      (if (vlax-curve-isclosed e)
    (not (equal (reverse pams)
            (cons 1. (cons 0. (cdr il)))
         )
    )
    (not (equal (vl-remove '0. (reverse pams)) il)) ;_假闭合情况
      )
    )
  )
)

164.47.1 [功能] pt到直线(弧)的垂点是否在直线(弧)上 自贡黄明儒

;;164.47.1 [功能] pt到直线(弧)的垂点是否在直线(弧)上 自贡黄明儒
;;(HH:PtInL (getpoint) (car (entsel)))
(defun HH:PtIn (pt Line)
  (equal (vlax-curve-getClosestPointTo Line Pt t)
     (vlax-curve-getClosestPointTo Line Pt)
     1e-5
  )
)

164.47.2 [功能] pt投影到p1p2上的点是否在p1p2之间 自贡黄明儒

;;164.47.2 [功能] pt投影到p1p2上的点是否在p1p2之间  自贡黄明儒
;;(PtIn2 (getpoint) (getpoint) (getpoint))  
(defun PtIn2 (p p1 p2)
  (< 0
     (caddr (trans (mapcar '- p p1) 0 (mapcar '- p2 p1)))
     (distance p1 p2)
  )
)

164.47.3 [功能] pt到曲线的垂点不在延长线上,返回T

;;164.47.3 [功能] pt到曲线的垂点不在延长线上,返回T
;;(HH:perPtIn (getpoint) (car(entsel)))
(defun HH:perPtIn (p curve / P1 P2 PA)
  (setq p1 (vlax-curve-getClosestPointTo curve p))
  (setq pa (vlax-curve-getParamAtPoint curve P1))        ;参数  
  (setq p2 (mapcar '+ (vlax-curve-getFirstDeriv curve pa) p1)) ;切线上一点
  (equal (caddr (trans (mapcar '- p p1) 0 (mapcar '- p2 p1))) 0 1e-5)
)

164.47.4 [功能] pt投影到p1p2上的点是否在p1p2之间 自贡黄明儒

;;164.47.4 [功能] pt投影到p1p2上的点是否在p1p2之间  自贡黄明儒
;;(perIn2p (getpoint) (getpoint)(getpoint))
(defun perIn2p (P p1 p2 / pt)
  (setq pt (mapcar '+ (MAT:Rot90 (mapcar '- p1 p2)) p));highflybir论矩阵
  (setq pt (inters p1 p2 p pt nil));垂点
  (equal (+ (distance p1 pt) (distance p2 pt)) (distance p1 p2) 1e-8)
)

164.48 [功能] 多线上的弧段的圆心列表

;;164.48 [功能] 多线上的弧段的圆心列表
;;(HH:GetCenter3 (car(setq en(entsel))))
(defun HH:GetCenter3 (curve / CENLIST EP FLAG MDERIV MP PARAM SP)
  ;;(setq curve (car (entsel)))
  (setq param (fix (vlax-curve-getEndParam curve)))
  (setq sp (vlax-curve-getPointAtParam curve param))
  (repeat param
    (setq param (1- param))
    (setq Ep (vlax-curve-getPointAtParam curve param))
    (setq Mp (vlax-curve-getPointAtParam curve (+ param 0.5))) ;中点
    (setq Mderiv (vlax-curve-getsecondderiv curve (+ param 0.5))) ;中点法线
    (setq Flag (car (trans (mapcar '- Mp Ep) 0 (mapcar '- Ep sp))))
    (cond ((equal Flag 0) nil)
      ((minusp Flag)
       (setq CenList (cons (mapcar '- Mp Mderiv) CenList))
      )
      (T
       (setq CenList (cons (mapcar '+ Mp Mderiv) CenList))
      )
    )
    (setq sp Ep)
  )
  CenList
)

164.49 [功能] 弧圆心或者半径

;;164.49 [功能] 弧圆心或者半径
;;示例(HH:getArcCen (car(entsel)))
(defun HH:getArcCen (e / CEN OBJ R)
  (setq obj (vlax-ename->vla-object e))
  (setq R (vlax-get obj 'Radius))
  (setq Cen (vlax-get obj 'Center))
  (list R Cen)
)

164.50 [功能] 弧与直线在X轴(Y轴)方向的最短距离

;;164.50 [功能] 弧与直线在X轴(Y轴)方向的最短距离
;;Flag T时,X轴方向最短距离
;;(HH:LineArcShort (car(entsel))(car(entsel)) T)=>(6.9505 (-1400.95 2003.86) (-1394.0 2003.86))
;;=>(距离 弧上点 直线上点) 或 nil(nil说明这种方法求得的不是最短距离)
(defun HH:LineArcShort (eA eL Flag / CEN E P1 P2 PT PTS SCOR)
  (setq Cen (cadr (HH:getArcCen eA)))
  (setq pt (vlax-curve-getClosestPointTo EL Cen T))
  (setq e (EntmakeLine Cen pt))                    ;圆心到直线的垂线
  (setq pts (HH:TwoEntsInters eA e 0))
  (entdel e)
  (cond
    (pts
     (setq p1 (car pts))                    ;弧与垂线交点
     (setq e (EntmakeXline p1 Flag))                ;作一射线
     (setq pts (HH:TwoEntsInters EL e 0))            ;射线与原直线交点
     (entdel e)
     (cond
       (pts
    (setq p2 (car pts))
    (setq Scor (list (distance p1 p2) p1 p2))
       )
     )
    )
  )
  Scor
)

164.51 [功能] 弧与弧在X轴(Y轴)方向的最短距离

;;164.51 [功能]  弧与弧在X轴(Y轴)方向的最短距离
;;Flag T时,X轴方向最短距离
;;(移动距离 第二对象移动基点 移动到)或者nil(nil表示此最小移动距离为端点)
;;(HH:TwoArcShort (car(entsel)) (car(entsel)) T)=>(12.3644 (-1334.55 2032.55 0.0) (-1346.91 2032.55))
(defun HH:TwoArcShort (eA1 eA2 Flag / CEN1 CEN2 ECIRCLE ELINE OBJ P2 PTS R1 R2 SCOR)  
  (setq Cen1 (HH:getArcCen eA1))
  (setq R1 (car Cen1))
  (setq Cen1 (cadr Cen1))
  (setq Cen2 (HH:getArcCen eA2))
  (setq R2 (car Cen2))
  (setq Cen2 (cadr Cen2))
  (setq eCircle (EntmakeCircle Cen2 (+ R1 R2)))            ;以第圆中心画一圆
  (if Flag
    (setq p2 (list (car Cen2) (cadr Cen1)))
    (setq p2 (list (cadr Cen2) (car Cen1)))
  )
  (setq eLine (EntmakeLine Cen1 p2))                ;圆1到圆2中心处,产生一直线
  (setq pts (car (HH:TwoEntsInters eCircle eLine 0)))        ;新产生圆与新产生直线交点
  (entdel eCircle)
  (entdel eLine)
  (if pts
    (progn
      (setq pts (mapcar '- pts Cen1))
      (setq p2 (mapcar '- Cen2 pts))                ;圆2新中心点
      (setq eLine (EntmakeLine Cen1 p2))
      (setq pts (HH:TwoEntsInters eA1 eLine 0))
      (cond
    (pts
     (setq obj (vla-copy (vlax-ename->vla-object eA2)))
     (vla-move obj (vlax-3d-point Cen2) (vlax-3d-point p2))
     (setq pts (HH:TwoEntsInters eLine (entlast) 0))
     (entdel eLine)
     (entdel (entlast))
     (cond
       (pts
        (setq Scor (list (distance p2 Cen2) Cen2 p2))
       )
     )
    )
    (T (entdel eLine))
      )
    )
  )
  Scor
)

164.52 [功能] 两多段线之间最小距离 自贡黄明儒2014.4.6

;;164.52 [功能] 两多段线之间最小距离 自贡黄明儒2014.4.6
(defun C:HH:TwoLWPShort    (/ CPT1 CPT2 E1 E2 LST P PTS1 PTS2 SS)
  (if (and
    (setq ss (ssget ":S" '((0 . "LWPOLYLINE"))))
    (equal (sslength ss) 2)
      )
    (progn
      (setq e1 (ssname ss 0))
      (setq e2 (ssname ss 1))
      (setq pts1 (HH:PtLists e1))                ;http://bbs.xdcad.net/thread-671377-1-1.html
      (setq pts2 (HH:PtLists e2))
      (setq Cpt1 (HH:GetCenter3 e1))
      (setq Cpt2 (HH:GetCenter3 e2))
      (foreach X pts1
    (setq p (vlax-curve-getClosestPointTo e2 x))
    (setq lst (cons (list (distance x p) x p) lst))
      )
      (foreach X pts2
    (setq p (vlax-curve-getClosestPointTo e1 x))
    (setq lst (cons (list (distance x p) p x) lst))
      )
      (if Cpt1
    (foreach X Cpt1
      (setq p (vlax-curve-getClosestPointTo e2 x))
      (setq x (vlax-curve-getClosestPointTo e1 p))
      (setq lst (cons (list (distance x p) x p) lst))
    )
      )
      (if Cpt2
    (foreach X Cpt2
      (setq p (vlax-curve-getClosestPointTo e1 x))
      (setq x (vlax-curve-getClosestPointTo e2 p))
      (setq lst (cons (list (distance x p) p x) lst))
    )
      )
      (setq lst (car (HH:ssPts:Sort lst "x" 0.001)))
      (grdraw (cadr lst) (caddr lst) 1)
    )
  )
  lst
)

164.53 [功能] 两多段线X(Y)轴方向最小距离 自贡黄明儒2014.4.6

;;164.53 [功能] 两多段线X(Y)轴方向最小距离 自贡黄明儒2014.4.6
;;ss两条多段线选择集 Flag T时X方向,nil时Y方向
(defun HH:XLWPShort (ss Flag / CMD1 E1 E11 E2 E21 I J LST S1 S2 SCOR SHORTC TYPE1 TYPE2)
  ;;错误处理
  (defun *error* (msg)
    (vl-bt)
    (if    *DOC*
      (_EndUndo *DOC*)                        ;块内图元增减
    )
    (while (not (equal (getvar "cmdnames") "")) (command nil))
    (if    cmd1
      (setvar "cmdecho" cmd1)
    )
    (if    SHORTC
      (setvar "SHORTCUTMENU" SHORTC)
    )
    (if s1 (vl-cmdf "_.erase" s1 ""))
    (if s2 (vl-cmdf "_.erase" s2 ""))
    (setvar "nomutt" 0)
    (princ "\n 出错啦!")
    (princ)
  )
  (setq e1 (ssname ss 0))
  (setq e2 (ssname ss 1))
  (vla-copy (vlax-ename->vla-object e1))
  (vl-cmdf "_.explode" (entlast))
  (setq s1 (ssget "_p"))
  (vla-copy (vlax-ename->vla-object e2))
  (vl-cmdf "_.explode" (entlast))
  (setq s2 (ssget "_p"))
  (repeat (setq i (sslength s1))
    (setq e11 (ssname s1 (setq i (1- i))))
    (setq type1 (cdr (assoc 0 (entget e11))))
    (repeat (setq j (sslength s2))
      (setq e21 (ssname s2 (setq j (1- j))))
      (setq type2 (cdr (assoc 0 (entget e21))))
      (cond
    ((and (equal type1 "LINE") (equal type2 "ARC"))
     (if (setq scor (HH:LineArcShort e21 e11 Flag))
       (setq lst (cons scor lst))
     )
    )
    ((and (equal type2 "LINE") (equal type1 "ARC"))
      (if (setq scor (HH:LineArcShort e11 e21 Flag))
        (setq lst (cons scor lst))
      )
    )
    ((and (equal type2 "ARC") (equal type1 "ARC"))
     (if (setq scor (HH:TwoArcShort e11 e21 Flag))
        (setq lst (cons scor lst))
      )     
    )
      )
    )
  )
  (vl-cmdf "_.erase" s1 s2 "")  
  (foreach x (HH:PtLists e1)
    (if    (setq scor (HH:XYCurvePt e2 x Flag))
      (setq lst (append lst scor))
    )
  )
  (foreach x (HH:PtLists e2)
    (if    (setq scor (HH:XYCurvePt e1 x Flag))
      (setq lst (append lst scor))
    )
  )  
  (if (setq lst (car (HH:ssPts:Sort lst "x" 0.001)))
    (grdraw (cadr lst) (caddr lst) 1)
  )
  lst
)

164.54 [功能] 过一点射线与曲线的交点

;;164.54 [功能] 过一点射线与曲线的交点
;;示例(HH:XYCurvePt (car(entsel)) (getpoint) "X"),返回过一点X轴上的点
(defun HH:XYCurvePt (e1 pt Flag / E2 LST PTS)
  (setq e2 (EntmakeXline pt Flag))
  (setq pts (HH:TwoEntsInters e1 e2 0))
  (entdel e2)
  (foreach x pts
    (setq lst (cons (list (distance x pt) x pt) lst))
  )
  lst
)

1