ReferencedFile From Drawing Document

ReferencedFile From Drawing Document

Anonymous
Not applicable
418 Views
5 Replies
Message 1 of 6

ReferencedFile From Drawing Document

Anonymous
Not applicable
This one really has me baffled. I am trying to use ReferencedFile from a
drawing view in a drawing document. All is well as long as the referenced
file is a part. However if the drawing is of an assembly any ReferencedFile
properties don't work. In fact it results in a runtime error 2147467259
(80004005). I did some digging on this runtime error and the best that I
can come up with is that it has something to do with the microsoft jet
database engine and how the file is already opened exclusively by another
user or you need permission to view this data.

This makes absolutely no sense to me. I have been trying to debug this for
some time now. I am just trying to control an addin that does the same as
the now deceased Custom Property Copy addin. I am trying to make sure I
have the assignment of ReferencedDocument going to the correct document
type, oPartDoc or oAssyDoc.

If you run this little bit of code you can see that it runs fine with a part
document placed in a drawing but will crash with an assembly document.

Dim Test As Variant

MsgBox "beforetest"
Test = oDwgDoc.ActiveSheet.DrawingViews(1).ReferencedFile.FullFileName
MsgBox Test

Does anyone know what could be happening here? How would I determine what
type of document it is since the ReferencedFile.DocumentType also causes a
crash?

Any assistance would be greatly appreciated!

Thanks!

Bryan Hemphill
Systematix Inc.
Waterloo, Ontario, Canada
0 Likes
419 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Hi Bryan,

I was able to reproduce this problem in Inventor 6. I'm unable to reproduce
it using Inventor 7, so apparently it's been fixed. A potential workaround,
depending on the contents of your drawings, is to use the ReferencedFiles
property of the document. This worked correctly for me in Inventor 6.
However you won't know which view the referenced file is associated with.

-Brian

"Bryan Hemphill" wrote in message
news:FE78C889A8A0578194089563B5E40DA7@in.WebX.maYIadrTaRb...
> This one really has me baffled. I am trying to use ReferencedFile from a
> drawing view in a drawing document. All is well as long as the referenced
> file is a part. However if the drawing is of an assembly any
ReferencedFile
> properties don't work. In fact it results in a runtime error 2147467259
> (80004005). I did some digging on this runtime error and the best that I
> can come up with is that it has something to do with the microsoft jet
> database engine and how the file is already opened exclusively by another
> user or you need permission to view this data.
>
> This makes absolutely no sense to me. I have been trying to debug this
for
> some time now. I am just trying to control an addin that does the same as
> the now deceased Custom Property Copy addin. I am trying to make sure I
> have the assignment of ReferencedDocument going to the correct document
> type, oPartDoc or oAssyDoc.
>
> If you run this little bit of code you can see that it runs fine with a
part
> document placed in a drawing but will crash with an assembly document.
>
> Dim Test As Variant
>
> MsgBox "beforetest"
> Test = oDwgDoc.ActiveSheet.DrawingViews(1).ReferencedFile.FullFileName
> MsgBox Test
>
> Does anyone know what could be happening here? How would I determine what
> type of document it is since the ReferencedFile.DocumentType also causes a
> crash?
>
> Any assistance would be greatly appreciated!
>
> Thanks!
>
> Bryan Hemphill
> Systematix Inc.
> Waterloo, Ontario, Canada
>
>
0 Likes
Message 3 of 6

Anonymous
Not applicable
Brian,

Thanks for the response. I'm not sure I understand all that is going on
with these referenced files. I did some more testing with the
ReferencedFileDescriptors and I found that the type that is returned from a
drawing file of an assembly model is not always correct. In some cases the
type returned from a drawing file of an assembly model is a
kPartDocumentObject or 12290. The part that is apparently being referenced
in place of the assembly model is in fact a component within the assembly
model. I have everything working with ReferencedFiles as you suggested and
I suppose I should leave well enough alone but I am really confused as to
the correct operation of these properties.

Again, Thanks for the help.

Hope to see that IV7 soon!

Bryan Hemphill
Systematix Inc.
Waterloo, Ontario, Canada

