码迷,mamicode.com
首页 > 其他好文 > 详细

VisualLisp若干常用代码

时间:2020-03-16 17:38:31      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:ssg   styles   一般来说   handle   text   net   stc   考证   active   

  1 ;;;当前AutoCAD任务中的顶层AutoCAD应用程序对象
  2 (Vlax-Get-Acad-Object)
  3 (Setq acadObject (Vlax-Get-Acad-Object))
  4 
  5 ;;;当前的文档
  6 (Vla-Get-ActiveDocument (Vlax-Get-Acad-Object))
  7 (Setq acadDocument (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument))
  8 
  9 ;;;模型空间对象
 10 (Vla-Get-ModelSpace (Vla-Get-ActiveDocument (Vlax-Get-Acad-Object)))
 11 (Setq mSpace (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘ModelSpace ))
 12 
 13 ;;;图纸空间对象
 14 (Vla-Get-PaperSpace (Vla-Get-ActiveDocument (Vlax-Get-Acad-Object)))
 15 (Setq pSpace (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘PaperSpace ))
 16 
 17 ;;;当前文档标注样式的集合
 18 (Setq DimStyles (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘DimStyles ))
 19 
 20 ;;;当前文档图层的集合
 21 (Setq Layers (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘Layers ))
 22 
 23 ;;;当前文档线型的集合
 24 (Setq Linetypes (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘Linetypes ))
 25 
 26 ;;;当前文档文字样式的集合
 27 (Setq textStylesObj (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘TextStyles ))
 28 
 29 ;;;当前文档块定义的集合
 30 (setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
 31 
 32 ;;;已知文字样式名称,获取该文字样式对象
 33 (Setq textStyleObj (Vlax-Invoke-Method (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘TextStyles) ‘Item "Ecidi_romans"))
 34 
 35 ;;;已知图层名称,获取该图层对象
 36 (Setq LayObj (Vlax-Invoke-Method (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘Layers) ‘Item "0"))
 37 
 38 ;;;已知某图层对象LayObj,获取该图层的名称
 39 (vla-get-name LayObj)
 40 (Setq LayerName (Vlax-Get LayObj ‘Name))
 41 
 42 ;;;已知文字样式对象名,获取字体文件、大字体文件
 43 (Setq fontFile (Vlax-Get textStyleObj ‘fontFile))
 44 (Setq BigFontFile (Vlax-Get textStyleObj ‘BigFontFile))
 45 
 46 ;;;建立选择集,且筛选图元类型
 47 (setq ss (ssget ‘((0 . "TEXT,LINE,LWPOLYLINE"))))
 48 
 49 ;;;已知VLA对象名obj,获取句柄handle
 50 (setq handle (Vlax-Get obj ‘Handle ))
 51 
 52 ;;;已知多段线VLA对象名plineObj,获取其顶点二维坐标表plineCoordinates
 53 (Setq plineCoordinates (Vlax-Get plineObj ‘Coordinates ))
 54 
 55 ;;;获取图元类型
 56 (setq szEntType (cdr (assoc 0 (entget (car (entsel))))));;返回值为一个字符串
 57 (setq szObjName (Vlax-Get (Vlax-Ename->Vla-Object (car (entsel))) ‘ObjectName));;返回值为一个字符串
 58 (setq nEntType (Vlax-Get (Vlax-Ename->Vla-Object (car (entsel))) ‘EntityType));;返回值为一个整数,(= AcText 32)的返回值为T
 59 ;;;《AutoCAD VBA开发精彩实例教程》(张帆 郑立楷 王华杰 编著)86页:
 60 ;;;要判断实体的对象类型,既可以使用ObjectName属性,又可以使用EntityType属性。如果使用ObjectName属性,它的取值是ARX中对应的类的名称,一般来说,是对象的类型加上AcDb前缀;如果使用EntityType属性(该属性在VBA中无法获得帮助信息,但是确实能够使用,对它的使用方法,并未获得权威资料的考证),一般来说可以在对象的类型前面加上Ac前缀。
 61 
 62 ;;;修改单行文字对象的文字样式
 63 (Vlax-Put-Property (Vlax-Ename->Vla-Object (car (entsel))) ‘StyleName "Ecidi_romans" );;返回值为nil
 64 
 65 ;;;获取单行文字对象的高度
 66 (setq textHeight (Vlax-Get (Vlax-Ename->Vla-Object (car (entsel))) ‘Height ))
 67 
 68 ;;;获取单行文字对象的宽度比例
 69 (setq scaleFactor (Vlax-Get (Vlax-Ename->Vla-Object (car (entsel))) ‘ScaleFactor ))
 70 
 71 ;;;改单行文字对象的文字样式
 72 (Vlax-Put-Property (Vlax-Ename->Vla-Object (car (entsel))) ‘StyleName (getvar "Ecidi_romans") )
 73 
 74 ;;;改单行文字对象的内容
 75 (Vlax-Put-Property txtObjName ‘TextString "99初名機工888株式会社99")
 76 
 77 ;;;改单行文字对象的颜色
 78 (Vlax-Put-Property txtObjName ‘Color 42 )
 79 
 80 ;;;改单行文字对象的对正方式
 81 (Vlax-Put-Property txtObjName ‘Alignment 4 )
 82 
 83 ;;;改单行文字对象的对齐点
 84 (Vlax-Put-Property txtObjName ‘TextAlignmentPoint (vlax-3D-point midPt) )
 85 
 86 ;;;改单行文字对象的插入点
 87 (Vlax-Put-Property (Vlax-Ename->Vla-Object (car (entsel))) ‘InsertionPoint (vlax-3D-point pt) )
 88 
 89 ;;;获取圆对象的圆心
 90 (setq LstCenter (cdr (assoc 10 (entget (car (entsel))))));返回值为一个三维圆心坐标表
 91 (setq variantCenter (Vla-Get-Center circleObj));返回值类型为变体,(vlax-safearray->list (vlax-variant-value (Vla-Get-Center (vlax-ename->vla-object (car (entsel))))))
 92 (Setq LstCenter (Vlax-Get circleObj ‘Center));返回值为一个三维圆心坐标表
 93 
 94 ;;;遍历块定义中每个图元
 95 (vlax-for obj (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) "块名")
 96     ...
 97 )
 98 
 99 ;;;遍历当前文档块定义的集合,获取每个块定义的名称,并存入表blockNameLst中
100 (setq blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
101 (setq blockNameLst nil)
102 (vlax-for block blocks
103     (setq blockName (Vlax-Get block ‘Name ))
104     (setq blockNameLst (append blockNameLst (list blockName)))
105 )
106 
107 ;;;当前文档中块定义的个数
108 (Vlax-Get (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘Blocks) ‘Count )
109 
110 ;;;第i个块定义对象
111 (Vlax-Invoke-Method (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘Blocks) ‘item i)
112 
113 ;;;第i个块定义对象的名称
114 (Vlax-Get (Vlax-Invoke-Method (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘Blocks) ‘item i) ‘Name )
115 (vla-get-name (Vlax-Invoke-Method (Vlax-Get (Vlax-Get (Vlax-Get-Acad-Object) ‘ActiveDocument) ‘Blocks) ‘item i))

 

VisualLisp若干常用代码

标签:ssg   styles   一般来说   handle   text   net   stc   考证   active   

原文地址:https://www.cnblogs.com/insipid1860/p/12468418.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!