Associate File

Associate File

Anonymous
Not applicable
489 Views
11 Replies
Message 1 of 12

Associate File

Anonymous
Not applicable
I have a two files A.ipt and A.idw. I used the SaveCopyAs method and created B.ipt and B.idw from A.ipt and A.idw respectively. Since B.idw is a copy of A.idw hence it is associated with A.ipt but I want that it should be associated with B.ipt using API. If I am doing it manually and as long as A.ipt is in search path there is no way but if I am removing the A.ipt from the search path and opening the B.idw, Inventor ask the part file of the B.idw and we can associate it with B.ipt. If we make any changes in B.ipt, it gets reflected in B.idw. I want the same result using API. Do any body has idea or some sample code od doing it.

Thanks in advance

Manoj
0 Likes
490 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
Here's some sample code that I believe accomplishes
what you want.  The sample takes advantage of the fact that we know the
particular case.  A more general solution would require a bit more work,
but this does demonstrate one use of the API to do what you want.

 

Private Sub CreateCopy()

    ' Create an instance of
Apprentice Server.
    Dim oApprentice As
ApprenticeServerComponent
    Set oApprentice = New
ApprenticeServerComponent
    

    ' Open the drawing
document.
    Dim oDrawDoc As
ApprenticeServerDocument
    Set oDrawDoc =
oApprentice.Open("C:\Temp\FrameTest\A.idw")
    

    ' Get a reference to the
FileSaveAs object from Apprentice.
    Dim oFileSaveAs As
FileSaveAs
    Set oFileSaveAs =
oApprentice.FileSaveAs
    

    ' Add the drawing file to the
FileSaveAs, defining the new filename.
    Call
oFileSaveAs.AddFileToSave(oDrawDoc,
"C:\Temp\FrameTest\B.idw")

    ' Add the part file to the
FileSaveAs, defining the new filename.  The part document is

    ' obtained from the
drawing and getting the list of referenced files.  In this case we
know

    ' there's only a single
file referenced so it just gets the first one in the ReferencedFileDescriptors
collection.

    Call
oFileSaveAs.AddFileToSave(oDrawDoc.ReferencedFileDescriptors.Item(1).ReferencedDocument,
"C:\Temp\FrameTest\B.ipt")

 

    ' Perform the actual SaveCopyAs.  This will
create the copies and readjust the references.
    Call
oFileSaveAs.ExecuteSaveCopyAs
End Sub

-Brian


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
have a two files A.ipt and A.idw. I used the SaveCopyAs method and created
B.ipt and B.idw from A.ipt and A.idw respectively. Since B.idw is a copy of
A.idw hence it is associated with A.ipt but I want that it should be
associated with B.ipt using API. If I am doing it manually and as long as
A.ipt is in search path there is no way but if I am removing the A.ipt from
the search path and opening the B.idw, Inventor ask the part file of the B.idw
and we can associate it with B.ipt. If we make any changes in B.ipt, it gets
reflected in B.idw. I want the same result using API. Do any body has idea or
some sample code od doing it.

Thanks in advance

Manoj

0 Likes
Message 3 of 12

Anonymous
Not applicable
Hi Brian

Thanks for your prompt response. The sample provided by you is what I was looking for. Thanks once again
0 Likes
Message 4 of 12

Anonymous
Not applicable
Brian,

 

I tried this code but I got "Permission denied". I
suppose it's because my test files was not migrated or?

When I tried to check if the file "
face="Times New Roman" size=3>NeedsMigrating" I got stuck.(Object doesn't
support this action)

Do you
maybe have sample code for this?

 

Lars

 



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Here's some sample code that I believe
accomplishes what you want.  The sample takes advantage of the fact that
we know the particular case.  A more general solution would require a bit
more work, but this does demonstrate one use of the API to do what you
want.

 

Private Sub CreateCopy()

    ' Create an instance of
Apprentice Server.
    Dim oApprentice As
ApprenticeServerComponent
    Set oApprentice = New
ApprenticeServerComponent
    

    ' Open the drawing
document.
    Dim oDrawDoc As
ApprenticeServerDocument
    Set oDrawDoc =
