TENGOMARK 发表于 2014-7-20 10:37:46

程序变得很慢,几乎无法接受?

为何读外部文件字符串后,再进行command画圆,字符显示与图像粘贴,循环程序会变得很慢很慢?求解决方案。

Andyhon 发表于 2014-7-20 10:46:08

与软硬体有关
与资料量有关
与多工有关
与防毒有关
...
大家一起猜

TENGOMARK 发表于 2014-7-20 11:41:59

我的硬件很好了,Intel(R) Core(TM) 2.6GHz, 2.6GHz
RAM 4G, 硬盘300G
贴入图片20张

TENGOMARK 发表于 2014-7-20 11:43:46

不过防病毒倒是提醒我了,因为是公司电脑,有很强大的防病毒功能

ysq101 发表于 2014-7-20 19:23:50

command 不行可以试试entmake

77077 发表于 2014-7-20 19:51:19

首先优化下读取文本文件的代码,有些不必要的就不要读进来了
其次,画圆建议你用(entmakex (list '(0 . "circle") (cons 10 pt) (cons 40 r)));pt为圆心 r为半径.
建议你将你的代码发出来,大家一起帮你优化~

TENGOMARK 发表于 2014-7-20 23:03:13

(defun c:inimageL (/              fname          fim              strname
                  imd              word          chklay      image
                  image_angle die_angle          scale_dim   die_center
                  die_center_asist          tape_center_asist
                  center_dimchksty          n1              n2
                  Imagelayerent1          layerIm   ssimage
                  n              n_cir          n_line      n_arc
                  en              endata          entype      image_num
                  x_number    y_number          image_xspace
                  image_yspace                  begpoint    p1
                  p2              txt_high          enscal      data01
                  data02      data00enscal01 k1 axi_point word ratio01
               )

(setvar "CMDECHO" 0)
(setq image_num (getreal "\n Input image numbers: ")) ;图片总数量输入
(setq x_number (fix (sqrt image_num))) ;图片X 方向分布数量
(princ "\n x-num: ")
(princ x_number)
(setq y_number (+ (fix (/ image_num x_number)) 1))
                                        ; 图片Y 方向的分布数量
(setq image_xspace (getreal "\n Input X-distance for every image: "))
                                        ;输入图片X方向占据的空间
(setq image_yspace (getreal "\n Input Y-distance for every image: "))
                                        ;输入图片Y 方向占据的空间
(princ "\n image xspace: ")
(princ image_xspace)
(setq txt_high (* image_yspace 0.1))        ;输入写入图片的文字高度
(princ "\n TextHeight:")
(princ txt_high)

(setq image_size (* image_xspace 0.7))        ; 写入图片初步放大到的尺寸
(princ "\n Image_size:")
(princ image_size)

(setq begpoint (getpoint "\n Input begin position: \n "))
                                        ;输入图片占据的起始点
(princ "\n Please Input Your Drawing Number List")

(setq fname (getfiled "Pls input file name" "" "pot" 8))
(setq fim (open fname "r"))
(setq strname (read-line fim))
(setq word (read strname)) ;读读取字符
(princ "\n 读取字符")
(princ strname)
(setq imd (strlen strname))

(setq        n2 0
        k1 0
        nx1 0
        ny1 0
)

(while (/= imd 0)
                                        ;(prin1 strname)
                                        ;(prin1 "\n123")
                                        ;(prin1 "\n123")
                                        ;(setq word (strcatstrname ))
                                        ;(setq aa " "strname"")
                                        ;(princ aa)
                                        ;(prin1 "\n 123")

    (princ "\n x_number & nx1:")
    (princ x_number)
    (princ " & ")
    (princ nx1)
    (setq nx1 (- k1 (* (fix (/ k1 x_number)) x_number))) ;Get x number
    (princ "\n nx1&n ")
    (princ nx1)
    (princ " & ")
    (princ k1)
    (setq ny1(fix (/ n2 x_number))) ;Get y number
    (setq x1 (car begpoint))                ;Get begpoint x vaule
    (setq y1 (cadr begpoint))                ;Get begpoint y value
    (setq x (+ x1 (* nx1 image_xspace)))
    (setq y (- y1 (* ny1 image_yspace)))
    (setq axi_point (list x y))
    (princ "\n 插入点:   ")
    (princ axi_point)


   

    (princ "\n 输入字符 :   ")
    (princ word)

   
    (command "-image" "attach" word axi_point 1 0 )
    (setq enscal01 (entlast))
    (setq enscal (entget (entlast)))        ;计算该图片需要放大的粗略倍数
    (setq data01 (cadr (assoc 11 enscal)))
    (setq data02 (cadr (assoc 13 enscal)))
    (setq data00 (* data01 data02))
    (setq ratio01 (/ image_size data00))
    (princ "\n 放大倍率:")
    (princ ratio01)
   


    (command "scale" enscal01 "" axi_point ratio01) ;放大倍率

    (command "text" axi_point txt_high "" word ""); 图名写入图片上

    (princ word)
    (setq strname (read-line fim))        ;读一行
    (setq imd (strlen strname));返回字符串的个数
    (setq word (read strname)) ;读取字符

    (setq k1 (1+ k1))
    (setq n2 (1+ n2))
   
)
(close fim)
(setvar "CMDECHO" 1)
(prompt "\n All rights belong to Tengo ")

)

TENGOMARK 发表于 2014-7-20 23:04:22

帮忙看看,这个程序29张图片运行了很长时间才完成,并且有时候不稳定

TENGOMARK 发表于 2014-7-20 23:05:31

非常感谢各位大侠

77077 发表于 2014-7-20 23:42:18

要那么多princ做什么,真搞不懂~
还有,好多变量时可以省略的,变量多了,不慢才怪~
页: [1] 2
查看完整版本: 程序变得很慢,几乎无法接受?