中国汽车工程师之家--聚集了汽车行业80%专业人士 

论坛口号:知无不言,言无不尽!QQ:542334618 

本站手机访问:直接在浏览器中输入本站域名即可 

  • 1546查看
  • 0回复

如何在工程图中体现比例和重量

[复制链接]


该用户从未签到

发表于 3-6-2009 19:20:01 | 显示全部楼层 |阅读模式

汽车零部件采购、销售通信录       填写你的培训需求,我们帮你找      招募汽车专业培训老师


如何在工程图中体现比例和重量

'用来实现工程图中重量自动计算的程序
'    1、修改工程图模板,在模板中增加自定义特性--重量
'    2、修改工程图中标题栏定义,在标题栏中添加一个与自定义特性重量关联的变量文本
'    3、将本程序加入工程图模板
'
Public Sub AutoSave()
    ' Set a reference to the part document.
    ' This assumes a part document is active.
    Dim oDrawingDoc As DrawingDocument
    Set oDrawingDoc = ThisApplication.ActiveDocument
   
    '==============================================
    '自动计算重量
   ' Set a reference to the mass properties object.
    Dim oMassProps As MassProperties
    Dim oDocuments As DocumentsEnumerator
   
    Set oDocuments = oDrawingDoc.ReferencedFiles
   
    If oDocuments.Count = 0 Then
        '修改自定义特征
        Dim oPropSet1 As PropertySet
        Set oPropSet1 = oDrawingDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
        Dim oProp1 As Property
        Set oProp1 = oPropSet1.Item("重量")
        oProp1.Value = ""
      Exit Sub
    End If
   
    Dim oDocument As Document
    Set oDocument = oDocuments.Item(1)
   
    Debug.Print "====================================="
    If oDocument.DocumentType = kAssemblyDocumentObject Then
      Dim oAssDoc As AssemblyDocument
      Set oAssDoc = oDocument
      Set oMassProps = oAssDoc.ComponentDefinition.MassProperties
    Else
      If oDocument.DocumentType = kPartDocumentObject Then
        Dim oParDoc As PartDocument
        Set oParDoc = oDocument
        Set oMassProps = oParDoc.ComponentDefinition.MassProperties
      Else
         Exit Sub
      End If
    End If
   
    'Set oMassProps = oPresDoc '.ComponentDefinition.MassProperties
   
    ' Set the accuracy to medium.
    oMassProps.Accuracy = k_Medium
   
    Dim massdt As String
    Dim massd As Double
   
    massd = oMassProps.Mass
    massdt = Format(massd, "0.000")
    'MsgBox "总重: " & oMassProps.Mass
   
    '修改自定义特征
    Dim oPropSet As PropertySet
    Set oPropSet = oDrawingDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
    Dim oProp As Property
    Set oProp = oPropSet.Item("重量")
    oProp.Value = massdt
    '=========================================================
    '自动计算比例
    Dim oSheet As Sheet
    Set oSheet = oDrawingDoc.ActiveSheet
   
    If oSheet.DrawingViews.Count < 1 Then
      Exit Sub
    End If
      
    Dim oDrawingView As DrawingView
    Set oDrawingView = oSheet.DrawingViews.Item(1)
   
    Dim dScale As Double
    dScale = oDrawingView.Scale
   
    Dim dRatio As Double
    Dim strRatio As String
    If dScale < 1 Then
      dRatio = 1# / dScale
      dRatio = Format(dRatio, "0")
      strRatio = "1:" & dRatio
    Else
     dScale = Format(dScale, "0")
     strRatio = dScale & ":1"
    End If
    'MsgBox "比例:" & strRatio
    oDrawingDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}").Item("比例").Value = strRatio
   
End Sub

快速发帖

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|Archiver|汽车工程师之家 ( 渝ICP备18012993号-1 )

GMT+8, 23-12-2024 12:08 , Processed in 0.321989 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2013 Comsenz Inc.