Você está na página 1de 8

Using a modeless .

NET dialog to display AutoCAD object properties - Through the Interface


http://through-the-interface.typepad.com/through_the_interface/2007/06/using-a-modeles.html[14/01/2014 18:23:38]
Translate this page Spanish
Microsoft

Translator
K E A N W A L M S L E Y

About the Author
Kean on Google+
J A N U A R Y 2 0 1 4
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
P O S T I N D E X
R E V E R S E I N D E X
Using a modal .NET dialog to display AutoCAD object properties | Main |
Applying a gradient fill to an AutoCAD hatch using .NET
June 29, 2007
Using a modeless .NET dialog to display AutoCAD object
properties
In this previous post we looked at creating a simple modal dialog and using it to
display object properties. This post looks at the structural changes you need to
make to your application for the same dialog to be used modelessly. In a later
post we'll look at the benefits you get from leveraging the Palette system for
modeless interaction inside AutoCAD.
Firstly, let's think about the interaction paradigm needed by a modeless dialog. A
few things come to mind:
There is no longer a need to hide and show the dialog around selection
Rather than asking the user to select an entity, it's neater to respond to
standard selection events
We no longer need a "browse" button
We now need to be more careful about document access
Our command automatically locked the document (and had
sole access) in the modal example
We should now lock it "manually" when we access it
So we can already simplify our dialog class - here's some modified C#code, with
the browse button removed and document-locking in place:
usi ng Aut odesk. Aut oCAD. Appl i cat i onSer vi ces;
usi ng Aut odesk. Aut oCAD. Dat abaseSer vi ces;
usi ng Aut odesk. Aut oCAD. Edi t or I nput ;
usi ng Aut odesk. Aut oCAD. Runt i me;
usi ng Syst em;
usi ng Syst em. Col l ect i ons. Gener i c;
usi ng Syst em. Component Model ;
usi ng Syst em. Dat a;
usi ng Syst em. Dr awi ng;
usi ng Syst em. Text ;
usi ng Syst em. Wi ndows. For ms;
namespace Cust omDi al ogs
{
publ i c par t i al cl ass TypeVi ewer For m : For m
{
publ i c TypeVi ewer For m( )
{
I ni t i al i zeComponent ( ) ;
}
1 0 R A N D O M
P O S T S
F E E D / S H A R E
Subscribe via RSS
ShareThis
675 Like
S E A R C H

Under the hood:
AutoCADs J avaScript API
Does anyone out there
use unnamed, empty (or
emptyish) groups in
AutoCAD?
Creating a layer group
inside AutoCAD using
.NET
Hosting our ASP.NET
Web API project on
Windows Azure Part 2
Linking Circles, Part 1:
Using .NET events to
relate AutoCAD geometry
J anuarys Plugin of the
Month live on Autodesk
Labs: DrawOrder By
Layer for AutoCAD
Using AJ AX to generate
pages hosting Freewheel
views
The Evolution of Autodesk
University
3D printing Star Wars
weaponry using an
AutoCAD model
Wolfram|Alpha a
computational knowledge
engine in the cloud
C A T E G O R I E S
3D printing 3ds Max
AJ AX Android Annotation
scaling Arduino
ASP.NET Async AU
Augmented Reality
AutoCAD
Spanish

Using a modeless .NET dialog to display AutoCAD object properties - Through the Interface
http://through-the-interface.typepad.com/through_the_interface/2007/06/using-a-modeles.html[14/01/2014 18:23:38]
A U T O D E S K B L O G S
AutoCAD Insider
Between the Lines
It's Alive in the Lab
Mod the Machine
The Building Coder
It's All J ust Ones and Zeros
Dances with Elephants
AutoCAD DevBlog
Cloud and Mobile DevBlog
AEC DevBlog
Manufacturing DevBlog
Infrastructure Modeling DevBlog
Around the Corner
More on autodesk.com...
publ i c voi d Set Obj ect Text ( st r i ng t ext )
{
t ypeText Box. Text = t ext ;
}
publ i c voi d Set Obj ect I d( Obj ect I d i d)
{
i f ( i d == Obj ect I d. Nul l )
{
Set Obj ect Text ( " " ) ;
}
el se
{
Document doc =
Aut odesk. Aut oCAD. Appl i cat i onSer vi ces.
Appl i cat i on. Document Manager . Mdi Act i veDocument ;
Document Lock l oc =
doc. LockDocument ( ) ;
usi ng ( l oc)
{
Tr ansact i on t r =
doc. Tr ansact i onManager . St ar t Tr ansact i on( ) ;
usi ng ( t r )
{
DBObj ect obj = t r . Get Obj ect ( i d, OpenMode. For Read) ;
Set Obj ect Text ( obj . Get Type( ) . ToSt r i ng( ) ) ;
t r . Commi t ( ) ;
}
}
}
}
pr i vat e voi d cl oseBut t on_Cl i ck( obj ect sender , Event Ar gs e)
{
t hi s. Cl ose( ) ;
}
}
}
So which event should we respond to, to find out when objects are selected? In
this case I chose a PointMonitor - this class tells you a lot of really useful
information about the current selection process. It also has the advantage of
picking up the act of hovering over objects - no need for selection to actually
happen. One other fun option would have been to use a Database event
(ObjectAppended) to display information about objects as they are added to the
drawing.
A few other comments about the code:
Predictably enough we now use ShowModelessDialog rather than
ShowModalDialog()
We have our form as a member variable of the class, as its lifespan
goes beyond the command we use to show it
I've also removed the selection code; we're no longer asking for objects
to be selected
Here's the updated command implementation:
usi ng Aut odesk. Aut oCAD. Appl i cat i onSer vi ces;
usi ng Aut odesk. Aut oCAD. Dat abaseSer vi ces;
usi ng Aut odesk. Aut oCAD. Edi t or I nput ;
usi ng Aut odesk. Aut oCAD. Runt i me;
usi ng Syst em;
usi ng Cust omDi al ogs;
AutoCAD
.NET AutoCAD OEM
Autodesk Autodesk
Exchange AutoLISP /
Visual LISP Azure Batch
processing Blocks
Books Civil 3D
Commands Concurrent
programming Conferences
Core Console Custom
objects Database
Debugging Design
DesignScript DevCasts
DevTV Dimensions
Documents Draw order
Drawing structure DWF
Dynamic Dynamic Blocks
Excel F# Facebook
Fields Fractals
Freewheel Games
Geometry Graphics
system Hatches HTML
Installation Instructables
Interviews Inventor iOS
IronPython IronRuby
J ava J avaScript J igs
J SON Kinect Leap
Motion LINQ Mac
Mobile Morgan Netduino
Notification / Events
Object properties
ObjectARX Overrules
Personal Plotting Plugin
of the Month Point
clouds Purge Python
Raspberry Pi RealDWG
Reality capture REST
Retro computing Revit
Robotics Ruby Runtime
SaaS Security
Selection Social media
Solid modeling Tables
Tinkercad Training
Transactions Translation
Travel Unity3D User
interface Visual Basic &
VBA Visual Studio
Web/Tech Weblogs
WinRT WPF XML
R E C E N T
P O S T S
Forcing AutoCAD object
snapping using .NET
Update on purging DGN
linestyles from AutoCAD
drawings using .NET
AU 2013 classes available
on-demand
Attack of the robots
Happy 2014
Merry Christmas!
Moving text in an
AutoCAD block using
.NET Part 3
Disabling snapping to
specific AutoCAD objects
using .NET Part 2
Disabling snapping to
specific AutoCAD objects
using .NET Part 1
Using a modeless .NET dialog to display AutoCAD object properties - Through the Interface
http://through-the-interface.typepad.com/through_the_interface/2007/06/using-a-modeles.html[14/01/2014 18:23:38]
namespace Cust omDi al ogs
{
publ i c cl ass Commands
{
TypeVi ewer For m t vf ;
publ i c Commands( )
{
t vf = new TypeVi ewer For m( ) ;
Document doc =
Appl i cat i on. Document Manager . Mdi Act i veDocument ;
Edi t or ed = doc. Edi t or ;
ed. Poi nt Moni t or +=
new Poi nt Moni t or Event Handl er ( OnMoni t or Poi nt ) ;
}
~Commands( )
{
t r y
{
t vf . Di spose( ) ;
Document doc =
Appl i cat i on. Document Manager . Mdi Act i veDocument ;
Edi t or ed = doc. Edi t or ;
ed. Poi nt Moni t or - =
new Poi nt Moni t or Event Handl er ( OnMoni t or Poi nt ) ;
}
cat ch( Syst em. Except i on)
{
/ / The edi t or may no l onger
/ / be avai l abl e on unl oad
}
}
pr i vat e voi d OnMoni t or Poi nt (
obj ect sender ,
Poi nt Moni t or Event Ar gs e
)
{
Ful l Subent i t yPat h[ ] pat hs =
e. Cont ext . Get Pi ckedEnt i t i es( ) ;
i f ( pat hs. Lengt h <= 0)
{
t vf . Set Obj ect I d( Obj ect I d. Nul l ) ;
r et ur n;
};
Obj ect I d[ ] obj s = pat hs[ 0] . Get Obj ect I ds( ) ;
i f ( obj s. Lengt h <= 0)
{
t vf . Set Obj ect I d( Obj ect I d. Nul l ) ;
r et ur n;
};
/ / Set t he " sel ect ed" obj ect t o be t he l ast i n t he l i st
t vf . Set Obj ect I d( obj s[ obj s. Lengt h - 1] ) ;
}
[ CommandMet hod( " vt " , CommandFl ags. UsePi ckSet ) ]
publ i c voi d Vi ewType( )
{
Local presentations and
musings on AR/VR
R E C E N T
C O M M E N T S
R.K. McSwain on Update
on purging DGN linestyles
from AutoCAD drawings
using .NET
Kean Walmsley on
Update on purging DGN
linestyles from AutoCAD
drawings using .NET
R.K. McSwain on Update
on purging DGN linestyles
from AutoCAD drawings
using .NET
Kean Walmsley on
Disabling snapping to
specific AutoCAD objects
using .NET Part 1
Scott Pause on Creating a
motion-detecting security
cam with a Raspberry Pi
Part 2
Scott Pause on Creating a
motion-detecting security
cam with a Raspberry Pi
Part 2
Scott Pause on Creating a
motion-detecting security
cam with a Raspberry Pi
Part 2
Kean Walmsley on
Disabling snapping to
specific AutoCAD objects
using .NET Part 1
Mark Douglas on
Disabling snapping to
specific AutoCAD objects
using .NET Part 1
Kean Walmsley on Minor
update to the DGN Purge
command
A R C H I V E S
J anuary 2014 (5)
December 2013 (9)
November 2013 (13)
October 2013 (13)
September 2013 (13)
August 2013 (14)
J uly 2013 (14)
J une 2013 (12)
May 2013 (14)
April 2013 (13)
March 2013 (12)
February 2013 (12)
J anuary 2013 (15)
Using a modeless .NET dialog to display AutoCAD object properties - Through the Interface
http://through-the-interface.typepad.com/through_the_interface/2007/06/using-a-modeles.html[14/01/2014 18:23:38]
Comments
Using a modal
.NET dialog to
display AutoCAD
object ...
Using a modeless
.NET dialog to
display properties
of ...
Using a palette
from .NET to
display properties
of multiple ...
Accessing the
AutoCAD objects
referred to by fields
using ...
Appl i cat i on. ShowModel essDi al og( nul l , t vf , f al se) ;
}
}
}
And here's the source project for this version of the application. When you run the
application you may experience issues with the dialog getting/retaining focus - this
is generally a problem with modeless dialogs that has been addressed
automatically by the Palette class, something we'll take a look at in a future post.
You might also like:
Linkwithin
Posted at 07:03 AM in AutoCAD, AutoCAD .NET, Object properties, User interface | Permalink
TrackBack
TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83452464869e200e0098798658833
Listed below are links to weblogs that reference Using a modeless .NET dialog to
display AutoCAD object properties:
Reply July 02, 2007 at 04:31 PM
Thank you for the code sample, and I have a question?
If you have for example, a polyline in the for of a slot
when two of the sides have an arc, and you have other
polylines that meet those sides and all around that slot
to leave it as an island.
Pointmonitor do not work and I have seen other cases
where fail to select.
Is there something we can do?
I have tried to use this class before in one of my
commands to select closed areas but not always was
giving me the right one.
Then, I end up making a selection of the closed
polylines on the screen and using a function to select
the polyline by defining an internal point, instead.
Thanks!
Luis.
Luis said...
December 2012 (12)
November 2012 (13)
October 2012 (14)
September 2012 (12)
August 2012 (13)
J uly 2012 (9)
J une 2012 (13)
More...
Using a modeless .NET dialog to display AutoCAD object properties - Through the Interface
http://through-the-interface.typepad.com/through_the_interface/2007/06/using-a-modeles.html[14/01/2014 18:23:38]
Reply July 06, 2007 at 05:37 AM
I have been using PointMonitor to display information
about the entity via AppendToolTipText. It works great
except for one thing: My drawing is mostly solids and if I
hover over a solid so that it is highlighted, it will actually
display the information of the solid that is behind the
object that I'm trying to get the information for.
How can I assure that I get the information for the
object that is being highlighted?
Tom said...
Reply July 06, 2007 at 11:39 AM
Luis -
I'm afraid your description of the geometry isn't clear to
me. Are you trying to detect when the cursor is hovering
within a particular object? Unfortunately "pick in space"
is not enabled when hovering over objects - the
PointMonitor doesn't pick them up. Unless I've
misunderstood...
Tom -
I'm not sure why this is happening. One thought is to
make sure you're not picking the wrong item from the
list (assuming there are more than one entity returned
by the PointMonitor). I tried to reproduce the problem in
my own code, but it seemed to work OK - a lot may
depend on which visual style you're working with, etc.
Regards,
Kean
Kean said...
Kean;
Excuse my bad explanation :(
Let see if I can explain better this time, by providing a
short sample that can give you an idea:
Draw an ellipse (with pellipse=1), then draw a rectangle
to enclosure that ellipse in the center.
Then, draw a line that divides the rectangle, can be
drawn vertical or horizontal. Then use the command
bpoly and generate two new closed polylines in the
areas between the rectangle and the ellipse on the
center.
Erase, the original rectangle, and the line, and now call
or use the pointmonitor, it won't select the ellipse, I
know it can be brought up with draworder and later use
the pointmonitor.
The sample I provided it is very simple, but in the case I
was thinking of using it it gets more complex, and the
idea is have an easy selection, that's why I end up
Luis said...
Using a modeless .NET dialog to display AutoCAD object properties - Through the Interface
http://through-the-interface.typepad.com/through_the_interface/2007/06/using-a-modeles.html[14/01/2014 18:23:38]
Reply July 07, 2007 at 04:38 AM
using a point inside the areas.
Hope, you are not sleep when reading this last line.
Thanks!
Reply July 09, 2007 at 03:21 PM
Luis,
I think the PointMonitor is working OK... check out the
latest post in this series to see if the code in there
helps.
Regards,
Kean
Kean said...
Reply July 20, 2007 at 04:11 PM
Hi Kean,
is it possible to have some examples of dockable
modelss dialogs using .Net? (no palettes)
thanks a lot in advance
David
David said...
Reply July 20, 2007 at 06:49 PM
Hi David,
The parent of CAdUiPaletteSet (the internal
MFC/ObjectARX class the PaletteSet wraps) is
CAdUiDockControlBar, which is not exposed through
the .NET API.
So PaletteSet is currently the way to go for
implementing a dockable modeless UI inside AutoCAD
using .NET.
Is there a particular reason you'd prefer not to use it?
Regards,
Kean
Kean said...
Hi,
1)loading
2)calling "VT"
3)terminating the dialogbox
4)recalling "VT" -->Throws an Exception! (Can't access
the object, Objectname: TypeViewerForm)
Regards,
David
David said...
Using a modeless .NET dialog to display AutoCAD object properties - Through the Interface
http://through-the-interface.typepad.com/through_the_interface/2007/06/using-a-modeles.html[14/01/2014 18:23:38]
Reply August 08, 2007 at 02:18 PM
Reply August 08, 2007 at 06:51 PM
Hi David,
It seems the form is betting disposed, and we then want
to bring it up again. One option is to call this.Hide() in
the closebutton handler, but we'd then have to set the
dialog not to show the "X" button.
The better option is probably to check for the availability
of the form inside the VT command implementation,
creating it again, as necessary:
[CommandMethod("vt",CommandFlags.UsePickSet)]
public void ViewType()
{
if (tvf == null || tvf.IsDisposed)
tvf =new TypeViewerForm();
Application.ShowModelessDialog(null, tvf, false);
}
Cheers,
Kean
Kean said...
Reply August 22, 2008 at 01:51 AM
Hi Kean, sorry if this is not relevant, but I would like to
draw the AutoCAD objects like lines and circles on the
dialog itself (or part of the dialog, a dialog item). Is this
possible?
Your help is greatly appreciated.
Cheers, Nabil.
Nabil Sleiman said...
Reply August 22, 2008 at 08:11 AM
Hi Nabil,
If you need to display entities from a drawing or even
temporary entities you add on the fly, you should look at
the BlockView sample.
Regards,
Kean
Kean said...
".. you may experience issues with the dialog
getting/retaining focus - this is generally a problem with
modeless dialogs.."
Hi Kean,
Would you please help me in finding a way to get/retain
ali said...
Using a modeless .NET dialog to display AutoCAD object properties - Through the Interface
http://through-the-interface.typepad.com/through_the_interface/2007/06/using-a-modeles.html[14/01/2014 18:23:38]
Comment below or sign in with Typepad Facebook Twitter Google+
and more...
(You can use HTML tags like <b> <i> and <ul> to style your text. URLs
automatically linked.)
Email address is not displayed with comment.

Reply June 03, 2013 at 03:28 PM
focus in a modeless form?
Many Thanks,
Reply June 04, 2013 at 12:16 PM
Hi ali,
I can't, right now. You might try posting to the
AutoCAD .NET discussion group, to see if
someone there can help.
Regards,
Kean
Kean Walmsley said in reply to ali...
Name
Email Address
Web Site URL
Post Preview

Você também pode gostar