在命名UCS中插入块
客户端有一堆需要插入到二维图形中的标记。每个图形都有一个命名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)
任何帮助/建议
克雷格 嗨,多里安!
好的,首先,你说的话似乎有一些遗漏的信息。我不知道你到底是怎么做的,因为你只谈论你的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,我们可以一步一步地这样做。
(defun c:test ()
(setq ChosenBlockEntsel (entsel "pick a block"));get the block
(setq ChosenBlockEname (car ChosenBlockEntsel));retrieve its <ename>
(setq ChosenBlockEList (entget ChosenBlockEname));retrieve the entity's list
(setq BInsertPointAssocList (assoc 10 ChosenBlockEList)); get the assoc of the OCS coordinate
(setq BInsertPointCoordOCS (cdr BInsertPointAssocList));retrieve the OCS coordinate
(setq BInsertPointCoordWCS (trans BInsertPointCoordOCS ChosenBlockEname 0));trans that coord to WCS
(setq NewBInsertPointCoordWCS (mapcar '+ '(1 1 1) BInsertPointCoordWCS));apply the wcs move vector
(setq NewBInsertPointCoordOCS (trans NewBInsertPointCoordWCS 0 ChosenBlockEname));trans that new coordinate in the block OCS
(setq NewBInsertPointAssocList (cons 10 NewBInsertPointCoordOCS));Rebuild the assoc 10 list with the new coordinate
(setq NewEListToEntmod (subst NewBInsertPointAssocList BInsertPointAssocList ChosenBlockEList));Rebuild the new block insert entity list
(entmod NewEListToEntmod); entmod it
(vl-cmdf "_.AttSync" "Select" ChosenBlockEname "Yes");needed if your block possess attributes.
)
那是老派风格!好的,下面是另一种更简单的移动积木的方法。简单得多(但仍然不是我需要使用的那个)。Vlax-3d-point和vla move不需要使用trans,因为它们使用的坐标始终相对于WCS。如果您询问用户的一些输入,如getpoint,请务必小心,因为getpoint的值与活动UCS有关,并且需要使用trans。注意,对于下面的示例,我没有询问任何用户输入,只在WCS的x轴上将块移动了2个单位(增量点2点1)。唯一需要的是将块ename传输到VL对象,我们可以开始了。
(defun c:test2()
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(setq ChosenBlockEntsel (entsel "pick a block"))
(setq ChosenBlockEname (car ChosenBlockEntsel))
(setq ChosenBlockVLObject (vlax-ename->vla-object ChosenBlockEname))
;; Define the points that make up the move vector
(setq point1 (vlax-3d-point 0 0 0)
point2 (vlax-3d-point 2 0 0))
(vla-Move ChosenBlockVLObject point1 point2)
)
好了,既然我们玩得很开心,也知道事情是如何运作的,让我们更认真、更高效。不要在坐标0,0处插入块,而是尝试ssget the block just inserted(and only the block just inserted),然后将其从插入点移动到用户选择的新坐标。。。。我们可以直接将其插入所需的坐标,与当前UCS对齐,merci bonsoir风格!FTOW!
(defun c:InsTag ( / acadObj doc insertionPnt modelSpace rotationangle blockRefObj)
;Jef! 2016-03-01
;Nota: the block"W2B_3D_ELEMENT_TAG" need to exist in the drawing
(vl-load-com)
(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(setq insertionPnt (vlax-3d-point (trans (getpoint "pick the coordinate for the insert point") 1 0)))
(setq modelSpace (vla-get-ModelSpace doc))
(setq rotationangle (angle '(0.0 0.0) (trans (getvar 'ucsxdir) 0 (trans '(0.0 0.0 1.0) 1 0 t) t)))
(setq blockRefObj (vla-InsertBlock modelSpace insertionPnt "W2B_3D_ELEMENT_TAG" 1 1 1 rotationangle))
)
在启动之前,只需确保“W2B\u 3D\u ELEMENT\u TAG”块定义在图形中。。正如active-X Ref指南所说:尝试使用未初始化的名称参数调用InsertBlock方法会导致意外行为。“。一定要做一切你不需要打破你的cad。
希望有帮助
干杯
杰夫!
页:
[1]