Reference model in a drawing document

Reference model in a drawing document

Anonymous
Not applicable
3,258 Views
13 Replies
Message 1 of 14

Reference model in a drawing document

Anonymous
Not applicable

I am in a drawing file.

I would like to reach for the Model Document of this drawing file, but in a specific way.

I need to do it not directly, but in an opened View (and by View I mean window), that's what makes things more complex.

 

I tried 2 solutions:

 

oView = ThisApplication.ActiveView	
model = oView.Document.File.ReferencedFiles.Item(1).AvailableDocuments.Item(1)

and:

 

 

oView = ThisApplication.ActiveView	
model = oView.Document.AllReferencedDocuments.Item(1)

 

When a drawing has only one reference - it works ok in both solutions.

When a drawing has many references (for example I have reference of an assembly and of a part of this assembly), it may happen, that I reach for wrong model document.

 

In attachment you'll find an example, where drawing has 2 references: Support (assembly) and Flat profile (part of this assembly).

My solution reaches Flat Profile instead of Support (that is because in this case Support is Item(2) - I don't know why not Item(1))

The drawing itself can recognize the main reference I need - the title block has correct values.

 

Maybe You have some idea how to solve it?

0 Likes
Accepted solutions (1)
3,259 Views
13 Replies
Replies (13)
Message 2 of 14

tdant
Collaborator
Collaborator

ActiveView is not referring to a drawing view, but rather an application view. I see two possible solutions. One I use pretty often is to run a Pick command and have the user select the correct view. In your case:

oView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select a drawing view")

The other option is more automated, but also more sensitive to how the drawing is created. If the first view placed is always the view you want to reference, this works:

Dim oDwg as DrawingDocument
oDwg = ThisApplication.ActiveDocument
oView = oDwg.ActiveSheet.DrawingViews(1)

I recommend the first option, but if manual selection is not an option, the second will work. Human intelligence is still the best intelligence (at least for now).

0 Likes
Message 3 of 14

Anonymous
Not applicable

As I said previously: I need to do it not directly, but in an opened View (and by View I mean window) - which means I am not interested in a drawing view, but in an application view.

 

That is because later I will use it to manage many open drawings with one rule (but that's another case).

0 Likes
Message 4 of 14

tdant
Collaborator
Collaborator

Do you mean you want to open the model in a new application view? Maybe a screencast could help clarify?

0 Likes
Message 5 of 14

Anonymous
Not applicable

No I don't want to open anything. I have an open drawing and want to reach a model document form this drawing (maybe the word reach is missleading) in order to manage it later.

model = oView.Document.AllReferencedDocuments.Item(1)

This code will reach for model document in currently open drawing (current application view).

I can now do many things, for example copy parameters from this model.

 

You can check the attachment - there you'll find a drawing which has few references. I want to reach this main reference (Support).

0 Likes
Message 6 of 14

tdant
Collaborator
Collaborator

Accessing the model via a DrawingView allows the same functionality you need, but also meets your reliability requirements. I don't understand what the View access provides that the DrawingView doesn't.

0 Likes
Message 7 of 14

Anonymous
Not applicable

Later I will use this rule to manage all drawings that are currently open - that is why I need to use Application View

0 Likes
Message 8 of 14

tdant
Collaborator
Collaborator

Would Application.Documents.VisibleDocuments sufficiently handle all the open drawings later? If that would work, then you could access the DrawingViews for each open DrawingDocument, and still retain the reliability.

0 Likes
Message 9 of 14

Sergio.D.Suárez
Mentor
Mentor

This simple code differentiates the type of view model file and extracts the part number of a part document.
It's an example, maybe it could be useful

 

Dim oDoc As Document = ThisDoc.Document
If oDoc.DocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject  Then	
		
	Dim oSheet As Sheet
	oSheet = oDoc.ActiveSheet
	Dim oViews As DrawingViews
	Dim oView As DrawingView
			
	For Each oView In oSheet.DrawingViews
		oViewModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
		'If oViewModelDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then
		If oViewModelDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then 
			Dim oViewModelName As String = oView.ReferencedDocumentDescriptor.ReferencedDocument.DisplayName
			Dim opartnamme As String = iProperties.Value(oViewModelName, "Project", "Part Number") 
			
			MessageBox.Show(opartnamme, "The Part Number is")
			
		End If
	Next	
			
Else
	MessageBox.Show("You must open a drawing file", "Ilogic")
End If

 I hope it will help you solve your problem


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 10 of 14

Anonymous
Not applicable

This solution does not refer to Application View, but to Sheet of Drawing View.

I need to do it to refering to Application View.

0 Likes
Message 11 of 14

tdant
Collaborator
Collaborator

As it stands, there is no way to programmatically guarantee referring to the correct document when accessing it via Application.View. If you would simply share why you favor Application.View, the forum may be able to help you find way to preserve that feature and also guarantee the correct document, and thus provide the help that you asked for in the first place. Continuing to insist on Application.View with no explanation is proving to be an ineffective way of getting help.

Message 12 of 14

Anonymous
Not applicable
Accepted solution

There is a way and I finally found it.

oView = ThisApplication.ActiveView 
model = oView.Document.ActiveSheet.DrawingViews.Item(1).ReferencedFile.ReferencedDocument

So when I'm in a drawing file, program will now search for the first-created Drawing View and then refer to its part/assembly document.

That means it will refer to the same part/assembly document as titleblock - and that is what I wanted (I mentioned it in my first post).

 

I think this case is solved.

0 Likes
Message 13 of 14

tdant
Collaborator
Collaborator

Maybe I’m dense, but I don’t understand how this differs at all from Application.ActiveDocument...?

0 Likes
Message 14 of 14

Anonymous
Not applicable

Using Application View is a decision from above - I have to work this way unless it's not possible.

0 Likes