[求助]怎么用VB在CAD中图案填充呀
<P> 哪位大哥帮帮忙,小弟做毕业设计急用.</P><P> 如何用VB ActiveX技术实现CAD中的图案填充呀</P>
<P> 另外,在CAD中用VB能不能实现图形的打断?</P> <P> 我也 是刚学的,从明经通道出的书上看的一点点 上面有图案填充源代码,摘录下来让你看看,我试过可行</P>
<P>'创建渐变填充<BR>'patType:0为预定义图案,1为用户定义图案<BR>'patName:包括LINEAR, CYLINDER, INVCYLINDER, SPHERICAL HEMISPHERICAL, CURVED, INVSPHERICAL, INVHEMISPHERICAL和INVCURVED<BR>Public Function AddHatchGC(ByRef objList() As AcadEntity, ByVal patType As Integer, ByVal patName As String, _<BR> ByVal associativity As Boolean, ByVal color1 As AcadAcCmColor, ByVal color2 As AcadAcCmColor) As AcadHatch<BR> On Error GoTo errHandle<BR> '定义填充对象<BR> Dim objHatch As AcadHatch<BR> <BR> Set objHatch = ThisDrawing.ModelSpace.AddHatch(patType, patName, True, acGradientObject)<BR> <BR> objHatch.GradientColor1 = color1<BR> objHatch.GradientColor2 = color2<BR> <BR> objHatch.AppendOuterLoop (objList)<BR> objHatch.Evaluate<BR> ThisDrawing.Regen True<BR> <BR> Set AddHatchGC = objHatch<BR> Exit Function<BR>errHandle:<BR> If Err.Number = -2145386493 Then<BR> MsgBox "填充定义边界未闭合!", vbCritical<BR> End If<BR> Err.Clear<BR>End Function</P>
<P>'创建真彩色填充<BR>'patType:0为预定义图案,1为用户定义图案<BR>'patName:包括LINEAR, CYLINDER, INVCYLINDER, SPHERICAL HEMISPHERICAL, CURVED, INVSPHERICAL, INVHEMISPHERICAL和INVCURVED<BR>Public Function AddHatchTC(ByRef objList() As AcadEntity, ByVal patType As Integer, _<BR> ByVal associativity As Boolean, ByVal color As AcadAcCmColor) As AcadHatch<BR> On Error GoTo errHandle<BR> '定义填充对象<BR> Dim objHatch As AcadHatch<BR> <BR> Set objHatch = ThisDrawing.ModelSpace.AddHatch(patType, "LINEAR", True, acGradientObject)<BR> <BR> objHatch.GradientColor1 = color<BR> objHatch.GradientColor2 = color<BR> <BR> objHatch.AppendOuterLoop (objList)<BR> objHatch.Evaluate<BR> ThisDrawing.Regen True<BR> <BR> Set AddHatchTC = objHatch<BR> Exit Function<BR>errHandle:<BR> If Err.Number = -2145386493 Then<BR> MsgBox "填充定义边界未闭合!", vbCritical<BR> End If<BR> Err.Clear<BR>End Function</P>
<P>'直接根据X、Y方向增量移动实体<BR>Public Function MoveEntity(ByVal objEntity As AcadEntity, ByVal x As Double, ByVal y As Double, _<BR> Optional z As Double = 0)<BR> Dim ptBase(2) As Double<BR> Dim ptDest(2) As Double<BR> <BR> '基点和目标点的位置<BR> ptBase(0) = 0: ptBase(1) = 0: ptBase(2) = 0<BR> ptDest(0) = x: ptDest(1) = y: ptDest(2) = z<BR> <BR> objEntity.Move ptBase, ptDest<BR>End Function</P>
<P>'复制对象,并将复制得到的对象移动一定的位置<BR>Public Function CopyEntity(ByVal objEntity As AcadEntity, ByVal x As Double, ByVal y As Double, _<BR> Optional z As Double = 0) As AcadEntity<BR> Dim ptBase(2) As Double<BR> Dim ptDest(2) As Double<BR> Dim objCopy As AcadEntity<BR> <BR> '基点和目标点的位置<BR> ptBase(0) = 0: ptBase(1) = 0: ptBase(2) = 0<BR> ptDest(0) = x: ptDest(1) = y: ptDest(2) = z<BR> <BR> Set objCopy = objEntity.Copy<BR> objCopy.Move ptBase, ptDest<BR> <BR> Set CopyEntity = objCopy<BR>End Function</P> <P> 我也 是刚学的,从明经通道出的书上看的一点点 上面有图案填充源代码,摘录下来让你看看,我试过可行</P>
<P>'创建渐变填充<BR>'patType:0为预定义图案,1为用户定义图案<BR>'patName:包括LINEAR, CYLINDER, INVCYLINDER, SPHERICAL HEMISPHERICAL, CURVED, INVSPHERICAL, INVHEMISPHERICAL和INVCURVED<BR>Public Function AddHatchGC(ByRef objList() As AcadEntity, ByVal patType As Integer, ByVal patName As String, _<BR> ByVal associativity As Boolean, ByVal color1 As AcadAcCmColor, ByVal color2 As AcadAcCmColor) As AcadHatch<BR> On Error GoTo errHandle<BR> '定义填充对象<BR> Dim objHatch As AcadHatch<BR> <BR> Set objHatch = ThisDrawing.ModelSpace.AddHatch(patType, patName, True, acGradientObject)<BR> <BR> objHatch.GradientColor1 = color1<BR> objHatch.GradientColor2 = color2<BR> <BR> objHatch.AppendOuterLoop (objList)<BR> objHatch.Evaluate<BR> ThisDrawing.Regen True<BR> <BR> Set AddHatchGC = objHatch<BR> Exit Function<BR>errHandle:<BR> If Err.Number = -2145386493 Then<BR> MsgBox "填充定义边界未闭合!", vbCritical<BR> End If<BR> Err.Clear<BR>End Function</P>
<P>'创建真彩色填充<BR>'patType:0为预定义图案,1为用户定义图案<BR>'patName:包括LINEAR, CYLINDER, INVCYLINDER, SPHERICAL HEMISPHERICAL, CURVED, INVSPHERICAL, INVHEMISPHERICAL和INVCURVED<BR>Public Function AddHatchTC(ByRef objList() As AcadEntity, ByVal patType As Integer, _<BR> ByVal associativity As Boolean, ByVal color As AcadAcCmColor) As AcadHatch<BR> On Error GoTo errHandle<BR> '定义填充对象<BR> Dim objHatch As AcadHatch<BR> <BR> Set objHatch = ThisDrawing.ModelSpace.AddHatch(patType, "LINEAR", True, acGradientObject)<BR> <BR> objHatch.GradientColor1 = color<BR> objHatch.GradientColor2 = color<BR> <BR> objHatch.AppendOuterLoop (objList)<BR> objHatch.Evaluate<BR> ThisDrawing.Regen True<BR> <BR> Set AddHatchTC = objHatch<BR> Exit Function<BR>errHandle:<BR> If Err.Number = -2145386493 Then<BR> MsgBox "填充定义边界未闭合!", vbCritical<BR> End If<BR> Err.Clear<BR>End Function</P>
<P>'直接根据X、Y方向增量移动实体<BR>Public Function MoveEntity(ByVal objEntity As AcadEntity, ByVal x As Double, ByVal y As Double, _<BR> Optional z As Double = 0)<BR> Dim ptBase(2) As Double<BR> Dim ptDest(2) As Double<BR> <BR> '基点和目标点的位置<BR> ptBase(0) = 0: ptBase(1) = 0: ptBase(2) = 0<BR> ptDest(0) = x: ptDest(1) = y: ptDest(2) = z<BR> <BR> objEntity.Move ptBase, ptDest<BR>End Function</P>
<P>'复制对象,并将复制得到的对象移动一定的位置<BR>Public Function CopyEntity(ByVal objEntity As AcadEntity, ByVal x As Double, ByVal y As Double, _<BR> Optional z As Double = 0) As AcadEntity<BR> Dim ptBase(2) As Double<BR> Dim ptDest(2) As Double<BR> Dim objCopy As AcadEntity<BR> <BR> '基点和目标点的位置<BR> ptBase(0) = 0: ptBase(1) = 0: ptBase(2) = 0<BR> ptDest(0) = x: ptDest(1) = y: ptDest(2) = z<BR> <BR> Set objCopy = objEntity.Copy<BR> objCopy.Move ptBase, ptDest<BR> <BR> Set CopyEntity = objCopy<BR>End Function</P>
页:
[1]