Hello, I have created a macro that allows you to configure my part (dimensions, machining with bossing or material removal, etc). Once the part is created, I would like that when I restart the macro on this part, the values displayed on the userform are the ones I put in the room to have a quick preview of my open part. Otherwise, the default values are displayed. So you should get the information from the part and send it back to the right boxes in my userform.
I managed to retrieve the dimensions of a sketch and return them using this: txt_Z.Text = Part.Parameter("D1@F"). SystemValue . but I can't get the TRUE or FALSE value of a function (mat. removal, bossing, drilling) to tell if it is enabled or deleted in my part.
If you have a solution, I'm interested :)
Hello
You have to look at swFeat.IsSuppressed2.
3 Likes
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim vConfNameArr As Variant
Dim vSuppStateArr As Variant
Dim i As Long
Dim bRet As Boolean
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
vConfNameArr = swModel.GetConfigurationNames
vSuppStateArr = swFeat.IsSuppressed2(swThisConfiguration, vConfNameArr)
Debug.Assert 0 = UBound(vSuppStateArr)
Debug.Print "File = " & swModel.GetPathName
Debug.Print " " & swFeat.Name
Debug.Print " " & vConfNameArr(i) & " ---> " & vSuppStateArr(i)
End Sub
Hello Cyril, this is what I need, I managed to get the value TRUE or FALSE with this code.
But, the problem is that I have to select the function before launching the macro. How do I make it so that when I launch the macro it takes all the functions I would have given it (in my code) so that it tells me if it's true or false? without having to select the functions?
(I specify that I'm a beginner in VBA, it's all I feel like I'm just starting to do macros on sw)
Hello
You have to list all the elements of the "Feature" and only work on the functions you want, look at the example given here.
Kind regards
2 Likes
Private Sub ActualiserInfosPiece()
actualisationInfoPiece = True
Dim swFeature As SldWorks.Feature
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim featureName As String
Dim status As Boolean
Dim vSuppStateArr As Variant
Dim vConfNameArr As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension
Set Part = swModel
If swModel Is Nothing Then
Exit Sub
End If
If (swModel.GetType <> swDocPART) Then
Call MsgBox("Macro valable uniquement pour une pièce", vbOKOnly, "AVERTISSEMENT")
Exit Sub
End If
vConfNameArr = swModel.GetConfigurationNames
Set swFeature = Part.FirstFeature
Do While Not swFeature Is Nothing
featureName = swFeature.name
status = swModelDocExt.SelectByID2(featureName, "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)
vSuppStateArr = swFeature.IsSuppressed2(swThisConfiguration, vConfNameArr)
Select Case featureName
Case "FONCTION SW 1"
TglB_N1.value = Not vSuppStateArr(0)
Case "FONCTION SW 2"
TglB_N2.value = Not vSuppStateArr(0)
Case "FONCTION SW 3"
TglB_N3.value = Not vSuppStateArr(0)
Case "FONCTION SW 4"
TglB_N4.value = Not vSuppStateArr(0)
Case "FONCTION SW 5"
TglB_N5.value = Not vSuppStateArr(0)
Case FONCTION SW 6"
TglB_N6.value = Not vSuppStateArr(0)
End Select
Set swFeature = swFeature.GetNextFeature()
Loop
ComboBox_HAUT.Text = Part.Parameter("D3@Esquisse FONCTION SW").SystemValue * 1000
ComboBox_BAS.Text = Part.Parameter("D4@Esquisse FONCTION SW").SystemValue * 1000
ComboBox_GAUCHE.Text = Part.Parameter("D2@Esquisse FONCTION SW").SystemValue * 1000
ComboBox_DROIT.Text = Part.Parameter("D1@Esquisse FONCTION SW").SystemValue * 1000
txt_X.Text = Part.Parameter("D3@Esquisse Débit").SystemValue * 1000
txt_Y.Text = Part.Parameter("D4@Esquisse Débit").SystemValue * 1000
txt_Z.Text = Part.Parameter("D1@F").SystemValue * 1000
actualisationInfoPiece = False
End Sub
Problem solved, thank you for your answer .