aps 发表于 2022-7-5 22:24:35

自定义转换和enti

你好
 
首先,很抱歉我的英语很差。我是AutoLISP的初学者,我主要使用GIS软件和数据,但我必须解决以下问题。我收到了一个大的DWG文件,其中包含大约30000个具有各种实体类型和多个图层的实体。一切都在一个自定义的局部坐标系中,我必须将其转换为另一个坐标系。我只有转换方程,所以我根据在本论坛和其他论坛上找到的代码创建了第一个AutoLISP文件:
 
它主要做我想要的,但有3个问题:
 
1、不移动多线和区域实体类型的对象。
 
2.它仅转换一部分直线和三维面图元。例如:线图元的一个节点移动到新位置,另一个节点保持在原始位置,因此结果是一条长线,一个节点在正确位置,一个节点在旧位置。
 
3.它可以完美地处理大多数文本实体,但也有一些文本保留在其原始位置,我无法找出“工作”文本和“非工作”文本之间的区别。
 
如何解决上述问题,有什么建议吗?
谢谢你的帮助!

marko_ribar 发表于 2022-7-5 22:34:43

对于MLINE???,区域和三维实体我帮不上忙,但我想对于所有其他类型,这个修复可以做到。。。
 
(defun c:customtransform ( / ss i entitylist obj new j x y )
(if (setq ss (ssget "_:L"))
   (repeat (setq i (sslength ss))
   (setq entitylist (entget (ssname ss (setq i (1- i)))))
   (setq obj (ssname ss i))
   (setq new nil)
   (repeat (setq j (length entitylist))
       (cond
         ( (= 10 (car (nth (setq j (1- j)) entitylist)))
         (setq x (cadr (nth j entitylist))
               y (caddr (nth j entitylist))
         )
         (setq y (+ (+ (+ 0 332134.109) (* 0.40008331 x)) (* 0.59595102 y)))
         (setq x (+ (+ (+ 0 1087.012) (* 0.59595102 x)) (* -0.40008331 y)))
         (setq new (cons (list 10 x y) new))
         )
         ( (= 11 (car (nth j entitylist)))
         (setq x (cadr (nth j entitylist))
               y (caddr (nth j entitylist))
         )
         (setq y (+ (+ (+ 0 332134.109) (* 0.40008331 x)) (* 0.59595102 y)))
         (setq x (+ (+ (+ 0 1087.012) (* 0.59595102 x)) (* -0.40008331 y)))
         (setq new (cons (list 11 x y) new))
         )
         ( (= 12 (car (nth j entitylist)))
         (setq x (cadr (nth j entitylist))
               y (caddr (nth j entitylist))
         )
         (setq y (+ (+ (+ 0 332134.109) (* 0.40008331 x)) (* 0.59595102 y)))
         (setq x (+ (+ (+ 0 1087.012) (* 0.59595102 x)) (* -0.40008331 y)))
         (setq new (cons (list 12 x y) new))
         )
         ( (= 13 (car (nth j entitylist)))
         (setq x (cadr (nth j entitylist))
               y (caddr (nth j entitylist))
         )
         (setq y (+ (+ (+ 0 332134.109) (* 0.40008331 x)) (* 0.59595102 y)))
         (setq x (+ (+ (+ 0 1087.012) (* 0.59595102 x)) (* -0.40008331 y)))
         (setq new (cons (list 13 x y) new))
         )
         ( (= 14 (car (nth j entitylist)))
         (setq x (cadr (nth j entitylist))
               y (caddr (nth j entitylist))
         )
         (setq y (+ (+ (+ 0 332134.109) (* 0.40008331 x)) (* 0.59595102 y)))
         (setq x (+ (+ (+ 0 1087.012) (* 0.59595102 x)) (* -0.40008331 y)))
         (setq new (cons (list 14 x y) new))
         )
         ( (= 15 (car (nth j entitylist)))
         (setq x (cadr (nth j entitylist))
               y (caddr (nth j entitylist))
         )
         (setq y (+ (+ (+ 0 332134.109) (* 0.40008331 x)) (* 0.59595102 y)))
         (setq x (+ (+ (+ 0 1087.012) (* 0.59595102 x)) (* -0.40008331 y)))
         (setq new (cons (list 15 x y) new))
         )
         ( (= 16 (car (nth j entitylist)))
         (setq x (cadr (nth j entitylist))
               y (caddr (nth j entitylist))
         )
         (setq y (+ (+ (+ 0 332134.109) (* 0.40008331 x)) (* 0.59595102 y)))
         (setq x (+ (+ (+ 0 1087.012) (* 0.59595102 x)) (* -0.40008331 y)))
         (setq new (cons (list 16 x y) new))
         )
         ( t
         (setq new (cons (nth j entitylist) new))
         )
       )
   )
   (entdel obj)
   (entmake new)
   )
)
(princ)
)
HTH,M.R。

BIGAL 发表于 2022-7-5 22:42:34

也许可以尝试这样做,将dwg作为块插入到另一个块中。您可以调整x和y比例0.40008 0.595等,然后进行移动。在拖动鼠标上按F8正交。输入3321434,然后再次输入y 1087,然后分解块并清除,以从dwg中删除块定义。

aps 发表于 2022-7-5 22:47:07

 
 
谢谢,但是当我尝试运行它时,我收到了一条错误消息:
 
错误:错误的参数值:非负:-1
 
这是什么意思?
 
仅在第一个条件和else条件下,其工作方式与之前相同:
2
 
但如果我添加第二个条件或任何其他条件,就会出现错误消息。

marko_ribar 发表于 2022-7-5 22:52:52

那是因为我没有测试它。。。我已经更新了修复程序,现在应该可以正常工作了,但我认为比格尔的建议是我应该做的。。。当然,在整个DWG的块上应用代码,分解并清除该块。。。
 
M、 R。

aps 发表于 2022-7-5 22:59:26

 
谢谢你的想法,但更多具有此类内容的DWG很快就会出现,我想为我的同事提供一个简单的工具。

aps 发表于 2022-7-5 23:04:25

 
你能给我看看代码的更新版本吗?
 
非常感谢。

marko_ribar 发表于 2022-7-5 23:06:43

 
http://www.cadtutor.net/forum/showthread.php?88736-自定义转换和实体类型&p=#2

BIGAL 发表于 2022-7-5 23:12:51

2件事如果缩放和移动对于每个都不同,那么您需要更改Marko的代码,以允许用户输入这些值。
 
回到我的问题,你可以问有关规模和移动和自动化使用插入方法以及。只需打开新的dwg并运行lisp。

aps 发表于 2022-7-5 23:19:08

嗨,我的问题回来了。谢谢Marco和BIGAL的帮助!
除了椭圆和区域外,Marko的代码运行良好。因此,我考虑了块的想法。我用Lee Mac的多段线到块代码扩展了LISP文件,所以现在它将所有对象转换为单个块,然后将其转换为新的坐标系。我很高兴,因为分解转换后的块后,我得到了我想要的东西,但在数据验证过程中,我发现这种方法导致坐标不准确。
 
我通过手工计算验证了Marko的纯变换代码是非常精确的。但是,当我将对象转换为单个块(使用Lee Mac的方法或在AutoCAD中使用hand),然后在该块上运行转换例程时,就会出现不准确的情况。不准确度似乎是恒定的,在10到100厘米(4-39”)之间,取决于变换前选择的块的基点。
为什么会出现这种不准确的情况?我怎样才能摆脱它?
页: [1] 2
查看完整版本: 自定义转换和enti