×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SW2k6 - Block Placement Macro Error

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:

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

RE: SW2k6 - Block Placement Macro Error

I couldn't find it in the API to check, but there might be extra arguments to the InsertCustomSymbol call which would allow you to specify the location.  If so you could try moving the position to that call rather than preselecting the point using the SelectByID call.

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

(OP)
Ahhh, you are correct about the InsertCustomSymbol... that seems to be an old call, and was taken over by DrawingDoc::InsertBlock, which allows you to specify a location when placing the symbol. I will have to give it a shot, however no indication of whether or not it'll let me specify anything over the 0.999 position.

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

(OP)
InsertBlock does work over 0.999. Looks like next time I need to start looking into the API before just going with what I've got, and see what is the latest commands. (doh!)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources