飞一飞 发表于 2006-5-25 16:47:00

[求助]怎么用VB在CAD中图案填充呀

<P>&nbsp;&nbsp;&nbsp; 哪位大哥帮帮忙,小弟做毕业设计急用.</P>
<P> 如何用VB ActiveX技术实现CAD中的图案填充呀</P>
<P>&nbsp;&nbsp;&nbsp;另外,在CAD中用VB能不能实现图形的打断?</P>

ycp9 发表于 2006-5-29 20:25:00

<P>&nbsp;&nbsp;&nbsp; 我也 是刚学的,从明经通道出的书上看的一点点 上面有图案填充源代码,摘录下来让你看看,我试过可行</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>&nbsp;&nbsp;&nbsp; ByVal associativity As Boolean, ByVal color1 As AcadAcCmColor, ByVal color2 As AcadAcCmColor) As AcadHatch<BR>&nbsp;&nbsp;&nbsp; On Error GoTo errHandle<BR>&nbsp;&nbsp;&nbsp; '定义填充对象<BR>&nbsp;&nbsp;&nbsp; Dim objHatch As AcadHatch<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set objHatch = ThisDrawing.ModelSpace.AddHatch(patType, patName, True, acGradientObject)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objHatch.GradientColor1 = color1<BR>&nbsp;&nbsp;&nbsp; objHatch.GradientColor2 = color2<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objHatch.AppendOuterLoop (objList)<BR>&nbsp;&nbsp;&nbsp; objHatch.Evaluate<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Regen True<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set AddHatchGC = objHatch<BR>&nbsp;&nbsp;&nbsp; Exit Function<BR>errHandle:<BR>&nbsp;&nbsp;&nbsp; If Err.Number = -2145386493 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "填充定义边界未闭合!", vbCritical<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; ByVal associativity As Boolean, ByVal color As AcadAcCmColor) As AcadHatch<BR>&nbsp;&nbsp;&nbsp; On Error GoTo errHandle<BR>&nbsp;&nbsp;&nbsp; '定义填充对象<BR>&nbsp;&nbsp;&nbsp; Dim objHatch As AcadHatch<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set objHatch = ThisDrawing.ModelSpace.AddHatch(patType, "LINEAR", True, acGradientObject)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objHatch.GradientColor1 = color<BR>&nbsp;&nbsp;&nbsp; objHatch.GradientColor2 = color<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objHatch.AppendOuterLoop (objList)<BR>&nbsp;&nbsp;&nbsp; objHatch.Evaluate<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Regen True<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set AddHatchTC = objHatch<BR>&nbsp;&nbsp;&nbsp; Exit Function<BR>errHandle:<BR>&nbsp;&nbsp;&nbsp; If Err.Number = -2145386493 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "填充定义边界未闭合!", vbCritical<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; Optional z As Double = 0)<BR>&nbsp;&nbsp;&nbsp; Dim ptBase(2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim ptDest(2) As Double<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '基点和目标点的位置<BR>&nbsp;&nbsp;&nbsp; ptBase(0) = 0: ptBase(1) = 0: ptBase(2) = 0<BR>&nbsp;&nbsp;&nbsp; ptDest(0) = x: ptDest(1) = y: ptDest(2) = z<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; Optional z As Double = 0) As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Dim ptBase(2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim ptDest(2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim objCopy As AcadEntity<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '基点和目标点的位置<BR>&nbsp;&nbsp;&nbsp; ptBase(0) = 0: ptBase(1) = 0: ptBase(2) = 0<BR>&nbsp;&nbsp;&nbsp; ptDest(0) = x: ptDest(1) = y: ptDest(2) = z<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set objCopy = objEntity.Copy<BR>&nbsp;&nbsp;&nbsp; objCopy.Move ptBase, ptDest<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set CopyEntity = objCopy<BR>End Function</P>

ycp9 发表于 2006-5-29 20:25:00

<P>&nbsp;&nbsp;&nbsp; 我也 是刚学的,从明经通道出的书上看的一点点 上面有图案填充源代码,摘录下来让你看看,我试过可行</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>&nbsp;&nbsp;&nbsp; ByVal associativity As Boolean, ByVal color1 As AcadAcCmColor, ByVal color2 As AcadAcCmColor) As AcadHatch<BR>&nbsp;&nbsp;&nbsp; On Error GoTo errHandle<BR>&nbsp;&nbsp;&nbsp; '定义填充对象<BR>&nbsp;&nbsp;&nbsp; Dim objHatch As AcadHatch<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set objHatch = ThisDrawing.ModelSpace.AddHatch(patType, patName, True, acGradientObject)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objHatch.GradientColor1 = color1<BR>&nbsp;&nbsp;&nbsp; objHatch.GradientColor2 = color2<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objHatch.AppendOuterLoop (objList)<BR>&nbsp;&nbsp;&nbsp; objHatch.Evaluate<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Regen True<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set AddHatchGC = objHatch<BR>&nbsp;&nbsp;&nbsp; Exit Function<BR>errHandle:<BR>&nbsp;&nbsp;&nbsp; If Err.Number = -2145386493 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "填充定义边界未闭合!", vbCritical<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; ByVal associativity As Boolean, ByVal color As AcadAcCmColor) As AcadHatch<BR>&nbsp;&nbsp;&nbsp; On Error GoTo errHandle<BR>&nbsp;&nbsp;&nbsp; '定义填充对象<BR>&nbsp;&nbsp;&nbsp; Dim objHatch As AcadHatch<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set objHatch = ThisDrawing.ModelSpace.AddHatch(patType, "LINEAR", True, acGradientObject)<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objHatch.GradientColor1 = color<BR>&nbsp;&nbsp;&nbsp; objHatch.GradientColor2 = color<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; objHatch.AppendOuterLoop (objList)<BR>&nbsp;&nbsp;&nbsp; objHatch.Evaluate<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Regen True<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set AddHatchTC = objHatch<BR>&nbsp;&nbsp;&nbsp; Exit Function<BR>errHandle:<BR>&nbsp;&nbsp;&nbsp; If Err.Number = -2145386493 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "填充定义边界未闭合!", vbCritical<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; Optional z As Double = 0)<BR>&nbsp;&nbsp;&nbsp; Dim ptBase(2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim ptDest(2) As Double<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '基点和目标点的位置<BR>&nbsp;&nbsp;&nbsp; ptBase(0) = 0: ptBase(1) = 0: ptBase(2) = 0<BR>&nbsp;&nbsp;&nbsp; ptDest(0) = x: ptDest(1) = y: ptDest(2) = z<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; Optional z As Double = 0) As AcadEntity<BR>&nbsp;&nbsp;&nbsp; Dim ptBase(2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim ptDest(2) As Double<BR>&nbsp;&nbsp;&nbsp; Dim objCopy As AcadEntity<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; '基点和目标点的位置<BR>&nbsp;&nbsp;&nbsp; ptBase(0) = 0: ptBase(1) = 0: ptBase(2) = 0<BR>&nbsp;&nbsp;&nbsp; ptDest(0) = x: ptDest(1) = y: ptDest(2) = z<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set objCopy = objEntity.Copy<BR>&nbsp;&nbsp;&nbsp; objCopy.Move ptBase, ptDest<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; Set CopyEntity = objCopy<BR>End Function</P>
页: [1]
查看完整版本: [求助]怎么用VB在CAD中图案填充呀