资源描述:
《辅助设计学习笔记》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、学习好资料欢迎下载添加第一个类AddTextPublicFunctionAddText(ByValtextStringAsString,ByValinsertStringAsVariant,ByValheightAsDouble)AsAcadTextDebug.Assert(VarType(insertPoint)=vbArray+vbDouble)Debug.Assert(UBound(insertPoint)=2)SetAddText=ThisDrawing.ModelSpace.AddText(insertPoin
2、t,Width,textString)EndFunction添加第二个类AddMTextPublicFunctionAddMText(ByValinsertPointAsVariant,ByValWidthAsDouble,ByValtextStringAsString)AsAcadMTextDebug.Assert(VarType(insertPoint)=vbArray+vbDouble)Debug.Assert(UBound(insertPoint)=2)SetAddMText=ThisDrawing.ModelS
3、pace.AddMText(insertPoint,Width,textString)EndFunction添加第三个类AddTextInRectanglePublicFunctionAddTextInRectangle(ByValpoint1AsVariant,ByValpoint2AsVariant,ByValtextStringAsString,OptionalratioAsDouble=0.7)AsAcadTextDebug.Assert(VarType(point1)=vbArray+vbDouble)Debu
4、g.Assert(UBound(point1)=2)Debug.Assert(VarType(point2)=vbArray+vbDouble)Debug.Assert(UBound(point2)=2)’计算矩形的宽、高和中心点DimrectHeightAsDouble,rectWidthAsDouble,centerPointAsVariantrectHeight=Abs(point1(1)-point2(1))rectWidth=Abs(point1(0)-point2(0))centerPoint=Math.Ge
5、tMiddlePointBetween2Point(point1,point2)‘创建文字,计算其高宽比DimtextAsAcadTextSettext=AddText(textString,centerPoint,rectHeight)DimminPointAsVariant,maxPointAsVarianttext.GetBoundingBoxminPoint,maxPointDimtextHeightAsDouble,TextWidthAsDoubletextHeight=Abs(minPoint(1)-maxP
6、oint⑴)TextWidth=Abs(minPoint(0)-maxPoint(0))学习好资料欢迎下载’根据矩形的宽、高和文字的容纳比例确定文字的高或宽DimheightRatioAsDoubleheightRatio=textHeight/TextWidthIf(heightRatio>rectHeight/rectWidth)ThentextHeight=rectHeight*ratioElseTextWidth=rectWidth*ratiotextHeight=TextWidth*heightRatioEnd
7、If'缩放和移动文字text.Alignment=acAlignmentBottomCentertext.AlignmentPoint=centerPointtext.height=textHeightSetAddTextInRectangle=textEndFunction主函数程序:PublicSubCreateText()Dimpoint1(0To2)AsDouble,point2(0To2)AsDoubleSetPoint3dpointl,0,0,0SetPoint3dpoint2,20,5,0DimmSpace
8、AsNewclsModelSpacemSpace.AddTextInRectanglepointl,point2,"cadhelp"mSpace.AddRectanglepointl,point2EndSub