Bonjour je cherche à faire des mise en plan automatique mais je suis bloqué. la macro que j'ai faites marche mais seulement pour une seule pièce (celle que je me suis servis pour faire la macro)
je cherche un moyen pour que cela marche pour n'importe quel pièce, mais je ne sais pas comment faire pour que au lieu que je donne les coordonnées des sommets de ma pièces ou la face, il le détecte automatiquement. Pour que peu importe la taille de la pièce insérée, la mise en plan puisse ce faire automatiquement.
Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Dim boolstatus As Boolean
Dim Part As SldWorks.ModelDoc2
Dim pathName As String
Const MODELE As String = "CHEMIN MISE EN PLAN\.drwdot"
Const TABLE As String = "CHEMIN TABLE DE PERCAGE\.sldholtbt"
Const TOP_FACE_NAME As String = "TOP_FACE"
Const RIGHT_FACE_NAME As String = "RIGHT_FACE"
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox "Cette Macro ne fonctionne que sur une pièce", vbCritical, "AVERTISSEMENT"
End
End If
If swModel.GetType <> swDocPART Then
MsgBox "Cette Macro ne fonctionne que sur une pièce", vbCritical, "AVERTISSEMENT"
End
End If
swModel.GetTitle
pathName = swModel.GetPathName
COMPOSANT = pathName
'Debug.Print COMPOSANT
Set spec = swApp.GetOpenDocSpec(COMPOSANT)
Set Part = swApp.OpenDoc7(spec)
Set Draw = swApp.NewDocument(MODELE, 12, 0.21, 0.297)
Set swDraw = swApp.ActiveDoc
Dim swCompModel As SldWorks.PartDoc
Set swCompModel = swApp.OpenDoc6(COMPOSANT, swDocumentTypes_e.swDocPART, swOpenDocOptions_e.swOpenDocOptions_Silent, "", 0, 0)
swApp.ActivateDoc3 COMPOSANT, False, 0, 0
Dim swFace As SldWorks.Entity
Set swFace = swCompModel.GetEntityByName(TOP_FACE_NAME, swSelectType_e.swSelFACES)
If Not swFace Is Nothing Then
swFace.SelectByMark False, 1
End If
Set swFace = swCompModel.GetEntityByName(RIGHT_FACE_NAME, swSelectType_e.swSelFACES)
If Not swFace Is Nothing Then
swFace.SelectByMark True, 2
End If
Dim swView As SldWorks.view
swApp.ActivateDoc3 swDraw.GetTitle, False, 0, 0
Set swView = swDraw.CreateRelativeView(COMPOSANT, 0.1, 0.13, swRelativeViewCreationDirection_e.swRelativeViewCreationDirection_FRONT, swRelativeViewCreationDirection_e.swRelativeViewCreationDirection_RIGHT)
Set Part = swDraw
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("", "DRAWINGVIEW", 0.0995, 0.13, 0, True, 0, Nothing, 0)
Set myView = Part.CreateUnfoldedViewAt3(0.16, 0.13, 0, False)
boolstatus = Part.Extension.SelectByID2("", "DRAWINGVIEW", 0.0995, 0.13, 0, True, 0, Nothing, 0)
Set myView = Part.CreateUnfoldedViewAt3(0.04, 0.13, 0, False)
boolstatus = Part.Extension.SelectByID2("", "DRAWINGVIEW", 0.0995, 0.13, 0, True, 0, Nothing, 0)
Set myView = Part.CreateUnfoldedViewAt3(0.0995, 0.18, 0, False)
boolstatus = Part.Extension.SelectByID2("", "DRAWINGVIEW", 0.0995, 0.13, 0, True, 0, Nothing, 0)
Set myView = Part.CreateUnfoldedViewAt3(0.0995, 0.08, 0, False)
'Vue aux. Droite
boolstatus = Part.Extension.SelectByID2("", "DRAWINGVIEW", 0.16, 0.127, 0, True, 16, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "VERTEX", 0.1609, 0.097, 0, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "FACE", 0.16, 0.127, 0, True, 2, Nothing, 0)
'Vue aux. Gauche
boolstatus = Part.Extension.SelectByID2("", "DRAWINGVIEW", 0.04, 0.127, 0, True, 16, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "VERTEX", 0.039, 0.097, 0, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "FACE", 0.04, 0.127, 0, True, 2, Nothing, 0)
'Vue aux. Haut
boolstatus = Part.Extension.SelectByID2("", "DRAWINGVIEW", 0.102, 0.18, 0, True, 16, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "VERTEX", 0.055, 0.18095, 0, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "FACE", 0.102, 0.18, 0, True, 2, Nothing, 0)
'Vue aux. Bas
boolstatus = Part.Extension.SelectByID2("", "DRAWINGVIEW", 0.102, 0.08, 0, True, 16, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "VERTEX", 0.055, 0.079, 0, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "FACE", 0.102, 0.08, 0, True, 2, Nothing, 0)
'Vue principale Dessus
boolstatus = Part.Extension.SelectByID2("", "DRAWINGVIEW", 0.0995, 0.13, 0, True, 16, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "VERTEX", 0.055, 0.097, 0, True, 1, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("", "FACE", 0.0995, 0.13, 0, True, 2, Nothing, 0)
'Dim myView As Object
Set myView = Part.SelectionManager.GetSelectedObjectsDrawingView2(1, -1)
Dim myHoleTable As Object
Set myHoleTable = myView.InsertHoleTable2(False, 0.291, 0.205, 2, "A", TABLE)
Part.ClearSelection2 True
boolstatus = Part.ActivateSheet("Sheet1")
'Set swDraw = swModel
Set swView = Part.CreateDrawViewFromModelView3(ModelPath, "*Dimétrique", 0.053, 0.032, 0)
boolstatus = Part.Extension.SelectByID2("", "FACE", 0.053, 0.032, 0, True, 2, Nothing, 0)
swDraw.ViewDisplayShaded
swDraw.ViewModelEdges
End Sub