本帖最后由 newer 于 2016-11-25 20:59 编辑
给你的是个例子代码,你想要什么,修改里面的参数。 其实你完全可以创建一个填充,然后用上面的代码改改修改成渐变色,都是相通的。
直接创建渐变色填充,可以去看看ACTIVEX 帮助手册里面的例子代码,帮助文件是很好的学习材料,下面摘自帮助文件。
颜色修改里面 setrgb后面的值,类型修改patternName,下面代码是运行在R19版本的CAD,你可以参照上面的我给你的例子,做成适合任意不版本的。
(vl-load-com)
(defun c:Example_GradientColor2()
;; This example changes the value of the GradientColor2 property.
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
;; Define the hatch
(setq patternName "CYLINDER")
(setq patternType acPreDefinedGradient)
(setq bAssociativity :vlax-true)
;; Create the associative Hatch object in model space
(setq modelSpace (vla-get-ModelSpace doc))
(setq hatchObj (vla-AddHatch modelSpace patternType patternName bAssociativity acGradientObject))
(setq col1 (vlax-create-object "AutoCAD.AcCmColor.19"))
(setq col2 (vlax-create-object "AutoCAD.AcCmColor.19"))
(setq newColor (vlax-create-object "AutoCAD.AcCmColor.19"))
(vla-SetRGB col1 255 0 0)
(vla-SetRGB col2 0 255 0)
(vla-SetRGB newColor 0 100 0)
(vla-put-GradientColor1 hatchObj col1)
(vla-put-GradientColor2 hatchObj col2)
;; Create the outer boundary for the hatch (a circle)
(setq center (vlax-3d-point 3 3 0)
radius 1)
(setq circle (vla-AddCircle modelSpace center radius))
(setq outerLoop (vlax-make-safearray vlax-vbObject '(0 . 0)))
(vlax-safearray-put-element outerLoop 0 circle)
;; Append the outerboundary to the hatch object, and display the hatch
(vla-AppendOuterLoop hatchObj outerLoop)
(vla-Evaluate hatchObj)
(vla-Regen doc :vlax-true)
(alert (strcat "Initial value of GradientColor2 is :"
"\nred = " (itoa (vla-get-Red (vla-get-GradientColor2 hatchObj)))
"\ngreen = " (itoa (vla-get-Green (vla-get-GradientColor2 hatchObj)))
"\nblue = " (itoa (vla-get-Blue (vla-get-GradientColor2 hatchObj)))))
(vla-put-GradientColor2 hatchObj newColor)
(alert (strcat "New value of GradientColor2 is :"
"\nred = " (itoa (vla-get-Red (vla-get-GradientColor2 hatchObj)))
"\ngreen = " (itoa (vla-get-Green (vla-get-GradientColor2 hatchObj)))
"\nblue = " (itoa (vla-get-Blue (vla-get-GradientColor2 hatchObj)))))
(vlax-release-object col1)
(vlax-release-object col2)
(vlax-release-object newColor)
)
|