RUN MACRO ON EACH PART WITHIN ASSEMBLY
RUN MACRO ON EACH PART WITHIN ASSEMBLY
(OP)
Hi,
I wish to open and execute a macro on each file from an open assy. How can I do it?
Thank you
I wish to open and execute a macro on each file from an open assy. How can I do it?
Thank you






RE: RUN MACRO ON EACH PART WITHIN ASSEMBLY
Jeff Mirisola
Director of Engineering
M9 Defense
My Blog
RE: RUN MACRO ON EACH PART WITHIN ASSEMBLY
CODE
Of course you will have to get dir to output just filenames and extensions and perhaps clean up the file in an editor a bit.
TOP
CSWP, BSSE
www.engtran.com www.niswug.org
www.linkedin.com/in/engineeringtransport
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
RE: RUN MACRO ON EACH PART WITHIN ASSEMBLY
TOP
CSWP, BSSE
www.engtran.com www.niswug.org
www.linkedin.com/in/engineeringtransport
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
RE: RUN MACRO ON EACH PART WITHIN ASSEMBLY
RE: RUN MACRO ON EACH PART WITHIN ASSEMBLY
When you open an assembly it automatically opens all of the files in that assembly. If you want to run code on every part in the assembly then you would do something like this:
CODE
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swComp As SldWorks.Component2
Dim swCompModel As SldWorks.ModelDoc2
Dim i As Integer
Dim vComps As Variant
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swAssy = swModel
vComps = swAssy.GetComponents(False)
For i = 0 To UBound(vComps)
Set swComp = vComps(i)
Set swCompModel = swComp.GetModelDoc2
If swCompModel.GetType = swDocPART Then
'run your code here
End If
Next i
End Sub
Make sure that you use swCompModel as the reference to the part's ModelDoc2 interface. Also, if you need to edit any feature data in that part, you'll want to use IComponent2::GetCorresponding to bring the part's ModelDoc2 interface into the context of the assembly. Otherwise you might run into issues.
Hope this helps.
RE: RUN MACRO ON EACH PART WITHIN ASSEMBLY
RE: RUN MACRO ON EACH PART WITHIN ASSEMBLY
How about you give us the big picture of what you are trying to do?
That way we all will not have to play twenty questions with each other.
Cheers,
Anna Wood
SW2011 SP5, Windows 7 x64
http://www.renderbay.com
http://www.solidmuse.com
http://www.phxswug.com
RE: RUN MACRO ON EACH PART WITHIN ASSEMBLY
The only problem is to overwrite parts, because the assy and part will be open. And the same thing should be done with assy too. Any Ideas?
RE: RUN MACRO ON EACH PART WITHIN ASSEMBLY