How to access an AutoCAD file embedded in an IDW via VBA?

How to access an AutoCAD file embedded in an IDW via VBA?

radugc
Contributor Contributor
790 Views
8 Replies
Message 1 of 9

How to access an AutoCAD file embedded in an IDW via VBA?

radugc
Contributor
Contributor

Is there any way you can access an AutoCAD file embedded in an IDW by using VBA?

I have an IDW with about 100 sheets; it would like to control which file is embedded in each of the sheets.

The best would be to use linked files but I do not know how to make certain files visible on certain sheets.

Kind Thanks, Radu

0 Likes
791 Views
8 Replies
Replies (8)
Message 2 of 9

xiaodong_liang
Autodesk Support
Autodesk Support

hi,

 

the embedded files are stored in Document.ReferencedOLEFileDescriptors. You can toggle its visibility by ReferencedOLEFileDescriptor.Visible.

 

The problem is : I do not see a way to know which sheet the referenced OLE file belongs to 😞 

0 Likes
Message 3 of 9

radugc
Contributor
Contributor

Thank you for looking into it - see below the code I am using - an embedded object is inside the attached document - could you please explain the reason the count is zero - also, I could not see the Visible property. Thank you for help.

 

Option Explicit
Dim oApp As Inventor.Application

Public Sub OLE()

Set oApp = ThisApplication

Dim oDoc As Inventor.Document
Set oDoc = oApp.ActiveDocument

Dim oRefOLEFileDescriptors As Inventor.ReferencedOLEFileDescriptors
Set oRefOLEFileDescriptors = oDoc.ReferencedOLEFileDescriptors

MsgBox oRefOLEFileDescriptors.Count

End Sub

0 Likes
Message 4 of 9

xiaodong_liang
Autodesk Support
Autodesk Support

This is the snapshot at my side. It looks it works well. Which version of Inventor are you using?

0 Likes
Message 5 of 9

radugc
Contributor
Contributor

Hi, I am using 2009. Radu

0 Likes
Message 6 of 9

xiaodong_liang
Autodesk Support
Autodesk Support

ReferencedOLEFileDescriptors started to return OLE (embedded mode) from Inventor 2011. Before 2011, it only returns OLE (link mode).

 

Following is a workaround:

 

Sub ToggleEmbeddedObjectVisibility() 

Dim bVisible As Boolean 
bVisible = False 
If MsgBox("Make visible?", vbYesNo) = vbYes Then 
bVisible = True 
End If 

Dim oDoc As DrawingDocument 
Set oDoc = ThisApplication.ActiveDocument 

' Get the "model" browser pane 
Dim oPane As BrowserPane 
Set oPane = oDoc.BrowserPanes.Item("DlHierarchy") 

Dim o3rdPartyNode As BrowserNode 
Set o3rdPartyNode = oPane.TopNode.BrowserNodes.Item("3rd Party") 

Dim oNode As BrowserNode 
Set oNode = o3rdPartyNode.BrowserNodes.Item("MM431 FLOW") 

oDoc.SelectSet.Clear 

Dim oCtrlDef As ButtonDefinition 
Set oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("AppOLEVisibilityCmd") 

If bVisible Then 
oNode.Visible = True 
oNode.DoSelect 

' If the ButtonDefinition is "pressed", the item is already visible. 
' Execute command only if invisible. 
If Not oCtrlDef.Pressed Then 
oCtrlDef.Execute 
End If 
Else 
oNode.DoSelect 

' If the ButtonDefinition is "pressed", the item is visible. 
' Make it invisible by executing the command. 
If oCtrlDef.Pressed Then 
oCtrlDef.Execute 
End If 

'If you want to let the browser node disappear 
oNode.Visible = False 
End If 

oDoc.SelectSet.Clear 
End Sub 

0 Likes
Message 7 of 9

radugc
Contributor
Contributor

We should get 2013 soon. Thank you for your support. Radu

0 Likes
Message 8 of 9

radugc
Contributor
Contributor

and I will try the workoround - Thanks again, Radu

0 Likes
Message 9 of 9

xiaodong_liang
Autodesk Support
Autodesk Support

forgot to comment: this code gets the browser node of the 'embedded', and execute the command to toggle its visiblity. The 'MM431 FLOW' is just the name of my demo. In your case, it is the name of your embedded file.

0 Likes