Click and place macro

Discussion in 'SolidWorks' started by b.w.towell, Feb 2, 2006.

  1. b.w.towell

    b.w.towell Guest

    Hello,

    Could any of you please help me with creating a macro to do the
    following?

    I have a drawing open and want to add a note in square border (with no
    leader). The content of the note is one alphabetic character (ie. A or
    B or C...Z...etc).

    What I want the macro to let me do is click on the drawing where i want
    to place the note and automatically add the note, then increment onto
    the next chararcter for the next click on the drawing.

    i.e.

    Click on drawing (example co-ord 10,35,0) add note A
    Click on drawing (example co-ord 14,35,0) add note B
    Click on drawing (example co-ord 1,347,0) add note C
    Click on drawing (example co-ord 100,366,0) add note D

    Is it possible to have an "interactive" macro?

    Thanks, B
     
    b.w.towell, Feb 2, 2006
    #1
  2. b.w.towell

    CS Guest

    Of course it is possible.

    ................ThisLibrary..........(found under SolidWorks Objects
    this code could also be added to a non-modal form)
    Public WithEvents DrawingDoc As DrawingDoc
    Public CurrentValue As Long
    Public ClearingSelectionFlag As Boolean

    Private Function DrawingDoc_NewSelectionNotify() As Long
    If ClearingSelectionFlag Then Exit Function
    If CurrentValue < 65 Then CurrentValue = 65
    Set CartListNoteObj = DrawingDoc.InsertNote(Chr(CurrentValue))
    CurrentValue = CurrentValue + 1
    ClearingSelectionFlag = True
    DrawingDoc.ClearSelection2 (True)
    ClearingSelectionFlag = False
    End Function

    .....................Module1.............(this code starts and stops the
    event watching)
    Sub StartAlphabetSoup()
    Dim swapp As SldWorks.SldWorks
    Set swapp = Application.SldWorks
    Set ThisLibrary.DrawingDoc = swapp.ActiveDoc
    End Sub

    Sub EndAlphabetSoup()
    Set ThisLibrary.DrawingDoc = Nothing
    End Sub
    ...........................................................
    Now all you have to do is run StartAlphabetSoup and start clicking
    away.
    then when you have finished your child's lunch you can run
    EndAlphabetSoup

    Regards,

    Corey Scheich
     
    CS, Feb 2, 2006
    #2
  3. b.w.towell

    b.w.towell Guest

    Thanks for the reply Corey.
     
    b.w.towell, Feb 3, 2006
    #3
  4. b.w.towell

    b.w.towell Guest

    Is there a way of inserting this into a larger program as an interrupt?

    I want to interrupt a main program, click some points on the screen,
    when run the rest of the main program.

    I have inserted the code from above into my program, but all the "main"
    runs and then I can click the places on the screen.

    Are there interrupt, pause, resume commands?

    Are there ways of passing values from the main program into ThisLibrary
    or vice versa?

    Below is the test code that I have been using.

    Thanks for any help.

    B


    Inserted in ThisLibrary
    **************************************************************************************************
    Public WithEvents DrawingDoc As DrawingDoc
    Public CurrentValue As Long
    Public ClearingSelectionFlag As Boolean


    Private Function DrawingDoc_NewSelectionNotify() As Long
    If ClearingSelectionFlag Then Exit Function
    If CurrentValue < 65 Then CurrentValue = 65
    Set CartListNoteObj = DrawingDoc.InsertNote(Chr(CurrentValue))
    CurrentValue = CurrentValue + 1
    ClearingSelectionFlag = True
    DrawingDoc.ClearSelection2 (True)
    ClearingSelectionFlag = False

    If CurrentValue = 70 Then
    Stop
    End If

    End Function
    ******************************************************************************************************

    In Module 1


    Dim swApp As Object
    Dim Part As Object
    Dim boolstatus As Boolean
    Dim longstatus As Long, longwarnings As Long
    Dim FeatureData As Object
    Dim Feature As Object
    Dim Component As Object

    Function Letters()

    Dim swApp As SldWorks.SldWorks
    Set swApp = Application.SldWorks
    Set ThisLibrary.DrawingDoc = swApp.ActiveDoc
    End Function

    Sub main()

    Set swApp = Application.SldWorks
    Set Part = swApp.NewDocument("D:\XXXXXXXXXXXXXXXXXXXX\temp_a.slddrt",
    0, 0.2159, 0.2794)
    Set Part = swApp.ActivateDoc2("Draw2 - Sheet1", False, longstatus)
    swApp.ActiveDoc.ActiveView.FrameState = 1

    Letters

    MsgBox "end of main"

    End Sub
     
    b.w.towell, Feb 3, 2006
    #4
  5. b.w.towell

    CS Guest

    Essencially you could use this code anywhere you want. You just need
    the ability to turn the watch on and off otherwise everytime you click
    until you shut down solidworks you will continue to add notes.

    You could also put the code in ThisLibrary in a Form instead.
    In sub main you would put this code
    ............................
    Sub Main ()

    Load UserForm1
    UserForm1.Show False 'setting the modal value to false allows you to
    select things in solidworks

    end sub

    ..............................UserForm1...............
    Public WithEvents DrawingDoc As DrawingDoc
    Public CurrentValue As Long
    Public ClearingSelectionFlag As Boolean


    Private Function DrawingDoc_NewSelectionNotify() As Long
    If ClearingSelectionFlag Then Exit Function
    If CurrentValue < 65 Then CurrentValue = 65
    Set CartListNoteObj = DrawingDoc.InsertNote(Chr(CurrentValue))
    CurrentValue = CurrentValue + 1
    ClearingSelectionFlag = True
    DrawingDoc.ClearSelection2 (True)
    ClearingSelectionFlag = False


    If CurrentValue = 70 Then
    Stop
    End If


    End Function

    Private Sub UserForm1_Load ()'this could also be a button click or any
    form event
    startalphabetsoup
    end sub

    Private Sub UserForm1_Unload()this could also be a button click or any
    form event
    endAlphabetsoup
    end sub

    Sub StartAlphabetSoup()
    Dim swapp As SldWorks.SldWorks
    Set swapp = Application.SldWorks
    Set ThisLibrary.DrawingDoc = swapp.ActiveDoc
    End Sub


    Sub EndAlphabetSoup()
    Set ThisLibrary.DrawingDoc = Nothing
    End Sub
     
    CS, Feb 3, 2006
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.