乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 63|回复: 4

[编程交流] 镜像中的变换点

[复制链接]

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 09:43:04 | 显示全部楼层 |阅读模式
今天这件事让我头痛不已。我有一个例程的请求,该例程应该用2x2dsolids“替换”块内的擦除。原因是我们使用了一个带有抹布的门框来“切割”墙壁&图案填充,而实际上不需要修剪。虽然这对技术绘图很有用,但当我们在做演示时,需要对门下的这些白点进行实体填充(就像每个门都有门槛板一样)。
 
所以我想我可以简单地重新定义块,用一个实体替换覆盖。但是不行,因为阴影区域可以有任何颜色,门的两侧可以有两种不同的颜色。我们现在的想法是在每个块参照之外创建两个单独的实体,并将它们发送到门块的正下方。这很好,甚至适用于缩放和/或动态块-但当它们被镜像时,我似乎无法通过简单的编码正确实现。
 
经过多次搜索,我发现了这条线索,但这些线索似乎都没有达到我的目的。目前,我正在使用PeterJamtgart的代码进行转换。因为它在非均匀缩放的块上效果最好,所以它的编码绝对最小。问题是,如果我在镜像块上使用它,实体始终处于关闭状态,就好像该块沿着其插入点的X/Y轴镜像回来一样。
 
我目前(针对Peter的代码)所做的工作是检查XEffectiveScaleFactor的值是否小于0.0(即,查看它是否镜像)。如果是这样,我将围绕Y轴为该块创建一个临时镜像,从该镜像生成点,并使用负Z法线的变换来“反镜像”该点。不幸的是,这使得每个blockreference有4个临时块(因为我想得到4点)。我知道我可以把它全部打包在一个撤销组中,但我觉得它很凌乱。有人知道我怎么摆脱这些临时障碍吗?要么通过来回变换原始数据,要么最好只是通过计算而不影响块?请参见cadtips页面中的修改后的lisp。
 
