为iPart表添加“重量”列

本文介绍了一种在Autodesk Inventor中为iPart成员自动设置重量属性的方法。通过编写VBA宏来代替手动操作,提高了工作效率,确保了准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址: http://modthemachine.typepad.com/my_weblog/2009/02/setting-the-weight-for-ipart-members.html


There was a question posted on the customization newsgroup that I spent a little time investigating and think the answer might be of general interest.  The objective is to have a column in the iPart table that has the weight for that member.  I wasn’t able to figure out a way to do this with built-in functionality in Inventor but it turned out it isn’t too difficult to write a program to accomplish the task.  Although the program and description below is specific to the weight of a part, it could be modified to handle other part information that you want to associate with an iPart member.

Brian在欧特克Inventor论坛上看到一个帖子,提及如何为为Part表添加“重量”列。虽然API没有提供直接的方法,但实现并不难。当然,你想添加其它信息也是类似的。“重量”只是个样例

First, let’s look at the iPart factory to see what needs to exist for the program to function correctly.  The only thing special is that I created a custom iProperty called “Weight” and added that as one of the iProperties that I want to set from the table.  It didn’t have to be an iProperty and could have been an “Other” value but using an iProperty provides the most flexibility for using the value elsewhere in Inventor.  For example, in the the drawing.  The picture below shows the iPart table after setting it up with this iProperty.  The values for this new column are empty.

首先看看iPart 工厂。我们增加了一个名为“weight" (重量)的自定义iProperty,并加入到iPart表中。并不是必须iProperty,你也可以使用其它值。但iProperty较灵活。下图中,可以看到Weight列,尚未填写数值。

iPartTable


如果手动填写,将是以下步骤:

Now we need to assign the correct weight for each row to the weight column.  If you had to this manually you would:

  1. Activate a member.
    激活iPart中某行
  2. Run the iProperties command
    进入iProoerties对话框
  3. Go to the “Physical” tab of the iProperties dialog.
    切入到”物理“ 选项卡
  4. Click the “Update” button on the “Physical” tab.
    点击”更新“
  5. Select and Copy the “Mass” field.
    选择并拷贝”重量“
  6. Open the iPart table and paste the mass value into the table for the correct row.
    打开iPart表,粘贴重量值到对应的格子
  7. Close the iPart table.
    关闭iPart表
  8. Repeat steps 1 to 7 for every row in the table.
    重复以上步骤,操作其它行

As you can see this is very tedious and prone to errors.  Instead of manually going through these steps they can be automated using Inventor’s programming interface.  Below is a VBA macro that will do the work.

相当麻烦!对吧。而用下面一个简单的宏,就可以自动搞定所有了。

Public Sub UpdateWeightOfiParts() 
    ‘ Get the active document.  This assumes it is a part. 
    ‘ 获取当前文档,假定是个零件
    Dim oPartDoc As PartDocument 
    Set oPartDoc = ThisApplication.ActiveDocument 

    ' Check that this part is an iPart factory. 
    ’判断是否是iPart工厂
    If Not oPartDoc.ComponentDefinition.IsiPartFactory Then 
        MsgBox "This part must be an iPart factory." 
        Exit Sub 
    End If 

    Dim oFactory As iPartFactory 
    Set oFactory = oPartDoc.ComponentDefinition.iPartFactory 

    ' Check that there's a "Weight" column in the iPart table,
    ' and get its index in the table. 
    ‘ 检查是否已经有”重量”列,并获取其序号
    Dim iWeightColumnIndex As Long 
    iWeightColumnIndex = GetColumnIndex(oFactory, "Weight") 
    If iWeightColumnIndex = -1 Then 
        MsgBox "The column ""weight"" does not exist in the table." 
        Exit Sub 
    End If 

    ' Iterate through the rows 
    ' 遍历所有行
    Dim oRow As iPartTableRow 
    For Each oRow In oFactory.TableRows 
        ' Make this the active row so the model will recompute. 
        ’ 激活某行
        oFactory.DefaultRow = oRow 

        ' Get the weight. 
