API - custom property

Hello everyone,

I have a question about custom property management in solidworks

Can we change a custom property from an assembly, let me explain:

I have an assembly open and from this assembly "CO37662-33867_Ensemble_goulotte_sortie" I want to modify the custom property of a part "CO37662-33867F09-1" 

Is it possible without opening the room?

I made a piece of code in VBA for testing but it doesn't work

' ******************************************************************************
' ******************************************************************************
Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()

Set swApp = _
Application.SldWorks

Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID2("CO37662-33867F09-1@CO37662-33867_Ensemble_goulotte_sortie", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Part.CustomInfo("No_article") = 2000200



' fonctionne dans une piece
'boolstatus = Part.AddCustomInfo3("", "No_article", 1, "")
'Part.CustomInfo("No_article") = 2000200
End Sub

 

Thank you for your help

1 Like

Hello

I don't have SW on hand to check but I think that you have to at least edit the part in the assembly to be able to intervene on its custom properties, which your piece of code doesn't do...

Kind regards

Hello

I put in editing the piece like this

boolstatus = Part.Extension.SelectByID2("CO37662-33867F01-1@CO37662-33867_Ensemble_goulotte_sortie", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)

 

But this changes the attribute of the assembly.

 

Hello

The SelectByID2 function is not an editing function but just a selection function...

To do what you want, you need to use the GetModelDoc2 function to retrieve the ModelDoc2 of the selected component, from there you can work on these custom properties.

Kind regards

2 Likes