Вы находитесь на странице: 1из 81

AutoCAD .

NET API
Developer Technical Services

Autodesk Presentation Title

!ettin" Ac#uainted
The Developer Technical Services Group

Who Are You?

Autodesk Presentation Title

200 Autodesk

Developer Technical Services


Worldwide Workgroup %ver 2 Specialists &orld &ide 'irtuall( 2) hour support* da(s a +eek Americas Team ,S -CA* A.* &A/* Canada* 0ra1il European Team S+it1erland* ,nited 2in"do3* 4rance* C1ech 5epu6lic* 5ussia APac Team China* 7apan* India

Autodesk Presentation Title

200 Autodesk

!ettin" Support
http: www!autodesk!com adn"devhelp Provides access to
%n8line kno+led"e 6ase Call su63ission Ne+s"roups

Calls are lo""ed auto3aticall(


18$ da( turnaround Call6acks as needed

Ans+ers to 9re#uentl( asked #uestions are posted in our on8line kno+led"e 6ase

Autodesk Presentation Title

200 Autodesk

Course %6:ective
#t is to understand: the 9unda3entals o9 the AutoCAD .NET API ho+ to teach (oursel9 the AutoCAD .NET API +here to "et help a9ter+ards What it is not: Teach (ou .NET 9ra3e+ork or C; * '0 pro"ra33in" lan"ua"e !ive (ou co3plete o9 covera"e o9 all API 9unctions

Autodesk Presentation Title

200 Autodesk

Class A"enda
$ectures with $a%s Slides "ive an abstract overvie+ =a6s and discussion "ive a practical perspective $ectures &verview o' !(ET! AutoCAD .NET 'isual Studio pro:ect settin"s > ?ello &orld@ ,ser Interaction 8 Si3ple ,ser Input and Entit( Selection Data6ase 4unda3entals > S(36ol ta6les* Transactions Data6ase 4unda3entals > Dictionaries* A5ecords* Ta6le Traversal Bore ,ser Interaction > Advanced Pro3pts ,ser Inter9ace desi"n 8 &in4or3 Dialo"s and Palettes Event handlin" > 5eactin" to AutoCAD Events in .NET.

Autodesk Presentation Title

<

200 Autodesk

Class Schedule
Time ):** " +:** =unch 12D00 8 1D00 Da, %vervie+ o9 .NET 'isual Studio Pro:ect Settin"s > =a6 1 Si3ple ,ser Input > =a6 2 Data6ase 4unda3entals > =a6 $ Bore Data6ase 4unda3entals > =a6 ) Da, . Bore ,ser Input > =a6 ,ser Inter9ace Desi"n > &in9or3 Dialo"s and Palettes > =a6 < Event ?andlin" > =a6 C

Autodesk Presentation Title

200 Autodesk

FuestionsG

Autodesk Presentation Title

200 Autodesk

.NET %vervie+

&hat

is .NETG o9 pro"ra33in" in .NET Concepts

0ene9its

I3portant

Autodesk Presentation Title

200 Autodesk