‘获得重量值
        Dim dWeight As Double 
        dWeight = oPartDoc.ComponentDefinition.MassProperties.Mass 

        ' Convert it to current mass units defined by the document. 
’按当前文档单位制转换
        Dim strWeight As String 
        strWeight = oPartDoc.UnitsOfMeasure.GetStringFromValue( _  
                                dWeight, kDefaultDisplayMassUnits) 

        ' Set the row value for the weight column. 
‘填写iPart表中对应的格子
        oRow.Item(iWeightColumnIndex).Value = strWeight 
    Next 
End Sub 


’ Function that given a factory and the name or a column will return 
’ the index number of the column, if it’s found in the factory’s 
’ table.  If the column is not found it returns –1.  The comparison 
’ of the name is done in a case insensitive way. 
’该函数用来获取重量列的序号。如果没有发现,则返回-1
Private Function GetColumnIndex(ByVal Factory As iPartFactory, _  
                                ByVal ColumnName As String) As Long 
    ‘ Iterate through all of the columns looking for a 
    ‘ match to the input name. 
   ‘ 遍历所有列,获取重量列
    Dim i As Long 
    For i = 1 To Factory.TableColumns.Count 
        Dim oColumn As iPartTableColumn 
        Set oColumn = Factory.TableColumns.Item(i) 

        ‘ Compare this column with the input name. 
’比较列名
        If LCase(oColumn.DisplayHeading) = LCase(ColumnName) Then 
            ' A matching column was found so exit. 
            GetColumnIndex = i 
            Exit Function 
        End If 
    Next 

    ' The column wasn't found so return -1. 
   ‘ 没有发现,则返回-1
    GetColumnIndex = -1 
End Function


The program is essentially performing the same steps that would be required to do this manually.  It’s just able to do it much faster and without any mistakes.  After running the macro on my factory the table now looks like this.

可见,代码的效率远大于手动的操作。执行后,可以看到iPart表的状态:

iPartTableAfter


It’s also important to recognize that the weight is a snapshot of the weight at the time the macro was run.  If the part is modified (for example, a new feature is added) or table values are edited that affect the part geometry, the weight will no longer be correct and the macro will need to be run again to update the weight column.

需要注意的是,重量将随着零件模型变化而变化,因此你需要在适当的时候及时更新iPart表,执行以上的代码。当然,也可以考虑在某些事件例如UserInputEventsSink.OnActivateCommand去做更新工作。



资源下载链接为: https://pan.quark.cn/s/5c50e6120579 在Android移动应用开发中,定位功能扮演着极为关键的角色,尤其是在提供导航、本地搜索等服务时,它能够帮助应用获取用户的位置信息。以“baiduGPS.rar”为例,这是一个基于百度地图API实现定位功能的示例项目,旨在展示如何在Android应用中集成百度地图的GPS定位服务。以下是对该技术的详细阐述。 百度地图API简介 百度地图API是由百度提供的一系开放接口,开发者可以利用这些接口将百度地图的功能集成到自己的应用中,涵盖地图展示、定位、路径规划等多个方面。借助它,开发者能够开发出满足同业务需求的定制化地图应用。 Android定位方式 Android系统支持多种定位方式,包括GPS(全球定位系统)和网络定位(通过Wi-Fi及移动网络)。开发者可以根据应用的具体需求选择合适的定位方法。在本示例中,主要采用GPS实现高精度定位。 权限声明 在Android应用中使用定位功能前,必须在Manifest.xml文件中声明相关权限。例如,添加<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />,以获取用户的精确位置信息。 百度地图SDK初始化 集成百度地图API时,需要在应用启动时初始化地图SDK。通常在Application类或Activity的onCreate()方法中调用BMapManager.init(),并设置回调监听器以处理初始化结果。 MapView的创建 在布局文件中添加MapView组件,它是地图显示的基础。通过设置其属性(如mapType、zoomLevel等),可以控制地图的显示效果。 定位服务的管理 使用百度地图API的LocationClient类来管理定位服务
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值