assembly context and component property
Posted: Tue Jan 23, 2024 4:22 am
I cannot post my sample code as my workplace has no access to this site and I am not allowed to upload company data from my office.
apologize for the inconvenience.
I used the code below inside my macro, but I noticed that when editing a component it sometimes try to return value from the assy instead of the component I selected and set to edited in context with my macro.
I used the getproperty function and I would like to know the logical steps to correctly use it.
codestack made an explanation about redirecting pointers, and the code is behaving strangely so my pointers are probably mixed up, but I am not able to follow the whole explaination.
a simple step by step explation would help me a lot. I cannot connect dots.
My objective is editing a component from an assy (1 component pre selected from the tree) I edit it in context, select a sketch Inside it and put in edit mode, read a property (with the function above) from the same component, edit the sketch with that value from the property and return to the assy.
https://www.codestack.net/solidworks-ap ... y/context/
apologize for the inconvenience.
I used the code below inside my macro, but I noticed that when editing a component it sometimes try to return value from the assy instead of the component I selected and set to edited in context with my macro.
Code: Select all
'**********************
'Copyright(C) 2023 Xarial Pty Limited
'Reference: https://www.codestack.net/solidworks-api/data-storage/custom-properties/
'License: https://www.codestack.net/license/
'**********************
Dim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
Debug.Print GetPropertyValue(swModel, "Part Number")
Debug.Print GetPropertyValue(swModel, "Revision")
End Sub
Function GetPropertyValue(model As SldWorks.ModelDoc2, prpName As String) As String
Dim prpVal As String
Dim swCustPrpMgr As SldWorks.CustomPropertyManager
If TypeOf model Is SldWorks.PartDoc Or TypeOf model Is SldWorks.AssemblyDoc Then
Set swCustPrpMgr = model.ConfigurationManager.ActiveConfiguration.CustomPropertyManager
swCustPrpMgr.Get4 prpName, True, "", prpVal
End If
If prpVal = "" Then
Set swCustPrpMgr = model.Extension.CustomPropertyManager("")
swCustPrpMgr.Get4 prpName, True, "", prpVal
End If
GetPropertyValue = prpVal
End Function
codestack made an explanation about redirecting pointers, and the code is behaving strangely so my pointers are probably mixed up, but I am not able to follow the whole explaination.
a simple step by step explation would help me a lot. I cannot connect dots.
My objective is editing a component from an assy (1 component pre selected from the tree) I edit it in context, select a sketch Inside it and put in edit mode, read a property (with the function above) from the same component, edit the sketch with that value from the property and return to the assy.
https://www.codestack.net/solidworks-ap ... y/context/