Jump to content

Recommended Posts

Posted

Hi there, I'm trying to change custom properties of solidworks files, parts, assemblies as well as drawings. This VBA code I used to start with:

Dim swApp As Object
Sub main()

Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
Set swConfigMgr = swDoc.ConfigurationManager
Set ActiveConfig = swConfigMgr.ActiveConfiguration

Dim Configuration As String
Dim FieldName As String
Dim FieldType As Integer
Dim FieldValue As String
Dim value As Boolean

ActConfigName = ActiveConfig.Name

value = swDoc.AddCustomInfo3(ActConfigName, "custom", swCustomInfoText, "hello")

value = swDoc.AddCustomInfo("custom", "Text", "hello")

End Sub

As far as I could find information on the internet I created this code:

$swApp = ObjCreate("SldWorks.Application")
If $swApp = 0 Then
    MsgBox(0, "Error", "Could not create SolidWorks Application Object")
    Exit
EndIf
$swDoc = $swApp.activatedoc("C:\Users\Robin\Desktop\Stenenvanger\000244.sldprt")
If $swDoc = 0 Then
    MsgBox(0, "Error", "Could not find or load file")
    Exit
EndIf
;$value = $swDoc.CustomInfo("", "Description")
$swConfigMgr = $swDoc.ConfigurationManager
$ActiveConfig = $swConfigMgr.ActiveConfiguration

The error I get is,

C:\Users\Robin\Desktop\Script\prepertietest.au3 (12) : ==> The requested action with this object has failed.:

$swConfigMgr = $swDoc.ConfigurationManager

$swConfigMgr = $swDoc.ConfigurationManager^ ERROR

but I don't know why and I can't find information on the internet.

Can anyone help me with this code? I how do you call the .custominfo and .activatedoc commands? Where can I find them for any other program?

Thanks in advance

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...