cll
2008-04-11, 09:28 AM
I have used this code for a long time to insert a logo as an external reference in a drawing titleblock og (if none) manually:
Public Sub InsLogo()
On Error GoTo Err_Control
Dim BlockObj As Object
Dim BlockObj1 As Object
Dim BlockObjName As String
Dim BlockObjName1 As String
Dim L1BlockObjAttributes
Dim colLayOuts As AcadLayouts
Dim objLayoutName As String
Dim objLayOut As AcadLayout
Dim UserName As String
Dim InsRef As AcadExternalReference
Dim PathName As String
Dim InsertPoint(0 To 2) As Double
Dim Scf As Double
PathName = "\\Data\Afdelinger\Teknik\Dokumentation\Mechanical\GEN\DWG\FORMAT\logo.dwg"
For Each BlockObj In ThisDrawing.ModelSpace
On Error Resume Next
BlockObjName = BlockObj.Name
Select Case BlockObjName
Case "PMC"
GoTo Ramme
Case "Pmc"
GoTo Ramme
End Select
Next
GoTo IngenTitel
Ramme:
For Each BlockObj1 In ThisDrawing.ModelSpace
On Error Resume Next
BlockObjName1 = BlockObj1.Name
Select Case BlockObjName1
Case "A4-V"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 209 * Scf: InsertPoint(1) = 21.77 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A4-H"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 120 * Scf: InsertPoint(1) = 27.77 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A3"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 326 * Scf: InsertPoint(1) = 23.07 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A2"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 484 * Scf: InsertPoint(1) = 21.27 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A1"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 751 * Scf: InsertPoint(1) = 21.57 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A0"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 1089 * Scf: InsertPoint(1) = 26.27 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
End Select
Next
GoTo IngenRamme
IngenTitel:
MsgBox "Der er ikke en standard titelblok"
GoTo Manuel
IngenRamme:
MsgBox "Der er ikke nogen standard tegningsramme"
GoTo Manuel
Manuel:
Dim Msg, Style, Title, Response, MyString
Msg = "Vil du indsætte Logo manuelt?" ' Define message.
Style = vbYesNo + vbQuestion + vbDefaultButton1 ' Define buttons.
Title = "Indsæt Logo..." ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
SendKeys "_xattach" & "{ENTER}"
Else ' User chose No.
MyString = "No" ' Perform some action.
GoTo Slut
End If
Slut:
RunMacro "magellan_2dmotion"
Exit_Here:
Exit Sub
Err_Control:
Select Case Err.Number
'Add your Case selections here
'Case Is = 1000
'Handle error
'Err.Clear
'Resume Exit_Here
Case Else
MsgBox Err.Number & ", " & Err.Description, , "InsLogo"
Err.Clear
Resume Exit_Here
End Select
End Sub
without problems.
Suddenly (two days ago) I get the:
Run-time error '-2147319765 (8002802b)'
Automation error
Element not found.
The highlighted line is:
For Each BlockObj In ThisDrawing.ModelSpace
The code has been running for years on my machine (several versions of AutoCad) and are still running on 5 other similar machines, so I don't think it has to do with the code.
I have uninstalled the latest windows-updates (from two-days ago) and an update for a SpacePilot (also recently), but with no effect to the problem.
I have searched this forum and google, but have not found a solution.
If any of you have had similar problem or a solution or a suggestion I'll be glad to hear about it.
Best Regards
Claus
Use:
AutoCad Mechanical 2008
Windows XP Professionel
Public Sub InsLogo()
On Error GoTo Err_Control
Dim BlockObj As Object
Dim BlockObj1 As Object
Dim BlockObjName As String
Dim BlockObjName1 As String
Dim L1BlockObjAttributes
Dim colLayOuts As AcadLayouts
Dim objLayoutName As String
Dim objLayOut As AcadLayout
Dim UserName As String
Dim InsRef As AcadExternalReference
Dim PathName As String
Dim InsertPoint(0 To 2) As Double
Dim Scf As Double
PathName = "\\Data\Afdelinger\Teknik\Dokumentation\Mechanical\GEN\DWG\FORMAT\logo.dwg"
For Each BlockObj In ThisDrawing.ModelSpace
On Error Resume Next
BlockObjName = BlockObj.Name
Select Case BlockObjName
Case "PMC"
GoTo Ramme
Case "Pmc"
GoTo Ramme
End Select
Next
GoTo IngenTitel
Ramme:
For Each BlockObj1 In ThisDrawing.ModelSpace
On Error Resume Next
BlockObjName1 = BlockObj1.Name
Select Case BlockObjName1
Case "A4-V"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 209 * Scf: InsertPoint(1) = 21.77 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A4-H"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 120 * Scf: InsertPoint(1) = 27.77 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A3"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 326 * Scf: InsertPoint(1) = 23.07 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A2"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 484 * Scf: InsertPoint(1) = 21.27 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A1"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 751 * Scf: InsertPoint(1) = 21.57 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
Case "A0"
Scf = BlockObj1.XScaleFactor
InsertPoint(0) = 1089 * Scf: InsertPoint(1) = 26.27 * Scf: InsertPoint(2) = 0
Set InsRef = ThisDrawing.ModelSpace.AttachExternalReference(PathName, _
"Logo", InsertPoint, Scf, Scf, Scf, 0, False)
GoTo Slut
End Select
Next
GoTo IngenRamme
IngenTitel:
MsgBox "Der er ikke en standard titelblok"
GoTo Manuel
IngenRamme:
MsgBox "Der er ikke nogen standard tegningsramme"
GoTo Manuel
Manuel:
Dim Msg, Style, Title, Response, MyString
Msg = "Vil du indsætte Logo manuelt?" ' Define message.
Style = vbYesNo + vbQuestion + vbDefaultButton1 ' Define buttons.
Title = "Indsæt Logo..." ' Define title.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
SendKeys "_xattach" & "{ENTER}"
Else ' User chose No.
MyString = "No" ' Perform some action.
GoTo Slut
End If
Slut:
RunMacro "magellan_2dmotion"
Exit_Here:
Exit Sub
Err_Control:
Select Case Err.Number
'Add your Case selections here
'Case Is = 1000
'Handle error
'Err.Clear
'Resume Exit_Here
Case Else
MsgBox Err.Number & ", " & Err.Description, , "InsLogo"
Err.Clear
Resume Exit_Here
End Select
End Sub
without problems.
Suddenly (two days ago) I get the:
Run-time error '-2147319765 (8002802b)'
Automation error
Element not found.
The highlighted line is:
For Each BlockObj In ThisDrawing.ModelSpace
The code has been running for years on my machine (several versions of AutoCad) and are still running on 5 other similar machines, so I don't think it has to do with the code.
I have uninstalled the latest windows-updates (from two-days ago) and an update for a SpacePilot (also recently), but with no effect to the problem.
I have searched this forum and google, but have not found a solution.
If any of you have had similar problem or a solution or a suggestion I'll be glad to hear about it.
Best Regards
Claus
Use:
AutoCad Mechanical 2008
Windows XP Professionel