It retrieves the existing information in the cartridge and allows updates to it without having to do everything manually. It works very well but if there is only one board.
My problem lies in the duplication of this information on a possible 2nd, 3rd etc... plank, if any. Knowing that suddenly the notes of the basemap that are updated on plate 1, will not have the same name on the added plates.
If anyone has an idea of how to do it, I'm all for it.
Is it a desire not to have the same names from one page to another? If this is not the case, the easiest way is to have properties linked to these notes and thus we only update the properties and it unfolds itself on the other folios
No, at all, that's an observation. By adding a new board in the MEP, the new notes do not have the same name. it is called "Object of détail1137@Fond of plan1" but on the new plate it is "Object of détail1137@Fond of plan3" the name of the sheet changes. and I couldn't manage this settings.
Effectively linked to a property would actually be simpler.
So first of all, you have to create templates for the basemap and the drawing. Once this is done, the notes in the basemap that should be related to the drawing itself should be written like this: §PRP:xxxx (xxxx being the name of the property) Having exactly the same background plans and notes in all page formats (from A4 to A0 for example) thus greatly simplifies the macro. You could also have done this in the property form editor rather than through a macro I think.
Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.DrawingDoc Dim config As SldWorks.Configuration Dim swCustProp As SldWorks.CustomPropertyManager Dim lRetVal As Long Dim vPropNames As Variant Dim vPropTypes As Variant Dim vPropValues As Variant Dim ValOut As String Dim ResolvedValOut As String Dim wasResolved As Boolean Dim linkToProp As Boolean Dim resolved As Variant Dim linkProp As Variant Dim nNbrProps As Long Sun j As Long Dim custPropType As Long Dim bRet As Boolean
Sub mainTest()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set config = swModel.GetActiveConfiguration
' Set cusPropMgr = config. CustomPropertyManager
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
There is no configuration in the drawings. Basically, the code would be this one (I pre-chewed the job by putting a processing loop for the application of the changes)
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim swDraw As SldWorks.DrawingDoc
Dim bRet As Boolean
Dim iAddProp As Integer
Dim lretVal As Long
Dim sProp(11) As String
Sub Tableprop()
sProp(0) = "REV1": sProp(1) = "DATE1": sProp(2) = "NOM1": sProp(3) = "MODIF1"
sProp(4) = "REV2": sProp(5) = "DATE2": sProp(6) = "NOM2": sProp(7) = "MODIF2"
sProp(8) = "REV3": sProp(9) = "DATE3": sProp(10) = "NOM3": sProp(11) = "MODIF3"
End Sub
Sub mainTest()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
Call Tableprop
For i = 0 To UBound(sProp)
If sProp(i) <> "" Then
lretVal = swCustProp.Set2(sProp(i), "yyy")
End If
Next i
End Sub
You have to add processing to retrieve the data from the form in a table variable and handle all possible cases (empty fields, checking a field already updated with the same value...) The "yyy" would therefore have to be replaced by the variable array that retrieves the results.
Thank you @Cyril.f for your precious help, after a little research and stubbornness I managed to get the complete code to work.
I put below the part of the code that updates the MEP and retrieve the existing information in the MEP.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim swDraw As SldWorks.DrawingDoc
Dim bRet As Boolean
Dim iAddProp As Integer
Dim lretVal As Long
Dim sProp(11) As String
Dim ValeursUsF(11) As String
Sub Tableprop()
sProp(0) = "REV1": sProp(1) = "DATE1": sProp(2) = "NOM1": sProp(3) = "MODIF1"
sProp(4) = "REV2": sProp(5) = "DATE2": sProp(6) = "NOM2": sProp(7) = "MODIF2"
sProp(8) = "REV3": sProp(9) = "DATE3": sProp(10) = "NOM3": sProp(11) = "MODIF3"
End Sub
Sub MajMEP()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
Call Tableprop
Call TableValeurTableau
For i = 0 To UBound(sProp)
If sProp(i) <> "" Then
lretVal = swCustProp.Set2(sProp(i), ValeursUsF(i))
End If
Next i
End Sub
Sub TableValeurTableau()
'Chaque champs du userform
ValeursUsF(0) = TabRev.Bx0.Value: ValeursUsF(1) = TabRev.Bx1.Value: ValeursUsF(2) = TabRev.Bx2.Value: ValeursUsF(3) = TabRev.Bx3.Value
ValeursUsF(4) = TabRev.Bx4.Value: ValeursUsF(5) = TabRev.Bx5.Value: ValeursUsF(6) = TabRev.Bx6.Value: ValeursUsF(7) = TabRev.Bx7.Value
ValeursUsF(8) = TabRev.Bx8.Value: ValeursUsF(9) = TabRev.Bx9.Value: ValeursUsF(10) = TabRev.Bx10.Value: ValeursUsF(11) = TabRev.Bx11.Value
End Sub
Sub RecupValMEP()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
Call Tableprop
Call TableValeurTableau
Dim Val As String
Dim resolved As Boolean
Dim Title As String
For i = 0 To UBound(sProp)
If sProp(i) <> "" Then
lretVal = swCustProp.Get5(sProp(i), False, ValeursUsF(i), Title, resolved)
End If
Next i
For i = 0 To UBound(ValeursUsF)
TabRev("Bx" & i).Value = ValeursUsF(i)
Next
End Sub
Nice collaborative work. And thanks for thinking about joining the completed Macro. All that remains is to validate the best answer, to close this subject.
No worries about help. On the other hand, I think that the code should be simplified or at least optimized. Initializing the swApp variable in two different procedures could generate a bug. If there is no output from the main procedure between checking out the values and updating, all of this code can be put into the main procedure:
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swModelDocExt = swModel.Extension
Set swCustProp = swModelDocExt.CustomPropertyManager("")
Call Tableprop
Call TableValeurTableau
I also have a little trouble understanding what this part of the code is for:
For i = 0 To UBound(sProp)
If sProp(i) <> "" Then
lretVal = swCustProp.Get5(sProp(i), False, ValeursUsF(i), Title, resolved)
End If
Next i
I don't really understand what you're trying to do in this snippet of code since it's not used afterwards.
Indeed it is quite optimizeable. I'm going to try to do that. Thank you
The second part allows me to retrieve the values of the properties, in the case of a plan already filled in, to display them in my userform with the line of code that follows.
For i = 0 To UBound(ValeursUsF)
TabRev("Bx" & i).Value = ValeursUsF(i)
Next
It may not be the best method but it has the merit of working.