nguyendan81985 发表于 2022-7-6 22:14:40

VBA填充多段线

您好,您能帮我在VBA上编写代码来填充多段线吗。
例如:我有一条多段线,如下代码。如何对该多段线进行图案填充。谢谢
 
作为AcadLWPolyline的尺寸线
将点L1(0到9)设置为双精度
点L1(0)=0:点L1(1)=0
点L1(2)=0:点L1(3)=500
点L1(4)=75:点L1(5)=500
点L1(6)=75:点L1(7)=0
点L1(=0:点L1(9)=0
 
设置直线=此图形。模型空间。AddLightWeightPolyline(点L1):直线。颜色=acRed

RICVBA 发表于 2022-7-6 23:24:27

看来我找不到正确的方法
这是我最后一次尝试
 

Sub Example_AddHatch()
   ' This example creates an associative gradient hatch in model space.
   
   Dim hatchObj As AcadHatch
   Dim patternName As String
   Dim PatternType As Long
   Dim bAssociativity As Boolean
   
   ' Define the hatch
   patternName = "CYLINDER"
   PatternType = acPreDefinedGradient '0
   bAssociativity = True
   
   ' Create the associative Hatch object in model space
   Set hatchObj = ThisDrawing.ModelSpace.AddHatch(PatternType, patternName, bAssociativity, acGradientObject)
   Dim col1 As AcadAcCmColor, col2 As AcadAcCmColor
   Set col1 = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.18")
   Set col2 = AcadApplication.GetInterfaceObject("AutoCAD.AcCmColor.18")
   Call col1.SetRGB(255, 0, 0)
   Call col2.SetRGB(0, 255, 0)
   hatchObj.GradientColor1 = col1
   hatchObj.GradientColor2 = col2
   
   ' Create the outer boundary for the hatch (a circle)
   Dim outerLoop(0 To 0) As AcadEntity
   Dim center(0 To 2) As Double
   Dim radius As Double
   center(0) = 3: center(1) = 3: center(2) = 0
   radius = 1
   Set outerLoop(0) = ThisDrawing.ModelSpace.AddCircle(center, radius)
   
   ' Append the outerboundary to the hatch object, and display the hatch
   hatchObj.AppendOuterLoop (outerLoop)
   hatchObj.Evaluate
   ThisDrawing.Regen True
End Sub

 
当然,您必须使其适应多段线情况。这应该是最省力的,而为了获得图案/颜色等,可能需要更多的试验和测试工作。。你需要
页: [1]
查看完整版本: VBA填充多段线