This is the code to change configuration properties of every part in an assemby. But the code doesn't seem to make any changes to the parts, what could be the problem?
Sub AddConfigPropertyToAssembly(filePath As String, propertyName As String, propertyValue As String)
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim longstatus As Long
Dim longwarnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.OpenDoc6(filePath, swDocASSEMBLY, swOpenDocOptions_Silent, "", longstatus, longwarnings)
If longstatus <> 0 Then
Dim swAssembly As SldWorks.AssemblyDoc
Set swAssembly = swModel
Dim vChildComp As Variant
vChildComp = swAssembly.GetComponents(False)
For i = 0 To UBound(vChildComp)
Dim swChildComp As SldWorks.Component2
Set swChildComp = vChildComp(i)
Dim swChildModel As SldWorks.ModelDoc2
Set swChildModel = swChildComp.GetModelDoc2
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Set swCustPropMgr = swChildModel.Extension.CustomPropertyManager("")
swCustPropMgr.Add2 propertyName, swCustomInfoType_Part, propertyValue
swChildModel.EditRebuild3
swChildModel.Save
Next
MsgBox "Custom property added successfully to all parts in the assembly."
Else
MsgBox "Could not open file. Check the file path." & vbNewLine & _
"Status: " & longstatus & vbNewLine & _
"Warnings: " & longwarnings
End If
End Sub
Sub Main()
Dim filePath As String
filePath = InputBox("Enter the path of the SolidWorks assembly file:")
Dim propertyName As String
propertyName = InputBox("Enter the property name:")
Dim propertyValue As String
propertyValue = InputBox("Enter the property value:")
Call AddConfigPropertyToAssembly(filePath, propertyName, propertyValue)
End Sub
- Board index CAD SolidWorks Macro Library
- Search
-
- It is currently Thu Nov 21, 2024 3:50 am
- All times are UTC-05:00
Changing Part's configuration properties macros code.
Library for macros
-
- Posts: 1
- Joined: Mon Feb 20, 2023 8:21 am
-
Answers: 0
Changing Part's configuration properties macros code.
- Quote
- 0 login to like this post
Jump to
- Welcome New Members
- ↳ Welcome
- ↳ Forum Rules
- CAD
- ↳ CAD Agnostic
- ↳ SolidWorks
- ↳ How To Questions
- ↳ SW General
- ↳ SolidWorks FAQ
- ↳ API
- ↳ Macro Library
- ↳ SolidWorks PDM
- ↳ 2D Drawings
- ↳ Routing-Electrical-Piping
- ↳ Surfacing
- ↳ Rendering - Visualize - Photoview
- ↳ SW Simulation
- ↳ SW Motion Analysis
- ↳ Enhancement Requests
- ↳ Solid Edge
- ↳ NX
- ↳ Onshape
- ↳ Creo
- ↳ Inventor
- ↳ Fusion 360
- ↳ KeyCreator
- ↳ Catia and 3DX
- ↳ IronCAD (CAXA)
- ↳ Shapr3D
- ↳ CAD Admin (Install, PDM, etc)
- ↳ subD and Mesh
- ↳ Hardware
- ↳ Misc CAD
- ↳ Draftsight
- Other Technology
- ↳ Computer Aided Engineering
- ↳ Rendering and Motion
- ↳ 3D Scan
- ↳ General Engineering and Design
- ↳ AI and Related Tech
- Manufacturing
- ↳ 3D Print
- ↳ CAM
- ↳ Molding, Casting, Powder Metal
- ↳ Robotics
- Board Business
- ↳ General Biz and Announcements
- ↳ Suggestions
- ↳ What's Wrong?
- ↳ What's New
- ↳ Events
- ↳ Media and Advertising
- Off Topic
- ↳ Kitty Dump
- ↳ Job Listings
- ↳ For Sale and Want To Buy