好建议米克。
作为插入函数,以下工作正常,但我稍后必须更改插入点(oBref.InsertionPoint=insPt),不知道为什么。
Function InsertBlockref(Space As AcadBlock, insPt As Variant, sName As String, Optional Sc As Double = 1, Optional Rot As Double = 0) As AcadBlockReference
Dim oBref As AcadBlockReference
Dim Zero(2) As Double
Dim N(2) As Double, oUcs As AcadUCS
Dim Att
Set oBref = Space.InsertBlock(Zero, sName, Sc, Sc, Sc, Rot)
If ThisDrawing.GetVariable("Worlducs") = 1 Then
Set InsertBlockref = oBref
Exit Function
End If
N(2) = 1
oBref.Normal = N
If oBref.HasAttributes Then
For Each Att In oBref.GetAttributes
Att.Normal = N
Next Att
End If
Set oUcs = GetActiveUcs
oBref.TransformBy oUcs.GetUCSMatrix
oBref.InsertionPoint = insPt
Set InsertBlockref = oBref
End Function
和一个函数
Function GetActiveUcs() As AcadUCS
Dim Origin
Dim Xaxis
Dim Yaxis
Dim strNm As String, sUcs As String
sUcs = ThisDrawing.GetVariable("UCSNAME")
If sUcs = "" Then
' Current UCS is not saved so get the data and save it
'A ucs is saved when a user makes and saves one or
' a user clicks on an isoview button
With ThisDrawing
If .GetVariable("WORLDUCS") = 1 Then
Xaxis = Zero: Yaxis = Zero
Xaxis(0) = 1: Yaxis(1) = 1
Set GetActiveUcs = ThisDrawing.UserCoordinateSystems.Add(Zero, Xaxis, Yaxis, "World")
Exit Function
End If
Origin = .GetVariable("UCSORG")
Xaxis = .GetVariable("UCSXDIR")
Yaxis = .GetVariable("UCSYDIR")
strNm = "Active"
End With
Set GetActiveUcs = ThisDrawing.UserCoordinateSystems.Add(Zero, Xaxis, Yaxis, strNm)
'Changing the origin later stops the error message
'-2145320930 UCS X axis and Y axis are not perpendicular
GetActiveUcs.Origin = Origin
ThisDrawing.ActiveUCS = GetActiveUcs
Else
Select Case sUcs
Case "*TOP*", "TOP"
Set GetActiveUcs = SetOrthoUCS("Top")
Case "*BOTTOM*"
Set GetActiveUcs = SetOrthoUCS("Bottom")
Case "*LEFT*"
Set GetActiveUcs = SetOrthoUCS("Left")
Case "*RIGHT*"
Set GetActiveUcs = SetOrthoUCS("Right")
Case "*FRONT*"
Set GetActiveUcs = SetOrthoUCS("Front")
Case "*BACK*"
Set GetActiveUcs = SetOrthoUCS("Back")
Case Else
Set GetActiveUcs = ThisDrawing.ActiveUCS 'current UCS is saved
End Select
End If
End Function