使用属性生成块,
我已经做了相当多的搜索,并没有找到任何很好的解释,使用entmake插入定义的块,并在插入时缩放或旋转该块。其思想是标记一条线(管道),并使用属性添加该管道的直径、长度和切割长度。我有代码来准备行信息,并且正在为属性块开发entmake来标记“管道”。
以下是属性块的代码:
(defun c:apd (/ LAY1 LAY2 LAY3 LAY4
CLR1 CLR2 CLR3 CLR4
LTP1 LTP2 LTP3 LTP4
FONT value1 value2 value3
rotation p)
;;; Change layer names and colors to suit user.
(setq LAY1 "S-Pipe-Detail"
LAY2 "S-Pipe-Dia"
LAY3 "S-Pipe-Length"
LAY4 "S-Pipe-Cut"
CLR1 1
CLR2 2
CLR3 3
CLR4 4
LTP1 "Continuous"
LTP2 "Continuous"
LTP3 "Continuous"
LTP4 "Continuous"
FONT "Standard"
)
;;;======================== Block Definition ======================
(defun DEF_PipeDetail () ;generated using EntMaker CAB 04- MakeEntmake.lsp
(entmake '((0 . "BLOCK")
(100 . "AcDbEntity")
(67 . 0)
(8 . "0")
(100 . "AcDbBlockReference")
(66 . 1)
(2 . "PipeDetail")
(10 0.0 0.0 0.0)
(70 . 2)
)
)
(entmake '((0 . "ATTDEF")
(100 . "AcDbEntity")
(67 . 0)
(8 . "S-Pipe-Dia")
(100 . "AcDbText")
(10 0.0 0.0 0.0)
(40 . 0.095833333333331)
(1 . "-DIA-")
(50 . 0.0)
(41 . 0.
(51 . 0.0)
(7 . "Standard")
(71 . 0)
(72 . 1)
(100 . "AcDbAttributeDefinition")
(280 . 0)
(3 . "PIPE DIAMETER:")
(2 . "DIA")
(70 . 0)
(74 . 1)
(280 . 0)
)
)
(entmake '((0 . "ATTDEF")
(100 . "AcDbEntity")
(67 . 0)
(8 . "S-Pipe-Length")
(100 . "AcDbText")
(10 0.0 0.0 0.0)
(40 . 0.095833333333331)
(1 . "-LENGTH-")
(50 . 0.0)
(41 . 0.
(51 . 0.0)
(7 . "Standard")
(71 . 0)
(72 . 1)
(100 . "AcDbAttributeDefinition")
(280 . 0)
(3 . "PIPE LENGTH:")
(2 . "PIPELENGTH")
(70 . 0)
(74 . 3)
(280 . 0)
)
)
(entmake '((0 . "ATTDEF")
(100 . "AcDbEntity")
(67 . 0)
(8 . "S-Pipe-Cut")
(100 . "AcDbText")
(10 0.0 0.0 0.0)
(40 . 0.095833333333331)
(1 . "-LENGTH-")
(50 . 0.0)
(41 . 0.
(51 . 0.0)
(7 . "Standard")
(71 . 0)
(72 . 1)
(100 . "AcDbAttributeDefinition")
(280 . 0)
(3 . "CUT LENGTH:")
(2 . "CUTLENGTH")
(70 . 0)
(74 . 3)
(280 . 0)
)
)
(entmake '((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
(princ)
) ; end DEF_PipeDetail
;;;======================== Insert Block ======================
(defun insert_PipeDetail (p lay rot d_lay pl_lay cl_lay font value1 value2 value3)
(entmake (list (cons 0 "INSERT")
(cons 2 "PipeDetail")
(cons 10 p)
(cons 8 lay)
(cons 66 1)
(cons 62 256)
(cons 39 0)
(cons 6 "BYLAYER")
(cons 50 rot);block rotation (radians)
)
)
(entmake (list (cons 0 "ATTRIB")
(cons 8 d_lay)
(cons 10 (mapcar '* (mapcar '+ p '(0.0 0.046875 0.0)) (list (getvar "textsize")(getvar "textsize")(getvar "textsize"))))
(cons 11 (mapcar '+ p '(0.0 0.140625 0.0)))
(cons 40 (getvar "textsize"));text height
(cons 1 Value1)
(cons 2 "DIA")
(cons 70 0);attr flag
(cons 50 0);text rot
(cons 41 1);relative x-factor, width
;;; (cons 51 0);oblique angle (default 0)
(cons 7 font)
;;; (cons 71 0);text flag (def 0, bkwrd 2, upside dn 4)
(cons 74 1);1 BCenter
(cons 72 1);1 Center
(cons 210 (list 0 0 1));extrusion (def 0,0,1)
;;; (cons 73 0)
(cons 62 256);color (bylayer 256)
;;; (cons 39 0);thickness (def 0)
(cons 6 "BYLAYER")
)
)
(entmake (list (cons 0 "ATTRIB")
(cons 8 pl_lay)
(cons 10 (mapcar '* (mapcar '+ p '(-0.046875 -0.140625 0.0)) (list (getvar "textsize")(getvar "textsize")(getvar "textsize"))))
(cons 11 (mapcar '+ p '(-0.046875 -0.140625 0.0)))
(cons 40 (getvar "textsize"));text height
(cons 1 Value2)
(cons 2 "PIPELENGTH")
(cons 70 0);attr flag
(cons 50 0);text rot
(cons 41 1);relative x-factor, width
;;; (cons 51 0);oblique angle (default 0)
(cons 7 font)
;;; (cons 71 0);text flag (def 0, bkwrd 2, upside dn 4)
(cons 74 3);3 TCenter
(cons 72 1);1 Center
(cons 210 (list 0 0 1));extrusion (def 0,0,1)
;;; (cons 73 0)
(cons 62 256);color (bylayer 256)
;;; (cons 39 0);thickness (def 0)
(cons 6 "BYLAYER");linetype name
)
)
(entmake (list (cons 0 "ATTRIB")
(cons 8 cl_lay)
(cons 10 (mapcar '* (mapcar '+ p '(0.046875 -0.28125 0.0)) (list (getvar "textsize")(getvar "textsize")(getvar "textsize"))))
(cons 11 (mapcar '+ p '(0.046875 -0.28125 0.0)))
(cons 40 (getvar "textsize"));text height
(cons 1 Value3)
(cons 2 "CUTLENGTH")
(cons 70 0);attr flag
(cons 50 0);text rot
(cons 41 1);relative x-factor, width
;;; (cons 51 0);oblique angle (default 0)
(cons 7 font)
;;; (cons 71 0);text flag (def 0, bkwrd 2, upside dn 4)
(cons 74 3);3 TCenter
(cons 72 1);1 Center
(cons 210 (list 0 0 1));extrusion (def 0,0,1)
;;; (cons 73 0)
(cons 62 256);color (bylayer 256)
;;; (cons 39 0);thickness (def 0)
(cons 6 "BYLAYER");linetype name
)
)
(entmake (list
(cons 0 "SEQEND")
(cons 8 lay)
)
)
)
;;;======================== Make Layers ======================
(defun make_layer (MyLayer MyColor MyLtype)
(entmake (list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 MyLayer)
(cons 6 MyLtype)
(cons 62 MyColor)
(cons 70 0)
)
)
)
;;;======================== Main Function =======================
(if (not (tblsearch "layer" LAY1))
(make_layer LAY1 CLR1 LTP1)
)
(if (not (tblsearch "layer" LAY2))
(make_layer LAY2 CLR2 LTP2)
)
(if (not (tblsearch "layer" LAY3))
(make_layer LAY3 CLR3 LTP3)
)
(if (not (tblsearch "layer" LAY4))
(make_layer LAY4 CLR4 LTP4)
)
(if (not (tblsearch "block" "PipeDetail"))
(DEF_PipeDetail)
)
;;; temporary setq
(setq value1 "MyDiameter"
value2 "MyLength"
value3 "MyCut"
rotation 1.5708
)
;;; end temporary setq
(setvar "osmode" 512)
(while
(setq p (getpoint "\nPick insertion point >> "))
(insert_PipeDetail p LAY1 rotation LAY2 LAY3 LAY4 FONT value1 value2 value3)
)
;;;end while
(princ)
)
这段代码可以工作,但我无法使较低的两个属性偏离直线(文字高度的一半),也无法使整个块旋转(我使用了旋转1.5708或90度)。
如果有人能启发我,或者把我踢向正确的方向,我将不胜感激。
谢谢CHL 正如你可能发现的那样,这可能是一个非常复杂的操作。有时,使用(命令)调用和顺序输入来插入/缩放/旋转/注释更容易。
通过使用(entmake),您几乎可以完全控制插入。然而,必须考虑并计算所有参数和一些其他系统变量。
ATTDEF的大多数块表定义可以随意操作。 我建议做一些清理(避免setq和重复:使用带有子功能的列表):
(defun C:test ( / make_layer DEF_PipeDetail insert_PipeDetail p a )
; local defuns:
(defun make_layer (MyLayer MyColor MyLtype)
(or (tblsearch "LAYER" MyLayer)
(entmake
(list
(cons 0 "LAYER") (cons 100 "AcDbSymbolTableRecord") (cons 100 "AcDbLayerTableRecord")
(cons 2 MyLayer) (cons 6 MyLtype) (cons 62 MyColor) (cons 70 0)
)
)
)
); defun make_layer
(defun DEF_PipeDetail ( / AttDef )
(defun AttDef ( dxf8 dxf1 dxf3 dxf2 )
(list
'(0 . "ATTDEF") '(100 . "AcDbEntity") (cons 8 dxf8)
'(100 . "AcDbText") '(10 0.0 0.0 0.0) (cons 40 (getvar 'textsize))
(cons 1 dxf1) '(50 . 0.0) '(41 . 0. '(51 . 0.0) '(7 . "Standard")
'(71 . 0) '(72 . 1) '(100 . "AcDbAttributeDefinition") '(280 . 0)
(cons 3 dxf3) (cons 2 dxf2) '(70 . 0) '(74 . 1) '(280 . 0)
)
); defun AttDef
(or (tblsearch "BLOCK" "PipeDetail")
(mapcar 'entmake
(append
'(((0 . "BLOCK") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbBlockReference") (66 . 1) (2 . "PipeDetail") (10 0.0 0.0 0.0) (70 . 2)))
(mapcar '(lambda (x) (apply 'AttDef x))
'(("S-Pipe-Dia" "-DIA-" "PIPE DIAMETER:" "DIA")
("S-Pipe-Length" "-LENGTH-" "PIPE LENGTH:" "PIPELENGTH")
("S-Pipe-Cut" "-LENGTH-" "CUT LENGTH:" "CUTLENGTH")
)
)
'(((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
)
)
)
); defun DEF_PipeDetail
(defun insert_PipeDetail (p lay rot atts / Attrib)
(defun Attrib ( p rot dxf8 dxf1 dxf2 dxf7 yf )
(list
(cons 0 "ATTRIB")
(cons 8 dxf8)
(cons 10 (polar p (+ (/ PI 2.) rot) (* yf (getvar 'textsize))))
(cons 11 (polar p (+ (/ PI 2.) rot) (* yf (getvar 'textsize))))
(cons 40 (getvar 'textsize)); Text height
(cons 1 dxf1)
(cons 2 dxf2)
(cons 70 0) ; attr flag
(cons 50 rot) ; text rot
(cons 41 1) ; relative x-factor, width
(cons 51 0) ; oblique angle (default 0)
(cons 7 dxf7) ; Text style name
(cons 71 0) ; text flag (def 0, bkwrd 2, upside dn 4)
(cons 74 1) ; 1 BCenter
(cons 72 1) ; 1 Center
(cons 210 (list 0 0 1)) ; extrusion (def 0,0,1)
(cons 73 0) ; Field length (optional; default = 0) (not currently used)
(cons 62 256) ; color (bylayer 256)
(cons 39 0) ; thickness (def 0)
(cons 6 "BYLAYER")
)
); defun Attrib
(if (tblsearch "BLOCK" "PipeDetail")
(mapcar 'entmake
(append
(list
(list
(cons 0 "INSERT") (cons 100 "AcDbEntity") (cons 8 lay) (cons 100 "AcDbBlockReference") (cons 66 1) (cons 2 "PipeDetail")
(cons 10 p) (cons 41 1.0) (cons 42 1.0) (cons 43 1.0) (cons 50 rot) (cons 62 256) (cons 6 "BYLAYER")
)
)
(mapcar '(lambda (x) (apply 'Attrib (append (list p rot) x))) atts)
(list (list (cons 0 "SEQEND") (cons 8 lay)))
)
)
); if
); defun insert_PipeDetail
; Main function:
(mapcar ; create the layers
'(lambda (x) (apply 'make_layer x))
'( ("S-Pipe-Detail" 1 "Continuous") ("S-Pipe-Dia" 2 "Continuous") ("S-Pipe-Length" 3 "Continuous") ("S-Pipe-Cut" 4 "Continuous") )
); mapcar
(DEF_PipeDetail) ; create the block definition
(while ; prompt to create inserts
(and
(setq p (getpoint "\nPick insertion point >> "))
(setq a (cond ((getreal "\nSpecify block rotation (in degrees) <0>: ")) (0.)))
); and
(insert_PipeDetail p "S-Pipe-Detail" (* PI (/ a 180))
'( ; atts
("S-Pipe-Dia" "MyDiameter" "DIA" "Standard" 1.5)
("S-Pipe-Length" "MyLength" "PIPELENGTH" "Standard" 0.0)
("S-Pipe-Cut" "MyCut" "CUTLENGTH" "Standard"-1.5)
)
)
); while
(princ)
); defun
谢谢David的回复。你过去曾帮助过我。
非常感谢Grrr,这就是我想要的。也谢谢你的清理工作。我还没有说到这一点(从代码中的许多评论中可以看出)。这实际上是一个较大程序的一部分,该程序将从选定的行中提取数据,然后插入属性块。一旦我工作正常,我也会把它清理干净。尽管如此,您已经演示了一些优秀的清理方法,我将尝试将这些方法合并到未来的代码中。
再次感谢大家。 我会像大卫一样轻松,你已经有了所有的答案。使用entmake速度更快,但如果您一次只做一个方块并拾取,您将不会看到任何停机时间。您只需制作一次块,即可从另一个dwg中剪切和粘贴,或将其保存为DWT的一部分。
(command "INSERT"blkname pt x "" ang att1 att2 att3)
了解BIGAL,这就是我们多年来一直在做的事情,其中blockname是一个长字符串,例如“G:\ACAD-BLOCKS\plupping\PIPEDETAIL.dwg”。
我正在努力清理菜单和例程,以避免我们在办公室里为四个学科设置了无数个街区。由于有如此多的块,这也会使模板文件变得庞大。
消除网络上的大型块库并使用entmake动态创建块、层等的另一个原因是,有了新的Autodesk订阅,工作中的用户可以选择在家用计算机上使用他们的ACAD席位。与其让每个在家工作的人偶尔将整个块目录复制到他们的主硬盘上,然后映射一个文件夹以显示为“G-drive”,不如在菜单/例程上使用entmake/x更有益处。
当然,我可以创建定义,然后返回到旧的“命令”调用,但这无助于我学习在定义之后插入文件的entmake方法。因此,每个小程序都成为一个学习工具,我从Grrr提供的代码中收集了很多信息。特别是关于我应该如何清理我们已经存在的大部分代码的一些聪明的方法。
谢谢大家,
CHL公司 您可以将所有块放入一个dwg中,并使用Lee mac的Steal lisp从另一个dwg中获取块所需的两行代码。加载steal,然后用blockname运行defun。我使用带有图像的菜单,因此路径在菜单中。你需要2个菜单,一个是C:\dwgs,另一个是网络G:。
如果您不想要g:\\mynetwork\projects\blocks\pipes,您可以将驱动器或子目录映射回一个字母,再加上最后一个目录B:\\pipes作为块的windows操作系统的一部分。
页:
[1]