Turn images on and off inside a drawing.

Turn images on and off inside a drawing.

engineeringYSRYL
Explorer Explorer
496 Views
5 Replies
Message 1 of 6

Turn images on and off inside a drawing.

engineeringYSRYL
Explorer
Explorer

I have a drawing that is generated by an Excel spreadsheet.  Almost all the text on the sheet is driven by the spreadsheet and rules.  I have several sets of pictures depicting different conditions based on the selected features.

 

I can change their visibility under the 3rd party drop down and select the ones I need but would like to automate the selection process.  Insert Object, create from file, was use to insert the pictures directly into the drawing.

 

Is there a way to turn these images on and off based on rules or anything else?  Is there a better way to put these images into the drawing that would allow me to turn them on and off?

0 Likes
497 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @engineeringYSRYL.  Just an idea, but what about using a DrawingSketch and adding the images as a SketchImage, which has its own Visible property.

Edit:  I just remembered that you can't insert an image into a regular DrawingSketch unless that sketch is for something like a BorderDefinition, TitleBlockDefinition, or SketchedSymbolDefinition, so that idea might not work either unless it was integrated into one of those.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

engineeringYSRYL
Explorer
Explorer
Thanks for the response.
Yep, I tried that and I couldn't get it to work. I've been scratching my head on this for a week with no luck. I can turn everything else on and off as required but not the images.

I have 4 sets stacked over each other and have to switch them manually for now. Always the chance to forget to switch them so I really would like to automate it.
John
0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

How about having multiple versions of the same Border or TitleBlock, some with images, some without, some with different pictures included?  Then simply switch the border or title block to switch the images.  I think I actually worked with someone else a couple years ago who was doing something similar to this, and that was fairly frustrating too.  I actually created an idea on the Inventor ideas forum about being able to dimension & constrain the borders of images in... back around that time.  Just another related thought that popped in there.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

engineeringYSRYL
Explorer
Explorer
I thought about doing this but it's still something I'd have to turn on and off manually so I guess I'll just have to turn the images on or off manually for now.

Thanks,
John
0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes