明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1327|回复: 1

关于将模型移动到新目录下并改名的问题请教!

[复制链接]
发表于 2014-7-19 15:47 | 显示全部楼层 |阅读模式
各位老师好,
       本来想上传模型来的,但是文件较大无法上传,现在只好用文字来表述了,希望能表述清楚

请看下面代码
Private Sub Button8_Click()
Dim oApprentice As New ApprenticeServerComponent
Dim oNewMainFile,ModelsSourceDir, ModelsTargetDir As String
ModelsSourceDir = "E:\123\1-Core"  & "_铁芯装配.iam"
ModelsTargetDir = "D:\234\1-Core\ "
oNewMainFile = ModelsTargetDir & "234_铁芯装配.iam"
StandardDir="E:\123\_StandardPart"

oApprentice.FileLocations.FileLocationsFile = "E:\123\123.ipj"
Call oApprentice.FileManager.CopyFile(ModelsSourceDir, oNewMainFile, kOverwriteExistingFile)

Dim oDoc As ApprenticeServerDocument
Set oDoc = oApprentice.Open(oNewMainFile)

    Dim oFileSaveAs As FileSaveAs
    Set oFileSaveAs = oApprentice.FileSaveAs

    Dim oRefFile As ApprenticeServerDocument
    Dim oRefFileDesc As ReferencedFileDescriptor

    Dim oNewFile As String

For Each oRefFile In oDoc.AllReferencedFiles

    If InStr(1, GetFullPath(oRefFile.FullDocumentName), StandardDir) = 0 Then
       oNewFile = ModelsTargetDir & "\" & "234"& ExtractFileName(oRefFile.FullFileName)
          For Each oRefFileDesc In oDoc.ReferencedFileDescriptors
              If oRefFileDesc.FullFileName = oRefFile.FullDocumentName Then
                    Call oApprentice.FileManager.CopyFile(oRefFile.FullFileName, oNewFile, kOverwriteExistingFile)
                    Call oRefFileDesc.PutLogicalFileNameUsingFull(oNewFile)               
              End If
          Next         
    Call oFileSaveAs.AddFileToSave(oRefFile, oNewFile)
    End If
Next

    Call oFileSaveAs.AddFileToSave(oDoc, oNewMainFile)
    oFileSaveAs.ExecuteSaveAs
    oApprentice.Close
    Set oDoc = Nothing
End Sub

定义了两个函数GetFullPath() 、ExtractFileName() 如下:

################################################
Function ExtractFileName(FullPathFileName) As String

    Dim AllElements As Variant
    AllElements = Split(FullPathFileName, "\")

        ExtractFileName = AllElements(UBound(AllElements))

End Function

##############################################
Function GetFullPath(FullPathFileName) As String
    Dim AllElements As Variant
    AllElements = Split(FullPathFileName, "\")

    Dim PathLong As String
    PathLong = AllElements(0)
    Dim i As Integer
    For i = 1 To UBound(AllElements) - 1
        PathLong = (PathLong & "\" & AllElements(i))
    Next
    GetFullPath = PathLong
End Function

模型创建中的一些澄清:
1.有一个名为“_ControlPart.ipt“零件,其他所有零件均衍生于此零件,个别部件也链接了此零件中的个别参数;
2."E:\123\_StandardPart"这个文件夹与"E:\123\1-Core"并列于项目文件夹下,前者用于存放自定义的标准件,
   后者用于存放制作的模型;
3.我使用的为Inventor2014版本,对个别的零部件使用了iLogic功能;
4.代码中的目录本由代码指定,此处省略。

运行代码后的问题:
1.当代码运行后,目标目录"D:\234\1-Core”确实生成了新的项目,名字也都加了前缀”234“,但是当用Inventor打开后,
   在模型树中发现总装配的名字依然是”_铁芯装配.iam“,而不是我想要的”234_铁芯装配.iam“,而其包含的零部件中,
   有1个子零件的名字也没变过来,有2个字子装配(子装配的名字变了)下的子零件名字也没变化;
2.当打开源目录下的"E:\123\1-Core"  & "_铁芯装配.iam",发现几乎所有衍生了“_ControlPart.ipt“的零部件的引用位置
   均指向了目标目录下的"D:\234\1-Core\234_ControlPart.ipt“,而不是原来的"E:\123\1-Core\_ControlPart.ipt“,这是
   我最不能接受的,等于破坏了将来我打算将其用作工具的模型。

我本要实现的目标:
1.将用作工具的源模型,迁移到新的项目目录下,生成的新的模型名字都统一加上前缀,相当于名字改变了,只需要
   文件名跟模型树中的显示名发生变化即可,其他名称不需要变化;
2.源文件必须保持原样,不能早到任何破坏。

求助的问题:
1.以上代码有什么问题吗
2.如果要实现我的目标,我又该怎么做!





该贴已经同步到 GT2014的微博
 楼主| 发表于 2014-7-21 10:37 | 显示全部楼层
没人能帮帮我吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-3-29 17:17 , Processed in 0.276639 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表