SW2k6 - Block Placement Macro Error
SW2k6 - Block Placement Macro Error
(OP)
I've got a macro that I am trying to create which inserts blocks at certain locations on drawings automatically depending on the size of the drawing. Eventually I need to modify it to give a choice of selections, hence the reason I don't just add it to my template.
I have no problems with A-D size drawings, however when I get to E size drawings, the X coordinate needs to be over 1.0, and SolidWorks doesn't seem to like this. If you've already selected the sheet by mouse click, it will place the block at that location, however if nothing is selected, it won't place anything.
Any ideas how to get this to work, or even suggestions as to a better method?
Here is the script as it sits:
I have no problems with A-D size drawings, however when I get to E size drawings, the X coordinate needs to be over 1.0, and SolidWorks doesn't seem to like this. If you've already selected the sheet by mouse click, it will place the block at that location, however if nothing is selected, it won't place anything.
Any ideas how to get this to work, or even suggestions as to a better method?
Here is the script as it sits:
CODE
Public swApp As Object
Public swModel As Object
Public swDraw As Object
Public swSheet As Object
Public vSheetProps As Variant
Public bRet As Boolean
Public MyDoc As Object
Public bPositions As String
Public bGen As String
Public bApp1 As String
Public bApp2 As String
Public SheetSize As String
Sub Main()
Set swApp = Application.SldWorks
Set MyDoc = swApp.ActiveDoc
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet
vSheetProps = swSheet.GetProperties
SheetSize = vSheetProps(0)
If SheetSize = "1" Then
Debug.Print "A"
ElseIf SheetSize = "2" Then
Debug.Print "B"
ElseIf SheetSize = "3" Then
Debug.Print "C"
ElseIf SheetSize = "4" Then
Debug.Print "D"
ElseIf SheetSize = "5" Then
Debug.Print "E"
Else
SheetSize = MsgBox("Please use only with valid drawing sizes!", vbOKOnly, "Alert!")
End
End If
'--- Write If statement to see if a General Finish is picked ---
'--- Write General Finish to sheet ---
If SheetSize = "1" Then
MyDoc.SelectByID "", "SHEET", 0.183, 0.0715, 0
ElseIf SheetSize = "2" Then
MyDoc.SelectByID "", "SHEET", 0.398, 0.0725, 0
ElseIf SheetSize = "3" Then
MyDoc.SelectByID "", "SHEET", 0.532, 0.081, 0
ElseIf SheetSize = "4" Then
MyDoc.SelectByID "", "SHEET", 0.836, 0.079, 0
ElseIf SheetSize = "5" Then
MyDoc.SelectByID "", "SHEET", 1.2, 0.075, 0
End If
MyDoc.InsertCustomSymbol "C:\Blocks\general_finish.SLDBLK"
End Sub
Public swModel As Object
Public swDraw As Object
Public swSheet As Object
Public vSheetProps As Variant
Public bRet As Boolean
Public MyDoc As Object
Public bPositions As String
Public bGen As String
Public bApp1 As String
Public bApp2 As String
Public SheetSize As String
Sub Main()
Set swApp = Application.SldWorks
Set MyDoc = swApp.ActiveDoc
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet
vSheetProps = swSheet.GetProperties
SheetSize = vSheetProps(0)
If SheetSize = "1" Then
Debug.Print "A"
ElseIf SheetSize = "2" Then
Debug.Print "B"
ElseIf SheetSize = "3" Then
Debug.Print "C"
ElseIf SheetSize = "4" Then
Debug.Print "D"
ElseIf SheetSize = "5" Then
Debug.Print "E"
Else
SheetSize = MsgBox("Please use only with valid drawing sizes!", vbOKOnly, "Alert!")
End
End If
'--- Write If statement to see if a General Finish is picked ---
'--- Write General Finish to sheet ---
If SheetSize = "1" Then
MyDoc.SelectByID "", "SHEET", 0.183, 0.0715, 0
ElseIf SheetSize = "2" Then
MyDoc.SelectByID "", "SHEET", 0.398, 0.0725, 0
ElseIf SheetSize = "3" Then
MyDoc.SelectByID "", "SHEET", 0.532, 0.081, 0
ElseIf SheetSize = "4" Then
MyDoc.SelectByID "", "SHEET", 0.836, 0.079, 0
ElseIf SheetSize = "5" Then
MyDoc.SelectByID "", "SHEET", 1.2, 0.075, 0
End If
MyDoc.InsertCustomSymbol "C:\Blocks\general_finish.SLDBLK"
End Sub






RE: SW2k6 - Block Placement Macro Error
As a side note the:
SheetSize = MsgBox("Please use only with valid drawing sizes!", vbOKOnly, "Alert!")
line looks odd. In that case you are setting SheetSize to the return value of the message box. It is used in the next set of if statements, and depending on the return value of the message box, it may match one of the cases.
Eric
RE: SW2k6 - Block Placement Macro Error
I will give the new command a shot this afternoon and re-post results. Hopefully that will solve my issues.
FWIW, the "SheetSize = MsgBox" command really only works when the returned sheet size is anything but 1-5 (A-E), so technically I should put an "End" after that point, though letting it run will just pass by any other statements since they're all based off of sheet size anyway.
RE: SW2k6 - Block Placement Macro Error