I have a weldment part, which contains multiple bodies. Due to the policy of our company, every assembly must be an assembly in a drawing, not a part of multiple bodies as it is a default policy of Solidworks software. To achieve this, I create a weldment structure as a parent part file, and then create a separate child part files for each structural element. I import a full parent part (Insert>Part) into a child and leave only one body in each of child parts by using "Delete bodies" feature. When I am done with all the child parts, I bring all these parts into an assembly ...
I described this because I would welcome any suggestion, how to get every structural member as a separate part in "Parts only" BOM (again, this is a requirement in our company, there are further actions being processed from these BOMs). I have wrote an enhancement request so that SW would implement a feature to "Show detailed cut list" in "Parts only" BOM with a possibility to dissolve it. But even if they will I guess it will take a while, so I have to get another solution until then ..
Anyhow, after bringing all the child parts to assembly, every child part must have a file's custom property "Length" with a value of the length of an imported tube. I am composing a simple macro which would do that automatically. For this exact task i know that I will always have one solid body, therefore one element in a "Solid bodies" folder. So I am finding the first one, and reading the "Length" of an cut list item. I am using "Get5" method of CustomPropertyManager. The problem I am facing is that the "Resolved value" it returns is still value of calculation, not a result. It returns the same values for ValOut and ResolvedValOut, which is:
LENGTH@@@TUBE, SQUARE 40 X 40 X 4<1>@Part1.SLDPRT
The code is working fine with a part that has native features, with native values (not "from parent" values).
Solidworks shows a good value if I manually go on the item in the feature tree and right click for properties.
Question: How do I get the resolved value of a cutlist item?
This is my macro code is bellow.
I also attach the .swb file of this macro code,
the parent part with few structural members,
the child part with imported parent and deleted bodies,
and a separate file with structural member (macro works good with this one)
Option Explicit Dim swApp As SldWorks.SldWorks Dim swModel As SldWorks.ModelDoc2 Dim SelMgr As SldWorks.SelectionMgr Dim cutFolder As SldWorks.BodyFolder Dim boolFound As Boolean Dim swFeature As SldWorks.Feature Dim swSubFeature As SldWorks.Feature Dim swModelDocExt As SldWorks.ModelDocExtension Dim swCutListFolder As Feature Dim swCustPropCL As CustomPropertyManager Dim swCustPropFile As CustomPropertyManager Sub main() Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc If Not swModel.GetType = swDocPART Then swApp.SendMsgToUser "File type: non Part. Exiting" Exit Sub End If Set swFeature = swModel.FirstFeature boolFound = False Do While (Not swFeature Is Nothing) And (boolFound = False) Debug.Print swFeature.GetTypeName Set swSubFeature = swFeature.GetFirstSubFeature Do While (Not swSubFeature Is Nothing) And (boolFound = False) If swSubFeature.GetTypeName = "CutListFolder" Then Set swCustPropCL = swSubFeature.CustomPropertyManager Dim strValue As String Dim strResolvedValOut As String Dim blnWasResolved As Boolean Dim lRetVal As Long lRetVal = swCustPropCL.Get5("LENGTH", False, strValue, strResolvedValOut, blnWasResolved) Debug.Print "Length = " & strValue Debug.Print "Resolved length = " & strResolvedValOut Set swModelDocExt = swModel.Extension Set swCustPropFile = swModelDocExt.CustomPropertyManager("") 'next two lines are for the future swCustPropFile.Add2 "AssignedLength", swCustomInfoText, "-" swCustPropFile.Set "AssignedLenth", "-" boolFound = True End If Set swSubFeature = swSubFeature.GetNextSubFeature Loop Debug.Print " " Set swFeature = swFeature.GetNextFeature Loop End Sub
help_me.rar 390.4 KB