EaBIM

标题: [用户交互] 交互式创建多义线 [打印本页]

作者: 萧闫子    时间: 2014-1-8 16:39
标题: [用户交互] 交互式创建多义线
Controlling interactive polyline creation - Part 1
I received this interesting question through by email over the weekend:
“How can I ask AutoCAD to let the user to draw a Polyline (just like the user pushed Polyline button) and then just after finishing drawing get the ObjectID of that entity? Is it possible?”
This is a fun one, as there are a number of different approaches to take. I’m going to outline (or just go ahead and implement, depending on the complexity) the various possibilities – taking the first two today and the others in (a) subsequent post(s).
The idea is to define our own command, say MYPOLY, and make sure we’re left with execution control – and the object ID/entity name – after the user has defined a polyline in the drawing window.
There are two basic ways to solve this problem, and each of these has two variants. The initial (and major) choice is whether to let the standard AutoCAD PLINE command provide the user-interface for creating the polyline. Doing so is certainly simpler, assuming you want the user to have access to all the polyline options. That said, you may actually prefer to limit the user’s options (for example, not to allow width or arc segments), in which case the approach to implement the UI yourself would be better suited.
So, now to tackle the first two options...
From the MYPOLY command, we want to call the PLINE command. Once the command has completed, we want to make sure our code is being executed, which will allow us to get the polyline's object ID.
This is where we get our next choice: how to find out when the PLINE command has ended. The first option (and the one typically used from Visual LISP for this type of task) is to loop until the command is finished, checking either CMDACTIVE or CMDNAMES. This is important, as polylines can have an arbitrary number of vertices, so we don’t know exactly how long the command will take to complete (in terms of how many “pauses” the command will have, requesting a point selection from the user).

复制代码

That's where I'll stop it there for now… the other two options I want to look at both revolve around defining your own user-interface. The first will simply collect a sequence of points from the user using GetPoint(), the second uses a Jig to do the same thing (I haven’t yet decided whether to actually implement this last one or not – we’ll see how much time I have later in the week).
During the first part of this series, we looked at ways to drive the PLINE command while retaining (or regaining) the thread of execution in your application.
During this and the next post (yes, I've decided to spread the series a little thinner :-) we're going to look at how to completely replace the user-interface to the polyline command, a very useful technique in certain situations. This post focuses on the simple use of GetPoint() to request vertex information from the user; the next post will look at a more advanced technique, the Jig.
Even the "simple" user-interface implemented in the below code takes some effort. To keep things as simple as possible, the below UI code only allows the user to define zero-width, linear polyline segments - no arcs, widths, etc. As mentioned in the previous post, this might well be an advantage in your application, depending on whether you want to hide certain options from the user. This approach is certainly not ideal if you do want to allow interactive selection of arc segments; the two approaches suggested last time, or the one shown in the next entry, would work better in that case.
A few notes on the implementation:
Temporary graphics are used to draw each polyline segment as soon as both its vertices have been defined
The actual polyline entity is only created once all the vertices have been selected
Point selection happens in the User Coordinate System, so we need to do some work to transform selected points to the Entity Coordinate System (or Object Coordinate System) belonging to the polyline. 2-dimensional polylines are planar entities and have their vertices defined as 2D points relative to the origin and normal of the polyline, so we use a "Plane" object to help us get the 2D points to feed to the polyline's AddVertexAt() function
Here's the code in C#

复制代码

Here's what happens when we execute this code:

复制代码
Next time we'll look at how we can use a Jig for this task.

作者: 苦田辛君    时间: 2014-3-10 13:26
顶......
楼下跟上.....
作者: 野风    时间: 2014-3-11 11:06
顶!!!!!!!!!!!!
作者: AK47    时间: 2014-3-11 11:09
顶起来…………
作者: 冰雨    时间: 2014-3-11 11:17
楼主辛苦……
作者: 车奴    时间: 2014-3-11 11:20
顶!!!!!!!!!!
作者: 妮可    时间: 2014-3-14 11:19
路过!!!
不发表意见……
作者: 雁田佬    时间: 2014-3-14 11:22
路过!!!
帮顶……
作者: zpklfruV    时间: 2014-3-14 11:29
顶!!!!!!!!!!
作者: lw7511    时间: 2014-3-14 11:33
路过!!!
帮顶……
作者: 静儿    时间: 2014-5-13 10:17
顶起来…………
作者: best    时间: 2014-5-13 10:21
路过!!!
帮顶……
作者: 元劭    时间: 2014-5-13 10:31
顶!!!!!!!!!!!!!!!!!!!!!!!!!
作者: 毫半字    时间: 2014-5-13 10:32
顶......
楼下跟上.....
作者: 月之影    时间: 2014-5-20 14:30
顶!!!!!!!!!!!!!!!!!!!!!!!!!
作者: 一梦千寻    时间: 2014-5-22 15:46
顶!!!!!!!!!!
作者: AK47    时间: 2014-6-9 15:47
路过!!!
帮顶……
作者: chen_0003    时间: 2014-6-9 15:52
顶!!!!!!!!!!!!!!!!!!!!!!!!!
作者: 野风    时间: 2014-6-11 18:13
顶!!!!!!!!!!
作者: 飞天舞    时间: 2014-6-11 18:15
路过!!!
帮顶……
作者: 黑超BB    时间: 2014-6-13 14:14
顶!!!!!!!!!!
作者: gba8297517    时间: 2014-6-13 14:20
顶!!!!!!!!!!!!!!!!!!!!!!!!!
作者: 一梦千寻    时间: 2014-6-13 14:29
顶......
楼下跟上.....
作者: 蓝天POLO    时间: 2014-6-13 14:33
顶起来…………




欢迎光临 EaBIM (https://eabim.net/) Powered by Discuz! X3.2