一定有一些arb的事情,我现在根本无法理解。也许我只是变老了?真丢脸。。。我没想到我已经过山了!
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 10:01:50 | 显示全部楼层
实际上,现在只需做一个测试,Peter的代码似乎比只使用镜像块还要糟糕。如果块的缩放和旋转不是0.0或180.0度,则点也会关闭。这是我的测试代码:
  1. ;****************************************************************************************************
  2. ; Written By: Peter Jamtgaard copr 2009
  3. ; Function for transforming a point from block object coordinate system to a world coordinate system.
  4. ; It handles non uniform scaled blocks
  5. ; Syntax:  (TranslateWorldToObject <block object> <point in world>)
  6. ; Syntax  (TranslateObjectToWorld <block object> <point inside block>)
  7. ; Returns point in World
  8. ;****************************************************************************************************
  9. (defun TranslateObjectToWorld (objBlock         ; Block object
  10.                               lstPointInBlock  ; Coordinates of point (RELATIVE TO BASE POINT)
  11.                                                ; inside the block
  12.                               /      
  13.                               lstInsertion     ; Insertion Point of Block
  14.                               lstPoint         ; List Point of return translate coordinates
  15.                               lstPointInWorld  ; Coordinates of point inside the WorldCS
  16.                               sngTheta         ; Rotation angle of Block
  17.                               varReturn        ; Variant return of translate coordinates
  18.                              )
  19. (if (not objDocument)(setq objDocument (vla-get-activedocument
  20.                                         (vlax-get-acad-object))))
  21. (setq lstInsertion    (vlax-get objBlock "insertionpoint")
  22.       sngTheta        (vla-get-rotation objBlock)
  23.       lstPointInBlock (list (* (vla-get-XEffectiveScaleFactor objBlock)
  24.                                 (+ (*    (cos sngTheta) (car  lstPointInBlock))
  25.                                    (* -1 (sin sngTheta) (cadr lstPointInBlock))))
  26.                              (* (vla-get-YEffectiveScaleFactor objBlock)
  27.                                 (+ (*    (sin sngTheta) (car  lstPointInBlock))
  28.                                    (*    (cos sngTheta) (cadr lstPointInBlock))))
  29.                              (* (vla-get-ZEffectiveScaleFactor objBlock)
  30.                                 (caddr lstPointInBlock)))
  31.       varReturn       (vla-translateCoordinates (vla-get-utility
  32.                                                 objDocument)               
  33.                                                 (vlax-3d-point lstPointInBlock)
  34.                                                 acOCS
  35.                                                 acWorld
  36.                                                 :vlax-false
  37.                                                 (vla-get-normal objBlock))
  38.       lstPointInWorld (mapcar '+ lstInsertion
  39.                                  (vlax-safearray->list (variant-value varReturn)))
  40. )
  41. )
  42. ;****************************************************************************************************
  43. ; Written By: Peter Jamtgaard copr 2009
  44. ; Function for transforming a point from block object coordinate system to a world coordinate system.
  45. ; It handles non uniform scaled blocks
  46. ; Syntax:  (TranslateWorldToObject <block object> <point in world>)
  47. ; Syntax  (TranslateObjectToWorld <block object> <point inside block>)
  48. ; Returns point in World
  49. ;****************************************************************************************************
  50. (defun TranslateObjectToWorld1 (objBlock ; Block object
  51.                               lstPointInBlock ; Coordinates of point (RELATIVE TO BASE POINT)
  52. ; inside the block
  53.                               / lstInsertion ; Insertion Point of Block
  54.                               lstPoint ; List Point of return translate coordinates
  55.                               lstPointInWorld ; Coordinates of point inside the WorldCS
  56.                               sngTheta ; Rotation angle of Block
  57.                               varReturn ; Variant return of translate coordinates
  58.                               toMirror ; State of mirrored block (by Irn?)
  59.                               )
  60. (if (not objDocument)
  61.    (setq objDocument
  62.           (vla-get-activedocument
  63.             (vlax-get-acad-object)
  64.           )
  65.    )
  66. )
  67. ;; By Irn?: Check if block's mirrored & create an "unmirrored" block about the Y axis.
  68. (if (setq toMirror (< (vla-get-XEffectiveScaleFactor objBlock) 0.0))
  69.    (setq objBlock     (vlax-invoke objBlock 'Mirror '(0.0 0.0 0.0) '(0.0 1.0 0.0)))
  70. )
  71. (setq lstInsertion (vlax-get objBlock "insertionpoint")
  72.        sngTheta     (vla-get-rotation objBlock)
  73.        lstPointInBlock (list (* (vla-get-XEffectiveScaleFactor objBlock)
  74.                                 (+ (* (cos sngTheta) (car lstPointInBlock))
  75.                                    (* -1 (sin sngTheta) (cadr lstPointInBlock))
  76.                                 )
  77.                              )
  78.                              (* (vla-get-YEffectiveScaleFactor objBlock)
  79.                                 (+ (* (sin sngTheta) (car lstPointInBlock))
  80.                                    (* (cos sngTheta) (cadr lstPointInBlock))
  81.                                 )
  82.                              )
  83.                              (* (vla-get-ZEffectiveScaleFactor objBlock)
  84.                                 (caddr lstPointInBlock)
  85.                              )
  86.                        )
  87.        varReturn       (vla-translateCoordinates
  88.                          (vla-get-utility
  89.                            objDocument
  90.                          )
  91.                          (vlax-3d-point lstPointInBlock)
  92.                          acOCS
  93.                          acWorld
  94.                          :vlax-false
  95.                          (vla-get-normal objBlock)
  96.                        )
  97.        lstPointInWorld (mapcar '+
  98.                                lstInsertion
  99.                                (vlax-safearray->list (variant-value varReturn))
  100.                        )
  101. )
  102. ;; By Irn?: Check if block was "unmirrored"
  103. (if toMirror
  104.    (progn
  105.      (vla-Delete objBlock) ;Erase the temporary "unmirored" block.
  106.      (trans lstPointInWorld '(0.0 0.0 -1.0) 0) ;Translate the "unmirored" point as mirrored about the Y axis
  107.    )
  108.    lstPointInWorld ;If not mirrored, just send calculated point
  109. )
  110. )
  111. (defun c:Pt2WCS-test (/ ss eo pts pt)
  112. (setq pts '((500.0 0.0 0.0) (0.0 0.0 0.0) (500.0 200.0 0.0)))
  113. (if (and (ssget "_:L" '((0 . "INSERT,*POLY*")))
  114.           (setq ss (vla-get-ActiveSelectionset (vla-get-ActiveDocument (vlax-get-acad-object))))
  115.      )
  116.    (progn
  117.      (vlax-for eo ss
  118.        (if (eq (vla-get-ObjectName eo) "AcDbBlockReference")
  119.          (progn
  120.            (setvar "CECOLOR" "1")
  121.            (command "_.PLINE")
  122.            (foreach pt pts
  123.              (command "_None" (TranslateObjectToWorld eo pt))
  124.            )
  125.            (command "")
  126.            (setvar "CECOLOR" "2")
  127.            (command "_.PLINE")
  128.            (foreach pt pts
  129.              (command "_None" (TranslateObjectToWorld1 eo pt))
  130.            )
  131.            (command "")
  132.            (setvar "CECOLOR" "BYLAYER")
  133.          )
  134.          (vla-Delete eo)
  135.        )
  136.      )
  137.      (vla-Delete ss)
  138.    )
  139. )
  140. (princ)
  141. )
命令为Pt2WCS测试。
 
附加的是生成的DWG。我做了一个测试块,上面有一些文字,可以很容易地看到镜像/缩放/旋转的想法。然后,测试代码生成2条多段线。每个都应该从块的右下角到插入点,再到右上角。彼得的代码是用红色绘制的,我修改的代码是用黄色绘制的。
 
对于非镜像块,Peter的近似正确,但旋转块的方向和比例似乎不正确。在镜像街区,距离“英里”。我的mod在非镜像上也做了同样的事情,但至少在镜像上没有更糟。
图纸1.dwg
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:13:41 | 显示全部楼层
试试这个Irne:
 
使用测试功能:
 
  1. 2
主要是根据我的程序在这里、这里和这里开发的。
回复

使用道具 举报

11

主题

968

帖子

919

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
99
发表于 2022-7-6 10:31:24 | 显示全部楼层
谢谢李,这似乎很有效。现在,为了弄清楚它实际上做了什么,我知道如何做,而不是简单地重复使用别人的代码!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:46:02 | 显示全部楼层
 
谢谢Irné,很高兴听到
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-7 00:36 , Processed in 0.353750 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表