使用AutoLISP生成新的尺寸样式

时间:2017-12-15 15:25:53

标签: styles autocad dimensions autocad-plugin autolisp

我想要一个AutoLISP例程,它会使用我的自定义设置自动创建一个新的维度样式。我知道可以将尺寸样式从一个图纸复制到另一个图纸,但每次都必须这样做是非常繁琐和耗时的。

我已经为我最常用的样式编译了一个我想要的变量列表,但理想情况下我希望能够在此列表中添加或删除变量。

手动执行此操作的过程是在命令行中设置每个变量,然后使用“-DIMSTYLE SAVE”命令将其保存为自定义名称。我试图自己解决这个项目,但是在AutoLISP中相对缺乏经验我很快就意识到我没有足够的知识来做到这一点。

以下是为我创建大多数新样式的重要变量列表:

DIMALTD 4

DIMAPOST    [null]

DIMALTF 1

DIMALTTD    4

DIMALTU 4

DIMADEC 1

DIMAZIN 0

DIMARCSYM   1

DIMBLK  ClosedFilled

DIMBLK1 ClosedFilled

DIMBLK2 ClosedFilled

DIMASZ  1

DIMCEN  0

DIMCLRD 3

DIMDLE  0

DIMLTYPE    BYBLOCK

DIMLWD  -2

DIMDLI  4

DIMLTEX1    BYBLOCK

DIMLTEX2    BYBLOCK

DIMCLRE 3

DIMEXE  0.5

DIMLWE  -2

DIMEXO  0.75

DIMFRAC 0

DIMJOGANG   45

DIMLDRBLK   ClosedFilled

DIMLUNIT    5

DIMSCALE    1

DIMRND  0

DIMSAH  Off

DIMCLRT 3

DIMTXT  1.5

DIMTIH  On

DIMGAP  0.1

DIMTOH  On

DIMTAD  0

DIMTXSTY    Standard

DIMTM   0

DIMTP   0

DIMTFAC 1

DIMTZIN 0

DIMZIN  0

2 个答案:

答案 0 :(得分:1)

尝试使用此代码:

(defun C:Test (  / *error*  ThisDrawing  dimstyles  style )
    (defun *error* ( msg / ) 
        (if (not (null msg ) )  (progn (princ "\nC:Test:*error*: " ) (princ msg ) (princ "\n")  ) )
    )
    (setvar "DIMALTD" 4 )
    (setvar "DIMALTF" 1 )
    (setvar "DIMBLK" "_DOTSMALL" )  ; more You can find for example here http://forums.augi.com/showthread.php?9852-Setting-DIMLDRBLK
    (setvar "DIMLTYPE" "BYBLOCK" )
    (setvar "DIMEXO" 0.75)

    (setq ThisDrawing (vla-get-activedocument (vlax-get-acad-object) ) )
    (setq dimstyles (vlax-get-property ThisDrawing 'DimStyles ) )
    (setq style (vlax-invoke-method dimstyles 'Add "TestStyle" ) )
    (vlax-invoke-method style 'CopyFrom ThisDrawing )

)

答案 1 :(得分:1)

谢谢,CAD开发人员。这让我开始了。这是我最终使用的代码。 AutoCAD不喜欢文本值变量,因此我只是将它们删除,因为它们对我来说并不重要。

;automatically create new dimension style
(defun c:jeff ()
    (setvar "DIMALTD" 4)
    (setvar "DIMALTF" 1)
    (setvar "DIMALTTD" 4)
    (setvar "DIMALTU" 4)
    (setvar "DIMADEC" 1)
    (setvar "DIMAZIN" 0)
    (setvar "DIMARCSYM" 1)
    (setvar "DIMASZ" 1)
    (setvar "DIMCEN" 0)
    (setvar "DIMCLRD" 3)
    (setvar "DIMDLE" 0)
    (setvar "DIMLWD" -2)
    (setvar "DIMDLI" 4)
    (setvar "DIMCLRE" 3)
    (setvar "DIMEXE" 0.5)
    (setvar "DIMLWE" -2)
    (setvar "DIMEXO" 0.75)
    (setvar "DIMFRAC" 0)
    (setvar "DIMLUNIT" 5)
    (setvar "DIMSCALE" 1)
    (setvar "DIMRND" 0)
    (setvar "DIMCLRT" 3)
    (setvar "DIMTXT" 1.5)
    (setvar "DIMGAP" 0.1)
    (setvar "DIMTAD" 0)
    (setvar "DIMTM" 0)
    (setvar "DIMTP" 0)
    (setvar "DIMTFAC" 1)
    (setvar "DIMTZIN" 0)
    (setvar "DIMZIN" 0)

    (command "dimstyle" "s" "Jeff")

    (princ)
)