Macro to make virtual and modify the material of all the parts. from STEP file

Hello.

I often need to recover 3D files (step) from industrial supplier. These most of the time send me step files that when I open them via solidworks are composed of assemblies, composed of the same assemblies and parts. Brief...

Today, for each of these files, I am forced to enter the sub-assemblies, open all the parts to: 1- Remove their appearance. 2-Assign a subject 3-Record it. 4- Make it Virtual.

Finally, when the head assembly is open, I just want to click on a macro that transforms all the parts files under the root, and all the others included in subassemblies of all the lower levels.

I think it's possible via a macro, to do all these operations at once, and very quickly.

Unfortunately I don't know Solidworks macros at all, and I'm not able to create the right code.

Has anyone ever done something similar, and could help me.

Thank you.

Jérémy

Solidworks PDM 2015

Hello Jérémy,

To make a room virtual, there is the MakeVirtual2 method (link).

To apply a material there is the SetMaterialProperty method (link). But how do you know which one to apply?

I also wanted to do this for my job but with the following variations:

  • - Without material management;
  • - With the removal of subassemblies that contain only one subassembly or part.

I never succeeded because the first step for me was to break the dependency on the original STEP file. And as far as I know, there is no function in the API for that (neither during the import nor after). When you do this manually while recording a macro, it doesn't put anything in the file.

M.

Here is a draft that converts a Step to sldprt, removes the appearance, assigns the material "AISI 304" and saves in the same directory.

Option Explicit
Sub main()
    Dim FilePath As String
    FilePath = "C:\MyFiles\PartTest.step"
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Set swApp = Application.SldWorks
    Set swModel = swApp.LoadFile4(FilePath, Empty, Nothing, Empty)
    swModel.SetMaterialPropertyName2 "Default", Empty, "AISI 304"
    swModel.Extension.RemoveMaterialProperty swInConfigurationOpts_e.swAllConfiguration, Nothing
    FilePath = Replace(FilePath, ".step", ".sldprt")
    swModel.Extension.SaveAs FilePath, swSaveAsVersion_e.swSaveAsCurrentVersion, swSaveAsOptions_e.swSaveAsOptions_Silent, Nothing, Empty, Empty
End Sub

 

2 Likes

I don't mind opening the step in solidworks. And as far as I know, the sldasm file doesn't keep a link with the step.

The problem also is that when I open the step in solidworks, in the sldasm file I get there are either other assemblies or parts. And that if I want to make them virtual, I have to open them beforehand. This wastes a considerable amount of time.

Is a macro able to open the file, change its appearance, its material, and then close it. Then open another file belonging to the head assembly,  do the same operations again, and so on, until the last file. And finally to delete all the temporary files belonging to the original step file generated when opening the file via solidworks, and also to delete the step.

Thank you for your help.

Jérémy

Yes, it's possible to make a macro for that

Hello, I have a basic macro to rename the parts and subsets that are already virtual.in 1 2 3 etc 

in SW2018 the sets from step are already virtual so I don't have this step like in SW 2015 

 


renommer_virtuel.swp
2 Likes

There is a link that is kept with the original WWTP, for parts or assemblies. This is true as of Solidworks 2017, however:

http://help.solidworks.com/2019/french/SolidWorks/sldworks/t_break_link_from_original_file.htm

However, it may not be a problem for your business. The only risk is that the WWTP will link two distinct parts/assemblies in two projects and that there will be cross-modifications (I had the case).

Thank you for your answers.

I may not go any further for the moment. We are supposed to move to Solidworks 2019 in a few months (Yes I know we are in 2020 !!) and so according to what G.casters says, we will no longer have the problem regarding the transformation of parts/temporary assemblies files into Virtual files.

Then I'm going to get the few lines of code from Jerome.P and mgauroy to try to tinker with something that can work.