- 积分
- 476
- 明经币
- 个
- 注册时间
- 2003-8-16
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2003-9-29 08:53:00
|
显示全部楼层
谢谢版主,我已经写出来了. 尺寸识别考虑了以text,mtext和有公差,没公差,提取内容方式不一样.
Function PreciseTransfer(preciseLong As Integer) As String
Select Case preciseLong
Case 0: PreciseTransfer = "0"
Case 1: PreciseTransfer = "0.0"
Case 2: PreciseTransfer = "0.00"
Case 3: PreciseTransfer = "0.000"
Case 4: PreciseTransfer = "0.0000"
Case 5: PreciseTransfer = "0.00000"
Case 6: PreciseTransfer = "0.000000"
Case 7: PreciseTransfer = "0.0000000"
Case 8: PreciseTransfer = "0.00000000"
End Select
End Function
Function blnTolerance(txt As String) As Boolean
Dim ps As Integer, i As Integer
Dim Defaultsymbol As String
For i = 1 To Len(txt) - 3
If Mid(txt, i, 1) = "<" And Mid(txt, i + 1, 1) = ">" And Mid(txt, i + 2, 1) = "{" And Mid(txt, i + 3, 1) = "}" Then
blnTolerance = True
Exit For
Else
blnTolerance = False
End If
Next i
End Function
Sub inputProcessInformation()
Dim retEnt As Object
Dim pnt As Variant
Dim MeasureValue As String, TxtOverride As String, dPrecise As String, tPrecise
Dim blkRefObj As AcadBlockReference
On Error Resume Next
' The following example waits for a input from user and returns the Line in retEnt
MsgBox "ÏÖÔÚÄú¿ÉÒÔ¶ÔͼÃæÉϵŤÒÕÐÅÏ¢½øÐÐÊäÈë»òÐÞ¸ÄÁË!"
Retry:
Err.Clear
ThisDrawing.Utility.GetEntity retEnt, pnt, "ÇëÑ¡ÔñÎïÌå:"
If Err <> 0 Then
Err.Clear
MsgBox "ÇëÑ¡ÔñÏà¹ØµÄʵÌå½øÐвÙ×÷!"
GoTo Retry
Else
NewRecord.ID = retEnt.ObjectID
Select Case retEnt.EntityName
Case "AcDbAlignedDimension", "AcDbRotatedDimension", "AcDbOrdinateDimension", "AcDbDiametricDimension", "AcDbRadialDimension"
MeasureValue = retEnt.Measurement
TxtOverride = retEnt.TextOverride
' judge whether the dimension is text or real dimension, if txt , txtoverride<>""
If TxtOverride = "" Then
' get the real dimension information
dPrecise = PreciseTransfer(retEnt.PrimaryUnitsPrecision)
NewRecord.BD = Format(MeasureValue, dPrecise)
If retEnt.EntityName = "AcDbDiametricDimension" Then NewRecord.BD = "?" & NewRecord.BD
If retEnt.EntityName = "AcDbRadialDimension" Then NewRecord.BD = "R" & NewRecord.BD
tPrecise = ret.TolerancePrecision
NewRecord.Ut = Format(retEnt.ToleranceUpperLimit, tPrecise)
NewRecord.Lt = Format(-retEnt.ToleranceLowerLimit, tPrecise)
If NewRecord.Ut = 0 And NewRecord.Lt = 0 Then
NewRecord.Ut = ""
NewRecord.Lt = ""
End If
Else
' if it is mtext/text method to produce the dimension and the tolerance exists.
dPrecise = PreciseTransfer(retEnt.PrimaryUnitsPrecision)
MeasureValue = Format(MeasureValue, dPrecise)
If blnTolerance(TxtOverride) = True Then
tPrecise = PreciseTransfer(retEnt.TolerancePrecision)
NewRecord.Ut = Format(retEnt.ToleranceUpperLimit, tPrecise)
NewRecord.Lt = Format(-retEnt.ToleranceLowerLimit, tPrecise)
NewRecord.BD = MeasureValue
If retEnt.EntityName = "AcDbDiametricDimension" Then MeasureValue = "Ö±¾¶" & NewRecord.BD
If retEnt.EntityName = "AcDbRadialDimension" Then MeasureValue = "R" & NewRecord.BD
Else
If retEnt.EntityName = "AcDbDiametricDimension" Then MeasureValue = "Ö±¾¶" & MeasureValue
If retEnt.EntityName = "AcDbRadialDimension" Then MeasureValue = "R" & MeasureValue
NewRecord.BD = Replace(TxtOverride, "<>", MeasureValue)
End If
End If
Case "AcDb2LineAngularDimension"
' change the unit of angle
MeasureValue = retEnt.Measurement
MeasureValue = MeasureValue * 180 / 3.1415926
TxtOverride = retEnt.TextOverride
' judge whether the dimension is text or real dimension, if txt , txtoverride<>""
If TxtOverride = "" Then
' get the real dimension information
dPrecise = PreciseTransfer(retEnt.TextPrecision)
NewRecord.BD = Format(MeasureValue, dPrecise) & "¶È"
NewRecord.Ut = Format(retEnt.ToleranceUpperLimit, tPrecise)
NewRecord.Lt = Format(-retEnt.ToleranceLowerLimit, tPrecise)
If NewRecord.Ut = 0 And NewRecord.Lt = 0 Then
NewRecord.Ut = ""
NewRecord.Lt = ""
End If
Else
' if it is mtext/text method to produce the dimension and the tolerance exists.
dPrecise = PreciseTransfer(retEnt.TextPrecision)
MeasureValue = Format(MeasureValue, dPrecise)
If blnTolerance(TxtOverride) = True Then
tPrecise = PreciseTransfer(retEnt.TolerancePrecision)
NewRecord.Ut = Format(retEnt.ToleranceUpperLimit, tPrecise)
NewRecord.Lt = Format(-retEnt.ToleranceLowerLimit, tPrecise)
NewRecord.BD = MeasureValue
Else
NewRecord.BD = Replace(TxtOverride, "<>", MeasureValue)
End If
End If
Case "AcDbMText", "AcDbText"
NewRecord.BD = retEnt.TextString
NewRecord.Ut = ""
NewRecord.Lt = ""
Case "AcDbBlockReference"
'Èç¹ûÑ¡ÔñµÄÊÇ¿éÒýÓ㬽«Æ丳¸ø¿éÒýÓöÔÏó
Set blkRefObj = retEnt
Dim attVars As Variant
Dim i As Integer
If blkRefObj.Name = "RRR" Or blkRefObj.Name = "RRL" Then
attVars = blkRefObj.GetAttributes
NewRecord.BD = "´Ö²Ú¶È" & attVars(0).TextString
MsgBox NewRecord.BD
ElseIf blkRefObj.Name = "RZU" Or blkRefObj.Name = "RZL" Then
NewRecord.BD = "Rz200"
Else
GoTo ChooseReply
End If
Case "AcDbFcf"
Dim tol As AcadTolerance
Set tol = retEnt
MsgBox tol.TextString
GoTo Retry
Case Else
'GoTo ChooseReply
MsgBox retEnt.EntityName
End Select
frminputprocessinformation.pShow
ChooseReply: ' reply the process until the user choose to cancel.
strmsg = MsgBox("ÄãÐèҪѡÔñÒ»¸öʵÌå½øÐвÙ×÷!" & vbCrLf & _
"¼ÌÐøÊäÈ빤ÒÕÐÅÏ¢°´È·¶¨¼ü,Í˳ö¹¤ÒÕÐÅÏ¢°´È¡Ïû!", vbOKCancel, "¹¤ÒÕÐÅÏ¢ÊäÈë")
If strmsg = vbOK Then
GoTo Retry
Else
Exit Sub
End If
End If
End Sub
不过,还有问题请帮主帮忙:
1). 对于直径,度数,还有形位公差符号,的这些字符如果从WORD里面复制到VBA界面,就变成了问号.而我在写程序时要用到,怎么办?
2)对应形位公差的部分,TEXTSTRING的属性提取出来的信息好像要写子程序识别才行.有没有好的简单办法.
谢谢! |
|