oApprentice.Open("C:\Temp\FrameTest\A.idw")
    

    ' Get a reference to the
FileSaveAs object from Apprentice.
    Dim oFileSaveAs As
FileSaveAs
    Set oFileSaveAs =
oApprentice.FileSaveAs
    

    ' Add the drawing file to the
FileSaveAs, defining the new filename.
    Call
oFileSaveAs.AddFileToSave(oDrawDoc,
"C:\Temp\FrameTest\B.idw")

    ' Add the part file to
the FileSaveAs, defining the new filename.  The part document
is

    ' obtained from the
drawing and getting the list of referenced files.  In this case we
know

    ' there's only a single
file referenced so it just gets the first one in the ReferencedFileDescriptors
collection.

    Call
oFileSaveAs.AddFileToSave(oDrawDoc.ReferencedFileDescriptors.Item(1).ReferencedDocument,
"C:\Temp\FrameTest\B.ipt")

 

    ' Perform the actual SaveCopyAs.  This will
create the copies and readjust the references.
    Call
oFileSaveAs.ExecuteSaveCopyAs
End Sub

-Brian


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
have a two files A.ipt and A.idw. I used the SaveCopyAs method and created
B.ipt and B.idw from A.ipt and A.idw respectively. Since B.idw is a copy of
A.idw hence it is associated with A.ipt but I want that it should be
associated with B.ipt using API. If I am doing it manually and as long as
A.ipt is in search path there is no way but if I am removing the A.ipt from
the search path and opening the B.idw, Inventor ask the part file of the
B.idw and we can associate it with B.ipt. If we make any changes in B.ipt,
it gets reflected in B.idw. I want the same result using API. Do any body
has idea or some sample code od doing it.

Thanks in advance

Manoj

0 Likes
Message 5 of 12

Anonymous
Not applicable
Brian,

 

I have tested your sample code and I got
an error (-2147467259 Method 'FileS
aveAs' of
object '_IRxApprenticeServer' failed) on the 'Set oFileSaveAs =
oApprentice.FileSaveAs' part.

