乐筑天下

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

[编程交流] 在命名UCS中插入块

[复制链接]

5

主题

12

帖子

7

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-5 17:59:17 | 显示全部楼层 |阅读模式
客户端有一堆需要插入到二维图形中的标记。
每个图形都有一个命名UCS视图,我想插入块,使其垂直于UCS。
 
我想做的是在UCS的0,0处插入块(W2B\u 3D\u ELEMENT\u标记),使用(ssget“\u C”'(-0.5-40)'(0-40))选择块。更改为WCS并移动到正确的WCS。
 
问题是它不会将块从它从完全不同的点拾取的插入点移动。
 
有没有一种方法可以使用ssget从块插入点进行拾取?
 
我知道还有一个trans命令,但不确定它是如何工作的
(trans’(1.0 2.0 3.0)0 1)
 
任何帮助/建议
 
克雷格
回复

使用道具 举报

28

主题

317

帖子

292

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-5 19:00:13 | 显示全部楼层
嗨,多里安!
 
好的,首先,你说的话似乎有一些遗漏的信息。我不知道你到底是怎么做的,因为你只谈论你的ssget,这是一个选择。我可以说,移动需要2个点来表示移动向量。“From”>“To”相当直接,如果你说块被另一个点拾取,我不确定如何继续。
 
首先会有,但我不会使用ssget“\u c”,因为有很多原因:它会抓取选择区域内的所有其他对象,它可能很挑剔,因为对象必须在屏幕上可见,也因为ssget“\u c”的机制。虽然窗口与wcs轴正交(有时可能是pita),但当前ucs中需要坐标。 
它将一个点从一个坐标系转换到另一个坐标系。trans。从/到I最常用的是0(wcs)、1(当前ucs)和。最后一个将用于在AutoCAD任意确定的任何对象坐标系(OCS)之间进行转换。假设当前ucs位于前方,您在坐标(0.2.0)处有一个点,并且希望其位置相对于WCS,您可以使用(trans’(0.2.0)1.0),该值将返回(0.0 0.0.2.0)。 
现在,为了更实际的使用,我将向您展示一种使用trans的方法。注:块参照插入点存储在assoc 10中,但在其OCS中。假设我想在WCS中将块移动x+1y+1z+1,我们可以一步一步地这样做。
  1. (defun c:test ()
  2. (setq ChosenBlockEntsel (entsel "pick a block"));get the block
  3. (setq ChosenBlockEname (car ChosenBlockEntsel));retrieve its <ename>
  4. (setq ChosenBlockEList (entget ChosenBlockEname));retrieve the entity's list
  5. (setq BInsertPointAssocList (assoc 10 ChosenBlockEList)); get the assoc of the OCS coordinate
  6. (setq BInsertPointCoordOCS (cdr BInsertPointAssocList));retrieve the OCS coordinate
  7. (setq BInsertPointCoordWCS (trans BInsertPointCoordOCS ChosenBlockEname 0));trans that coord to WCS
  8. (setq NewBInsertPointCoordWCS (mapcar '+ '(1 1 1) BInsertPointCoordWCS));apply the wcs move vector
  9. (setq NewBInsertPointCoordOCS (trans NewBInsertPointCoordWCS 0 ChosenBlockEname));trans that new coordinate in the block OCS
  10. (setq NewBInsertPointAssocList (cons 10 NewBInsertPointCoordOCS));Rebuild the assoc 10 list with the new coordinate
  11. (setq NewEListToEntmod (subst NewBInsertPointAssocList BInsertPointAssocList ChosenBlockEList));Rebuild the new block insert entity list
  12. (entmod NewEListToEntmod); entmod it
  13. (vl-cmdf "_.AttSync" "Select" ChosenBlockEname "Yes");needed if your block possess attributes.
  14. )

那是老派风格!好的,下面是另一种更简单的移动积木的方法。简单得多(但仍然不是我需要使用的那个)。Vlax-3d-point和vla move不需要使用trans,因为它们使用的坐标始终相对于WCS。如果您询问用户的一些输入,如getpoint,请务必小心,因为getpoint的值与活动UCS有关,并且需要使用trans。注意,对于下面的示例,我没有询问任何用户输入,只在WCS的x轴上将块移动了2个单位(增量点2点1)。唯一需要的是将块ename传输到VL对象,我们可以开始了。
  1. (defun c:test2()
  2.    (setq acadObj (vlax-get-acad-object))
  3.    (setq doc (vla-get-ActiveDocument acadObj))
  4.    (setq ChosenBlockEntsel (entsel "pick a block"))
  5.    (setq ChosenBlockEname (car ChosenBlockEntsel))
  6.    (setq ChosenBlockVLObject (vlax-ename->vla-object ChosenBlockEname))
  7.    ;; Define the points that make up the move vector
  8.    (setq point1 (vlax-3d-point 0 0 0)
  9.          point2 (vlax-3d-point 2 0 0))
  10.    (vla-Move ChosenBlockVLObject point1 point2)
  11. )

 
好了,既然我们玩得很开心,也知道事情是如何运作的,让我们更认真、更高效。不要在坐标0,0处插入块,而是尝试ssget the block just inserted(and only the block just inserted),然后将其从插入点移动到用户选择的新坐标。。。。我们可以直接将其插入所需的坐标,与当前UCS对齐,merci bonsoir风格!FTOW!
  1. (defun c:InsTag ( / acadObj doc insertionPnt modelSpace rotationangle blockRefObj)
  2.    ;Jef! 2016-03-01
  3.    ;Nota: the block  "W2B_3D_ELEMENT_TAG" need to exist in the drawing
  4.    (vl-load-com)
  5.    (setq acadObj (vlax-get-acad-object))
  6.    (setq doc (vla-get-ActiveDocument acadObj))
  7.    (setq insertionPnt (vlax-3d-point (trans (getpoint "pick the coordinate for the insert point") 1 0)))
  8.    (setq modelSpace (vla-get-ModelSpace doc))
  9.    (setq rotationangle (angle '(0.0 0.0) (trans (getvar 'ucsxdir) 0 (trans '(0.0 0.0 1.0) 1 0 t) t)))
  10.    (setq blockRefObj (vla-InsertBlock modelSpace insertionPnt "W2B_3D_ELEMENT_TAG" 1 1 1 rotationangle))
  11. )

在启动之前,只需确保“W2B\u 3D\u ELEMENT\u TAG”块定义在图形中。。正如active-X Ref指南所说:尝试使用未初始化的名称参数调用InsertBlock方法会导致意外行为。“。一定要做一切你不需要打破你的cad。
 
希望有帮助
干杯
杰夫!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 00:39 , Processed in 0.427295 second(s), 56 queries .

© 2020-2025 乐筑天下

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