- UID
- 10
- 积分
- 1213
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-3
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2002-9-26 10:33:57
|
显示全部楼层
- <body>
- <table cellPadding="2" width="581" bgColor="#ffcc33" border="0">
- <tbody>
- <tr>
- <td bgColor="#ffcc33" width="571">所有留言及回应</td>
- </tr>
- </tbody>
- </table>
- <a name="link1"></a><a name="s"></a>
- <table cellSpacing="0" cellPadding="2" width="581" bgColor="#e0e0e0" border="0">
- <tbody>
- <tr>
- <td width="575">
- <table cellSpacing="0" cellPadding="0" align="right" border="0">
- <tbody>
- <tr>
- <td><font face="Courier New" size="2">Message 1 in thread</font></td>
- </tr>
- </tbody>
- </table>
- <font size="2">寄件者:</font><font face="Courier New" size="2"><a href="http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&q=author:holderm%40atscorporation.com+" target="_top">Mark
- Holder</a> (<a href="mailto:holderm@atscorporation.com">holderm@atscorporation.com</a>)<br>
- </font><font size="2">主旨:</font><font face="Courier New" size="2">VLisp
- from VB - Episode IV: The Variant Menace<br>
- </font><font size="2">新闻群组:</font><font face="Courier New" size="2"><a href="http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&group=autodesk.autocad.customization.vba" target="_top">autodesk.autocad.customization.vba</a><br>
- </font>
- <table cellSpacing="0" cellPadding="0" align="right" border="0">
- <tbody>
- <tr>
- <td><a href="http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=37C5B503.8A7A0E88%40atscorporation.com" target="_top"><font face="Courier New" size="2">View
- this article only</font></a></td>
- </tr>
- </tbody>
- </table>
- <font size="2">日期:</font><font face="Courier New" size="2">1999/08/26<br>
- </font></td>
- </tr>
- </tbody>
- </table>
- <pre><font face="Courier New">A recent thread in this NG brought to my attention a new (to me, at
- least) group of VLisp functions. I refer specifically to the very
- powerful vlax-Curve-xxx functions, though there are probably many more
- that could be useful. I posted a request for information on how to use
- these functions from VB(A).
- After much trial and error, I managed to get what I was after. The
- snippet of code below demonstrates obtaining the length of a polyline
- using some of these functions.
- To save others time and frustration, I offer the following observations
- along with the working code:
- 1) Variables to be passed as arguments to VLisp must be declared as
- Variant, though constants are coerced ok.
- 2) Those same arguments must be converted back to Lisp values with
- (vlax-variant-value <v>) before being used in "standard" lisp function
- calls (like (handent), or ones you might write) in the Lisp code you
- will be calling from VB.
- 3) You can only call Lisp defined functions (as opposed to internal ones
- like vlax-curve-xxx) directly, because internal functions cannot be
- found by vld.Functions.Item(fName).
- 4) I call (vl-load-com) in my AcadDoc.LSP file, to ensure that it is
- always loaded, and to avoid calling it in every routine I write. If you
- don't, make sure it is called before you do anything that depends on it.
- 5) The Lisp code can be defined in a standard text or vlx file, in which
- case it need not be built into your code. By putting it in your code you
- can be sure it is available, and not visible to others.
- 6) I chose to prefix my ActiveX Lisp function names with "vb" to
- indicate that their arguments have to be made into ActiveX variants
- (with vlax-make-variant) if they are to be called from regular Lisp
- code.
- <font color="#000080">Private Sub GetEnd(ByVal anEnt As AutoCAD.AcadEntity)
- Dim vl_Read As Variant, vl_Eval As Variant, vl_Defun As Variant, ret
- As Variant
- Dim vld As Variant
- Dim arg As Variant
- Dim fName As String
- Dim NoFunc As String
- On Error GoTo Failed
- </font><font color="#008000"> ' Your code to Set vld will call GetInterfaceObject or CreateObject.
- </font><font color="#000080">
- Set vld = myAcadSession.VLisp.ActiveDocument
- </font><font color="#008000"> ' An arbitrary function name is used.
- </font><font color="#000080"> fName = "vbEntityLength"
- Set vl_Defun = vld.Functions.Item(fName)
- </font><font color="#008000"> ' One might think that the value of vl_Defun or Err would indicate
- whether function fName
- ' was already available, but NOOOO! It is always an Object.
- </font><font color="#000080">
- </font><font color="#008000"> ' An error will be raised when we try to use the function...
- </font><font color="#000080"> On Error Resume Next
- </font><font color="#008000"> ' Note: Passing anEnt.Handle directly does NOT work. Parameters MUST
- be variants
- </font><font color="#000080"> arg = anEnt.Handle
- ret = vl_Defun.funcall(arg)
- If Err Then
- </font><font color="#008000"> ' Err.Number=2000, whether the reason is no function definition or
- the entity is not a curve
- </font><font color="#000080"> NoFunc = "no function definition:"
- If UCase(Left$(Err.Description, Len(NoFunc))) = UCase(NoFunc) Then
- </font><font color="#008000"> ' MsgBox Err.Description & " (" & Err.Number & ")",
- vbInformation, "Defining function " & fName & ":"
- </font><font color="#000080"> Err.Clear
- Set vl_Read = vld.Functions.Item("read")
- Set vl_Eval = vld.Functions.Item("eval")
- </font><font color="#008000"> ' Note: a mopre legible version of the Lisp code appears below,
- after the 'End Sub' statement
- </font><font color="#000080"> Set vl_Defun = vl_Read.funcall("(defun " & fName & " (x /
- picked rc lgth) (setq picked (handent (vlax-variant-value x))) (setq rc
- (Vlax-Curve-GetEndPoint picked)) (setq lgth (vlax-curve-GetDistAtPoint
- picked rc)))")
- Set vl_Defun = vl_Eval.funcall(vl_Defun)
- Set vl_Defun = vld.Functions.Item(fName)
- arg = anEnt.Handle
- ret = vl_Defun.funcall(arg)
- Else
- MsgBox Err.Description & " (" & Err.Number & ")",
- vbInformation, "Error in " & fName & ":"
- End If
- Else
- MsgBox "Function " & fName & " was already defined:"
- End If
- MsgBox "Length = " & ret & "."
- Exit Sub
- Failed:
- MsgBox Err.Description, vbInformation, "Error:"
- Err.Clear
- Exit Sub
- End Sub
- </font>A more legible version of the Lisp code is:
- <font color="#000080">(defun vbEntityLength ( x /
- picked rc lgth
- )
- </font><font color="#008000"> ; The argument passed in is an ActiveX variant, which must be
- converted into a plain Lisp value
- ; before Handent can use it.
- </font><font color="#000080"> (setq picked (handent (vlax-variant-value x)))
- </font><font color="#008000"> ; Now, we can call the VLisp function to get the end point
- </font><font color="#000080"> (setq rc (Vlax-Curve-GetEndPoint picked))
- </font><font color="#008000"> ; And the length is the distance at the end point
- </font><font color="#000080"> (setq lgth (vlax-curve-GetDistAtPoint picked rc))
- )</font></font></pre>
- <a name="link2"></a>
- <table cellSpacing="0" cellPadding="2" width="558" bgColor="#e0e0e0" border="0">
- <tbody>
- <tr>
- <td width="552">
- <table cellSpacing="0" cellPadding="0" align="right" border="0">
- <tbody>
- <tr>
- <td><font face="Courier New" size="2">Message 2 in thread</font></td>
- </tr>
- </tbody>
- </table>
- <font size="2">寄件者:</font><font face="Courier New" size="2"><a href="http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&q=author:degag%40videotron.ca+" target="_top">Denis
- Gagne</a> (<a href="mailto:degag@videotron.ca">degag@videotron.ca</a>)<br>
- </font><font size="2">主旨:</font><font face="Courier New" size="2">Re:
- VLisp from VB - Episode IV: The Variant Menace<br>
- </font><font size="2">新闻群组:</font><font face="Courier New" size="2"><a href="http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&group=autodesk.autocad.customization.vba" target="_top">autodesk.autocad.customization.vba</a><br>
- </font>
- <table cellSpacing="0" cellPadding="0" align="right" border="0">
- <tbody>
- <tr>
- <td><a href="http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=7q7eoo%24miu32%40adesknews2.autodesk.com" target="_top"><font face="Courier New" size="2">View
- this article only</font></a></td>
- </tr>
- </tbody>
- </table>
- <font size="2">日期:</font><font face="Courier New" size="2">1999/08/27<br>
- </font></td>
- </tr>
- </tbody>
- </table>
- <pre><font face="Courier New">Not enough for a marriage consumption
- between Lisp and Vba but at least it's the
- beginning of a more solid frequentation.
- Very well done, Mark
- Denis</font></pre>
- <a name="link3"></a>
- <table cellSpacing="0" cellPadding="2" width="557" bgColor="#e0e0e0" border="0">
- <tbody>
- <tr>
- <td width="551">
- <table cellSpacing="0" cellPadding="0" align="right" border="0">
- <tbody>
- <tr>
- <td><font face="Courier New" size="2">Message 3 in thread</font></td>
- </tr>
- </tbody>
- </table>
- <font size="2">寄件者:</font><font face="Courier New" size="2"><a href="http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&q=author:holderm%40atscorporation.com+" target="_top">Mark
- Holder</a> (<a href="mailto:holderm@atscorporation.com">holderm@atscorporation.com</a>)<br>
- </font><font size="2">主旨:</font><font face="Courier New" size="2">Re:
- VLisp from VB - Episode IV: The Variant Menace<br>
- </font><font size="2">新闻群组:</font><font face="Courier New" size="2"><a href="http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&group=autodesk.autocad.customization.vba" target="_top">autodesk.autocad.customization.vba</a><br>
- </font>
- <table cellSpacing="0" cellPadding="0" align="right" border="0">
- <tbody>
- <tr>
- <td><a href="http://groups.google.com/groups?hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=37C7D6C2.85F9EB3E%40atscorporation.com" target="_top"><font face="Courier New" size="2">View
- this article only</font></a></td>
- </tr>
- </tbody>
- </table>
- <font size="2">日期:</font><font face="Courier New" size="2">1999/08/28</font><font face="Courier New"><br>
- </font></td>
- </tr>
- </tbody>
- </table>
- <pre><font face="Courier New">Denis,
- Clearly, a better approach would be to expose functions like these
- through an AcitveX DLL like DbConnect does for database connectivity.
- Perhaps an adesker like Jorge or Albert or an intrepid 3rd party ARX
- developer will take on the task. Or maybe we just haven't yet found out
- what DLL we need to reference.
- Mark Holder
- Denis Gagne wrote:
- <font color="#660066">> Not enough for a marriage consumption
- > between Lisp and Vba but at least it's the
- > beginning of a more solid frequentation.
- >
- > Very well done, Mark
- >
- > Denis</font></font></pre>
- <table cellSpacing="0" cellPadding="0" width="100%" border="0">
- <tbody>
- <tr>
- <td bgColor="#ffcc33"><font face="Courier New"><img height="3" alt src="http://groups.google.com/images/cleardot.gif"></font></td>
- </tr>
- </tbody>
- </table>
- <font face="Courier New"><br>
- <center><font size="-1">©2002 Google</font></center></font>
- </body>
|
|