SolidWorks Expected Function or Variable Error

Hello everyone,

I have this error: " Compilation error: function or variable expected "

The error is on the next line and the function " GetTransparency "

Debug.Print swSketchPicture.GetTransparency(Style, Transparency, MatchingColor, MatchingTolerance)

I'm on SolidWorks 2022 and the code is as follows:

Sub recupTranparenceImage()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swSketchPicture As SldWorks.ISketchPicture
Dim boolstatus As Boolean
'Dim instance As ISketchPicture
Dim Style As Long
Dim Transparency As Double
Dim MatchingColor As Long
Dim MatchingTolerance As Double
 
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'boolstatus = swModel.Extension.SelectByID2("Feuille1", "SHEET", 5.43900806628579E-02, 0.13276815279762, 0, False, 0, Nothing, 0)
swModel.EditTemplate
swModel.EditSketch
boolstatus = swModel.Extension.SelectByID2("Image d'esquisse2", "SKETCHBITMAP", 0.166852606603703, 0.134853758836237, 0, False, 0, Nothing, 0)
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Set swSketchPicture = swFeat.GetSpecificFeature2
'Debug.Print swSketchPicture.SetTransparency(2, 0.97, 0, 0)

Debug.Print swSketchPicture.GetTransparency(Style, Transparency, MatchingColor, MatchingTolerance)
Debug.Print Transparency
swModel.EditSheet
End Sub

Any idea what's wrong?

Hello

Try to convert the return value to a type that can be displayed by a print:

Debug.Print CStr( swSketchPicture.GetTransparency(Style, Transparency, MatchingColor, MatchingTolerance) )

Thanks @Sylk , but no change, I still have the same error.

And what about

swSketchPicture.GetTransparency(Style, Transparency, MatchingColor, MatchingTolerance)
Debug.Print Style
Debug.Print Transparency
Debug.Print MatchingColor
Debug.Print MatchingTolerance

If the GetTransparency function does not return any value, you must use the variables in its arguments.

1 Like

Yes thank you @Sylk , that's exactly what I just tested, thanks to your value reflection returned by the function:

Sub recupTranparenceImage()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swSketchPicture As SldWorks.ISketchPicture
Dim boolstatus As Boolean
Dim Style As Long
Dim Transparency As Double
Dim MatchingColor As Long
Dim MatchingTolerance As Double
 
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
swModel.EditTemplate
swModel.EditSketch
boolstatus = swModel.Extension.SelectByID2("Image d'esquisse2", "SKETCHBITMAP", 0.166852606603703, 0.134853758836237, 0, False, 0, Nothing, 0)
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Set swSketchPicture = swFeat.GetSpecificFeature2

swSketchPicture.GetTransparency Style, Transparency, MatchingColor, MatchingTolerance
Debug.Print Transparency
swModel.EditSheet
End Sub
1 Like