理解装配中的文件引用-1

原文地址:http://modthemachine.typepad.com/my_weblog/2008/11/understanding-file-references.html

我们知道, Inventor的装配需要插入零件,子装配, 零件中心零件等. 而底层的机制只是使用了源文件的一部分信息, 而不是整个文件都插入. 在需要的时候.例如显示,则从原文件获取数据,创建代理实体,从而在屏幕上看到结果. 这种机制, 从API的角度, 叫做"引用".

本文更详细的介绍如何理解"引用".

Overview

To start let's look at a very simple case of creating an assembly.  When you first create the assembly (Assembly.iam in this example) it is empty and doesn't have any references to other files.    When you place a part into the assembly there are two things that Inventor creates.  It creates the occurrence that you see in the graphics window and as a node in the browser, and it also creates a reference to the part file.  The file reference isn't something you see in the user interface but is an internal action that takes place.

 一个新装配一开始 没有任何内容. 插入一个零件后, Inventor做了两件事情. 首先创建了零件实例,从而看到了零件表达的图形,浏览窗口也能看到一个新节点.另外Inventor创建了对零件的引用. 这种引用是从用户界面看不到的,而是作为内部使用的机制.

To make sense of the file reference concept, I visualize the references as a table in each Inventor document.  The table is a list of all of the files that file references.  The table doesn't know why the reference exists (in this example because of an occurrence being placed), but just that there is a reference to a certain file.  Below is a picture that illustrates this.  It's the assembly with a single instance of Part1.ipt.  We see the part in the graphics window and in the browser.  It also shows a representation of the internal table that contains a list of the referenced files, which in this case has a single file in the list.

打个比方, 在每个Inventor文档虚构一个引用表,列出了所有该装配引用的文件. 表格本身并不知为何该引用存在,但只是知道有个引用。下面是一张截图:一个含有part1.ipt的装配。可以看到左面的浏览窗口列出了该零件。在右面的表格也显示出当前装配有一个引用。

FileReferences1

Now I've added a second part to the assembly, Part2.ipt, with the result shown below.  The result shouldn't be surprising; a new occurrence in the graphics window and browser and another file in the reference table.

当我们插入第二个零件,part2.ipt,则结果是浏览器窗口和表格都反应出增加的这个引用。

FileReferences2

Now I've added two more instances of Part1.ipt.  You see the additional occurrences in the graphics window and the browser but the reference table hasn't changed.  That's because there was already a reference to Part1.ipt.  There's never more than one reference for a particular file.

接着再插入一次part1.ipt,这时浏览器增加了一个节点,而表格却没有任何新内容。这是因为part1.ipt已经被引用,无论插入多少次,都只算作一次引用。

FileReferences3

When this assembly is opened, Inventor reads the referenced file table, finds the actual file on disk, and opens it.  Inventor can then use the contents of that file for whatever the reference is used for; assembly occurrences, drawing views, derived parts, etc.

因此每当我们打开一个装配,Inventor将读取引用表,找到对应的文件,打开之。接着Inventor读取其中的内容(例如几何信息)在装配中显示出来。

File References and Where Used

One important thing to highlight here  is that the files being referenced, (Part1.ipt and Part2.ipt in this example) don't know they're referenced by another file.  Referencing a file doesn't change it in any way.  This is important because a part can be used in any number of assemblies or drawings.  Also a file might be read-only because of being an approved part and not available for edit or because the file exists on a read-only media. 

A couple of the recent questions on the newsgroup had to do with determining where a file is used.  Given Part1.ipt they want to know where it is used.  It's a reasonable question, but as you can see from the discussion above, it's not a question that Part1.ipt can answer because it doesn't know.  Design Assistant supports where usedfunctionality but it does this within the limitations we've just discussed.  Design Assistant looks through all of the files in a specified set of directories and reads the referenced file list within each file to see if that file references the file you want the where used information for.  This has the limitation that it's only reporting for the files in the searched directories.  PDM applications will typically save file reference information in a database when files are checked in and use this data to determine where used information.

这里需要注意的是,part1.ipt和part2.ipt并不知道它们被哪个装配引用了。有些需求就是想知道哪些装配引用了某零件。 Design Assistant 可在所有特定的文件夹中去寻找哪些文件引用了某零件。而局限就是只是这些特定文件夹。

Projects

Another topic that's important to understand relative to file references is projects.  In the previous example, I explained that when the assembly is opened Inventor reads the referenced file list and then finds and opens the referenced files.  To find the files Inventor uses the project information.  The easy way to visualize a project is that it defines a list of directories to search.  When Inventor reads Part1.ipt from the referenced file list it looks through the directories specified by the project to find Part1.ipt.  Because of the flexibility of defining where files are you can easily move files around and as long as the project points to the new location Inventor will find and open the file.  The file reference stored is basically just the file name, not the path because the path is dynamically defined by the current project.

另外需要理解的是,相对于项目的引用。前面提到,装配打开后,将找寻引用的文件。最方便的就是项目所包含的文件夹。因此Inventor首先尝试从这些文件夹去寻找。这样,当做复制时,可以直接拷贝整个项目。

Changing References

A common task is to change a file reference.  Here's a simple example to illustrate.  It starts with the assembly from the previous example where it references two parts; Part1.ipt and Part2.ipt.

用户还可能修改引用文件。例如前面插入了part1和part2的装配。

FileReferences4

I want to make a revision to Part1.ipt so I make a copy to Part1_Rev1.ipt and make the required changes.  The picture below illustrates the current situation.  The assembly is unchanged but I have a new file, Part1_Rev1.ipt, sitting on my disk.

我想修改part1,则复制了一份Part1_Rev1.ipt ,做修改,如下面最右面的图示。装配当然没有变化。

FileReferences5 

I want my assembly to use the Part1_Rev1.ipt instead of Part1.ipt, as shown below.  There are a few ways to accomplish this but the result is that the reference in the assembly is changed to another file.  The occurrences that use that reference automatically reflect the new file.

当引用从 Part1.ipt变化到 Part1_Rev1.ipt ,则装配会发生更新,如下图。

FileReferences6

There are a few ways to get the result shown above.  Within Inventor you do it using the Replace Component or Replace All command, which indirectly will edit the referenced file list.  You can also accomplish this using Design Assistant.  Finally Inventor's API lets you change the file references.  In fact, from the API you have direct access to the reference file table, which is also what Design Assistant uses internally.

API提供了替换的相关方法, 例如ComponentOccurrence.Replace。


Limitation

There is one limitation to be aware when attempting to change a file reference.  The general rule is that the new file must be a descendant of the original file.  In the example above, Part1_Rev1.ipt is a descendant of Part1.ipt because it was created by copying Part.ipt and then subsequently edited.  Because of this when the reference is changed, assembly constraints are able to compute correctly and the assembly behaves as expected.

需要注意,被替换文件和替换文件需要时同源的。上面提到的Part1_Rev1.ipt 和Part1.ipt同源,因为前者是从后者复制的。只有同源的替换,原有的约束等信息才能计算正确。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值