Solidworks macro that moves parts in a assembly

I have to move and save a bunch of parts in a assembly and then save a tiff image of them. I have to repeate it about 200 times, so i want have a macro do the job for me.

But i cannot get the macro to move the selected components. It just saves the same image again and again.

Here is the macro code. Does anyoen have any idea what might be wrong?

Regards

Peter

' ****************************************************************************** ' C:\DOCUME~1\vmpeut\LOKALE~1\Temp\swx3864\Macro1.swb - macro recorded on 03/10/05 by vmpeut ' ****************************************************************************** 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 counter As Integer

Sub main()

Set swApp = Application.SldWorks For counter = 1 To 10

Set Part = swApp.ActiveDoc boolstatus = Part.Extension.SelectByID("emnederived-1@flytbund", "COMPONENT", 0, 0, 0, False, 0, Nothing) boolstatus = Part.Extension.SelectByID("centraludstøder2-1@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("udstøder-4@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("udstøder-3@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("udstøder-2@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("udstøder-1@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("bevægelig opspændingsplade-1@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("udstøderholdeplade-1@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("udstødertrykplade-1@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("lineal-3@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("lineal-2@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("indsats-1@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) boolstatus = Part.Extension.SelectByID("bevægelig formplade-1@flytbund", "COMPONENT", 0, 0, 0, True, 0, Nothing) Part.TranslateComponent Part.ClearSelection2 True

Part.SaveAs2 "\\stsfil\Brugerprofiler\vmpeut\Desktop\a" & Str(counter) & ".tif", 0, True, False Next counter End Sub

Reply to
Peter Uttrup
Loading thread data ...

Looks like TranslateComponent activates the move component command then waits for the user to move a part(s). It doesn't move anything by itself. What you need is a form that stores the tiff image after each move. Put a STORE button or something similar on it. All you need to assign to the store button is the SaveAs2 method. You should only have to select the components once before you start.

If you are trying to automatically move the parts, I think you've got a lot more programming to do. Look at the Transform2 property for components in SWx API help.

Hope this helps...

Kent

formatting link

Reply to
KCS Company

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.