useless macro

Discussion in 'SolidWorks' started by DragonAtWork, Apr 7, 2006.

  1. DragonAtWork

    DragonAtWork Guest

    Using solidworks 2006. Record a macro (part elongation). undo change
    (recorded) or load assembly again (or even another assembly. Try to
    invoke macro. no change to part. Seems to me this should work without
    much ado. I am in the process of re-installing SW now. In the meantime,
    any ideas as to how/why it is not working for me?
     
    DragonAtWork, Apr 7, 2006
    #1
  2. DragonAtWork

    TOP Guest

    You have to understand that macro recordings are not one for one
    keystroke recordings. Way back in SW95 they were, but no more. In
    addition, not all GUI functionality is possible in a macro.

    When you say part elongation what are you doing to elongate the part?
     
    TOP, Apr 7, 2006
    #2
  3. DragonAtWork

    Fye Guest

    Recording a macro will capture the commands you issue, but you have to
    remember that it's possible that it will only work again if ALL other
    variables are kept the same the next time you run the macro. For
    example, changing the length on a part should be easy, but may not work
    if you change window size, view orientation, part name, etc. when you
    run the macro the next time.

    Recording macros are a great way to start an API project, and also
    helpful if you can't figure out a certain command. I have never ever
    simply recorded a macro without editing it heavily after the fact. Of
    course this take a bit of API knowledge.

    I always keep a "temp.swp" macro which I use to record new stuff to
    (overwrites it all the time) so I can use the recorded code later.
     
    Fye, Apr 8, 2006
    #3
  4. DragonAtWork

    Jeff Guest

    TOP hit the issue right on the head. Not all commands are reproducible
    in VBA. Most of the time, you have to replace the recorded one with a
    valid call.
     
    Jeff, Apr 10, 2006
    #4
  5. DragonAtWork

    DragonAtWork Guest

    Taking a pin and enlongating the shaft by changing it's value. Tried
    some examples of macros off the web, but they also did not work. I
    don't mind programming (have a lot of VB and other expereince), prehaps
    I have had better APIs to work from in past....
     
    DragonAtWork, Apr 10, 2006
    #5
  6. DragonAtWork

    TOP Guest

    Dragon,

    This might explain some things.

    Option Explicit

    '
    ******************************************************************************
    ' C:\DOCUME~1\KELLNERP\LOCALS~1\Temp\swx132\Macro1.swb - macro recorded
    on 04/10/06 by kellnerp
    '
    ' REQUIRES A NEW EMPTY PART BEING OPEN
    '
    '
    ******************************************************************************
    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
    Dim ANNOTATION As Object 'HAD TO ADD THIS LINE BECAUSE SW FORGOT, SEE
    OPTION EXPLICIT

    Sub main()

    Set swApp = Application.SldWorks

    Set Part = swApp.ActiveDoc
    boolstatus = Part.Extension.SelectByID("Front", "PLANE", 0, 0, 0,
    False, 0, Nothing)
    boolstatus = Part.Extension.SelectByID("Front", "PLANE", 0, 0, 0,
    False, 0, Nothing)
    Part.InsertSketch2 True
    Part.ClearSelection2 True
    Part.CreateCircle 0, 0, 0, 0.01863896961691, -0.01974623513871, 0
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID("Arc1", "SKETCHSEGMENT",
    0.01974623513871, 0.01679352708058, 0, False, 0, Nothing)
    Set ANNOTATION = Part.AddDimension2(0.0570242, 0.0544406, 0)
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID("D1@",
    "DIMENSION", 0.05739326287979, 0.05333328929987, 0, False, 0, Nothing)
    Part.Parameter("D1@Sketch1").SystemValue = 0.0254
    Part.ShowNamedView2 "*Trimetric", 8
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID("D1@",
    "DIMENSION", 0.05739326287979, 0.05333328929987, 0, False, 0, Nothing)
    Part.FeatureManager.FeatureExtrusion True, False, False, 0, 0, 0.0762,
    0.00254, False, False, False, False, 0.01745329251994,
    0.01745329251994, False, False, False, False, 1, 1, 1
    Part.SelectionManager.EnableContourSelection = 0
    Part.ViewZoomtofit2
    ' OK HERE WE GO
    ' PICK PIN
    boolstatus = Part.Extension.SelectByID("", "FACE", 0.007306839262867,
    0.01038749729173, 0.04061127328708, False, 0, Nothing)
    ' ACTIVATE PIN CAUSING DIMS TO APPEAR
    Part.ActivateSelectedFeature
    boolstatus = Part.Extension.SelectByID("D1@",
    "DIMENSION", 0.01309206995176, -0.003006131781169, 0.03323381468602,
    False, 0, Nothing)
    ' CHANGE DIMENSION. OOPS, SW DOESN'T SHOW THIS IN THE MACRO, IT JUST
    REBUILDS. SHOULD HAVE SHOWN PART.PARAMETER( ) LINE HERE.
    Part.EditRebuild
    Part.ClearSelection2 True
    Part.ViewZoomtofit2
    ' LETS DO IT FOR REAL AND PUT IN THE CHANGE TO THE EXTRUDE DIM.
    Part.Parameter("D1@Extrude1").SystemValue = 0.0254 * 5
    Part.EditRebuild
    End Sub
     
    TOP, Apr 10, 2006
    #6
  7. DragonAtWork

    Fye Guest

    Heh - so true. The Macro recorder is really a POS, but once you trudge
    your way through a few basic macros (RTFM), it's not hard to figure out
    what to do to make the macros work.

    Best advice would be to find someone with a macro similar to what you
    need (that works of course), and use it as a basis for your program.
     
    Fye, Apr 11, 2006
    #7
  8. DragonAtWork

    TOP Guest

    I would say that the macro recorder doesn't come up to customer
    expectations. The vast majority of SW users don't know much about VB
    and much less about object oriented programming. The API does not
    capture many useful and important GUI commands. And, as in this
    example, it misses something very simple. For all that it is much
    better than, say , SolidEdge which has no macro recorder at all. And it
    is helpful for getting started. For the average user something that
    captured keystrokes would probably be more helpful, but on the whole
    the macro/API has been quite usefull to me even with its steep learning
    curve.
     
    TOP, Apr 11, 2006
    #8
  9. DragonAtWork

    Jeff Guest

    What exactly are you trying to create, I may already have one that does
    it or is a good starting point.
     
    Jeff, Apr 11, 2006
    #9
  10. DragonAtWork

    TOP Guest

    I don't know what Dragon is trying to create.
     
    TOP, Apr 11, 2006
    #10
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.