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 Err.Clear Set objApp = CreateObject("SolidEdge.Application") Else 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") objLayer.show = false 'to clear all the temporary variables objApp = Nothing objDoc = Nothing objDraft = Nothing End Sub
Solved! Go to Solution.
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.