lee_12345
发表于 2004-6-6 09:37:00
别找了!给你,接好了哟!!!
VLAX类 - VLAX.cls:
VERSION 1.0 CLASS<BR>BEGIN<BR> MultiUse = -1 'True<BR>END<BR>Attribute VB_Name = "VLAX"<BR>Attribute VB_GlobalNameSpace = False<BR>Attribute VB_Creatable = False<BR>Attribute VB_PredeclaredId = False<BR>Attribute VB_Exposed = False<BR>' VLAX.CLS v2.0 (Last updated 8/1/2003)<BR>' Copyright 1999-2001 by Frank Oquendo<BR>' <BR>' 该程序由明经通道修改支持2004版本<BR>' <A href="http://www.mjtd.com/" target="_blank" >http://www.mjtd.com</A><BR>'<BR>' Permission to use, copy, modify, and distribute this software<BR>' for any purpose and without fee is hereby granted, provided<BR>' that the above copyright notice appears in all copies and<BR>' that both that copyright notice and the limited warranty and<BR>' restricted rights notice below appear in all supporting<BR>' documentation.<BR>'<BR>' FRANK OQUENDO (THE AUTHOR) PROVIDES THIS PROGRAM "AS IS" AND WITH<BR>' ALL FAULTS. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY<BR>' OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. THE AUTHOR<BR>' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE<BR>' UNINTERRUPTED OR ERROR FREE.<BR>'<BR>' Use, duplication, or disclosure by the U.S. Government is subject to<BR>' restrictions set forth in FAR 52.227-19 (Commercial Computer<BR>' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)<BR>' (Rights in Technical Data and Computer Software), as applicable.<BR>'<BR>' VLAX.cls allows developers to evaluate AutoLISP expressions from<BR>' Visual Basic or VBA<BR>'<BR>' Notes:<BR>' All code for this class module is publicly available througout various posts<BR>' at <A href="news://discussion.autodesk.com/autodesk.autocad.customization.vba" target="_blank" >news://discussion.autodesk.com/autodesk.autocad.customization.vba</A>. I do not<BR>' claim copyright or authorship on code presented in these posts, only on this<BR>' compilation of that code. In addition, a great big "Thank you!" to Cyrille Fauvel<BR>' demonstrating the use of the VisualLISP ActiveX Module.<BR>'<BR>' Dependencies:<BR>' Use of this class module requires the following application:<BR>' 1. VisualLISP
Private VL As Object<BR>Private VLF As Object
Private Sub Class_Initialize()
If Left(ThisDrawing.Application.Version, 2) = "15" Then<BR> Set VL = ThisDrawing.Application.GetInterfaceObject("VL.Application.1")<BR> ElseIf Left(ThisDrawing.Application.Version, 2) = "16" Then<BR> Set VL = ThisDrawing.Application.GetInterfaceObject("VL.Application.16")<BR> End If<BR> Set VLF = VL.ActiveDocument.Functions
End Sub
Private Sub Class_Terminate()
Set VLF = Nothing<BR> Set VL = Nothing
End Sub
Public Function EvalLispExpression(lispStatement As String)
Dim sym As Object, ret As Object, retval<BR> <BR> Set sym = VLF.Item("read").funcall(lispStatement)<BR> On Error Resume Next<BR> retval = VLF.Item("eval").funcall(sym)<BR> If Err Then<BR> EvalLispExpression = ""<BR> Else<BR> EvalLispExpression = retval<BR> End If
End Function
Public Sub SetLispSymbol(symbolName As String, value)
Dim sym As Object, ret, symvalue<BR> <BR> symvalue = value<BR> Set sym = VLF.Item("read").funcall(symbolName)<BR> ret = VLF.Item("set").funcall(sym, symvalue)<BR> EvalLispExpression "(defun translate-variant (data) (cond ((= (type data) 'list) (mapcar 'translate-variant data)) ((= (type data) 'variant) (translate-variant (vlax-variant-value data))) ((= (type data) 'safearray) (mapcar 'translate-variant (vlax-safearray->list data))) (t data)))"<BR> EvalLispExpression "(setq " & symbolName & "(translate-variant " & symbolName & "))"<BR> EvalLispExpression "(setq translate-variant nil)"
End Sub
Public Function GetLispSymbol(symbolName As String)
Dim sym As Object, ret, symvalue<BR> <BR> symvalue = value<BR> Set sym = VLF.Item("read").funcall(symbolName)<BR> GetLispSymbol = VLF.Item("eval").funcall(sym)
End Function
Public Function GetLispList(symbolName As String) As Variant
Dim sym As Object, list As Object<BR> Dim Count, elements(), i As Long<BR> <BR> Set sym = VLF.Item("read").funcall(symbolName)<BR> Set list = VLF.Item("eval").funcall(sym)<BR> <BR> Count = VLF.Item("length").funcall(list)<BR> <BR> ReDim elements(0 To Count - 1) As Variant<BR> <BR> For i = 0 To Count - 1<BR> elements(i) = VLF.Item("nth").funcall(i, list)<BR> Next<BR> <BR> GetLispList = elements<BR> <BR>End Function
Public Sub NullifySymbol(ParamArray symbolName())
Dim i As Integer<BR> <BR> For i = LBound(symbolName) To UBound(symbolName)<BR> EvalLispExpression "(setq " & CStr(symbolName(i)) & " nil)"<BR> Next
End Sub
<BR>======================================================================================<BR>曲线操作Curve.cls:
<BR>VERSION 1.0 CLASS<BR>BEGIN<BR> MultiUse = -1 'True<BR>END<BR>Attribute VB_Name = "Curve"<BR>Attribute VB_GlobalNameSpace = False<BR>Attribute VB_Creatable = False<BR>Attribute VB_PredeclaredId = False<BR>Attribute VB_Exposed = False<BR>' Curve.cls v1.3 (Last updated 12/18/2001)<BR>' Copyright 2000, 2001 by Frank Oquendo<BR>'<BR>' Permission to use, copy, modify, and distribute this software<BR>' for any purpose and without fee is hereby granted, provided<BR>' that the above copyright notice appears in all copies and<BR>' that both that copyright notice and the limited warranty and<BR>' restricted rights notice below appear in all supporting<BR>' documentation.<BR>'<BR>' FRANK OQUENDO (THE AUTHOR) PROVIDES THIS PROGRAM "AS IS" AND WITH<BR>' ALL FAULTS. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY<BR>' OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. THE AUTHOR<BR>' DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE<BR>' UNINTERRUPTED OR ERROR FREE.<BR>'<BR>' Use, duplication, or disclosure by the U.S. Government is subject to<BR>' restrictions set forth in FAR 52.227-19 (Commercial Computer<BR>' Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)<BR>' (Rights in Technical Data and Computer Software), as applicable.<BR>'<BR>' Curve.cls allows developers to access the various VLAX-CURVE functions<BR>' from Visual Basic or VBA.<BR>'<BR>' Notes:<BR>' I do not claim copyright or authorship of the code being wrapped by this module,<BR>' only on this compilation of that code.<BR>'<BR>' Dependencies:<BR>' Use of this class module requires the following files:<BR>' 1. VLAX.CLS - This file can be obtained by visiting <A href="http://www.acadx.com/" target="_blank" >http://www.acadx.com</A>
Private objVLAX As VLAX<BR>Private mvarEntity As AcadEntity<BR>Private types(8) As String
Private Sub Class_Initialize()
Set objVLAX = New VLAX<BR> types(0) = "AcDbCircle": types(1) = "AcDbLine"<BR> types(2) = "AcDbArc": types(3) = "AcDbSpline"<BR> types(4) = "AcDb3dPolyline": types(5) = "AcDbPolyline"<BR> types(6) = "AcDb2dPolyline": types(7) = "AcDbEllipse"<BR> types(8) = "AcDbLeader"
End Sub
Private Sub Class_Terminate()
Set objVLAX = Nothing
End Sub
Public Property Set Entity(ent As AcadEntity)
Dim tmp As String, i As Long, bFound As Boolean<BR> <BR> tmp = ent.ObjectName<BR> <BR> For i = 0 To 8<BR> If tmp = types(i) Then<BR> Set mvarEntity = ent<BR> bFound = True<BR> Exit For<BR> End If<BR> Next<BR> <BR> If Not bFound Then Err.Raise vbObjectError + 1, , "That entity is not a curve."
End Property
Public Property Get Entity() As AcadEntity
Set entityt = mvarEntity
End Property
Public Property Get CurveType() As String
CurveType = mvarEntity.ObjectName
End Property
Public Property Get Area() As Double
Dim retval As Double<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> retval = .EvalLispExpression("(vlax-curve-getArea (handent handle))")<BR> .NullifySymbol "handle"<BR> End With<BR> Area = retval
End Property
Public Property Get Closed() As Boolean
Dim retval As Boolean<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> retval = .EvalLispExpression("(vlax-curve-isClosed (handent handle))")<BR> .NullifySymbol "handle"<BR> End With<BR> Closed = retval
End Property
Public Property Get EndParameter() As Double
Dim retval As Double<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> retval = .EvalLispExpression("(vlax-curve-getEndParam (handent handle))")<BR> .NullifySymbol "handle"<BR> End With<BR> EndParameter = retval
End Property
Public Property Get EndPoint() As Variant
Dim retval As Variant, pt(0 To 2) As Double<BR> Dim i As Long<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .EvalLispExpression "(setq lst (vlax-curve-getEndPoint (handent handle)))"<BR> retval = .GetLispList("lst")<BR> .NullifySymbol "handle", "lst"<BR> End With<BR> <BR> For i = 0 To 2<BR> pt(i) = retval(i)<BR> Next<BR> <BR> EndPoint = pt
End Property
Public Function GetClosestPointTo(Point, Optional Extend As Boolean = False) As Variant
Dim retval As Variant, pt(0 To 2) As Double<BR> Dim i As Long<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "givenPt", Point<BR> If Extend Then .EvalLispExpression "(setq ext T)"<BR> .EvalLispExpression "(setq lst (vlax-curve-getClosestPointTo (handent handle) givenPt ext))"<BR> retval = .GetLispList("lst")<BR> .NullifySymbol "handle", "lst", "ext", "givenPt"<BR> End With<BR> <BR> For i = 0 To 2<BR> pt(i) = retval(i)<BR> Next<BR> <BR> GetClosestPointTo = pt
End Function
Public Function GetDistanceAtParameter(Param As Double) As Double
Dim retval As Double<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "param", Param<BR> retval = .EvalLispExpression("(vlax-curve-getDistAtParam (handent handle) param)")<BR> .NullifySymbol "handle", "param"<BR> End With<BR> GetDistanceAtParameter = retval
End Function
Public Function GetDistanceAtPoint(Point As Variant) As Double
Dim retval As Double<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "point", Point<BR> retval = .EvalLispExpression("(vlax-curve-getDistAtPoint (handent handle) point)")<BR> .NullifySymbol "handle", "point"<BR> End With<BR> GetDistanceAtPoint = retval
End Function
Public Function GetFirstDerivative(Param As Double) As Variant
Dim retval As Variant<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "param", Param<BR> .EvalLispExpression "(setq lst (vlax-curve-getFirstDeriv (handent handle) param))"<BR> retval = .GetLispList("lst")<BR> .NullifySymbol "handle", "param", "lst"<BR> End With<BR> GetFirstDerivative = retval
End Function
Public Function GetParameterAtDistance(Dist As Double) As Double
Dim retval As Double<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "dist", Dist<BR> retval = .EvalLispExpression("(vlax-curve-getParamAtDist (handent handle) dist)")<BR> .NullifySymbol "handle", "dist"<BR> End With<BR> GetParameterAtDistance = retval
End Function
Public Function GetParameterAtPoint(Point As Variant) As Double
Dim retval As Double<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "point", Point<BR> retval = .EvalLispExpression("(vlax-curve-getparamAtPoint (handent handle) point)")<BR> .NullifySymbol "handle", "point"<BR> End With<BR> GetParameterAtPoint = retval
End Function
Public Function GetPointAtDistance(Dist As Double) As Variant
Dim retval As Variant, pt(0 To 2) As Double<BR> Dim i As Long<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "dist", Dist<BR> .EvalLispExpression "(setq lst (vlax-curve-getPointAtDist (handent handle) dist))"<BR> retval = .GetLispList("lst")<BR> .NullifySymbol "handle", "dist", "lst"<BR> End With<BR> <BR> For i = 0 To 2<BR> pt(i) = retval(i)<BR> Next<BR> <BR> GetPointAtDistance = pt
End Function
Public Function GetPointAtParameter(Param As Double) As Variant
Dim retval As Variant, pt(0 To 2) As Double<BR> Dim i As Long<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "param", Param<BR> .EvalLispExpression "(setq lst (vlax-curve-getPointAtParam (handent handle) param))"<BR> retval = .GetLispList("lst")<BR> .NullifySymbol "handle", "param", "lst"<BR> End With<BR> <BR> For i = 0 To 2<BR> pt(i) = retval(i)<BR> Next<BR> <BR> GetPointAtParameter = pt
End Function
Public Function GetSecondDerivative(Param As Double) As Variant
Dim retval As Variant<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "param", Param<BR> .EvalLispExpression "(setq lst (vlax-curve-getSecondDeriv (handent handle) param))"<BR> retval = .GetLispList("lst")<BR> .NullifySymbol "handle", "param", "lst"<BR> End With<BR> GetSecondDerivative = retval
End Function
Public Property Get length() As Double
Dim retval As Double<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .EvalLispExpression "(setq curve (handent handle))"<BR> retval = .EvalLispExpression("(vlax-curve-getDistAtParam curve (vlax-curve-getEndParam curve))")<BR> .NullifySymbol "handle", "curve"<BR> End With<BR> length = retval
End Property
Public Property Get Periodic() As Boolean
Dim retval As Boolean<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> retval = .EvalLispExpression("(vlax-curve-isPeriodic (handent handle))")<BR> .NullifySymbol "handle"<BR> End With<BR> Periodic = retval
End Property
Public Property Get Planar() As Boolean
Dim retval As Boolean<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> retval = .EvalLispExpression("(vlax-curve-isPlanar (handent handle))")<BR> .NullifySymbol "handle"<BR> End With<BR> Planar = retval
End Property
Public Property Get StartPoint() As Variant
Dim retval As Variant, pt(0 To 2) As Double<BR> dim As Long<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .EvalLispExpression "(setq lst (vlax-curve-getStartPoint (handent handle)))"<BR> retval = .GetLispList("lst")<BR> .NullifySymbol "handle", "lst"<BR> End With<BR> <BR> For i = 0 To 2<BR> pt(i) = retval(i)<BR> Next<BR> <BR> StartPoint = pt
End Property
Public Function GetClosestPointToProjection(Point As Variant, Normal As Variant, Optional Extend As Boolean = False) As Variant
Dim retval As Variant, pt(0 To 2) As Double<BR> Dim i As Long<BR> <BR> With objVLAX<BR> .SetLispSymbol "handle", mvarEntity.Handle<BR> .SetLispSymbol "givenPt", Point<BR> .SetLispSymbol "normal", Normal<BR> If Extend Then .EvalLispExpression "(setq ext T)"<BR> .EvalLispExpression "(setq lst (vlax-curve-getClosestPointToProjection (handent handle) givenPt normal ext))"<BR> retval = .GetLispList("lst")<BR> .NullifySymbol "handle", "lst", "normal", "ext", "givenPt"<BR> End With<BR> <BR> For i = 0 To 2<BR> pt(i) = retval(i)<BR> Next<BR> <BR> GetClosestPointToProjection = pt
End Function
anyc100
发表于 2010-11-23 17:15:00
呵呵