Hi @engineeringYSRYL. I don't know if you have already tried this approach or not, but have you tried looking into the DrawingDocument.ReferencedOLEFileDescriptors yet. That is sort of the behind the scenes way of adding, accessing, or removing those types of things. When I use the 'Insert Objects' tool (on that Manage tab > Insert panel), then use 'Create from file' option to insert an image into a test drawing, that is where I find it by code. And there appears to be properties for each 'ReferencedOLEFileDescriptor' to control things like 'Visible' (supposed to control if this object is visible in graphics window, according to Intellisence tip), and BrowserVisible (supposed to control if this object is visible under the 3rdPartyFolder, according to Intellisence tip). However, in my testing, trying to set the ReferenceOLEFileDescriptor.Visible to False did not hide the image in my graphics window. I don't know if that is a glitch or what. I'm currently using 2022.4.1, so if it was a glitch, hopefully they have fixed it in later releases. I even deleted that image out of the document, then inserted another, then checked the status of that Visible property and it was already False, before doing anything to it, and it was clearly visible on my screen at the time, so something seems to be wrong there.
Then after more testing/monitoring I found the ControlDefinition that is executed when you right-click on that "Embedding 1" object and uncheck the Visible setting. Its name is "AppOLEVisibilityCmd". With that in mind, I assume that I could add this object to the DrawingDocument.SelectSet, then execute that command to turn its visibility off. But that command 'toggles' visibility of the selected objects, not just turns it off, so you would have to be aware of their current state. Had trouble testing this too though. Maybe you will have better luck with these codes.
Code to try changing the property:
Dim oDoc As Document = ThisDoc.Document
Dim oRefOLEFDs As ReferencedOLEFileDescriptors = oDoc.ReferencedOLEFileDescriptors
Logger.Info("oRefOLEFDs.Count = " & oRefOLEFDs.Count)
If oRefOLEFDs.Count = 0 Then Exit Sub
For Each oRefOLEFD As ReferencedOLEFileDescriptor In oRefOLEFDs
Logger.Info("oRefOLEFD.DisplayName = " & oRefOLEFD.DisplayName)
' If oRefOLEFD.DisplayName = "Embedding 1" Then
Logger.Info("oRefOLEFD.Visible = " & oRefOLEFD.Visible)
Try : oRefOLEFD.Visible = False : Catch : End Try
Logger.Info("oRefOLEFD.BrowserVisible = " & oRefOLEFD.BrowserVisible)
' Try : oRefOLEFD.BrowserVisible = False : Catch : End Try 'works, but not good result
Logger.Info("oRefOLEFD.ReferenceStatus.ToString = " & oRefOLEFD.ReferenceStatus.ToString)
' End If
Next
Code to use the command:
Dim oDoc As Document = ThisDoc.Document
Dim oRefOLEFDs As ReferencedOLEFileDescriptors = oDoc.ReferencedOLEFileDescriptors
If oRefOLEFDs.Count = 0 Then Exit Sub
Dim oCD As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("AppOLEVisibilityCmd")
For Each oRefOLEFD As ReferencedOLEFileDescriptor In oRefOLEFDs
oDoc.SelectSet.Clear
oDoc.SelectSet.Select(oRefOLEFD)
oCD.Execute
Next
Wesley Crihfield

(Not an Autodesk Employee)