Macro solidworks (Vba)

Hello

I just created a macro to automatically create my unfolded view and then a 2nd one with the 3 views and an isometric view.

I would like the 3 views to be with a style on "visible hidden lines" and the isometric view with shaded image edge (ok) and especially with the "visible tangent edges" (only for the iso view)

I'm missing much more but as I'm struggling a helping hand will inevitably help me.

Here's my code:

Sub MepPliage()
    Dim SwDraw As SldWorks.DrawingDoc
    Dim swSheet As SldWorks.Sheet
    Dim boolstatus As Boolean
    Dim swView As SldWorks.View
    Set SwDraw = swApp.ActiveDoc
    
    
    bRet = SwDraw.NewSheet4("Feuille2", swDwgPaperA4sizeVertical, swDwgTemplateA4sizeVertical, 1, 1, True, sDrTemplatePliage, 0.297, 0.21, "", 0.5, 0.5, 0.5, 0.5, 0, 0)

    
    
    
    'On rend la feuille2active
    bRet = SwDraw.ActivateSheet("Feuille2")
    
    

    
    'Création des 3 vues
    bRet = SwDraw.Create3rdAngleViews(sOutputFolder + ".sldprt")
    
    
    'Création de la vue Isométrique
    Set swView = SwDraw.CreateDrawViewFromModelView3(sOutputFolder + ".sldprt", "*Isométrique", 0.23, 0.15, 0)
    swView.UseSheetScale = True
    bRet = swView.SetDisplayMode3(False, swSHADED, False, True)
    

    'On change le fond de plan et l'échelle
    bRet = SwDraw.SetupSheet6("Feuille2", swDwgPaperSizes_e.swDwgPapersUserDefined, swDwgTemplates_e.swDwgTemplateCustom, 1, 5, True, sDrTemplatePliage, 0.2794, 0.2159, "Default", True, 0, 0, 0, 0, 0, 0)

End Sub

 

Hello

I don't have access to Solidworks at the moment,  but I think it's possible to create all  your constraints in a background plan model.

 

Cdlt

 

It is complicated in this macro to go through a document template since the code displayed represents only a small part of the macro. (Completion of sheet 2)

That's why I would like to do it in vba, but that's where I get stuck despite several leads.

I suggested a use without macro.

For my part,  I use several types of background model.

One specific to sheet metal.

Another for machining.

Another for commercial parts plans

 

After by macro it must be possible,  I let the specialists answer.

 

1 Like

Impossible, my 1st sheet has the unfolded view and it is not possible to create it directly without going through a macro.

For the dotted lines it's good more than the tangent edges visible.
 

Sub MepPliage()
    Dim SwDraw As SldWorks.DrawingDoc
    Dim swSheet As SldWorks.Sheet
    Dim boolstatus As Boolean
    Dim swView As SldWorks.View
    Set SwDraw = swApp.ActiveDoc
      
    bRet = SwDraw.NewSheet4("Feuille2", swDwgPaperA4sizeVertical, swDwgTemplateA4sizeVertical, 1, 1, True, sDrTemplatePliage, 0.297, 0.21, "", 0.5, 0.5, 0.5, 0.5, 0, 0)

        
    'On rend la feuille2active
    bRet = SwDraw.ActivateSheet("Feuille2")
    
    
    'Création des 3 vues
    bRet = SwDraw.Create3rdAngleViews(sOutputFolder + ".sldprt")
    'On sélectionne la 1èer vue (vue parente)
    Set SwDraw = swApp.ActiveDoc
    Set swView = SwDraw.GetFirstView.GetNextView
        Debug.Print "View = " + swView.Name
    Debug.Print "  Current mode = " + Str(swView.GetDisplayMode2)
    
    'On affiche les arrêtes caché
    swView.SetDisplayMode3 False, swHIDDEN_GREYED, False, True
    Debug.Print "  New mode = " + Str(swView.GetDisplayMode2)
    
    
    'Création de la vue Isométrique
    Set swView = SwDraw.CreateDrawViewFromModelView3(sOutputFolder + ".sldprt", "*Isométrique", 0.23, 0.15, 0)
    swView.UseSheetScale = True

  'ici code pour arrêtes tangentes visibles

    bRet = swView.SetDisplayMode3(False, swSHADED, False, True)
    

    'On change le fond de plan et l'échelle
    bRet = SwDraw.SetupSheet6("Feuille2", swDwgPaperSizes_e.swDwgPapersUserDefined, swDwgTemplates_e.swDwgTemplateCustom, 1, 5, True, sDrTemplatePliage, 0.2794, 0.2159, "Default", True, 0, 0, 0, 0, 0, 0)
End Sub

 

I just ended up finding the last part for tangent edges hidden, visible, or visible with a font.

Here is the final code:

Sub MepPliage()
    Dim SwDraw As SldWorks.DrawingDoc
    Dim swSheet As SldWorks.Sheet
    Dim boolstatus As Boolean
    Dim swView As SldWorks.View
    Set SwDraw = swApp.ActiveDoc
    
    bRet = SwDraw.NewSheet4("Feuille2", swDwgPaperA4sizeVertical, swDwgTemplateA4sizeVertical, 1, 1, True, sDrTemplatePliage, 0.297, 0.21, "", 0.5, 0.5, 0.5, 0.5, 0, 0)

    'On rend la feuille2active
    bRet = SwDraw.ActivateSheet("Feuille2")
    
    'Création des 3 vues
    bRet = SwDraw.Create3rdAngleViews(sOutputFolder + ".sldprt")
    'On sélectionne la 1èer vue (vue parente)
    Set SwDraw = swApp.ActiveDoc
    Set swView = SwDraw.GetFirstView.GetNextView
        Debug.Print "View = " + swView.Name
    Debug.Print "  Current mode = " + Str(swView.GetDisplayMode2)
    
    'On affiche les arrêtes caché
    swView.SetDisplayMode3 False, swHIDDEN_GREYED, False, True
    Debug.Print "  New mode = " + Str(swView.GetDisplayMode2)
    
    
    'Création de la vue Isométrique
    Set swView = SwDraw.CreateDrawViewFromModelView3(sOutputFolder + ".sldprt", "*Isométrique", 0.23, 0.15, 0)
    swView.UseSheetScale = True
    bRet = swView.SetDisplayMode3(False, swSHADED, False, True)
    
    
    'Afficher (cacher ou montrer avec une police) les arrêtes tangentes sur la vue ISO
    Dim iDisplayIn As Integer
    'iDisplayIn = swDisplayTangentEdges_e.swTangentEdgesHidden
    'iDisplayIn = swDisplayTangentEdges_e.swTangentEdgesVisible
    iDisplayIn = swDisplayTangentEdges_e.swTangentEdgesVisibleAndFonted
    swView.SetDisplayTangentEdges2 (iDisplayIn)


    'On change le fond de plan et l'échelle
    bRet = SwDraw.SetupSheet6("Feuille2", swDwgPaperSizes_e.swDwgPapersUserDefined, swDwgTemplates_e.swDwgTemplateCustom, 1, 5, True, sDrTemplatePliage, 0.2794, 0.2159, "Default", True, 0, 0, 0, 0, 0, 0)

End Sub

Thanks anyway for the answers.

1 Like