alehasan 发表于 2022-7-6 12:10:02

如何在中运行vba lisp例程

大家好,
我想知道是否有人能帮我解决这个问题。
我有一个vba lisp例程,我真的不知道它的任何东西,只是想在我的auto cad中运行这段代码,如果有人能给我一步一步的指示如何在我的autocad中运行这段代码,我不知道任何关于lisp的事,所以请给我完整的指示,直到我得到它在我的autocad中运行和使用,谢谢
代码如下:
 
Option Explicit
Function GetActiveSpace() As AcadBlock
   With ThisDrawing
       If .ActiveSpace = acModelSpace Then
         Set GetActiveSpace = .ModelSpace
       Else
         Set GetActiveSpace = .PaperSpace
       End If
       End With
   End Function
Function StoreLayerStatus() As Variant
   Dim oLayer As AcadLayer
   Dim oLayers As AcadLayers
   Dim i As Integer
   With ThisDrawing
       Set oLayers = .Layers
   End With
   ReDim layerArr(0 To oLayers.Count - 1, 0 To 2) As Variant
   For Each oLayer In oLayers
       layerArr(i, 0) = oLayer.Name
       layerArr(i, 1) = oLayer.Lock
       layerArr(i, 2) = oLayer.Freeze
       On Error Resume Next
       oLayer.Freeze = False
       If Err Then Err.Clear
       i = i + 1
   Next oLayer
   On Error GoTo 0
   StoreLayerStatus = layerArr
End Function
Private Sub RestoreLayerStatus(ByVal ar As Variant)
   Dim oLayer As AcadLayer
   Dim oLayers As AcadLayers
   Dim i As Integer
       With ThisDrawing
       Set oLayers = .Layers
   End With
   For i = LBound(ar, 1) To UBound(ar, 1)
   Set oLayer = oLayers(ar(i, 0))
   On Error Resume Next '<-- to bypass active layer
   With oLayer
   .Lock = ar(i, 1)
   .Freeze = ar(i, 2)
   End With
   If Err Then Err.Clear
   Next i
   On Error GoTo 0
   
End Sub

Sub BlockReplace()
Dim lsArr As Variant
lsArr = StoreLayerStatus
Dim oSpace As AcadBlock
Dim varPt As Variant
Dim oEnt As AcadEntity
Dim oldBlkRef As AcadBlockReference
Dim newBlkRef As AcadBlockReference
Dim oldblkName As String
Dim newblkName As String
Dim layName As String
Dim xscl As Double
Dim yscl As Double
Dim zscl As Double
Dim rot As Double
Dim insPt(2) As Double
Dim ftype(0) As Integer
Dim fdata(0) As Variant
Dim dxfCode, dxfValue
Dim oSset As AcadSelectionSet
ThisDrawing.Utility.GetEntity oEnt, varPt, vbCrLf & "Select new block instance to replace with:"
If Not TypeOf oEnt Is AcadBlockReference Then
MsgBox "Selected object isn't a block reference"
Exit Sub
End If
Set newBlkRef = oEnt
If newBlkRef.IsDynamicBlock Then
newblkName = newBlkRef.EffectiveName
Else
newblkName = newBlkRef.Name
End If
         With ThisDrawing.SelectionSets
            While .Count > 0
                   .Item(0).Delete
            Wend
         Set oSset = .Add("$ReplaceBlocks$")
         End With
         
ftype(0) = 0
fdata(0) = "INSERT"
dxfCode = ftype: dxfValue = fdata
oSset.SelectOnScreen dxfCode, dxfValue
Set oSpace = GetActiveSpace
For Each oEnt In oSset
Set oldBlkRef = oEnt
With oldBlkRef
layName = .Layer
xscl = .XScaleFactor
yscl = .YScaleFactor
zscl = .ZScaleFactor
rot = .Rotation
varPt = .InsertionPoint
insPt(0) = varPt(0): insPt(1) = varPt(1): insPt(2) = varPt(2)
.Delete
End With
Set newBlkRef = oSpace.InsertBlock(insPt, newblkName, xscl, yscl, zscl, rot)
newBlkRef.Layer = layName
Next oEnt
RestoreLayerStatus (lsArr)
ThisDrawing.Regen acActiveViewport
End Sub

alehasan 发表于 2022-7-6 12:18:41

抱歉,大家忘了告诉你,这段代码是用来用另一个块替换一个块的特定实例的。

Tiger 发表于 2022-7-6 12:34:11

试试这个解释
 

rkmcswain 发表于 2022-7-6 12:37:36

 
VBA和Lisp是两个不同的东西。
您的代码是VBA,而不是lisp。
 
看起来Tiger给了你运行这段代码的步骤。。。

alehasan 发表于 2022-7-6 12:49:51

谢谢你,老虎,
你能解释一下激活lisp例程的单词是什么吗。

alehasan 发表于 2022-7-6 12:53:07

是的,我的代码是vba,有人能用我给的代码举例吗??我很欣赏tiger的回答,但运行我的代码仍然让我感到困惑,因为它与tiger在其示例中使用的代码不同,谢谢

Tiger 发表于 2022-7-6 13:07:30

 
因为我对VBA例程几乎一无所知,所以我不能帮你。我会把这个帖子转移到定制论坛,你可能会在那里得到更快的答案。

rkmcswain 发表于 2022-7-6 13:16:29

 
实际代码并不重要。Tiger为您概述的过程是相同的,只需使用您的代码。我可能提到的唯一区别是,您可以运行VBARUN命令并从对话框中选择宏,而不是在命令行中使用“vbastmt”命令。
 
注意:如果您运行的是AutoCAD 2010,则不包括VBA。不过,您可以从Autodesk下载它。
页: [1]
查看完整版本: 如何在中运行vba lisp例程