Access ActiveX object with Autolisp
在搜尋許多高手的Autolisp 會發現他們使用一些 Active X 的擴充函數,在developer documentation 的說明中又找不到這類函數的說明怎麼解決這個問題呢?
試著在 developer documentation 搜尋 ActiveX ,在 Vlax-get-property 中有個完整的範例 :
以下是使用 ActiveX 的定型範例
(vl-load-com) ;;<-----use activeX function
(setq acadObject (vlax-get-acad-object))
(setq acadDocument (vlax-get-property acadObject 'ActiveDocument))
(setq mSpace (vlax-get-property acadDocument 'Modelspace))
轉換Autolisp entity 到ActiveX 物件
(setq vlaobj (vlax-ename->vla-object enname))
enname 是 entity名稱
ent 來自 entsel 函數傳回entity名稱
(setq enname (car ent))
ent 來自 entget 函數傳回群碼列表
(setq enname (cdr(assoc -1 ent)))
重點來了,怎麼找到該屬性的名稱?
在 AutoCAD Toolplate 的Autolisp Expression
填入這句
(vlax-dump-object (vlax-Ename->Vla-Object (car (entsel))) T)
點選你要列示的物件它的屬性就會在文字視窗例 :
Command: (vlax-dump-object (vlax-Ename->Vla-Object (car (entsel))) T)
Select object: ; IAcadLWPolyline: AutoCAD Lightweight Polyline Interface
; Property values:
; Application (RO) = #
; Area (RO) = 9660.3
; Closed = -1
; ConstantWidth = 0.0
; Coordinate = ...Indexed contents not shown...
; Coordinates = (894.159 2258.2 894.159 2246.2 1699.18 2246.2 ... )
; Document (RO) = #
; Elevation = 0.0
; Handle (RO) = "1CA6B"
; HasExtensionDictionary (RO) = 0
; Hyperlinks (RO) = #
; Layer = "0"
; Length (RO) = 1634.05
; Linetype = "ByLayer"
; LinetypeGeneration = 0
; LinetypeScale = 1.0
; Lineweight = -1
; Material = "ByLayer"
; Normal = (0.0 0.0 1.0)
; ObjectID (RO) = 2128989720
; ObjectName (RO) = "AcDbPolyline"
; OwnerID (RO) = 2128948472
; PlotStyleName = "ByLayer"
; Thickness = 0.0
; TrueColor = #
; Visible = -1
; Methods supported:
; AddVertex (2)
; ArrayPolar (3)
; ArrayRectangular (6)
; Copy ()
; Delete ()
; Explode ()
; GetBoundingBox (2)
; GetBulge (1)
; GetExtensionDictionary ()
; GetWidth (3)
; GetXData (3)
; Highlight (1)
; IntersectWith (2)
; Mirror (2)
; Mirror3D (3)
; Move (2)
; Offset (1)
; Rotate (2)
; Rotate3D (3)
; ScaleEntity (2)
; SetBulge (2)
; SetWidth (3)
; SetXData (2)
; TransformBy (1)
; Update ()
T
列出一堆。
存取屬性的方法
取得屬性
(vlax-get-property object property)
範例:
(setq col (getstring "\nNew Color Number: "))
(vlax-put-property obj 'color col)
修改屬性
(vlax-put-property obj property arg)
範例:
(vlax-put-property vlaobj 'ExtensionLineOffset 0)
(setq pos (getpoint "\nNew Position:"))
(vlax-put-property obj 'textalignmentpoint (vlax-3d-point pos) )
標籤: AutoLisp
0 個意見:
張貼留言
訂閱 張貼留言 [Atom]
<< 首頁