"Brian Ekins (Autodesk)" wrote in message
news:CD110A92F6E4A81D148AE31FC6793202@in.WebX.maYIadrTaRb...
> Hi Bryan,
>
> I was able to reproduce this problem in Inventor 6. I'm unable to
reproduce
> it using Inventor 7, so apparently it's been fixed. A potential
workaround,
> depending on the contents of your drawings, is to use the ReferencedFiles
> property of the document. This worked correctly for me in Inventor 6.
> However you won't know which view the referenced file is associated with.
>
> -Brian
>
> "Bryan Hemphill" wrote in message
> news:FE78C889A8A0578194089563B5E40DA7@in.WebX.maYIadrTaRb...
> > This one really has me baffled. I am trying to use ReferencedFile from
a
> > drawing view in a drawing document. All is well as long as the
referenced
> > file is a part. However if the drawing is of an assembly any
> ReferencedFile
> > properties don't work. In fact it results in a runtime error 2147467259
> > (80004005). I did some digging on this runtime error and the best that
I
> > can come up with is that it has something to do with the microsoft jet
> > database engine and how the file is already opened exclusively by
another
> > user or you need permission to view this data.
> >
> > This makes absolutely no sense to me. I have been trying to debug this
> for
> > some time now. I am just trying to control an addin that does the same
as
> > the now deceased Custom Property Copy addin. I am trying to make sure I
> > have the assignment of ReferencedDocument going to the correct document
> > type, oPartDoc or oAssyDoc.
> >
> > If you run this little bit of code you can see that it runs fine with a
> part
> > document placed in a drawing but will crash with an assembly document.
> >
> > Dim Test As Variant
> >
> > MsgBox "beforetest"
> > Test = oDwgDoc.ActiveSheet.DrawingViews(1).ReferencedFile.FullFileName
> > MsgBox Test
> >
> > Does anyone know what could be happening here? How would I determine
what
> > type of document it is since the ReferencedFile.DocumentType also causes
a
> > crash?
> >
> > Any assistance would be greatly appreciated!
> >
> > Thanks!
> >
> > Bryan Hemphill
> > Systematix Inc.
> > Waterloo, Ontario, Canada
> >
> >
>
>
0 Likes
Message 4 of 6

Anonymous
Not applicable
I had the same problem. The ReferencedFileDescriptor is a very weakly type object and does not work properly.
I had to go with the Document.ReferencedFiles.FullFileName.
It took me several month to find this. Now it works 99.9% (.1% one never knows what Inventor does). Since we are connected to an SAP system we update this through SAP.
Here is the code hope it will help.

Sub ProcessIpnIdw()
Dim oInvDoc As Document
Dim oRefDoc As Document
Dim oPropSetidwuser As PropertySet
Dim oPropSetidwsap As PropertySet
Dim oPropSetidwDesignTrack As PropertySet
Dim opropset As PropertySet
Dim oProp As Property
Dim has_material As Boolean
Dim oFdescript As ReferencedFileDescriptor
Dim full_file_name As String
Dim reference_document As String
Dim file_in_directory As String
Dim revuser As String
Dim object_link As String
Dim curr_obj_link As String
Dim oRefDocType As DocumentTypeEnum
Dim docname As String
Dim pos As Integer

On Error Resume Next
Set oInvDoc = ThisApplication.ActiveDocument
revuser = Environ("ACADUSER")

If revuser = "" Then
MsgBox "Local Variable ACADUSER Not Set" & vbCrLf & " See your System Administrator", _
vbExclamation Or vbOKOnly Or vbSystemModal, "Local Variable"
End If

If oInvDoc.DocumentType = kDrawingDocumentObject Then
DrawingReferenceFile oInvDoc, full_file_name, reference_document
ElseIf oInvDoc.DocumentType = kPresentationDocumentObject Then
IpnReferenceFile oInvDoc, full_file_name, reference_document
End If

If full_file_name = "" Then
MsgBox "No Refence File Specified, Update Cancelled", _
vbMsgBoxSetForeground Or vbExclamation Or vbOKOnly Or vbSystemModal, "Update Cancelled"
Set oInvDoc = Nothing
Set ThisApplication = Nothing
MakeTopMost (Me.hwnd)
Exit Sub
End If
file_in_directory = Dir(full_file_name, vbNormal)
If file_in_directory = "" Then
MsgBox "Reference File " & reference_document & " Not in Working Directory" & vbCrLf & _
oInvDoc.DisplayName & " was NOT Updated", vbCritical Or vbOKOnly Or vbSystemModal, "File Not Found"
Set oInvDoc = Nothing
Set ThisApplication = Nothing
MakeTopMost (Me.hwnd)
Exit Sub
End If


ThisApplication.Documents.Open full_file_name, True
Set oRefDoc = ThisApplication.ActiveDocument
oInvDoc.Activate

GetMaterialLink oRefDoc, object_link
If object_link = "" Then
MsgBox "No Material for Objectlink Found in " & reference_document & vbCrLf & _
oInvDoc.DisplayName & " was NOT Updated", vbCritical Or vbOKOnly Or vbSystemModal, "Material Not Found"
Set oInvDoc = Nothing
Set ThisApplication = Nothing
MakeTopMost (Me.hwnd)
Exit Sub
End If

has_material = False

curr_obj_link = ""
For Each opropset In oInvDoc.PropertySets
If opropset.DisplayName = "User Defined Properties" Then
Set oPropSetidwuser = opropset
ElseIf opropset.DisplayName = "SAP_HEAD_MAT" Then
Set oPropSetidwsap = opropset
For Each oProp In oPropSetidwsap
curr_obj_link = oProp.Value
Next
has_material = True
ElseIf opropset.DisplayName = "Design Tracking Properties" Then
Set oPropSetidwDesignTrack = opropset
End If
Next

