明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2207|回复: 16

[讨论] 程序变得很慢,几乎无法接受?

  [复制链接]
发表于 2014-7-20 10:37 | 显示全部楼层 |阅读模式
为何读外部文件字符串后,再进行command画圆,字符显示与图像粘贴,循环程序会变得很慢很慢?求解决方案。
发表于 2014-7-20 10:46 | 显示全部楼层
与软硬体有关
与资料量有关
与多工有关
与防毒有关
...
大家一起猜
 楼主| 发表于 2014-7-20 11:41 | 显示全部楼层
我的硬件很好了,Intel(R) Core(TM) 2.6GHz, 2.6GHz
RAM 4G, 硬盘300G
贴入图片20张
 楼主| 发表于 2014-7-20 11:43 | 显示全部楼层
不过防病毒倒是提醒我了,因为是公司电脑,有很强大的防病毒功能

点评

关键靠代码的效率  发表于 2014-7-20 13:03
发表于 2014-7-20 19:23 | 显示全部楼层
command 不行可以试试entmake
发表于 2014-7-20 19:51 | 显示全部楼层
首先优化下读取文本文件的代码,有些不必要的就不要读进来了
其次,画圆建议你用(entmakex (list '(0 . "circle") (cons 10 pt) (cons 40 r)));pt为圆心 r为半径.
建议你将你的代码发出来,大家一起帮你优化~
 楼主| 发表于 2014-7-20 23:03 | 显示全部楼层
(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_dim  chksty          n1              n2
                  Imagelayer  ent1          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      data00  enscal01 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 (strcat  strname ))
                                        ;(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 ")

)
 楼主| 发表于 2014-7-20 23:04 | 显示全部楼层
帮忙看看,这个程序29张图片运行了很长时间才完成,并且有时候不稳定
 楼主| 发表于 2014-7-20 23:05 | 显示全部楼层
非常感谢各位大侠
发表于 2014-7-20 23:42 | 显示全部楼层
要那么多princ做什么,真搞不懂~
还有,好多变量时可以省略的,变量多了,不慢才怪~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-26 20:47 , Processed in 2.551880 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表