(I'm running IV6 SP2/WinXP Pro)

Do you have any suggestion?

 

Lars


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

Here's some sample code that I believe
accomplishes what you want.  The sample takes advantage of the fact that
we know the particular case.  A more general solution would require a bit
more work, but this does demonstrate one use of the API to do what you
want.

 

Private Sub CreateCopy()

    ' Create an instance of
Apprentice Server.
    Dim oApprentice As
ApprenticeServerComponent
    Set oApprentice = New
ApprenticeServerComponent
    

    ' Open the drawing
document.
    Dim oDrawDoc As
ApprenticeServerDocument
    Set oDrawDoc =
oApprentice.Open("C:\Temp\FrameTest\A.idw")
    

    ' Get a reference to the
FileSaveAs object from Apprentice.
    Dim oFileSaveAs As
FileSaveAs
    Set oFileSaveAs =
oApprentice.FileSaveAs
    

    ' Add the drawing file to the
FileSaveAs, defining the new filename.
    Call
oFileSaveAs.AddFileToSave(oDrawDoc,
"C:\Temp\FrameTest\B.idw")

    ' Add the part file to
the FileSaveAs, defining the new filename.  The part document
is

    ' obtained from the
drawing and getting the list of referenced files.  In this case we
know

    ' there's only a single
file referenced so it just gets the first one in the ReferencedFileDescriptors
collection.

    Call
oFileSaveAs.AddFileToSave(oDrawDoc.ReferencedFileDescriptors.Item(1).ReferencedDocument,
"C:\Temp\FrameTest\B.ipt")

 

    ' Perform the actual SaveCopyAs.  This will
create the copies and readjust the references.
    Call
oFileSaveAs.ExecuteSaveCopyAs
End Sub

-Brian


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
I
have a two files A.ipt and A.idw. I used the SaveCopyAs method and created
B.ipt and B.idw from A.ipt and A.idw respectively. Since B.idw is a copy of
A.idw hence it is associated with A.ipt but I want that it should be
associated with B.ipt using API. If I am doing it manually and as long as
A.ipt is in search path there is no way but if I am removing the A.ipt from
the search path and opening the B.idw, Inventor ask the part file of the
B.idw and we can associate it with B.ipt. If we make any changes in B.ipt,
it gets reflected in B.idw. I want the same result using API. Do any body
has idea or some sample code od doing it.

Thanks in advance

Manoj

0 Likes
Message 6 of 12

Anonymous
Not applicable
Did you set a reference to Inventor Apprentice before trying to run it?

--
Kent Keller
Member of the Autodesk Discussion Forum Moderator Program

http://www.MyMcad.com/KWiK/Mcad.htm

"Lars Andersson" wrote in message
news:E34B4D61625E96A262BF04351E5DBAF1@in.WebX.maYIadrTaRb...
> Brian,
>
> I tried this code but I got "Permission denied". I suppose it's because my
test files was not migrated or?
> When I tried to check if the file "NeedsMigrating" I got stuck.(Object
doesn't support this action)
> Do you maybe have sample code for this?
>
0 Likes
Message 7 of 12

Anonymous
Not applicable
Kent,

No I missed that, but it didn't help. Any more ideas?

Lars

"Kent Keller" skrev i meddelandet
news:EECFB1C09841E9FF7E7304F498C652CB@in.WebX.maYIadrTaRb...
> Did you set a reference to Inventor Apprentice before trying to run it?
>
> --
> Kent Keller
> Member of the Autodesk Discussion Forum Moderator Program
>
> http://www.MyMcad.com/KWiK/Mcad.htm
>
> "Lars Andersson" wrote in message
> news:E34B4D61625E96A262BF04351E5DBAF1@in.WebX.maYIadrTaRb...
> > Brian,
> >
> > I tried this code but I got "Permission denied". I suppose it's because
my
> test files was not migrated or?
> > When I tried to check if the file "NeedsMigrating" I got stuck.(Object
> doesn't support this action)
> > Do you maybe have sample code for this?
> >
>
>
0 Likes
Message 8 of 12

Anonymous
Not applicable
Lars

Where are you doing this? I don't believe this code is meant to run inside of Inventor.

I started a new file in Excel
Alt F11 to get into the IDE,
RMB insert module
Pasted the code into the module
Changed the names of files in the code to filenames on my system
Added a reference to Inventor Apprentice

And it ran fine.


--
Kent
Assistant Moderator
Autodesk Discussion Forum Moderator Program



"Lars Andersson" wrote in message
news:95C479A74816937A2FE1DB9C5F765731@in.WebX.maYIadrTaRb...
> Kent,
>
> No I missed that, but it didn't help. Any more ideas?
>
> Lars
0 Likes
Message 9 of 12

Anonymous
Not applicable
Lars,

I don't know what's causing the problems you're seeing, but here are a
couple of things to try. Make sure your files are already migrated. The
second thing is to see is if the files you're using are defined within the
current project. I'm not sure if this would impact this or not, but it's
worth trying.

-Brian

"Lars Andersson" wrote in message
news:95C479A74816937A2FE1DB9C5F765731@in.WebX.maYIadrTaRb...
> Kent,
>
> No I missed that, but it didn't help. Any more ideas?
>
> Lars
>
> "Kent Keller" skrev i meddelandet
> news:EECFB1C09841E9FF7E7304F498C652CB@in.WebX.maYIadrTaRb...
> > Did you set a reference to Inventor Apprentice before trying to run it?
> >
> > --
> > Kent Keller
> > Member of the Autodesk Discussion Forum Moderator Program
> >
> > http://www.MyMcad.com/KWiK/Mcad.htm
> >
> > "Lars Andersson" wrote in message
> > news:E34B4D61625E96A262BF04351E5DBAF1@in.WebX.maYIadrTaRb...
> > > Brian,
> > >
> > > I tried this code but I got "Permission denied". I suppose it's
because
> my
> > test files was not migrated or?
> > > When I tried to check if the file "NeedsMigrating" I got stuck.(Object
> > doesn't support this action)
> > > Do you maybe have sample code for this?
> > >
> >
> >
>
>
0 Likes
Message 10 of 12

Anonymous
Not applicable
I have tried to create new test files by using IV6 and have a projet set
with Workgroup Serch Path set to the folder containing the files. I have
pasted your(Brian) code as a macro (within Inventor). I have also checked
that a have 'RxApprentice.tlb' as a reference.
Right now is the 'Set oFileSaveAs = oApprentice.FileSaveAs' that cause me
all my problem. (-2147467259 Method 'FileSaveAs' of object
'_IRxApprenticeServer' failed)

Lars

"Brian Ekins (Autodesk)" skrev i meddelandet
news:523AF7EA6AB635C00AA235FA510D15CC@in.WebX.maYIadrTaRb...
> Lars,
>
> I don't know what's causing the problems you're seeing, but here are a
> couple of things to try. Make sure your files are already migrated. The
> second thing is to see is if the files you're using are defined within the
> current project. I'm not sure if this would impact this or not, but it's
> worth trying.
>
> -Brian
>
> "Lars Andersson" wrote in message
> news:95C479A74816937A2FE1DB9C5F765731@in.WebX.maYIadrTaRb...
> > Kent,
> >
> > No I missed that, but it didn't help. Any more ideas?
> >
> > Lars
> >
> > "Kent Keller" skrev i meddelandet
> > news:EECFB1C09841E9FF7E7304F498C652CB@in.WebX.maYIadrTaRb...
> > > Did you set a reference to Inventor Apprentice before trying to run
it?
> > >
> > > --
> > > Kent Keller
> > > Member of the Autodesk Discussion Forum Moderator Program
> > >
> > > http://www.MyMcad.com/KWiK/Mcad.htm
> > >
> > > "Lars Andersson" wrote in message
> > > news:E34B4D61625E96A262BF04351E5DBAF1@in.WebX.maYIadrTaRb...
> > > > Brian,
> > > >
> > > > I tried this code but I got "Permission denied". I suppose it's
> because
> > my
> > > test files was not migrated or?
> > > > When I tried to check if the file "NeedsMigrating" I got
stuck.(Object
> > > doesn't support this action)
> > > > Do you maybe have sample code for this?
> > > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 11 of 12

Anonymous
Not applicable
Here is the code. (I have a form with the CommonDialog1)
I'm not a Pro on programming so don't laugh to much........


Sub CreateCopy()
Dim Respons
Dim FileToCopy, FileToCreate As String
On Error GoTo Err_CreateCopy

CreateCopyOfTo.CommonDialog1.FileName = ""
CreateCopyOfTo.CommonDialog1.Filter = "Inventor Drawing (*.idw)|*.idw"
CreateCopyOfTo.CommonDialog1.CancelError = True
CreateCopyOfTo.CommonDialog1.ShowOpen
If Dir(CreateCopyOfTo.CommonDialog1.FileName) = "" Then
MsgBox "File does not exist! File copy terminated."
Exit Sub
Else
FileToCopy = CreateCopyOfTo.CommonDialog1.FileName
End If
CreateCopyOfTo.CommonDialog1.FileName = ""
CreateCopyOfTo.CommonDialog1.ShowSave
If Dir(CreateCopyOfTo.CommonDialog1.FileName) <> "" Then
Respons = MsgBox("File already exist! Replace the file?", vbOKCancel
+ vbDefaultButton2, "Varning")
If Respons = vbCancel Then Exit Sub
End If
FileToCreate = CreateCopyOfTo.CommonDialog1.FileName

'MsgBox FileToCopy
'MsgBox FileToCreate

' Create an instance of Apprentice Server.
Dim oApprentice As ApprenticeServerComponent
Set oApprentice = New ApprenticeServerComponent

' Open the drawing document.
Dim oDrawDoc As ApprenticeServerDocument
Set oDrawDoc = oApprentice.Open(FileToCopy)

' Get a reference to the FileSaveAs object from Apprentice.
Dim oFileSaveAs As FileSaveAs
Set oFileSaveAs = oApprentice.FileSaveAs

' Add the drawing file to the FileSaveAs, defining the new filename.
Call oFileSaveAs.AddFileToSave(oDrawDoc, FileToCreate)

' Add the part file to the FileSaveAs, defining the new filename. The
part document is
' obtained from the drawing and getting the list of referenced files.
In this case we know
' there's only a single file referenced so it just gets the first one in
the ReferencedFileDescriptors collection.
Call
oFileSaveAs.AddFileToSave(oDrawDoc.ReferencedFileDescriptors.Item(1).Referen
cedDocument, Left(FileToCreate, Len(FileToCreate) - 3) & "ipt")

' Perform the actual SaveCopyAs. This will create the copies and
readjust the references.
Call oFileSaveAs.ExecuteSaveCopyAs

Exit Sub
Err_CreateCopy:
If Err.Number <> 32755 Then MsgBox "Error: " & Err.Number & " (" &
Err.Description & ")" 'Cancel
End Sub




"Brian Ekins (Autodesk)" skrev i meddelandet
news:523AF7EA6AB635C00AA235FA510D15CC@in.WebX.maYIadrTaRb...
> Lars,
>
> I don't know what's causing the problems you're seeing, but here are a
> couple of things to try. Make sure your files are already migrated. The
> second thing is to see is if the files you're using are defined within the
> current project. I'm not sure if this would impact this or not, but it's
> worth trying.
>
> -Brian
>
> "Lars Andersson" wrote in message
> news:95C479A74816937A2FE1DB9C5F765731@in.WebX.maYIadrTaRb...
> > Kent,
> >
> > No I missed that, but it didn't help. Any more ideas?
> >
> > Lars
> >
> > "Kent Keller" skrev i meddelandet
> > news:EECFB1C09841E9FF7E7304F498C652CB@in.WebX.maYIadrTaRb...
> > > Did you set a reference to Inventor Apprentice before trying to run
it?
> > >
> > > --
> > > Kent Keller
> > > Member of the Autodesk Discussion Forum Moderator Program
> > >
> > > http://www.MyMcad.com/KWiK/Mcad.htm
> > >
> > > "Lars Andersson" wrote in message
> > > news:E34B4D61625E96A262BF04351E5DBAF1@in.WebX.maYIadrTaRb...
> > > > Brian,
> > > >
> > > > I tried this code but I got "Permission denied". I suppose it's
> because
> > my
> > > test files was not migrated or?
> > > > When I tried to check if the file "NeedsMigrating" I got
stuck.(Object
> > > doesn't support this action)
> > > > Do you maybe have sample code for this?
> > > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 12 of 12

Anonymous
Not applicable
I tried "my" code in VB6 and it worked perfectly.


"Brian Ekins (Autodesk)" skrev i meddelandet
news:523AF7EA6AB635C00AA235FA510D15CC@in.WebX.maYIadrTaRb...
> Lars,
>
> I don't know what's causing the problems you're seeing, but here are a
> couple of things to try. Make sure your files are already migrated. The
> second thing is to see is if the files you're using are defined within the
> current project. I'm not sure if this would impact this or not, but it's
> worth trying.
>
> -Brian
>
> "Lars Andersson" wrote in message
> news:95C479A74816937A2FE1DB9C5F765731@in.WebX.maYIadrTaRb...
> > Kent,
> >
> > No I missed that, but it didn't help. Any more ideas?
> >
> > Lars
> >
> > "Kent Keller" skrev i meddelandet
> > news:EECFB1C09841E9FF7E7304F498C652CB@in.WebX.maYIadrTaRb...
> > > Did you set a reference to Inventor Apprentice before trying to run
it?
> > >
> > > --
> > > Kent Keller
> > > Member of the Autodesk Discussion Forum Moderator Program
> > >
> > > http://www.MyMcad.com/KWiK/Mcad.htm
> > >
> > > "Lars Andersson" wrote in message
> > > news:E34B4D61625E96A262BF04351E5DBAF1@in.WebX.maYIadrTaRb...
> > > > Brian,
> > > >
> > > > I tried this code but I got "Permission denied". I suppose it's
> because
> > my
> > > test files was not migrated or?
> > > > When I tried to check if the file "NeedsMigrating" I got
stuck.(Object
> > > doesn't support this action)
> > > > Do you maybe have sample code for this?
> > > >
> > >
> > >
> >
> >
>
>
0 Likes