ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
IVIsaac Vur04/02/2021

Hello,

the macro that I want to write takes a value out of a property from the Fileproperties and writes the value into the cutting list attribute.

The property is Teilenummer, the value of this property is taken into the code.

The attribute in the cutting list is also Teilenummer (it does already exist, see screenshot), and there I want to write the value.

The code makes a welded part and then updates the cutting list folder.

And then swFeat.CustomPropertyManager.Set2 is not working ?!

Screenshot of cutting list:

CODE Concept:

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Dim swModelDocExt As ModelDocExtension
Dim swCustProp As CustomPropertyManager
Dim val As String
Dim valout As String
Dim bool As Boolean


Dim swAssy As SldWorks.AssemblyDoc

Sub main()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swModelDocExt = swModel.Extension

' Get the custom property data
Set swCustProp = swModelDocExt.CustomPropertyManager("")

'Funktion schreibt Teilenummer-Werte in val und valout

bool = swCustProp.Get4("Teilenummer", False, val, valout)

Debug.Print "Value:                    " & val
Debug.Print "Evaluated value:          " & valout
Debug.Print "Up-to-date data:          " & bool

MsgBox "Der Wert/Textaudruck der Zeile in den Eigenschften ist:  " & val & "Der evaluierte Wert ist: " & valout

'Mache Schweißteil aus Part
Dim swFeatureMgr As SldWorks.FeatureManager
Dim swFeature As SldWorks.Feature
Set swFeatureMgr = swModel.FeatureManager
Set swFeature = swFeatureMgr.InsertWeldmentFeature()


'UPDATE CUTTING LIST BEGIN
Dim vComps As Variant
Dim swFeat As SldWorks.Feature
           
Set swFeat = swModel.FirstFeature


Dim swBodyFolder As SldWorks.BodyFolder
                    'Set swBodyFolder = swFeat.GetSpecificFeature2
               

'Lese swFeat aus , swFeat entspricht erstem Ordner im Feature Baum
Dim Auslesen As String
Auslesen = swFeat.GetTypeName
MsgBox Auslesen
' Auslesen sagt Favorit Folder

' gehe Folder im Feauter Baum durch bis Cutlist Folder kommt

Dim Counter As Integer
Counter = 0
' 10. Zeile im FeatureManager Tree ist hier die Zuschnitssliste

Do While Counter < 10
'Get Next Feature
Set swFeat = swFeat.GetNextFeature
Auslesen = swFeat.GetTypeName
'MsgBox Auslesen
Counter = Counter + 1
            
Loop

       Set swBodyFolder = swFeat.GetSpecificFeature2
              swBodyFolder.UpdateCutList
              
              

'UPDATE CUTTING LIST END

'Aktualiesere Partdatei
    Dim boolstatus As Boolean
    Dim topOnly As Boolean

    Set swApp = CreateObject("SldWorks.Application")
    Set swModel = swApp.ActiveDoc
 
    topOnly = True
    


'Next Teilenummer in Zuschnittsliste BEGINN

'Next Teilenummer in Zuschnittsliste ENDE

'bool = swFeat.AddCustomProperty("Teilenummer", "30", "Verify1")
Dim x2 As Integer
x2 = 222
Debug.Print "x2 VORHER:          " & x2
x2 = swFeat.CustomPropertyManager.Set2("Teilenummer", 222)

Dim CustomPropertiesAuslesen1 As String
CustomPropertiesAuslesen1 = "Anfangs"
Debug.Print "CustomPropertiesAuslesen1     " & CustomPropertiesAuslesen1
CustomPropertiesAuslesen1 = swFeat.CustomPropertyManager.IGetNames(9)
Debug.Print "CustomPropertiesAuslesen1     " & CustomPropertiesAuslesen1


Debug.Print "x2 Nachher: :          " & x2
'   1 = Custom property does not exist
'http://help.solidworks.com/2020/english/api/swconst/SOLIDWORKS.Interop.swconst~SOLIDWORKS.Interop.swconst.swCustomInfoSetResult_e.html
End Sub