Setting up with excel in vba

Hello

I made an Excel file coded in VBA to modify an assembly and its parts. I am missing a few things to finish.

- Which code to use to reactivate or deactivate a function of a part in a specific configuration of this part (default or sym)

- I give the possibility to change the names of the parts in my Excel file, but I can't recreate the links with my new assembly, it recovers the original name. How to give it the new links with the modified parts.

I'm attaching the code as an example.

Please help me.

Kind regards.


code_pour_assemblage_parametre.txt

Hello.

 

You must have had a lot of fun creating your little program ^^. Brief

I may be saying, but to save your name, you tell him to go and look in the cell "D3" ... But you don't tell him which file/sheet. As a result, if the sheet is not active at that time, he doesn't know where to look.

 

I'm also sticking you the Sldw help for the Saveas3

 

IModelDoc2
Dim NewName As String
Dim SaveAsVersion As Integer
Dim Options As Integer
Dim value As Integer (ton "chemin_enr" que tu as déclaré "as long")
 
value = instance.SaveAs3(NewName, SaveAsVersion, Options)

 So, for you it could be

IModelDoc2
Dim NewName As String
Dim SaveAsVersion As Integer
Dim Options As Integer

Newname = Z:\MACHINE\CONFO\" & Sheet3.Cells(3, "D"). Value2 & ".sldprt"

(In case your box is sheet 3. I'm not convinced that you should add .sldprt at the end. To be tested)

chemin_enr = swModel.Saveas3(Newname, 0, 2)

 

Thanks to the Coin37coin pipe, but my Save as Parts function works fine, it's just when I open the assembly, it doesn't know the new parts paths, and therefore opens the original files.

Maybe I should open the assembly before modifying my parts, and save them?

 

Kind regards.

Haaa, sorry I misunderstood.

 

If it saves many parts, indeed, you should ask your macro to open the assembly before saving the part and then save the assembly at the end (don't forget this step ;) )

 

In fact, it will act as if you were doing it yourself: When your assembly is open and you save a part, it saves the new path in the whole. (the famous "save copy" box to check when you don't want to do it)

Otherwise, for configurations, you should try the code "getconfigurationname" which will give the list of configurations of your room. 

Then make a drop-down menu to be able to choose the right configuration. Then the "openmodelconfiguration" should allow you to open with the chosen config

And a little "getactiveconfiguration" at the beginning of the program should allow you to select the current one and come back to it when you close the room

 

But these are only assumptions, I have never tested these codes

I found the solution:

-for the configs:

boolstatus = Part.Extension.SelectByID2("défaut@Embase confo ORIGIN. SLDPRT", "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)
        boolstatus = Part.ShowConfiguration2("default")
        boolstatus = Part.Extension.SelectByID2("CongĂ©2@Embase confo ORIGIN-1@confo ORIGIN", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
        Part.EditSuppress2  to enable a function in such a configuration of the part
        Part.ClearSelection2 True

- for registration:

Set swModel = swApp.OpenDoc6("Z:\MACHINE\CONFO\0 confo ORIGINE 3D\confo ORIGINE.sldasm", 2, 0, "", longstatus, longwarnings)    
    Set Part = swApp.ActiveDoc
    
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Comfortable header ORIGIN-1@confo ORIGIN", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    boolstatus = swModel.ReplaceComponents("Z:\MACHINE\CONFO\" & Range("d1"). Value2 & " embase.sldprt", "", True, True)
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Confo wing ORIGIN-1@confo ORIGIN", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    boolstatus = swModel.ReplaceComponents("Z:\MACHINE\CONFO\" & Range("d1"). Value2 & " wing.sldprt", "", True, True)
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Aisle confo ORIGIN-1@confo ORIGIN", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    boolstatus = swModel.ReplaceComponents("Z:\MACHINE\CONFO\" & Range("d1"). Value2 & " corridor.sldprt", "", True, True)
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Confo sym corridor ORIGIN-1@confo ORIGIN", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    boolstatus = swModel.ReplaceComponents("Z:\MACHINE\CONFO\" & Range("d1"). Value2 & " SYM.sldprt Corridor", "", True, True)
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Reinforcement comfy ORIGIN-1@confo ORIGIN", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    boolstatus = swModel.ReplaceComponents("Z:\MACHINE\CONFO\" & Range("d1"). Value2 & " reinforcement embase.sldprt", "", True, True)
    Part.ClearSelection2 True
    boolstatus = Part.Extension.SelectByID2("Reinforcement conffunction sym ORIGIN-1@confo ORIGIN", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
    boolstatus = swModel.ReplaceComponents("Z:\MACHINE\CONFO\" & Range("d1"). Value2 & " SYM.sldprt header reinforcement", "", True, True)
    Part.ClearSelection2 True
    
    chemin_enr = swModel.Saveas3("Z:\MACHINE\CONFO\" & Range("d1"). Value2 & ".sldasm", 0, 2)
    swApp.CloseDoc (swModel.GetTitle)
    Set swModel = swApp.OpenDoc6("Z:\MACHINE\CONFO\" & Range("d1"). Value2 & ".sldasm", 2, 0, "", longstatus, longwarnings)
    Set Part = swApp.ActiveDoc

 

Regards

2 Likes

Hello, Do you have an example on Excel (Macro) + file to activate or deactivate a function of a part please?

Hello

I advise you to recreate a question because this one is more than two years old.