To run a macro
with the 3DEXPERIENCE Transition
task:
- In the 3DEXPERIENCE Transition task, select the files you want to run the
macro on. See Creating a 3DEXPERIENCE Transition Task.
- Click Next.
- In the
Options dialog box, under
Custom Actions, select Run
macro:.
- Browse for a SOLIDWORKS macro (.swp).
- Click Finish.
The macro appears in the Task Scheduler
with the title you set for the task.
Sample SOLIDWORKS Macro
To test this functionality, you can paste the following text into a
SOLIDWORKS macro (.swp).
This sample macro adds a property named "Hello" with a value of
"Hello World" to any part, assembly, or drawing in the list of task files.
- For parts and assemblies, it adds a configuration-specific
property to the active configurations.
- For drawings, it adds a custom property, because drawings do
not contain configurations.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim config As SldWorks.Configuration
Dim cusPropMgr As SldWorks.CustomPropertyManager
Dim lRetVal As Long
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
' If no model is currently loaded, then exit
Exit Sub
End If
If (swModel.GetType <> swDocDRAWING) Then
' Add a Configuration Property named "Hello" to the active configuration for a Part or Assembly
Set config = swModel.GetActiveConfiguration
Set cusPropMgr = config.CustomPropertyManager
lRetVal = cusPropMgr.Add3("Hello",
swCustomInfoType_e.swCustomInfoText, "Hello World",
swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
Else
' Add a Property named "Hello" for a Drawing
Set cusPropMgr = swModel.Extension.CustomPropertyManager("")
lRetVal = cusPropMgr.Add3("Hello",
swCustomInfoType_e.swCustomInfoText, "Hello World",
swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
End If
End Sub