日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Delphi连接AutoCAD_计算任意线条的长度宏的嵌套

發布時間:2024/9/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Delphi连接AutoCAD_计算任意线条的长度宏的嵌套 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在AutoCAD里可以通過 List 和Area命令求的樣條曲線等任意一條曲線的長度。但是要在delphi得到AutoCAD里任意一條曲線的長度就需要編寫宏,然后再將宏嵌入到Delphi里 這是在AutoCAD2004下調試通過的宏 Sub SecFunc()
??? Dim SelectionSet As AcadSelectionSet
??? Dim lSpLine As AcadSpline
???????
??? Dim sysVarName As String
??? Dim sysVarData As Variant
??? Dim DataType As Integer
???????
??? ThisDrawing.SelectionSets.Item(0).Delete
??? Set SelectionSet = ThisDrawing.SelectionSets.Add("New_SelectionSet")
??? SelectionSet.SelectOnScreen Set lSpLine = SelectionSet.Item(0)
???
??? ThisDrawing.SetVariable "USERR1", 1.5
??? ThisDrawing.SendCommand "(vl-load-com)" & vbCr
???
??? Dim StrCom As String
???
??? StrCom = "(setvar " & Chr(34) & "USERR1" & Chr(34) & Chr(32) & "(vlax-curve-getdistatparam (vlax-ename->vla-object (handent " & Chr(34) & lSpLine.Handle & Chr(34) & ")) (vlax-curve-getendparam (vlax-ename->vla-object (handent " & Chr(34) & lSpLine.Handle & Chr(34) & ")))))" & vbCr
??? ThisDrawing.SendCommand StrCom
??? MsgBox StrCom
??? sysVarData = ThisDrawing.GetVariable("USERR1")
??? MsgBox sysVarData
End Sub 這是Delphi里對該宏的嵌入式調用 function GetLengthOfObject(pHandle:THandle;pCadDoc:OleVariant):Real;
var
? lTempVariant:OleVariant;
? lTempVar:wideString;
begin
??? lTempVariant:=0;
??? lTempVar:='USERR1';
??? pCadDoc.SetVariable(lTempVar,lTempVariant);
??? lTempVar:='(vl-load-com)' + #13;
??? pCadDoc.SendCommand(lTempVar); lTempVar:='(setvar ' + Chr(34) + 'USERR1'+Chr(34)+ Chr(32) +
??????????????????????? '(vlax-curve-getdistatparam (vlax-ename->vla-object '+
??????????????????????? '(handent '+ Chr(34) +IntToStr(pHandle)+ Chr(34)+')) '+
??????????????????????? '(vlax-curve-getendparam (vlax-ename->vla-object '+
??????????????????????? '(handent '+ Chr(34) +IntToStr(pHandle)+Chr(34) +
??????????????????????? ')))))'+#13;
??? pCadDoc.SendCommand(lTempVar);
??? Result:=pCadDoc.GetVariable('USERR1');
end;
體會: 1,宏的語法就是VB的語法。 2,宏里面的"&"符號就是字符串的連接,在delphi里面就是字符串的相加。比如 宏里面的 "(setvar " & Chr(34) & "USERR1" & Chr(34) & Chr(32) 在delphi里面就是"(setvar "?+ Chr(34)?+ "USERR1"?+ Chr(34)?+ Chr(32) 其中 Chr(34)是 " 符號 Chr(32)是空字符 3 宏里面的VbCr就相當于是按了一下回車鍵,而在delphi里面就是#13 4 在delphi里面嵌套宏一定要注意空格和回車。比如在宏里面是"USERR1",在delphi里? 面也必須寫成:'USERR1',如果寫成'USERR1 ',在連接AutoCAD時就會出線“呼叫被拒絕”,或者是及時在delphi里面能運行通過,你卻得不到想要的結果。 5 關于參數的傳遞 與函數的調用。 AutoCAD里提供一個設置系統變量的函數 SetVariable 原型是: object.SetVariable Name, Value Object :Document
????????????????????????????????????????? The object or objects this method applies to.????? Name :String; input-only
??????????????????????????????????????? The name of the system variable to set.?? Value:Variant; input-only
???????????????????????????????????????? The new value for the specified system variable.???? Example Sub Example_SetVariable()' This example sets various system variables, each of' a different data type.Dim sysVarName As StringDim sysVarData As VariantDim DataType As Integer' Set FILEDIA system variable (data type Integer) to 1. NOTE that' you need to declare a variable as the data type of system variable,' assign data to that variable and then make it variant typeDim intData As IntegersysVarName = "FILEDIA"intData = 1sysVarData = intData ' Integer dataThisDrawing.SetVariable sysVarName, sysVarData' Check the variable using GetVariablesysVarData = ThisDrawing.GetVariable(sysVarName)MsgBox sysVarName & " = " & sysVarData, , "SetVariable Example"' Set DCTCUST system variable (data type String) to "My Custom Dictionary"Dim strData As StringsysVarName = "DCTCUST"strData = "My Custom Dictionary"sysVarData = strData ' String dataThisDrawing.SetVariable sysVarName, sysVarData' Check the variable using GetVariablesysVarData = ThisDrawing.GetVariable(sysVarName)MsgBox sysVarName & " = " & sysVarData, , "SetVariable Example"' Set CHAMFERA system variable (data type Double) to 1.5Dim dataDouble As DoublesysVarName = "CHAMFERA"dataDouble = 1.5sysVarData = dataDouble ' Double dataThisDrawing.SetVariable sysVarName, sysVarData' Check the variable using GetVariablesysVarData = ThisDrawing.GetVariable(sysVarName)MsgBox sysVarName & " = " & sysVarData, , "SetVariable Example"' Set INSBASE system variable (data type array) to (1.0,1.0,0)Dim arrayData3D(0 To 2) As DoublesysVarName = "INSBASE"arrayData3D(0) = 1#: arrayData3D(1) = 1#: arrayData3D(2) = 0sysVarData = arrayData3D ' 3D array dataThisDrawing.SetVariable sysVarName, sysVarData' Check the variable using GetVariablesysVarData = ThisDrawing.GetVariable(sysVarName)MsgBox sysVarName & " = " & sysVarData(0) & ", " & sysVarData(1) & ", " & sysVarData(2), , "SetVariable Example"End Sub 這個函數在AutoCAD提供的類型庫里的原型是這樣的: procedure SetVariable(const Name: WideString; Value: OleVariant); safecall; 理論上這樣調用是沒有問題的 SetVariable('USERR1',1.5); 但是這樣編譯能通的過去,運行的時候就會報錯“無法設置系統變量值” 如果聲明一個WideString類型的變量就可以了 如: var lName:WideString; lName:='USERR1'; SetVariable(lName,1.5);

轉載于:https://blog.51cto.com/bigpower/92208

總結

以上是生活随笔為你收集整理的Delphi连接AutoCAD_计算任意线条的长度宏的嵌套的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。