Macro for changing the orientation of views in solidworks

Hello everyone, I'm currently looking for a way to automate the reorientation of the front view of a file imported directly from a manufacturer's site, otherwise the part is not recognized on Altium. It's only the original shots that are not well oriented, and the file uploaded to the site doesn't allow me to modify it.

I think you can look at the Copy move function http://help.solidworks.com/2016/french/solidworks/sldworks/hidd_dve_feat_move_surf.htm

see if the function corresponds and in which case you will be able to save the macro of what interests you (Rotation 90° on X or Y or Z)

@MaD, as I could understand, it is not trying to move the room, but to change the view of the room.

Try with the macro recorder to place yourself on it and see if you have a usable code.

@KVuilleumier, it is the orientation of the part that I want to be able to modify in relation to the coordinate system so that the front view is the one I want. I also need to redefine the placement of the marker, maybe I should have gone through that first. I'm a novice in solidworks, I was previously on ProE and so I don't know how to go about it, especially since I don't know how to do macro (I'll have to learn it one day). 

Thank you for your answers! 

Can you put the part you have at the beginning and tell us the direction you want in the end?

This is the piece that is only there to physically illustrate what I want to do. The front view is currently a pierced view, I want to change the orientation of the part in relation to the coordinate system in order to have the front view on the current face of the top (not drilled). 

This code works, I'll leave it to you adapted to your needs

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID2("Congé9", "SOLIDBODY", 0.306720518918638, 0.145146136734809, 2.68172410638385E-02, False, 1, Nothing, 0)
Dim myFeature As Object

Set myFeature = Part.FeatureManager.InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, 0, 1.5707963267949, False, 1)
End Sub

For the function see this link

http://help.solidworks.com/2016/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.ifeaturemanager~insertmovecopybody2.html

 

For the SW example macro http://help.solidworks.com/2016/english/api/sldworksapi/Move_Bodies_Example_VB.htm

'-------------------------------------------------------------
' Preconditions:
' 1. Specified part document to open exists.
' 2. Run the macro.
'
' Postconditions: All of the bodies in the part document
' are moved to the specified location.
'
' NOTE: Because this part is used elsewhere, do not save
' any changes when closing it.
'--------------------------------------------------------------
Option Explicit
Sub SelectBodies(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, bodyArr As Variant)
' Select and mark the bodies to move
    Dim swSelMgr As SldWorks.SelectionMgr
    Dim swSelData As SldWorks.SelectData
    Dim body As Variant
    Dim swBody As SldWorks.Body2
    Dim status  As Boolean
    Set swSelMgr = swModel.SelectionManager
    Set swSelData = swSelMgr.CreateSelectData
    If IsEmpty(bodyArr) Then Exit Sub
    For Each body In bodyArr
        Set swBody = body
        swSelData.Mark = 1
        status = swBody.Select2(True, swSelData)
    Next body
End Sub
Sub main()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swPart As SldWorks.PartDoc
    Dim bodyArr As Variant
    Dim swFeatMgr As SldWorks.FeatureManager
    Dim swFeat As SldWorks.Feature
    Dim fileName As String
    Dim errors As Long
    Dim warnings As Long
    Set swApp = Application.SldWorks
    fileName = "C:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\samples\tutorial\multibody\multi_inter.sldprt"
    Set swModel = swApp.OpenDoc6(fileName, swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", errors, warnings)
    Set swPart = swModel
    Set swFeatMgr = swModel.FeatureManager
    swModel.ClearSelection2 True    
    ' Get the bodies to move
    bodyArr = swPart.GetBodies2(swAllBodies, false)
    SelectBodies swApp, swModel, bodyArr
    ' Move the bodies
    Set swFeat = swFeatMgr.InsertMoveCopyBody2(0.1, 0.2, 0.3, 0#, 0#, 0#, 0#, 0#, 0#, 0#, False, 1)
  End Sub

 

Thank you very much for the indications, I will try to implement all this. I will keep you informed if the macro works on my part.

Well, I tried the macro after getting the hang of solidworks. I changed the filename to have the part I wanted, but when running the macro the part was only expelled very far from its planes but its orientation remains the same and the planes have the same coincidence on their respective surfaces as before the macro run. 

I will try to explain myself better about my problem. I want to change my view from top to front. Because when I want to do my drawing in SW I want to make a project of the views of my front plane. 

I hope I'm clear enough even if I admit that I have a little trouble explaining what I want to do, thank you in any case!

The second macro is an example mecro in your case changed

InsertMoveCopyBody2(0.1, 0.2, 0.3, 0#, 0#, 0#, 0#, 0#, 0#, 0#, False, 1)

by

InsertMoveCopyBody2(0, 0, 0, 0, 0, 0, 0, 0, 0, 1.5707963267949, False, 1)

where 1.57 is the rotation value in radians

https://www.google.fr/webhp?sourceid=chrome-instant&rlz=1C1RLNS_frFR739FR739&ion=1&espv=2&ie=UTF-8#q=90deg+en+radians

 

Learn more about the InsertMoveCopy function http://help.solidworks.com/2016/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.ifeaturemanager~insertmovecopybody2.html

The macro works perfectly after replacing the insertmovecopybody line, but I realized that I would have liked to rotate the part 180° on Y while keeping my coordinate system and my planes fixed.

Thank you for this macro which is very useful to me! 

I'll let you mark your problem as solved in this case as far as the Y rotation is concerned, I'll let you put the value in the same line that you modified, look in the help previously provided to hole the location of the Y rotation

Okay and for information I also changed the path of the filename so that when I run the Macro, it is my part that is active in solidworks and not always the same of the filename on which the operation is performed. 

Thank you again for your very precious help!