If has_material Then
If object_link <> curr_obj_link Then
Dim mess As String
Dim resp As Integer

mess = "Replace Existing " & curr_obj_link & " with " & object_link
resp = MsgBox(mess, vbSystemModal Or vbYesNo Or vbQuestion, "Replace Existing Material")
If resp = vbNo Then
object_link = curr_obj_link
End If
End If
For Each oProp In oPropSetidwsap
oProp.Value = object_link
Next
Else
Set oPropSetidwsap = oInvDoc.PropertySets.Add("SAP_HEAD_MAT")
Set oProp = oPropSetidwsap.Add(object_link, "MARA-MATNR")
' oPropSetidwsap.Delete
End If

frmUpdateDone.Label2.Caption = ""
frmUpdateDone.Label2.Caption = object_link


For Each oProp In oPropSetidwDesignTrack
Select Case oProp.Name
Case "Part Number"
If object_link <> "" Then
oProp.Value = object_link
End If
End Select
Next

If oInvDoc.DocumentType = kPresentationDocumentObject Then
FinishUpdate oInvDoc
Exit Sub
End If

If oRefDoc.DocumentType = kPartDocumentObject Then
Dim srawdescription As String
Dim srawmaterial As String
Dim srawqty As String
Dim srawuom As String
Dim inom As Integer
Dim dnomin As Double
Dim ddec As Double

GetRawMaterial oRefDoc, srawdescription, srawmaterial, srawqty, srawuom

Trim srawqty
If srawqty <> "" Then
inom = CInt(srawqty)
ddec = CDbl(srawqty) - CDbl(inom)
End If
If ddec = 0# Then
srawqty = CStr(inom)
End If
inom = CInt(srawqty)
ddec = CDbl(srawqty) - CDbl(inom)
If ddec = 0# Then
srawqty = CStr(inom)
End If

For Each oProp In oPropSetidwuser
Select Case oProp.Name
Case "RawDescription"
oProp.Value = srawdescription
Case "RawMaterial"
oProp.Value = srawmaterial
Case "RawQty"
oProp.Value = srawqty
Case "RawUom"
oProp.Value = srawuom
End Select
Next
End If

For Each oProp In oPropSetidwuser
Select Case oProp.Name
Case "CreatedBy"
oProp.Value = revuser
Case "DocumentNumber"

pos = InStr(1, oInvDoc.DisplayName, "_")
If pos = 0 Then
pos = InStr(1, oInvDoc.DisplayName, ".")
End If
docname = Mid(oInvDoc.DisplayName, 1, pos - 1)
oProp.Value = docname
Case "SCALE"
oProp.Value = GetViewScale(oInvDoc)
End Select
Next
oInvDoc.Update
FinishUpdate oInvDoc

End Sub

Sub DrawingReferenceFile(oRefDoc As Document, ByRef full_file_name As String, ByRef reference_document As String)
Dim oFdescript As ReferencedFileDescriptor
Dim idx As Integer
Dim n As Integer
Dim i As Integer
Dim xref As Document
Dim osheet As Sheet
Dim oview As DrawingView


If oRefDoc.ReferencedFiles.Count > 1 Then
frmRefSel.Combo1.Clear
use_reference = ""
idx = 1
For i = 1 To oRefDoc.ReferencedFiles.Count
If idx = 1 Then
frmRefSel.Combo1.Text = oRefDoc.ReferencedFiles.Item(i).FullFileName
End If
frmRefSel.Combo1.AddItem oRefDoc.ReferencedFiles.Item(i).FullFileName
idx = 2
Next
frmRefSel.Show 1
For i = 1 To oRefDoc.ReferencedFiles.Count
If oRefDoc.ReferencedFiles.Item(i).FullFileName = use_reference Then
full_file_name = oRefDoc.ReferencedFiles.Item(i).FullFileName
reference_document = oRefDoc.ReferencedFiles.Item(i).DisplayName
Exit For
End If
Next
ElseIf oRefDoc.ReferencedFiles.Count = 1 Then
full_file_name = oRefDoc.ReferencedFiles.Item(1).FullFileName
reference_document = oRefDoc.ReferencedFiles.Item(1).DisplayName
End If
End Sub
If there are several referenced files I put it in a Form combo box and let the user choose.
0 Likes
Message 5 of 6

Anonymous
Not applicable
Sorry about the garbled code.
0 Likes
Message 6 of 6

Anonymous
Not applicable
If you want to get the the drawing view also there is this way.

On Error Resume Next
Set oDrawDoc = ThisApplication.ActiveDocument
For Each oSheet In oDrawDoc.Sheets
oSheet.Activate
For Each oView In oSheet.DrawingViews
Debug.Print oView.Name & ":" & _
oView.ReferencedFile.DisplayName
Next
next

The On error resume next must be placed if there is a draft view in it or you can check for view type.

This just intriged me and I hope it helps any one thawt needs to access this functionality

Erhard
0 Likes