.NET %vervie+
What is !(ET?

Bicroso9tIs Technolo"( o9 a &e6 6ased in9rastructure


Sea3less interaction 6et+een applications and the Internet Access in9or3ation across an(ti3e* an(+here 9ro3 an( device

Autodesk Presentation Title

10

200 Autodesk

.NET %vervie+
What is !(ET?

/omponents o' !(ET

The .NET 4ra3e+ork used 9or 6uildin" and runnin" all kinds o9
so9t+are* includin" &e686ased applications* s3art client applications* and AB= &e6 Services

Developer tools such as Bicroso9t 'isual Studio .NET A set o9 servers that inte"rate* run* operate* and 3ana"e &e6

services and &e686ased applications

Client so9t+are that helps developers deliver a deep and co3pellin"


user eJperience across a 9a3il( o9 devices and eJistin" products.

Autodesk Presentation Title

11

200 Autodesk

.NET 4ra3e+ork
40 /66 /7 8Script 9 4isual Studio!(ET

/ommon $anguage Speci'ication ASP!(ET Windows 5orms

Data and 23$ 0ase /lass $i%rar, /ommon $anguage 1untime

Autodesk Presentation Title

12

200 Autodesk

.NET %vervie+
What is !(ET?

(ET 5ramework

Co33on =an"ua"e 5unti3e -C=5/


%6:ect8%riented pro"ra33in" environ3ent Co33on eJecution environ3ent 9or .NET applications "Similar to 8ava 43 : %ut with much stronger interopera%ilit,

4ra3e+ork Class =i6rar( -4C=/

%6:ect %riented Collection o9 re8usa6le t(pes

(Source: MSDN)
Autodesk Presentation Title 1$
200 Autodesk

.NET %vervie+

C=5 EJecution Bodel


Source code /ompiler 3anaged /ode <dll or e;e= 40 v%c!e;e Assem%l, #$ /ode /7 csc!e;e Assem%l, #$ /ode /66 cc!e;e Assem%l, #$ /ode

/ommon $anguage 1untime


8#T /ompiler
(ative /ode

&perating S,stem Services


Autodesk Presentation Title 1)
200 Autodesk

&hat is Bicroso9t .NETG

&hat +e kno+ 9ro3 our eJperience so 9arK


#ntelligent s,m%olic representation

Bature lan"ua"e constructs Collections* Events* Dele"ates Co33on pro"ra33in" pit9alls addressed Be3or( 3ana"e3ent* consistent EJception handlin"* uni9ied strin"s

Source and %inar, inter"module communication Programming st,le

"oes 6e(ond CLL and C%B Beta data allo+s desi"n8 and run8ti3e o6:ect usa"e and eJtension Bultiple supported lan"ua"es > Choose (our +eapons

Autodesk Presentation Title

200 Autodesk

.NET %vervie+

&hat

is .NETG o9 pro"ra33in" in .NET Concepts

0ene9its

I3portant

Autodesk Presentation Title

1<

200 Autodesk

.NET %vervie+
0ene'its o' programming in !(ET

Consistent %6:ect %riented Develop3ent plat9or3 Auto3atic 3e3or( 3ana"e3ent > !ar6a"e collection Support 9or 3ultiple lan"ua"es

(Source: MSDN)
Autodesk Presentation Title 1C
200 Autodesk

.NET %vervie+
/onsistent &%>ect &riented Development plat'orm Everything you see can be treated as an Object! Dim m,$ine As (ew $ine<= m,$ine!StartPoint ? (ew Point@d<*A *A *= m,$ine!EndPoint ? (ew Point@d<-*A -*A *= m,$ine!Get/losestPointTo<(ew Point@d<+A +!-A *=A 5alse= Dim ; as #nterger ? B Dim s as String ? ;!ToString<=

%6:ects are instances o9 a Type or C ass -9or eJa3ple m,$ine is an o6:ect and $ine is a t(pe/ %6:ects have properties such as StartPoint* and 3ethods such as Get/losestPointTo<=
1E
200 Autodesk

Autodesk Presentation Title

.NET %vervie+
/onsistent &%>ect &riented Development plat'orm Mature API Constructs
Whats wrong with this function? int acedSS!et-const char M str* const void M pt1* const void M pt2* const struct res6u9 M 9ilter* adsNna3e ss/O

Autodesk Presentation Title

1H

200 Autodesk

.NET %vervie+
/onsistent &%>ect &riented Development plat'orm Mature !"# Constructs So$e % ne& c asses de'ined to encapsu ate acedSS(et() Dim values<.= As T,ped4alue CDe'ine the selection criteria values<*= ? (ew T,ped4alue<D;'/ode!StartA D/ircleE= values<-= ? (ew T,ped4alue<D;'/ode!/olorA -= Dim sel5ilter As (ew Selection5ilter<values= Dim sel&pts As (ew PromptSelection&ptions<= sel&pts!AllowDuplicates ? True C1un the selection Dim res As PromptSelection1esult ? Editor!GetSelection<sel&ptsA sel5ilter=

Autodesk Presentation Title

20

200 Autodesk

.NET %vervie+
0ene'its o' programming in !(ET

Consistent %6:ect %riented Develop3ent plat9or3 Auto3atic 3e3or( 3ana"e3ent -!ar6a"e collection/ and consistent e;ception handling Support 9or 3ultiple lan"ua"es

(Source: MSDN)

Autodesk Presentation Title

21

200 Autodesk

.NET %vervie+
0ene'its o' programming in !(ET
Automatic memory management

%ld &a( -CLL/ 8 Potential 9or 3e3or( leaks@

char MpNa3eP-charM/3alloc-12E/O strcp(-pNa3e*Q?elloQ/O RR... 9ree-pNa3e/O

Ne+ &a( 8 .NET


CLL 8 Strin" MpNa3ePne+ Strin"-Q?elloQ/ '0 8 Di3 Na3e As Strin" P Q?elloQ C; 8 Strin" Na3ePS?elloTO

RR !ar6a"e collection handles deallocationO no UdeleteI@

Autodesk Presentation Title

22

200 Autodesk

.NET %vervie+
0ene'its o' programming in !(ET
Consistent e)ception hand ing

%ld &a( > '0D Can 6e ver( con9usin" and pro6le3atic@ &n Error GoTo Fne;pectedError Dim ; As Dou%le?-* * C9errorG Fne;pectedError: 3sg0o; StrH<Err!(um%er= Ne+ > '0 .NET Tr, Dim ; As Dou%le?-* * C9error which throws e;ception /atch C9what happened? Division %, IeroG 5inall, C9cleanup " do this either wa, End Tr,
2$
200 Autodesk

Autodesk Presentation Title

.NET %vervie+
0ene'its o' programming in !(ET

Consistent %6:ect %riented Develop3ent plat9or3 Auto3atic 3e3or( 3ana"e3ent -!ar6a"e collection/ and consistent e;ception handling Support 9or 3ultiple lan"ua"es

(Source: MSDN)

Autodesk Presentation Title

2)

200 Autodesk

.NET %vervie+
0ene'its o' programming in !(ET
Support 'or multiple languages

C;* '0 3ost co33onl( used Can interop 6et+een code +ritten in di99erent lan"ua"es. 4or eJa3ple* a class +ritten in C; can 6e inherited 9ro3 a class +ritten in '0@ In 9act* AutoCADIs 3ana"ed asse36lies are +ritten usin" 3ana"ed CLL +hich (ou +ill access 9ro3 '0.NET. No si"ni9icant di99erence in per9or3ance as all lan"ua"es co3pile to I= -Inter3ediate =an"ua"e/ eJecuted 6( the C=5

Autodesk Presentation Title

200 Autodesk

.NET %vervie+

&hat

is .NETG o9 pro"ra33in" in .NET Concepts

0ene9its

I3portant

Autodesk Presentation Title

2<

200 Autodesk

.NET %vervie+
#mportant /oncepts Assem%lies V 5undamental unit o' deplo,ment and e;ecution in !(ET Contains a 3ani9est that descri6es the asse36l( V 0oundar, 'or code e;ecution and access permission Asse36l( Bani9est
Na3eG &hat 9iles 3ake up the asse36l(G Dependent asse36liesG 'ersion and CultureG

net3odule

Dlls

03p

(Source: MS !"
Autodesk Presentation Title 2C
200 Autodesk

Class A"enda
$ectures and $a%s

%vervie+ o9 .NET. Auto/AD !(ET 4isual Studio pro>ect settings : Jello WorldG ,ser Interaction 8 Si3ple ,ser Input and Entit( Selection Data6ase 4unda3entals > S(36ol ta6les* Transactions Data6ase 4unda3entals > Dictionaries* A5ecords* Ta6le Traversal Bore ,ser Interaction > Advanced Pro3pts ,ser Inter9ace desi"n 8 &in4or3 Dialo"s and Palettes Event handlin" > 5eactin" to AutoCAD Events in .NET.

Autodesk Presentation Title

2E

200 Autodesk

AutoCAD .NET API Docu3entation


*o& do # get started+ &%>ectA12 SDK #ncludes: SD2 Sa3ples@ %6:ectA5A DeveloperIs !uide Bana"ed 5e9erence !uide

ArJ3"d.ch3

AD( we%site DevNotes Dev?elp %nline 4isual Studio /lass 0rowser


Autodesk Presentation Title 2H
200 Autodesk

Develop3ent Environ3ent
3icroso't 4isual Studio .**L or .**+ Auto/AD .*-* 3icroso't Windows 2P or 3icroso't Windows vista

Autodesk Presentation Title

$0

200 Autodesk

.NET De6u""in" Tools

5e9lector

0ro+se .NET asse36lies* disasse36le* deco3pile httpDRRsharptool6oJ.3ad"eek.co3 Disasse36le .NET asse36lies 'isual Studio Tools Dia"nose load ti3e pro6le3s 'isual Studio Tools Check con9or3ance +ith Desi"n !uidelines httpDRR+++."otdotnet.co3Rtea3R9JcopR

Ildas3

4uslo"v

4JCop

Autodesk Presentation Title

$1

200 Autodesk

Snoop Tools -9or AutoCADIs data6ase/


ArJD6" -CLL/ B"dD6"-C;/

%6:ectA5A SD2 ADN

Autodesk Presentation Title

$2

200 Autodesk

'isual Studio pro:ect settin"s> ?ello &orld@


Start +ith a Class =i6rar( application t(pe +ith D== output. Add re9erences to AutoCADIs 3ana"ed asse36lies

acd63"d.dll

Data6ase services and D&! 9ile 3anipulation -like %6:ectD0A/ AutoCAD Application speci9ic -like %6:ectA5A/

ac3"d.dll

4ind the3 in the AutoCAD install 9older -set C%PW =%CA= P 4A=SE/

/:MProgram 5ilesMAuto/AD .*-*M /:M&%>ectA12 .*-*Minc"win@. <or /:M&%>ectA12 .*-*Minc";NO=

Autodesk Presentation Title

$$

200 Autodesk

'isual Studio pro:ect settin"s> ?ello &orld@


1e'erence namespaces ,ou will use in ,our pro>ect In '0.NET ,se I3ports ke(+ordD #mports Autodesk!Auto/AD!ApplicationServices Access to the Auto/AD application #mports Autodesk!Auto/AD!Editor#nput Access to the Auto/AD editor #mports Autodesk!Auto/AD!1untime /ommand registration #mports Autodesk!Auto/AD!Data%aseServices Access to the Auto/AD Data%ase and Entities

Autodesk Presentation Title

$)

200 Autodesk

'isual Studio pro:ect settin"s> ?ello &orld@


Add a simple command : JelloWorld

Bake a 9unction an AutoCAD co33and 6( addin" an attribute Pu%lic /lass /lassP/ommand3ethod<QJelloWorldQ=R S Pu%lic 5unction JelloWorld<= End 5unction End /lass

The attri6ute is added to the 3etadata 9or that 9unction

Co33andBethod or Co33andBethodAttri6ute t(pe accepts several para3eters in its constructor such as "roup na3e* "lo6al and local na3es* co33and 9la"s and 3ore -,se the o6:ect 6ro+ser/
$
200 Autodesk

Autodesk Presentation Title

'isual Studio pro:ect settin"s> ?ello &orld@


To print a string to command line

!et the editor ob#ect 9or the active docu3ent Dim ed As Editor ?
Application!Document3anager!3diActiveDocument!Editor

Call the editorIs &riteBessa"e 3ethod Pu%lic /lass /lassP/ommand3ethod<QJelloWorldQ=R S Pu%lic 5unction JelloWorld<= ed!Write3essage<QJello WorldQ= End 5unction End /lass

Autodesk Presentation Title

$<

200 Autodesk

=oadin" .NET asse36l(


NET=%AD co33and De3and =oad -5e"istr(/ Startup %n co33and invocation %n re#uest

%n proJ( detection

5rom another application

TJKEYS$&/A$S3A/J#(EMS&5TWA1EMAutodeskMAuto/ADM1-L!*MA/AD" L**-:O*)MApplicationsMAc$a,erU QDES/1#PT#&(Q?QAuto/AD $a,er 3anagerQ Q$&ADE1Q?Q/:MMProgram 5ilesMMAuto/AD .*-*MMacla,er!dllQ Q$&AD/T1$SQ?dword:*******e Q3A(AGEDQ?dword:*******TJKEYS$&/A$S3A/J#(EMS&5TWA1EMAutodeskMAuto/ADM1-L!*MA/AD" L**-:O*)MApplicationsMAc$a,erM/ommandsU Q$AYE1Q?Q$AYE1Q TJKEYS$&/A$S3A/J#(EMS&5TWA1EMAutodeskMAuto/ADM1-L!*MA/AD" L**-:O*)MApplicationsMAc$a,erMGroupsU QA/$AYE1S/3DSQ?QA/$AYE1S/3DSD

,se #nsta ers to set these -eys!


Autodesk Presentation Title $C
200 Autodesk

=a6 1 > ?ello &orld@

Autodesk Presentation Title

$E

200 Autodesk

Class A"enda
$ectures and $a%s

%vervie+ o9 .NET. AutoCAD .NET 'isual Studio pro:ect settin"s > ?ello &orld@ Fser #nteraction " Simple Fser #nput and Entit, Selection Data6ase 4unda3entals > S(36ol ta6les* Transactions Data6ase 4unda3entals > Dictionaries* A5ecords* Ta6le Traversal Bore ,ser Interaction > Advanced Pro3pts ,ser Inter9ace desi"n 8 &in4or3 Dialo"s and Palettes Event handlin" > 5eactin" to AutoCAD Events in .NET.

Autodesk Presentation Title

$H

200 Autodesk

Pro3ptin" 9or ,ser Input

,se Pro3pt$$$%ptions to set the para3eters 9or pro3ptin"


$$$ is the value t(pe +e +ant to pro3pt* such as An"le* Strin"* Distance* Corner etc. ,se Bessa"e and 2e(+ords properties to set the pro3pt strin" and list o9 ke(+ords ,se Allo+%%% to set conditions 9or pro3ptin". &or e'g'( Allow!egati)e

To pro3pt* use EditorIs !etAAA 9unctions


EJa3ples 8 !etAn"le* !etStrin"* !etDistance* !etCorner etc Pass Pro3pt$$$%ptions into !et$$$

5esult o9 pro3ptin" stored in Pro3pt5esult or derived t(pes

EJa3ples > Pro3ptDou6le5esult* Pro3ptInte"er5esult etc.


)0
200 Autodesk

Autodesk Presentation Title

%6:ectA5A 2010 &i1ards


AppWiVard : Templates 'or a 40!(ET or /7 application Add"#n

Autodesk Presentation Title

)1

200 Autodesk

=a6 2 > Si3ple ,ser Input

Autodesk Presentation Title

)2

200 Autodesk

Class A"enda
$ectures and $a%s

%vervie+ o9 .NET. AutoCAD .NET 'isual Studio pro:ect settin"s > ?ello &orld@ ,ser Interaction 8 Si3ple ,ser Input and Entit( Selection Data%ase 5undamentals : S,m%ol ta%lesA Transactions Data6ase 4unda3entals > Dictionaries* A5ecords* Ta6le Traversal Bore ,ser Interaction > Advanced Pro3pts ,ser Inter9ace desi"n 8 &in4or3 Dialo"s and Palettes Event handlin" > 5eactin" to AutoCAD Events in .NET.

Autodesk Presentation Title

)$

200 Autodesk

AutoCAD Dra+in" Data6ase

In8Be3or( representation o9 the D+" 4ile


%6:ects are stored hierarchicall( in the data6ase 8 D6 Structure All o6:ects have identities > %6:ectId* like Primary *ey in a relational data6ase %6:ects are al+a(s accessed in a transaction The transaction de9ines the 6oundar( o9 data6ase operations %6:ects have to 6e opened 9irst in a transaction 6e9ore the( can 6e used %6:ects can re9er to other o6:ects > such as a line havin" a re9erence to a la(er

DWG

Autodesk Presentation Title

))

200 Autodesk

Data6ase Structure
DATABASE

R12 SymbolTables

Block Table
Model Space Paper Space Other BTR

Named Object Dictionary


Dictionary Entry

Header Variables

Entity

Entity

Entity

Autodesk Presentation Title

200 Autodesk

Data6ase Co3ponents

S(36ol Ta6les

EJa3ples =a(er Ta6le* =inet(pe Ta6le* TeJtst(le Ta6le etc. Containers to store S(36ol Ta6le +ecor,s EJa3ple =a(erTa6le+ecor,* =inet(peTa6le+ecor, etc All S(36ol Ta6les have co33on 3ethods o9 a container such as Add > to add a record Ite3 > to lookup an entr( +ith a search strin" ?as > To kno+ i9 an entr( eJists Is enu3era6le Each s(36ol ta6le can hold onl( records o9 a speci9ic t(pe 4or eJa3ple* a =a(erTa6le can hold onl( =a(erTa6le5ecords

,se SnoopD6 to see +here the =a(ers reside

Autodesk Presentation Title

)<

200 Autodesk

Data6ase Co3ponents

0lock Ta6le

Child o9 S(36ol Ta6le ?olds a collection o9 0lockTa6le5ecords -or 0lock De9initions/

0lockTa6le5ecords -0T5/ in turn is a container that holds onl( "raphical entities -i.e.* those derived 9ro3 Entit( t(pe/ T+o de9ault 0lockTa6le5ecords cannot 6e re3oved > Bodel Space and one Paper Space

Searcha6le +ith a strin" or an %6:ectId -3ore on this later/ Neither the 0lock Ta6le nor the S(36ol Ta6les are created 6( the user. The( are created 6( de9ault +hen (ou create a ne+ data6ase.

Create a 6lock de9inition and use ArJD6" or B"dD6" to see +here the 6lock de9inition is stored and peek into its contents

Autodesk Presentation Title

)C

200 Autodesk

!ettin" a Data6ase %6:ect

Construct %ne

In Be3or(

!et the one currentl( active in AutoCAD

?ostApplicationServices.&orkin"Data6ase-/

Autodesk Presentation Title

)E

200 Autodesk

%6:ect Identit( 8 %6:ectID

All %6:ects that eJist in the data6ase have an %6:ectId


Is uni-ue per session -or instance/ o9 AutoCAD Is "enerated auto3aticall( 9or an o6:ect +hen it is added to the data6ase Non8data6ase resident o6:ects do not have an %6:ectId set Can 6e cached to open an o6:ect later

!et it usin" %6:ectId propert(

Autodesk Presentation Title

)H

200 Autodesk

Transactions

Transactions

Sets the 6oundar( 9or data6ase operations ?andles eJception cleanl( %perates +ith a sin"le ,ndo 9iler Can 6e co33itted > All data6ase operations are saved rolled 6ack > All data6ase operations are a6orted Can 6e nested

Autodesk Presentation Title

200 Autodesk

Nestin" Transactions
1 2
obj2 obj

Transaction 2 Transaction 1
obj1 obj2

obj1 Database obj2

obj

-! /lient starts Trans- and gets &%>- W &%>. .! /lient starts Trans. and gets &%>. W &%>@ @! /lient commits Trans. Trans. changes are committed Oa! /lient commits Trans Trans- changes are committed O%! /lient a%orts Trans- instead Trans- <and Trans.= changes are rolled %ack
Autodesk Presentation Title 1
200 Autodesk

Transactions

To start a transaction* use Data6asesI StartTransaction-/ 5or e;ample: Dim d% As Data%ase ? JostApplicationServices!WorkingData%ase<= CGet the current d% used %, Auto/AD Dim trans As Transaction ? d%!Transaction3anager!StartTransaction<= X %egin the transaction

To co33it a transaction* use transactionIs Co33it-/ To A6ort a transaction* use transactionIs A6ort-/ &hen done +ith a transaction it 3ust 6e

e;plicitl, disposedG

Autodesk Presentation Title

200 Autodesk

Transactions

Standard d6 access +ith Transactions


Pu%lic 5unction 3,5unc<= CGet the data%ase current in Auto/AD Dim d% As Data%ase ? JostApplicationServices!WorkingData%ase<= CStart a transaction using the data%ase transaction manager Dim trans As Transaction ? d%!Transaction3anager!StartTransaction<= Tr, CDo all data%ase operations here C$ets get the %lock ta%le 'rom the data%ase CDrill into the data%ase and o%tain a re'erence to the 0lockTa%le Dim %t As 0lockTa%le ? trans!Get&%>ect<d%!0lockTa%le#dA &pen3ode!5orWrite= CEver,thing success'ulA so commit the transaction trans!commit<= /atch trans!A%ort<= 5inall, CAll ok! /all Dispose e;plicitl, %e'ore e;iting trans!dispose<= End Tr, End 5unction

Autodesk Presentation Title

200 Autodesk

Transaction 8 %penin" an %6:ect


V Fse transactionYs Get&%>ect to open an o%>ect The 9irst para3eter is the %6:ectId Second para3eter is the open 3ode
4or5ead > Access 6ut not Bodi9( 4or&rite > Bodi9( and Access 4orNoti9( > &hen the o6:ect is noti9(in"

Dim %t As 0lockTa%le ? trans!Get&%>ect< S d%!0lockTa%le#dA S &pen3ode!5orWrite S =

Autodesk Presentation Title

200 Autodesk

Addin" an %6:ect to the data6ase

4ind the ri"ht o+ner to add a ne+l( created o6:ect to


All o6:ects have eJactl( one o+ner The o+ner can 6e the data6ase itsel9@ 4or eJa3ple* ne+l( created =a(erTa6le5ecord can only 6e added to the =a(er Ta6le* its o+ner* or a ne+l( created entit( can 6e only added to a 6lock ta6le record

,se Add 3ethod 9or addin" S(36ol Ta6le 5ecords to add to S(36ol Ta6le ,se AppendAAA to add add other kinds o9 o6:ects to its o+ners 4or eJa3ple

AppendEntit( to add to 0lockTa6le5ecord

%nce an o6:ect is added to an o+ner* al+a(s let the transaction kno+@ 4or eJa3ple
new0tr!AppendEntit,<circle= CAdd our circle to its owner the 0T1 trans!Add(ewl,/reatedD0&%>ect<circleA True=

Autodesk Presentation Title

200 Autodesk

I3portant Bana"ed Classes

Autodesk Presentation Title

<

200 Autodesk

%6:ect 3e3or( 3ana"e3ent


Note 3ana"ed o6:ects wrap an un3ana"ed CLL o6:ect@ So +e create the3 +ith Ne+* Do the( need to 6e disposedG

No 8 "ar6a"e collection disposes the o6:ect +hen it +ants to reclai3 3e3or(

I9 the o6:ect is not in the data6ase >> this ,eletes the underl(in" un3ana"ed o6:ect I9 the o6:ect is in the data6ase > this Closes the underl(in" un3ana"ed o6:ect

I9 opened in a transaction* disposin" or co33ittin" the transaction closes it auto3aticall(@ > Clean 3e3or( 3ana"e3ent.

Autodesk Presentation Title

200 Autodesk

=a6 $
/reate Emplo,ee %lock De'inition

Autodesk Presentation Title

200 Autodesk

Class A"enda
$ectures and $a%s

%vervie+ o9 .NET. AutoCAD .NET 'isual Studio pro:ect settin"s > ?ello &orld@ ,ser Interaction 8 Si3ple ,ser Input and Entit( Selection Data6ase 4unda3entals > S(36ol ta6les* Transactions Data%ase 5undamentals : DictionariesA 21ecordsA Ta%le Traversal Bore ,ser Interaction > Advanced Pro3pts ,ser Inter9ace desi"n 8 &in4or3 Dialo"s and Palettes Event handlin" > 5eactin" to AutoCAD Events in .NET.

Autodesk Presentation Title

200 Autodesk

5eco33ended Transaction ,se

Standard d6 access +ith Transactions


Pu%lic 5unction 3,5unc<= CGet the data%ase current in Auto/AD Dim d% As Data%ase ? JostApplicationServices!WorkingData%ase<= CStart a transaction using the data%ase transaction manager Fsing trans As Transaction ? d%!Transaction3anager!StartTransaction<= CDo all data%ase operations here C$ets get the %lock ta%le 'rom the data%ase CDrill into the data%ase and o%tain a re'erence to the 0lockTa%le Dim %t As 0lockTa%le ? trans!Get&%>ect<d%!0lockTa%le#dA &pen3ode!5orWrite= CEver,thing success'ulA so commit the transaction trans!commit<= End Fsing End 5unction

Autodesk Presentation Title

<0

200 Autodesk

Dictionaries and A5ecords

Dictionaries -T(pe D6Dictionar(/


Containers to hold data onl( ?olds other Dictionaries ?olds non8"raphical %6:ects -derived 9ro3 D6%6:ect 6ut not D6Entit(@/ Is enu3era6le Each ite3 has a strin" ke( Ite3s searcha6le +ith a strin" ke( usin" !etAt-/ or Ite3 Na3ed %6:ects Dictionar( -N%D/ %+ned 6( the data6ase Availa6le 6( de9ault ,sed to store data6ase level data EJtension Dictionar( %+ned 6( an Entit( Created 6( the user onl( +hen needed ,sed to store entit( level data

T+o +oot dictionaries

,se SnoopD6 to look +here the dictionaries are stored

Autodesk Presentation Title

<1

200 Autodesk

Dictionaries and A5ecords

A5ecord

Data containers ?olds data in a 5es6u9 chain -5esult 0u99er/ 5es6u9 > =inked =ist o9 T(ped'alues -DataT(pe>'alue pair/ No S2e(T to search values +ithin a 5es6u9. Should kno+ the order data is stored in the list A5ecords can 6e added to Dictionaries I9 stored in N%D >data6ase level data I9 stored in EJtension Dictionar( > entit(8level data

Autodesk Presentation Title

<2

200 Autodesk

!et N%D

To get the N%D 9or the data6ase

Di3 d6 P ?ostApplicationServices.&orkin"Data6ase
Di3 N%D As D0Dictionar( P trans.!et%6:ect-d6.Na3ed%6:ectsDictionar(Id* %penBode.4or&rite* 4alse/

To create an EJtensionDictionar( 9or an entit( m,Entit,!/reateE;tensionDictionar,<=

Autodesk Presentation Title

<$

200 Autodesk

Iteratin" Throu"h Containers


&%>ects that are enumera%le S(36ol Ta6les 0lock Ta6le 5ecords Dictionaries Pol(lines Pol(4aceBesh X Pol("onBesh ACIS Solids

Called traversers %nl( use9ul +hen attri6utes are present

0lock5e9erences -Inserts/

Autodesk Presentation Title

<)

200 Autodesk

S(36ol Ta6le Traversal

Start +ith a data6ase pointer

?ostApplicationServices.&orkin"Data6ase > !et used to this one@

Iterate do+n into each su68ta6le 9ro3 thereK


Dim d% As Data%ase ? JostApplicationServices!WorkingData%ase<= Dim %t As 0lockTa%le ? trans!Get&%>ect<d%!0lockTa%le#dA &pen3ode!5orWrite=

Di3 id As %6:ectId 4or Each id In 6t Di3 6tr As 0lockTa6le5ecord P trans.!et%6:ect-id* %penBode.4or5ead/ NeJt
Autodesk Presentation Title <
200 Autodesk

5unti3e T(pe Identi9ication -5TTI/

T(pe in9or3ation -such as constructors* 3ethods* properties* events etc/ are contained in the Betadata Fuer( 3etadata at runti3e usin" t(pes de9ined in S(ste3.5e9lection na3espace

Not onl( to #uer( t(pe in9or3ation 6ut also d(na3icall( create the3. ?eart o9 5e9lection is provided 6( S(ste3.T(pe class The class is a6stract. I3ple3enters need to inherit 3ethods to descri6e the t(pe !et it usin"

%6:ect.!etT(pe T(pe%9 operator -'0* C; or CLL/

Autodesk Presentation Title

<<

200 Autodesk

Castin"M

'0.NET
Castin" is auto3atic 6( assi"n3ent > %nl( i9 %ptionStrict is turned o99 EJplicit castin" > CT(pe- e.pression* type / T(pe%9 > I9 T(pe%9 3(%6:ect is =ine ThenK I9 o6:1.!etT(pe-/ Is o6:2.!etT(pe-/ ThenK

In C;

=ine 3(=ine P -=ine/3(%6:ectO UasI operator 8 =ine 3(=ine P 3(%6:ect as =ineO 8 i9 it 9ails* no eJception* 6ut o6:ect "ets set to null@ UisI operator > i9 -3(%6: is =ine/ K t(peo9 operator > i9 t(peo9 -o6:1/ PP t(peo9-o6:2/K !etT(pe 8 I9 o6:1.!etT(pe-/ PP o6:2.!etT(pe-/ K

(. Source: The Code "roject)


Autodesk Presentation Title <C
200 Autodesk

=a6 )
Adding /ustom Data

Autodesk Presentation Title

<E

200 Autodesk

Class A"enda
$ectures and $a%s

%vervie+ o9 .NET. AutoCAD .NET 'isual Studio pro:ect settin"s > ?ello &orld@ ,ser Interaction 8 Si3ple ,ser Input and Entit( Selection Data6ase 4unda3entals > S(36ol ta6les* Transactions Data6ase 4unda3entals > Dictionaries* A5ecords* Ta6le Traversal 3ore Fser #nteraction : Advanced Prompts ,ser Inter9ace desi"n 8 &in4or3 Dialo"s and Palettes Event handlin" > 5eactin" to AutoCAD Events in .NET.

Autodesk Presentation Title

<H

200 Autodesk

Bore ,ser Interaction

Pro3ptsAAA%ptions is used to control pro3ptin" such as

Set the Message

Enter (um%er o' Sides:

Set *eywor,s

Enter (um%er o' Sides TTriangle SZuare PentagonU :

Set efaults

Enter (um%er o' Sides TTriangle SZuare PentagonU P@R:

Set Allowe, values

Enter (um%er o' Sides TTriangle SZuare PentagonU P@R: "+ 4alue must %e positive and nonVero!

Pro3ptAAA5esult is used to o6tain result o9 pro3ptin"


C0
200 Autodesk

Autodesk Presentation Title

Pro3pts
T,pes:

Pro3ptPoint%ptions Pro3ptStrin"%ptions Pro3ptDou6le%ptions Pro3ptAn"le%ptions Pro3ptCorner%ptions Pro3ptDistance%ptions Pro3ptEntit(%ptions Pro3ptInte"er%ptions Pro3pt2e(+ord%ptions Pro3ptNestedEntit(%ptions Pro3ptNestedEntit(%ptions Pro3ptSelection%ptions Etc.

Autodesk Presentation Title

C1

200 Autodesk

=a6
Prompts and Selection

Autodesk Presentation Title

C2

200 Autodesk

Class A"enda
$ectures and $a%s

%vervie+ o9 .NET. AutoCAD .NET 'isual Studio pro:ect settin"s > ?ello &orld@ ,ser Interaction 8 Si3ple ,ser Input and Entit( Selection Data6ase 4unda3entals > S(36ol ta6les* Transactions Data6ase 4unda3entals > Dictionaries* A5ecords* Ta6le Traversal Bore ,ser Interaction > Advanced Pro3pts Fser #nter'ace design " Win5orm Dialogs and Palettes Event handlin" > 5eactin" to AutoCAD Events in .NET.

Autodesk Presentation Title

C$

200 Autodesk

,ser Inter9ace Desi"n

AutoCAD De9ined

Benus > Application level 3enu* ConteJt 3enu Dialo"s AutoCADIs Enhanced Secondar( &indo+s - Palettes / Color* =inet(pe* =ine+ei"ht* %pen4ile dialo"s Ta66ed Dialo" EJtensions -to %ptions Dialo"/ Status 0ar Tra( Dra"8Drop And 3ore. EJplore Autodesk.AutoCAD.&indo+s na3espace

&indo+s De9ined
&indo+s 4or3s -&in9or3/ ?ost o9 other controls de9ined in C=5

Autodesk Presentation Title

C)

200 Autodesk

,ser Inter9ace

Add ConteJt Benu


Application =evel > Application.AddDe9aultConteJtBenuEJtension %6:ect =evel > Application. Add%6:ectConteJtBenuEJtension >per 5AClass

Sho+in" Bodal and BodelessDialo"s


Application.Sho+BodalDialo" Application.Sho+BodelessDialo" Persists si1e and position auto3aticall(

Autodesk Presentation Title

200 Autodesk

=a6 <
Fser #nter'ace Design

Autodesk Presentation Title

C<

200 Autodesk

Class A"enda
$ectures and $a%s

%vervie+ o9 .NET. AutoCAD .NET 'isual Studio pro:ect settin"s > ?ello &orld@ ,ser Interaction 8 Si3ple ,ser Input and Entit( Selection Data6ase 4unda3entals > S(36ol ta6les* Transactions Data6ase 4unda3entals > Dictionaries* A5ecords* Ta6le Traversal Bore ,ser Interaction > Advanced Pro3pts ,ser Inter9ace desi"n 8 &in4or3 Dialo"s and Palettes Event handling : 1eacting to Auto/AD Events in !(ET!

Autodesk Presentation Title

CC

200 Autodesk

?andlin" Events

Event

3essa"e sent 6( an o6:ect to noti9( so3ethin" has happened 3essa"e is received in a 9unction call 6( one or 3ore listeners event sender onl( re#uires 9unction pointer to dispatch a 3essa"e an( interested part( can i3ple3ent the 9unction and receive the event 9unction 3ust have a speci9ic si"nature that the sender re#uires ,se .NET dele"ates to UwireI sender and receiver

Dele"ates

=ike a class -can 6e instantiated/ 6ut +ith a si"nature ?olds re9erences to 9unctions havin" sa3e si"nature =ike UT(pe8Sa9eI 9unction pointer Can encapsulate an( 3ethod +hich 3atches the speci9ic si"nature

Autodesk Presentation Title

CE

200 Autodesk

,sin" Dele"ates

Dele"ates in AutoCADIs .NET API usuall( have UEvent?andlerI su99iJ

=ookup the si"nature o9 the dele"ate in the o6:ect 6ro+ser

I3ple3ent a 9unction +ith sa3e si"nature Instantiate the dele"ate passin" address o9 the 9unction into its constructor Add the dele"ate instance to senderIs list o9 listeners

C;* use LP operator '0* use Add?andler

Delegate m,Delegate ? new Delegate<address o' m,5unction=[ EventSender!Event 6? m,Delegate[ m,5unction<delegate signature= \ ] DonIt 9or"et to re3ove the listener@

Autodesk Presentation Title

CH

200 Autodesk

Event ?andlin" 8 EJa3ple

Create the event handler -call6ack/


Su% o%>Appended<0,4al o As &%>ectA 0,4al e As &%>ectEventArgs= 3essage0o;!Show<Q&%>ectAppendedGQ= CDo something here CDo something elseA etc! End Su%

Associate the event handler +ith an event


Dim d% As Data%ase d% ? JostApplicationServices!WorkingData%ase<= AddJandler d%!&%>ectAppendedA (ew&%>ectEventJandler<Address&' o%>Appended=

Disconnect the event handler


1emoveJandler d%!&%>ectAppendedA Address&' o%>Appended
E0
200 Autodesk

Autodesk Presentation Title

=a6 C
Event Jandling

Autodesk Presentation Title

E1

200 Autodesk

Вам также может понравиться