864643236 发表于 2017-11-10 22:48:05

cad程序视图问题,请大神指点

cad 中的很多插件默认的只能在顶视图中自动生成图形和使用,转换到其他视图就不能用了,要怎么修改才能在其它视图里正常使用呢,有知道的朋友,求指点

比如下面这个程序就只能在cad的俯视图里使用,找了半天不知道什么原因



xy轴比例调节
(defun C:11 (/ bp ss xscal yscal entL)
(setvar "qaflags" 0)
(defun errexit (s)
    (princ "\nError:")
    (princ s)
    (restore)
)

(defun restore ()
    (setvar "CMDECHO" (car oldvar))
    (setq *error* olderr)
    (princ)
)

(defun MAKEUNBLOCK (ss ip / tmp errexit mbx BLAYER)
    (setq olderr*error*
          *error* errexit
    )
    (setq oldvar (list (getvar "CMDECHO")))
    (setvar "CMDECHO" 0)
    (terpri)
    (if        BLAYER
      (command "._LAYER"
             (if (tblsearch "LAYER" BLAYER)
               "_S"
               "_M"
             )
             BLAYER
             ""
      )
    )
    (if        (and
          ip
          ss
        )
      (progn
        (entmake (list (cons '0 "BLOCK")
                     (cons '2 "*U")
                     (cons '70 1)
                     (cons '10 ip)
               )
        )
        (setq cnt (sslength ss))
        (while (>= (setq cnt (1- cnt))
                   0
             )
          (setq tmp (ssname ss cnt))
          (entmake (setq el (entget tmp)))
          (if (> (cdr (assoc 66 el)) 0)
          (while (/= "SEQEND"
                     (cdr (assoc 0
                                   (entmake (setq el
                                                   (entget
                                                     (entnext
                                                     (cdr
                                                       (assoc -1 el)
                                                     )
                                                     )
                                                   )
                                          )
                                   )
                          )
                     )
                   )
          )
          )
          (entdel tmp)
        )
        (setq tmp (entmake (list (cons '0 "ENDBLK"))))
        (entmake
          (list (cons '0 "INSERT") (cons '2 tmp) (cons '10 ip))
        )
      )
    )
    (restore)
)
(setq ss (cadr (ssgetfirst)))
(while (= ss nil)
    (setq ss (ssget))                        ; 选择缩放实体
)
(setq        i 0
        dwcorn nil
        upcorn nil
)
(repeat (sslength ss)
    (setq ent (ssname ss i))
    (setq obj (vlax-ename->vla-object ent))
    (vla-GetBoundingBox obj 'pta 'ptb)
    (setq dwcorn (cons (vlax-safearray->list pta) dwcorn))
    (setq upcorn (cons (vlax-safearray->list ptb) upcorn))
    (setq i (1+ i))
)
(setq        ptlist (append
               dwcorn
               upcorn
             )
)
(setq        x (mapcar
          'car
          ptlist
          )
)
(setq        y (mapcar
          'cadr
          ptlist
          )
)
(setq        x1 (apply
             'min
             x
           )
)
(setq        y1 (apply
             'min
             y
           )
)
(setq        x2 (apply
             'max
             x
           )
)
(setq        y2 (apply
             'max
             y
           )
)
(setq xx (- (car (list x2 y2)) (car (list x1 y1))))
(setq yy (- (cadr (list x2 y2)) (cadr (list x1 y1))))
(if ss
    (progn
      (setq bp (polar (list x1 y1)
                      (angle (list x1 y1) (list x2 y2))
                      (/ (distance (list x1 y1) (list x2 y2)) 2)
             )
      )
      (setq xx1 (getdist "\n指定新的X方向尺寸:"))
      (setq yy1 (getdist "\n指定新的Y方向尺寸:"))

      (setq xscal (/ xx1 xx))
      (setq yscal (/ yy1 yy))
      (MAKEUNBLOCK ss bp)
      (setq entL (entget (entLast))
          entL (subst
                   (cons 41 xscal)
                   (assoc 41 entL)
                   entL
               )
          entL (subst
                   (cons 42 yscal)
                   (assoc 42 entL)
                   entL
               )
      )
      (entmod entL)
      (command "_explode" "l")
    )
)
(princ)
)

ll_j 发表于 2017-11-10 23:12:22

刚才试了一下,还不止是trans那么简单,得到的结论是,按要求几乎没办法。
问题的结症是entmake无名块,ent族函数得到的点几乎都是相对世界坐标系的,所有无名块不管在什么坐标系中entmake,实际上都还是相对于世界坐标系的,此时用户坐标系若相对于世界坐标系进行变换,比如旋转,那么用户坐标系中的xy比例变换,在世界坐标系中就不简单地是xy变换,而是一个向量在空间转换,不仅仅是组码41和42的问题了。
同样,vla-GetBoundingBox函数得到的包围盒,也是世界坐标系下的数值,在用户坐标系中进行变换也是个空间问题,不是简单比例的。
有点拗口。
知道问题所在,那么如果绕开entmake的思路,直接使用block命令做块(转换的事交给acad自己),或许能达到要求的效果,只是多了个块名,并且由于不能使用vla-GetBoundingBox函数,所以最终只能按比例缩放。

864643236 发表于 2017-11-11 08:43:53

ll_j 发表于 2017-11-10 23:12
刚才试了一下,还不止是trans那么简单,得到的结论是,按要求几乎没办法。
问题的结症是entmake无名块,en ...

那按照你的见解,这个程序在直接输入xy值得情况下,要想运用于所有视图,是不可能完成了是不

xinxirong 发表于 2017-11-11 21:52:29

ll_j 发表于 2017-11-10 23:12
刚才试了一下,还不止是trans那么简单,得到的结论是,按要求几乎没办法。
问题的结症是entmake无名块,en ...

你想得太复杂了。。。

864643236 发表于 2017-11-11 22:45:06

xinxirong 发表于 2017-11-11 21:52
你想得太复杂了。。。

我也想想简单一点,可以是我不太懂
页: [1]
查看完整版本: cad程序视图问题,请大神指点