8Complex
Mechanical
- Jan 28, 2004
- 38
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