Check for Disconnected Model in IDW

Check for Disconnected Model in IDW

MarkyTomm
Enthusiast Enthusiast
403 Views
3 Replies
Message 1 of 4

Check for Disconnected Model in IDW

MarkyTomm
Enthusiast
Enthusiast

Hi All,

 

Quick question - is there a way to check for a disconnected model in an Inventor IDW

I want to scan through all sheets and if the model is disconnected (meaning that I have deleted it from the project) then delete that sheet.

 

Have my usual code snippet here - I may be using the wrong call by looking at the drawing view

 

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oView As DrawingView
On Error Resume Next
For Each oActiveSheet In oDoc.Sheets
oActiveSheet.Activate
Set oView = oDoc.ActiveSheet.DrawingViews(1)
*****Code here to check if the model is disconnected and delete the sheet if it is ********
Next

 

Any help, much appreciated

 

Regards

Mark

0 Likes
Accepted solutions (2)
404 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor
Accepted solution

You can try something like this:

 

Dim doc As DrawingDocument = ThisDoc.Document
Dim disconectedSheets As New List(Of Sheet)
For Each sheet As Sheet In doc.Sheets
    For Each view As DrawingView In sheet.DrawingViews
        If (view.ReferencedDocumentDescriptor.ReferencedDocument Is Nothing) Then
            disconectedSheets.Add(sheet)
        End If
    Next
Next

For Each sheet As Sheet In disconectedSheets
    sheet.Delete()
Next

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @MarkyTomm.  Looks like my response is a little slower, but it is in VBA, since your initial code seemed to be in VBA, and I don't use that much anymore.  You can give this version a try though, just in case it may work any better for you.  In this code I am checking if the 'reference is missing', instead of Is Nothing, because draft views may also not have a referenced document, and I did not know if you had any of those.

Sub DeleteSheetsWithMissingModelLinks()
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		Call MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument
	Set oDDoc = ThisApplication.ActiveDocument
	Dim oSheets As Inventor.Sheets
	Set oSheets = oDDoc.Sheets
	Dim oSheet As Inventor.Sheet
	For Each oSheet In oSheets
		Dim oViews As DrawingViews
		Set oViews = oSheet.DrawingViews
		If oViews.Count = 0 Then Continue For
		Dim oView As DrawingView
		Set oView = oViews.Item(1)
		If oView.ReferencedDocumentDescriptor.ReferenceMissing Then
			oSheet.Delete
		End If
	Next
End Sub

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 4

MarkyTomm
Enthusiast
Enthusiast

Many tanks guys - going to go with the reference missing version coupled with the add sheet references to an array and delete at the end which I think will excute quickest. Will throw in an active sheet and user confirm dialogue just for checking. Will post the code here when finished. Have a good one!

0 Likes