From: Not Necessarily Me on
Just started playing with macros and so far have had very little success.
I've been using the RECORD macro but everything I think I'm recording
doesn't show up when I go and edit the macro. Basically I load a drawing,
start recording, open the layer properties, change the color of one layer,
create another layer, exit the layer properties. Then I right click on the
sheet tab, select edit sheet format, activate the sketch entities filter,
draw a window around the sheet border (selecting all sketch entities), and
then use the layer drop down to change the layer to the newly corrected
layer. And then stop recording. When I try running the macro on another
drawing not much happens. When I edit the macro all I see is:

'
****************************************************************************
**
' C:\DOCUME~1\jeff\LOCALS~1\Temp\swx1076\Macro1.swb - macro recorded on
03/02/05 by jeff
'
****************************************************************************
**
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
Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
swApp.ActiveDoc.ActiveView.FrameState = 1
boolstatus = Part.Extension.SelectByID2("Sheet1", "SHEET", 0, 0, 0, False,
0, Nothing, 0)
Part.EditTemplate
Part.EditSketch
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Line182", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line183", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line184", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line185", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line186", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line187", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line188", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line189", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line190", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line191", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line192", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line193", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line194", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line195", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line196", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line197", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line198", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line199", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line200", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line201", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line202", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line203", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line204", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line205", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line206", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line207", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line208", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line212", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line213", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line214", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line215", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line216", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line218", "SKETCHSEGMENT", 0, 0, 0,
True, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Sheet Format1", "SHEET", 0, 0, 0,
False, 0, Nothing, 0)
Part.EditSheet
Part.EditSketch
Part.ClearSelection2 True
Part.Save2 False
End Sub

What am I missing here...I see none of the layer stuff being done. It was
my intent that all I would have to do was figure out how to select all
sketch entities and change the layer. Thanks for any help you can give me.

--
Jeff


From: That70sTick on
Macro recording is a poor way of capturing selections. That's one of
the things macro recording is not good at. To manage selections
effectively, you will need to learn how to use the "Selection Manager"
object. This will not appear in a recorded macro.

If you have a desire to write macros, I HIGHLY recommend that you get
VB literate first. Get a book or two about VB6 or VBA and do some
non-SW VB projects to get familiar with VB & object-oriented
programming. Then the SW API will make much more sense.

From: customsolids on
I'll second that.

The Macro Recorder by itself will rarely get you to where you really
want to go. It might, however, give you some clues on things to
include in your own code. Study a little VB, then peruse the examples
in the SW API help file and on the SolidWorks website. The Macro
Recorder might sound easy, but I'm afraid it's really not much of a
shortcut.

--Brenda

That70sTick wrote:
> Macro recording is a poor way of capturing selections. That's one of
> the things macro recording is not good at. To manage selections
> effectively, you will need to learn how to use the "Selection
Manager"
> object. This will not appear in a recorded macro.
>
> If you have a desire to write macros, I HIGHLY recommend that you get
> VB literate first. Get a book or two about VB6 or VBA and do some
> non-SW VB projects to get familiar with VB & object-oriented
> programming. Then the SW API will make much more sense.

 | 
Pages: 1
Prev: regression in 1.1?
Next: epicyclic curve