Solved! Go to solution

Solid Edge Excel VBA to show or hide layer

Hello Experts, 

I am trying to Hide or show layer in a draft file using excel VBA.

I really dont know what is the mistake I made here.

below is the code please solve for me.


Sub test()
Dim objApp As SolidEdgeFramework.Application
Dim objDoc As SolidEdgeAssembly.AssemblyDocument
Dim objDraft As SolidEdgeDraft.DraftDocument
Dim objSheet As SolidEdgeDraft.Sheet
Dim objLayer As SolidEdgeFramework.Layer
Dim objLayers As SolidEdgeFramework.Layers

'to check whether the application is already open.
On Error Resume Next
Set objApp = GetObject(, "SolidEdge.Application")
If Err Then
    Set objApp = CreateObject("SolidEdge.Application")
    Set objDoc = objApp.ActiveDocument
End If
'visibility of all activities
objApp.Visible = True
objDoc.Visible = True
objDraft.Visible = True
objApp.DisplayAlerts = False
objDoc.DisplayAlerts = False
objDraft.DisplayAlerts = False
Set objDraft = objApp.Documents.Open("E:\Jackson\drafting.dft")

'Hide a layer
Set objSheet = objDraft.ActiveSheet
Set objLayers = objSheet.Layers
objLayer.Name = objLayers.item(Name:= "ATB 4-8") = false
'to clear all the temporary variables
objApp = Nothing
objDoc = Nothing
objDraft = Nothing

End Sub

Thank you.

Accepted by topic author Jackson
‎05-05-2016 07:37 AM

Re: Solid Edge Excel VBA to show or hide layer

[ Edited ]

Hi @Jackson


Make the following 3 changes to your code in this line:

objLayer.Name = objLayers.item(Name:= "ATB 4-8")

1. Remove the .Name from the above line

2. Add Set before objLayer

3. Remove Name:= in the argument


The line should now look like:

Set objLayer = objLayers.item("ATB 4-8")


With these changes, I was able to hide the layer successfully.

If you are able to as well, mark this post as accepted solution.


~Tushar Suradkar

Solid Edge Users Facebook Group

Re: Solid Edge Excel VBA to show or hide layer

Thank you so much Mr Tushar, 

Working super cool..


Thank you again.

Re: Solid Edge Excel VBA to show or hide layer

You are welcome @Jackson

I'd also suggest posting coding related questions to the dedicated Solid Edge Developer Forum


You can navigate to the Developer Forum using the link above or as shown in image below: