124350440 发表于 2010-10-10 15:48:00

能否修改一下:批量插入图块

;;------------------------------------DCL语句-----------------------------------------------------
这个程序有时会把所有的图块都插到一起,而没有阵列,并且读取文件名的时候是没有规律的读取
YH_批量出入图块 : dialog {
label="批量插入图块对话框 V1.0测试版";
:column {
:row {
:boxed_column {
label="阵列参数";
:edit_box {
label="行数:";
key="YH_rnum";
}
:edit_box {
label="行距:";
key="YH_rdis";
}
:edit_box {
label="列数:";
key="YH_cnum";
}
:edit_box {
label="列距:";
key="YH_cdis";
}
}
:column{
:boxed_column {
label="插入点";
:radio_button{
label="手工逐个点取";
value="1";
key="YH_mode1";
}
:radio_button{
label="阵列布置";
key="YH_mode2";
}
}
:boxed_column {
label="阵列布置方向";
:radio_button {
label="横向排列";
key="YH_H1";
value="1";
fixed_width=true;
}
:radio_button {
label="竖向排列";
key="YH_V1";
fixed_width=true;
}
}
}
}
:edit_box {
label="图块图名";
key="YH_blockname";
}
}
:row{
:edit_box {
label="图块目录";
key="YH_fileload";
is_enabled=true;
}
:button {
label="浏览";
key="YH_brows";
fixed_width=true;
}
}
:boxed_row {
label="实时说明";
:list_box{
fixed_height=true;
width=41;
height=10;
key="YH_softtext";
}
}
ok_cancel;
}

;;------------------------------------DCL语句-----------------------------------------------------

;;------------------------------------主 程 序-----------------------------------------------------

(defun c:ib ()
(setq YH_oldosmode (getvar "osmode"))
(setvar "osmode" 0)
(YH_dclset)
(if (= YH_mode1 "1")
(YH_insert1)
(YH_insert2)
)
(setvar "osmode" YH_oldosmode)
(princ)
;;清空系统变量
(setq YH_BLOCK nil
YH_FILELIST nil
YH_INDEX nil
YH_CDIS nil
YH_H1 nil
YH_POINT1 nil
YH_RDIS nil
YH_X1 nil
YH_Y1 nil
YH_CDIS nil
YH_CNUM nil
YH_HREM nil
YH_INDEX1 nil
YH_INDEX2 nil
YH_INDEX3 nil
YH_LOOP1 nil
YH_LOOP2 nil
YH_POINT2 nil
YH_ROWNUM2 nil
YH_X2 nil
YH_Y2 nil
)
)

;;对话框处理程序
(defun YH_dclset ()
(setq YH_DCLID (load_dialog "YH_insertblocks.dcl"))
(new_dialog "YH_批量出入图块" YH_DCLID)
(if (/= YH_filepath nil) (set_tile "YH_fileload" YH_filepath))
(if (/= YH_filename1 nil) (set_tile "YH_blockname" YH_filename1))
;;对话框化
(YH_dclmode)
(action_tile "YH_mode1" "(YH_dclmode)")
(action_tile "YH_mode2" "(YH_dclHV)")
(action_tile "YH_H1" "(YH_dclH1)")
(action_tile "YH_V1" "(YH_dclV1)")
(action_tile "YH_brows" "(YH_getFolder)(YH_setfile)")
(action_tile "accept" "(YH_value)")
(action_tile "YH_blockname" "(YH_blockname1)")
(action_tile "YH_fileload" "(YH_setfile)")
(action_tile "cancel" "(exit)")
(start_dialog)
(unload_dialog YH_DCLID)
(princ)
)

(defun YH_dclmode ()
(mode_tile "YH_rnum" 1)
(mode_tile "YH_cnum" 1)
(mode_tile "YH_rdis" 1)
(mode_tile "YH_cdis" 1)
(mode_tile "YH_H1" 1)
(mode_tile "YH_V1" 1)
(mode_tile "YH_mode1" 2)
(start_list "YH_softtext" 3 0)
(add_list "手工逐个点取")
(add_list "")
(add_list "请在图块名中指定图块名称条件,支持统配符*")
(add_list "图块名称输入请不要带有后缀。如不指定图名")
(add_list "将默认全部DWG文件,同时请注意图块插入点的")
(add_list "制作。")
(add_list " ")
(add_list " --2005.10 by sailorcwx")
(end_list)
)

(defun YH_dclHV ()
(mode_tile "YH_H1" 0)
(mode_tile "YH_V1" 0)
(YH_dclH1)
(start_list "YH_softtext" 3 0)
(add_list "根据第一个插入点进行阵列布置")
(add_list "")
(add_list "请在图块名中指定图块名称条件,支持统配符*")
(add_list "图块名称输入请不要带有后缀。如不指定图名")
(add_list "将默认全部DWG文件,同时请注意图块插入点的")
(add_list "制作。")
(add_list " ")
(add_list " --2005.10 by sailorcwx")
(end_list)
)

(defun YH_dclH1 ()
(mode_tile "YH_rnum" 1)
(mode_tile "YH_rdis" 0)
(mode_tile "YH_cnum" 0)
(mode_tile "YH_cdis" 0)
(start_list "YH_softtext" 3 0)
(add_list "横向排列是沿X轴方向根据每行的列数布置")
(add_list "")
(add_list "请在图块名中指定图块名称条件,支持统配符*")
(add_list "图块名称输入请不要带有后缀。如不指定图名")
(add_list "将默认全部DWG文件,同时请注意图块插入点的")
(add_list "制作。")
(add_list " ")
(add_list " --2005.10 by sailorcwx")
(end_list)
)

(defun YH_dclV1 ()
(mode_tile "YH_rnum" 0)
(mode_tile "YH_rdis" 0)
(mode_tile "YH_cnum" 1)
(mode_tile "YH_cdis" 0)
(start_list "YH_softtext" 3 0)
(add_list "横向排列是沿Y轴方向根据每列的行数布置")
(add_list "")
(add_list "请在图块名中指定图块名称条件,支持统配符*")
(add_list "图块名称输入请不要带有后缀。如不指定图名")
(add_list "将默认全部DWG文件,同时请注意图块插入点的")
(add_list "制作。")
(add_list " ")
(add_list " --2005.10 by sailorcwx")
(end_list)
)

(defun YH_getFolder (/ WinShell shFolder path catchit)
(vl-load-com)
(setq winshell (vlax-create-object "Shell.Application"))
(setq shFolder (vlax-invoke-method
WinShell 'BrowseForFolder 0 "选择目录" 1)
)
(setq
catchit (vl-catch-all-apply
'(lambda ()
(setq shFolder (vlax-get-property shFolder 'self))
(setq path (vlax-get-property shFolder 'path))
)
)
)
(if (vl-catch-all-error-p catchit)
nil
path
)
(set_tile "YH_fileload" path)
)

(defun YH_setfile()
(setq YH_filelist nil)
(setq YH_filepath (get_tile "YH_fileload"))
(if (/= YH_filepath "")
(progn
(setq YH_filename1 (get_tile "YH_blockname"))
(setq YH_filename YH_filename1)
(if (= YH_filename "") (setq YH_filename "*.dwg") (setq YH_filename (strcat YH_filename ".dwg")))
(setq YH_filelist (vl-directory-files YH_filepath YH_filename 1))
(start_list "YH_softtext" 3 0)
(add_list "符合条件的图块如下:")
(mapcar 'add_list YH_filelist)
(add_list " --2005.10 by sailorcwx")
(end_list)
)
)
)

(defun YH_blockname1()
(setq YH_filepath (get_tile "YH_fileload"))
(if (/= YH_filepath "") (YH_setfile))
)

(defun YH_value()
(setq YH_errorinput 1)
(setq YH_mode1 (get_tile "YH_mode1")
YH_mode2 (get_tile "YH_mode2")
YH_H1 (get_tile "YH_H1")
YH_V1 (get_tile "YH_V1")
YH_rnum (get_tile "YH_rnum")
YH_rdis (get_tile "YH_rdis")
YH_cnum (get_tile "YH_cnum")
YH_cdis (get_tile "YH_cdis")
YH_filename (get_tile "YH_blockname")
YH_filename1 (get_tile "YH_blockname")
YH_filepath (get_tile "YH_fileload")
)
(if (= YH_filepath "") (progn (setq YH_errorwhy "错误输入,图块目录不能为空")(setq YH_errorinput 0)))
(if (= YH_mode2 "1")
(progn
(if (and (= YH_H1 "1") (= (atof YH_cnum) 0)) (progn (setq YH_errorwhy "错误输入,列数必须为非零数字")(setq YH_errorinput 0)))
(if (and (= YH_V2 "1") (= (atof YH_rnum) 0)) (progn (setq YH_errorwhy "错误输入,行数必须为非零数字")(setq YH_errorinput 0)))

)
)
(if (= YH_errorinput 0) (alert YH_errorwhy) (progn (YH_setfile)(done_dialog)))
(princ)
)

(defun YH_insert1 ()
(setq YH_index (length YH_filelist))
(repeat YH_index
(setq YH_block (strcat YH_filepath "\\" (car YH_filelist)))
(setq YH_filelist (cdr YH_filelist))
(command "insert" YH_block pause "1" "1" "0")
)
)

(defun YH_insert2 ()
(setq YH_block (strcat YH_filepath "\\" (car YH_filelist)))
(command "insert" YH_block pause "1" "1" "0")
(setq YH_point1 (getvar "lastpoint"))
(setq YH_index (length YH_filelist))
(setq YH_x1 (car YH_point1)
YH_y1 (cadr YH_point1)
)
(if (= YH_rdis "") (setq YH_rdis 0) (setq YH_rdis (atof YH_rdis)))
(if (= YH_cdis "") (setq YH_cdis 0) (setq YH_cdis (atof YH_cdis)))
(if (= YH_H1 "1") (YH_insertH) (YH_insertV))
)

(defun YH_insertH()
(setq YH_rownum2 (fix (/ (+ YH_index 1) (atof YH_cnum))))
(setq YH_Hrem (rem YH_index (atof YH_cnum)))
(if (= YH_Hrem 0) (setq YH_loop1 YH_rownum2 YH_loop2 0)
(progn
(if (= YH_rownum2 0) (setq YH_loop1 0 YH_loop2 YH_Hrem)
(setq YH_loop1 YH_rownum2 YH_loop2 YH_Hrem)
)
)
)
(if (/= YH_loop1 0)
(progn
(setq YH_index1 0)
(repeat YH_loop1
(setq YH_y2 (+ YH_y1 (* YH_rdis YH_index1)))
(setq YH_index1 (1+ YH_index1))
(setq YH_index2 0)
(repeat (fix (atof YH_cnum))
(setq YH_x2 (+ YH_x1 (* YH_cdis YH_index2)))
(setq YH_index2 (1+ YH_index2))
(setq YH_point2 (list YH_x2 YH_y2))
(setq YH_block (strcat YH_filepath "\\" (car YH_filelist)))
(setq YH_filelist (cdr YH_filelist))
(command "insert" YH_block YH_point2 "1" "1" "0")
)
)
(if (/= YH_loop2 0)
(progn
(setq YH_y2 (+ YH_y1 YH_rdis))
(repeat (fix YH_loop2)
(setq YH_index3 0)
(setq YH_x2 (+ YH_x1 (* YH_cdis YH_index3)))
(setq YH_index3 (1+ YH_index3))
(setq YH_point2 (list YH_x2 YH_y2))
(setq YH_block (strcat YH_filepath "\\" (car YH_filelist)))
(setq YH_filelist (cdr YH_filelist))
(command "insert" YH_block YH_point2 "1" "1" "0")
)
)
)
)
)
(princ)
)

(defun YH_insertV()
(setq YH_rownum2 (fix (/ (+ YH_index 1) (atof YH_rnum))))
(setq YH_Hrem (rem YH_index (atof YH_rnum)))
(if (= YH_Hrem 0) (setq YH_loop1 YH_rownum2 YH_loop2 0)
(progn
(if (= YH_rownum2 0) (setq YH_loop1 0 YH_loop2 YH_Hrem)
(setq YH_loop1 YH_rownum2 YH_loop2 YH_Hrem)
)
)
)
(if (/= YH_loop1 0)
(progn
(setq YH_index1 0)
(repeat YH_loop1
(setq YH_x2 (+ YH_x1 (* YH_cdis YH_index1)))
(setq YH_index1 (1+ YH_index1))
(setq YH_index2 0)
(repeat (fix (atof YH_rnum))
(setq YH_y2 (+ YH_y1 (* YH_rdis YH_index2)))
(setq YH_index2 (1+ YH_index2))
(setq YH_point2 (list YH_x2 YH_y2))
(setq YH_block (strcat YH_filepath "\\" (car YH_filelist)))
(setq YH_filelist (cdr YH_filelist))
(command "insert" YH_block YH_point2 "1" "1" "0")
)
)
(if (/= YH_loop2 0)
(progn
(setq YH_x2 (+ YH_x1 YH_cdis))
(repeat (fix YH_loop2)
(setq YH_index3 0)
(setq YH_y2 (+ YH_y1 (* YH_rdis YH_index3)))
(setq YH_index3 (1+ YH_index3))
(setq YH_point2 (list YH_x2 YH_y2))
(setq YH_block (strcat YH_filepath "\\" (car YH_filelist)))
(setq YH_filelist (cdr YH_filelist))
(command "insert" YH_block YH_point2 "1" "1" "0")
)
)
)
)
)
(princ)
)

124350440 发表于 2010-10-10 16:03:00

是插入对象不能整除插入列数或行数时才出现插块重叠现象

124350440 发表于 2010-10-15 09:34:00

<font face="Verdana">要能读文件名的时候按一定的顺序排列,还有是插入对象个数不能整除插入列数或行数时才出现插块重叠现象</font>

lik132 发表于 2010-12-17 11:09:47

现在也正在学习,过来学习一下

xiaxiang 发表于 2011-1-14 11:45:20

是流浪水手的程序,好久没有更新啦

hdlyt11 发表于 2011-1-16 20:23:17

这个程序我今天也看到了,也不能用,提示语法错误

czb203 发表于 2011-11-19 14:19:09

测试一下,真的还不错啊 谢谢啊

10410024 发表于 2011-12-14 14:38:40

过来学习一下
页: [1]
查看完整版本: 能否修改一下:批量插入图块