画线接近折线 [英] drawing line close to polyline
问题描述
我有一个三角形作为折线,我想绘制一个高度.我为命令"line"
或"_line"
指定了正确的点,但是AutoCAD绘制了从顶点到相邻顶点的线.
I have a Triangle as a polyline and I want to draw an Altitude. I give the command "line"
or "_line"
the right points but AutoCAD draws the line from the vertex to the adjacent vertex.
不仅仅是在AutoLISP中,AutoCAD不允许我从顶点到折线的边中间绘制一条线.
It's not just in AutoLISP, AutoCAD won't let me draw a line from a vertex to the middle of an edge in a polyline.
我该怎么做?
我想在折线中添加一个顶点,但这并没有太大帮助.我试图添加连接器:圆或另一个对象关闭 足够的直线并连接高度,但这也无济于事.
I thought of adding a vertex in the polyline, but this didn't help that much. I tried to add connector: a circle or another object close enough to the line and connect the altitude to it, but that didn't help either.
有什么建议吗?
推荐答案
首先,我怀疑您当前尝试的问题是在提供指向LINE
命令的点时活动对象捕捉模式的影响.
Firstly, I suspect that the issue with your current attempts is the influence of active Object Snap modes when supplying points to the LINE
command.
有几种方法可以避免这种情况:
There are several ways to avoid this:
通过AutoLISP command
表达式为AutoCAD命令提供点时,可以通过在该点之前添加none
或non
Object Snap修饰符来避免任何活动的Object Snap模式的影响.
When supplying points to an AutoCAD command through an AutoLISP command
expression, you can avoid the effect of any active Object Snap modes by preceding the point with the none
or non
Object Snap modifier.
这类似于您在点之前使用end
来强制激活端点对象捕捉"修改器的方式,但是在这种情况下,none
或non
表示"忽略所有对象捕捉模式".可用前缀的完整列表可在
This is similar to how you might precede a point with end
to force the activation of the Endpoint Object Snap modifier, but in this case, none
or non
means "ignore all Object Snap modes". The full list of available prefixes may be found here.
以下是此方法的示例:
(setq p '(0.0 0.0 0.0)
q '(1.0 1.0 0.0)
)
(command "_.line" "_non" p "_non" q "")
上述注意事项:
-
下划线前缀
_
(在"_.line"
和"_non"
中使用)使AutoCAD将输入解释为非本地化的命令输入(即英语),否则,如果将此类输入提供给了非英语版本的AutoCAD,它可能在非英语语言中带有另一种含义.A few notes on the above:
The underscore prefixes
_
(as used in"_.line"
and"_non"
) cause AutoCAD to interpret the input as non-localised command input (i.e. English), else, if such input were supplied to a non-English version of AutoCAD, it may carry another meaning in the non-English language.点/句点前缀
.
(在"_.line"
中使用)使AutoCAD始终使用命令的原始定义,而不是重新定义的版本(如果用户使用The dot/period prefix
.
(as used in"_.line"
) causes AutoCAD to always use the original definition of the command, and not a redefined version (as may exist if the user has used theUNDEFINE
command).尽管上述方法承认可能存在活动的对象捕捉"模式,从而迫使每个点输入都忽略了这种模式,但是如果发出许多涉及大量点输入的命令调用,则可能会发现更干净的方法是暂时禁用对象完全捕捉,然后在程序完成后重新启用以前的活动模式.
Whilst the above method acknowledges that there may be active Object Snap modes, forcing such modes to be ignored for every point input, if you are issuing many command calls involving numerous point inputs, you may find it cleaner to simply temporarily disable Object Snap altogether, and then reenable the previously active modes following completion of your program.
实现此目的的明显方法是存储
OSMODE
系统变量的当前值,在发出command
表达式之前将该系统变量设置为0
,然后将OSMODE
系统变量重置为其先前的值,例如:The obvious way to achieve this would be to store the current value of the
OSMODE
system variable, set such system variable to0
before issuing yourcommand
expression, and then reset theOSMODE
system variable to its previous value, e.g.:(setq p '(0.0 0.0 0.0) q '(1.0 1.0 0.0) m (getvar 'osmode) ;; Store current OSMODE ) (setvar 'osmode 0) ;; Set OSMODE to 0 (disables all snaps) (command "_.line" p q "") (setvar 'osmode m) ;; Reset OSMODE to stored value
However, this method has the disadvantage that if an error occurs during the time in which
OSMODE
is set to0
, in the absence of an appropriate error handler,OSMODE
will remain equal to0
and the user will be apoplectic when they discover they have lost their Object Snap settings.因此,暂时禁用
OSMODE
的另一种优美"方法是利用16384位,该位在置位时表示对象捕捉已关闭.Therefore, a more 'graceful' way to temporarily disable
OSMODE
is to make use of bit 16384 which, when set, indicates that Object Snap has been turned off.现在,而不是使用
if
语句来测试OSMODE
值中是否存在16384
位,如果存在,请从该值中减去它,我们可以使用AutoLISPlogior
(包含按位OR
)功能可在单个表达式中说明这两种情况:Now, rather than using an
if
statement to test whether bit16384
is present in theOSMODE
value, and if so, subtract it from the value, we can make use of the AutoLISPlogior
(inclusive bitwiseOR
) function to account for both scenarios in a single expression:(setvar 'osmode (logior 16384 (getvar 'osmode)))
这将返回位
16384
与系统变量OSMODE
的当前值之间的按位包含OR
运算的结果.因此,如果16384
已经存在于值中,它将被返回,否则将被添加.This will return the result of a bitwise inclusive
OR
operation between bit16384
and the current value of theOSMODE
system variable. Therefore, if16384
is already present in the value, it will be returned, else it will be added.这可以实现如下:
(setq p '(0.0 0.0 0.0) q '(1.0 1.0 0.0) m (getvar 'osmode) ;; Store current OSMODE ) (setvar 'osmode (logior 16384 m)) ;; Turn off Object Snap (command "_.line" p q "") (setvar 'osmode m) ;; Reset OSMODE to stored value
现在,如果在关闭对象捕捉"时代码遇到错误,则对象捕捉"设置不会丢失-用户可能只需要使用 F3 重新打开对象捕捉"即可.
Now, if the code encounters an error whilst Object Snap is turned off, the Object Snap settings are not lost - the user may simply need to turn Object Snap back on using F3.
当然,要避免对象捕捉"对命令点输入的影响,最防弹的方法就是完全避免使用命令!
Of course, the most bulletproof way of avoiding the influence of Object Snap on command point input is to avoid commands entirely!
相反,您可以使用
entmakex
函数可将DXF数据直接附加到图形数据库:Instead, you can use the
entmake
orentmakex
function to append the DXF data to the drawing database directly:(setq p '(0.0 0.0 0.0) q '(1.0 1.0 0.0) ) (entmake (list '(0 . "LINE") (cons 10 p) (cons 11 q)))
或者,您可以遵循Visual LISP ActiveX路线并使用
Or, you can follow the Visual LISP ActiveX route and use the
AddLine
method of the relevant Block container, e.g. to create a Line in Modelspace you might use:(vl-load-com) (setq p '(0.0 0.0 0.0) q '(1.0 1.0 0.0) ) (vla-addline (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) (vlax-3D-point p) (vlax-3D-point q) )
这篇关于画线接近折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!