Objectarx by Lemanhhung

Embed Size (px)

Citation preview

  • 7/23/2019 Objectarx by Lemanhhung

    1/71

    http://arxdummies.blogspot.com/

    Requirements

    Hello,

    Prior to begin the course I would like to list what are the requirements to create,compile and use ObjectARX applications.

    I will use the most recent ersion that is ObjectARX !""#. $ost o% %eatures

    presented will be compatible to preious ersions &I will consider release !""" andaboe'.

    (hat )ou will need*

    Auto+A !""",!"""i and !""! &plus erticals'* ObjectARX !""" and

    $icroso%t -isual + /."0

    Auto+A !""1, !""# and !""/ &plus erticals'* ObjectARX !""1 and

    $icroso%t -isual +.234 !""! &5."'0

    Auto+A !""5, !""6 and !""7 &plus erticals'* ObjectARX !""5 and

    $icroso%t -isual +.234 !""# &6."'0

    8ou ma) download Auto+A trial ersions %rom Autodesk web site&www.autodesk.com

    '.

    4o download ObjectARX &%or %ree', go to www.objectar9.com&this will redirect )outo the right page at Autodesk:s web site'.

    Once )ou hae the aboe products, proceed with the installation*

    Install Auto+A &%ull option recommended'0

    Install -isual +0

    Install &just need to e9tract' ObjectARX to )our computer0

    On the ne9t post I will e9pla in how to install the ObjectARX (i;ard tool.

    +heers?c ti@n B bCt Du khEa hFc tGi mun lit k@ cJc )@u cDu B tKo, bi@n dLch = sMdNng ng dNng ObjectARX.

    4Gi s sM dNng phi@n bQn gDn ) nhSt l= ObjectARX !""#. HDu hTt cJc tUnh nVngbao h=m s t>Wng thUch ?i cJc phi@n bQn tr>?c E &4Gi s 9em 9t phi@n bQn !"""= tr@n nYa'.

    ZKn s cDn g[*

    Auto+A !""",!"""i = !""! &cJc phi@n bQn b\ sung'* ObjectARX !""" =

    $icroso%t -isual + /."0

    Auto+A !""1, !""# = !""/ &cJc phi@n bQn b\ sung'* ObjectARX !""1 =

    $icroso%t -isual +.234 !""! &5."'0

    Auto+A !""5, !""6 = !""7 &cJc phi@n bQn b\ sung'* ObjectARX !""5 =

    $icroso%t -isual +.234 !""# &6."'0

    ZKn cE thB tQi Auto+A phi@n bQn d]ng thM t^ trang web c_a Autodesk&www.autodesk.com

    '.

    `B tQi ObjectARX &min phU', t?i trang www.objectar9.com&s h>?ng bKn TnchUnh trang web c_a Autodesk'.

    $t khi bKn cE cJc sQn phm tr@n, tiTn h=nh cJc c=i t*

    +=i t Auto+A &mc Lnh t]) chFn D) _'0 +=i t -isual +0

    +=i t &ch cDn giQi nn' ObjectARX =o trong \ cng mJ) tUnh0

    4rong phDn tiTp theo tGi s giQi thUch cJch chK) cGng cN ObjectARX (in;ard.

    -ui l@n n=o

  • 7/23/2019 Objectarx by Lemanhhung

    2/71

    http://arxdummies.blogspot.com/

    Class 1 - Overview

    Introduction

    ObjectARX is an Auto+A Runtime 39tension.(ith ObjectARX f )ou can build applications that will alow )ou to e9tendAuto+A %eatures like commands, dialog bo9es, entities, objects and much more.

    4he ObjectARX application is actuall) a DLLthat is loaded into Auto+Aenironment and allows )ou to access new %eatures as mentioned aboe. 4o beable to build these s )ou need to %ollow some basic rules to setup $icroso%t-isual ftudio.234 enironment and assert )our application will respect Auto+Arequirements.

    4he per%ormance o% this application will be the same o% natie %eatures. Z) thewa), Autodesk uses ObjectARX to build ertical products )ou ma) alread) knowlike Autodesk $AP and Architectural esktop, among man) others.

    User Requirements

    Zecause ObjectARX is not a simple customi;ation tool, some requirements must beobsered to allow )ou to be able to proceed. I% )ou don:t match theserequirements I would recommend )ou to %irst increase )our skills and then go backto tr) this course.

    4he minimum requirements to learn at least basic ObjectARX are*

    Zasic -isual ftudio.234 concepts0

    Aerage + knowledge0

    Adanced Auto+A knowledge0

    $+ &$icroso%t oundation +lasses' concepts0

    Object Oriented 4echniques0

    As mentioned be%ore, this course is not intended to be a comple9 guide or eencoer adanced %eatures. I beliee )ou can go %urther b) )oursel% a%ter learn thebasic %eatures and mainl) the basic concepts which are the secret o% ObjectARX.

    Bi 1 Tng quan

    Gii thiu

    ObjectARX l= mt Auto+A Runtime m rng.-?i ObjectARX f bKn cE thB 9) dng cJc ng dNng m rng cJc tUnh nVng

    trong Auto+A nh> cJc lnh, hp thoKi, cJc thc thB, i t>ng = hWn thT nYa.

    ng dNng ObjectARX tht chSt l= mt DLL>c tQi =o mGi tr>ng Auto+A chophp bKn tru) cp cJc c tUnh m?i = cJc cp tr@n. `B cE thB 9) dng cJc bKn cDn tun th_ =i ngu)@n tCc cW bQn B c=i t mGi tr>ng $icorso%t -isualftudio.234 = khng Lnh rng ng dNng c_a bKn s >t qua cJc )@u cDu c_aAuto+A.

    uJ tr[nh thc hin ng dNng ging nh> nhYng c tUnh ngu)@n bQn. Zng cJchE, Autodesk sM dNng ObjectARX B 9) dng trc tiTp cJc sQn phm m= cE thBbKn biTt nh> Autodesk $AP = Architectural esktop, cng nh> nhiu sQn phmkhJc.

    Yu cu vi ngi s dng

    Zi ObjectARX khGng phQi cGng cN t]) biTn Wn giQn, mt =i iu kin phQi >c9em 9t B bKn cE thB theo u\i. 2Tu bKn khGng Jp ng >c cJc iu kin n=)tGi khu)@n bKn h) nng cao kv nVng tr>?c ri qua) lKi khEa hFc n=) sau.`iu kin ti thiBu B hFc ObjectARX cW bQn l=*

    +Jc khJi nim cW bQn -isual ftudio.2340

    HiBu biTt + mc trung b[nh0

    iTn thc Auto+A th=nh thKo0

    hJi nim $+ &$icroso%t oundation +lasses'0

    v thut lp tr[nh h>?ng i t>ng Object Oriented0

    2h> cp t^ tr>?c, khEa hFc n=) khGng phQi l= h>?ng dxn phc tKp hocmun che giSu cJc >u nVng. 4Gi tin bKn cE thB t m[nh tiTn 9a sau khi hFc cJc >unVng cW bQn = mt s khJi nim cW bQn cE trong ObjectARX.

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    3/71

    http://arxdummies.blogspot.com/

    I will not coer .234 ramework capabilitiesto make the course as much simple asI can. Once )ou learn and %igure out how Auto+A works %rom inside )ou will open)our mind to ObjectARX capabilities and will be able to build great applicationWng tr[nh

    tu)t i mNc sau b@n trong*

    )*r+,*#s* 4h> mNc n=) cha ng cJc thiTt lp c_a th> in ch khac mt =i khUa cKnh c_a

    ObjectARX.

    )c,*ssm*-* 4h> mNc n=) cha bQn Auto+A ?i c) phn cSp l?p ObjectARX.

    )docs* 4h> mNc n=) bao gm cJc %ile tr gi|p trc tu)Tn ObjectARX..

    )inc* 4h> mNc inc cha ng cJc Du mNc %ile ObjectARX.

    ),i#* 4h> mNc lib cha cJc %ile th> in ObjectARX.

    )redistri#* 4h> mNc n=) gm s cE thB >c )@u cDu B chK) ng dNng ObjectARX.)s*m-,es* +ha ng mt =i U dN ng dNng ObjectARX.

    )uti,s* +ha cJc th> in khJc nh> ZR3P cho tr[nh b=) bi@n = ObjARX(i; cho ObjectARX

    wi;ards..

    3n c4c ,- c5* "#$ect%R&

    +Jc l?p ObjectARX theo sau cJc tin t chun sau*

    %cR+* ?p B h}a trn ng dNng = B thao tJc Vng k~ = nhn din l?p.

    %c0d* `Vng k~ lnh Auto+A ngu)@n bQn = cho cJc thGng bJo s kin c_a Auto+A.

    %cD#* +Jc l?p cW sM dY liu &database' c_a Auto+A.

    %cGi* ?p hFa B ho=n trQ thc thB Auto+A.%cGe* ?p tin Uch cho Ki s tu)Tn tUnh = cJc i t>ng h[nh hFc.

    4]) =o tp hp c iBm n=o sM dNng trong ng dNng, bKn cDn sM dNng cJc th>in t>Wng ng sau*

    %cR+* acad.lib, r9api.lib, acdb{/.lib

    %c0d* acad.lib, r9api.lib, acedapi.lib, acdb{/.lib

    %cD#* acad.lib, r9api.lib, acdb{/.lib

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    4/71

    http://arxdummies.blogspot.com/

    %cGi* acad.lib, r9api.lib, acdb{/.lib

    %cGe* acad.lib, r9api.lib, acge{/.lib, acdb{/.lib

    "#$ect%R& 6i7*rd

    I will b)pass the -isual ftudio enironment con%iguration to build ObjectARXapplications. 8ou could re%er to this in%ormation inside f documentation. (e willuse on this course the (i;ard proided b) A2 &Autodesk eeloper 2etwork'team. It is located inside ObjectARX director) called )uti,s)"#$%R&6i7. Inside it)ou will %ind the installation package named %r+6i7*rds8msi.

    4o install this (i;ard, close )our -isual ftudio.234 and double click the aboementioned %ile. ollow the steps. (hen %inished, open -isual ftudio.234 again and)ou will see a new toolbar.

    fee )ou on +lass !?c. hi ho=n th=nh, m -isual ftudio.2et lKi = bKn s n[n thS) mttoolbar m?i.

    Xem tiTp b=i !Bho*ngA* `i t>ng c bit B l>u giY = quQn l~ cJc b i

    t>ng &bQng l?p, bQng nt,...'0

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    6/71

    http://arxdummies.blogspot.com/

    "#$ects* Objects without an) graphical representation &groups, la)outs, ...'.

    Auto+A:s atabase structure

    .re*ting o#$ects

    4o create an object through ObjectARX we hae some kind o% recipe depending on

    what t)pe o% object it is and where we would like to store it &most o% time we need

    to store an objects inside its speci%ic container'. Zasicall), )ou will %ollow this

    sequence*

    {. eclare a -ointer to the o#$ectt)pe )ou would like to create and call its

    new operator0

    !. (ith this pointer, c*,, *--ro-ri*te methodso% this object to change its

    %eatures0

    . yet a -ointer to the D*t*#*sewhere )ou would like to create the object

    &most o% time the current atabase'0

    1. "-en the *--ro-ri*te cont*inerwhere it should be stored0

    #. +all the s-eciCic cont*iner method to store our o#$ectpassing its

    pointer0

    /. Receive its "#$ectIdautomaticall) generated b) its container0

    5. inish the operation c,osing *,, o-ened o#$ectsincluding containers and

    the object )ou hae just created.

    Obiousl) )ou will create some hand) classes to allow the automation o% this

    processes because the) are er) similar and can be easil) reused. 4he main idea is

    to create a sort o% database utilit) %uncions like* Adda)er, Addine, Add+ircle,

    Add4e9tft)le, etc.

    3E- ng phi hFa &groups, la)outs, ...'.

    +Su tr|c cW s dY liu Auto+A

    3o c4c tE- ng bng ObjectARX ch|ng ta cE mt =i cGng thc da =o

    kiBu i t>ng = nWi ch|ng ta mun l>u giY nE &hDu hTt thi gian ch|ng ta cDn

    l>u giY cJc i t>ng b@n trong chUnh cJc khoang c_a nE'. - cW bQn, bKn s theo

    cJc chui sau*

    {. hai bao con trH ti Bi@u ng B tha) \i cJc

    tUnh nVng c_a nE0

    . S) mt con trH ti D*t*#*senWi bKn mun tKo i t>ng &hDu hTt l=

    atabase hin h=nh'0

    1. 9K mt Bho*ng chJ*nWi cha dY liu E0

    #. yFi -hng thJc Bho*ng

  • 7/23/2019 Objectarx by Lemanhhung

    7/71

    http://arxdummies.blogspot.com/

    5. Ho=n th=nh tiTn tr[nh Wng ng = cE thB sM dNng lKi d d=ng. t>ng chUnh l=

    B tKo ra mt loKi h=m tin Uch database nh>* Addla)er, Addine, Add4e9tft)le,

    ..

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    8/71

    http://arxdummies.blogspot.com/

    * It is very important to not forget to close opened objects because this

    will cause AutoCAD to terminate.

    '*m-,e code to cre*te * ,ine >%cD#LineA

    4his code demonstrates how to create a simple line between two points. 4he

    process is simple and no error check is made. 4his code needs to be embedded

    inside an ObjectARX application structure to work. 4he main idea is to show )ou

    the concepts. urther we will create a working code. Pa) attention to the order o%opening and closing operations.

    // We first need to declare a couple of points

    AcGePoint3dstartPt(1.0, 1.0, 0.0);

    AcGePoint3dendPt(10.0, 10.0, 0.0);

    // Now we need to instantiate an AcD!ine pointer

    // "n t#is case, its constructor allows $e to pass t#e % points

    AcD!ine&p!ine ' newAcD!ine(startPt, endPt);

    // Now we need to open t#e appropriate container w#ic# is inside

    loc*ale

    AcDloc*ale&ploc*ale ' N+!!;

    // irst, -et t#e current dataase and t#en -et t#e loc*ale

    AcDDataase& pD ' acdostApplicationerices()2worin-Dataase();

    pD2-et$ol*ale(ploc*ale, AcD44or5ead);

    // "nside loc*ale, open t#e 6odelpace

    AcDloc*ale5ecord& ploc*ale5ecord ' N+!!;

    ploc*ale2-etAt(A7D869D:!8PA7:, ploc*ale5ecord,

    AcD44orWrite);

    // After -et 6odelpace we can close t#e loc*ale

    ploc*ale2close();

    // +sin- 6odelpace pointer we can add our rand new line

    AcD9ect"dline"d ' AcD9ect"d44Null;

    ploc*ale5ecord2appendAcD:ntit(line"d, p!ine);

    // *o finis# t#e process we need to close 6odelpace and t#e entit

    ploc*ale5ecord2close();

    p!ine2close();

    On the ne9t class we will present the ObjectARX application structure

    and will build and compile a simple application using the aboe code.fee )ou therec. +h| ~ mt ch|t t?i lnh c_a

    quJ tr[nh m = Eng.

    // n ta p#?i #ai @o $t cBp Ci$

    AcGePoint3dstartPt(1.0, 1.0, 0.0);

    AcGePoint3dendPt(10.0, 10.0, 0.0);

    // E -iF ta s #Hi tIo $t con trJ AcD!ine

    // *rKFn- #Lp nM, p#Kn- t#Oc #Hi tIo c#o p#p t#Qn- Rua % Ci$

    AcD!ine&p!ine ' newAcD!ine(startPt, endPt);

    // *a s $H #oan- t#Sc# #Lp >n tron- loc*ale

    AcDloc*ale&ploc*ale ' N+!!;

    // n, lT dataase #iUn tIi M sau CV lM loc*ale

    AcDDataase& pD ' acdostApplicationerices()2worin-Dataase();

    pD2-et$ol*ale(ploc*ale, AcD44or5ead);

    // >n tron- loc*ale, $H ra 6odelpace

    AcDloc*ale5ecord& ploc*ale5ecord ' N+!!;

    ploc*ale2-etAt(A7D8aaaaaaaaaaaaaaaaaaaaaaaa69D:!8PA7: ,

    ploc*ale5ecord, AcD44orWrite);

    // au #i cV 6odelpace c#n- ta cV t# CVn- loc*ale

    ploc*ale2close();

    // Xu dYn- con trJ 6odelpace ta cV t# t#>$ line $Zi

    AcD9ect"dline"d ' AcD9ect"d44Null;

    ploc*ale5ecord2appendAcD:ntit(line"d, p!ine);

    //

  • 7/23/2019 Objectarx by Lemanhhung

    9/71

    http://arxdummies.blogspot.com/

    p!ine2close();

    4rong b=i tiTp, ta s t[m hiBu cSu tr|c ng dNng ObjectARX, s 9)dng = bi@n dLch mt ng dNng nh ?i code tr@n. Hn gp lKi E cp tr>?c E, ObjectARX thc chSt l= mt . 2E cE thB li@n kTt hoc

    khGng t?i m rng 9S.. HDu hTt bKn u mun li@n kTt ?i $+. Autodesk cung

    cSp mt (in;ard tu)t i cho php ng>i sM dNng nhanh chEng tKo >c ng

    dNng ObjectARX ?i s l>ng code giQn thiBu ti a.

    4r>?c khi tiTn h=nh tGi mun bKn phn bit >c s khJc nhau giYa ng dNng

    "#$ect%R&?i "#$ectDT&. uan trFng nhSt l= -hVn chi* gi*o din v2 c gFi l= "#$ect BhP dng. `iu E khGng tht s bCt buc

    nh>ng nE l= mt thc h=nh lp tr[nh tt = Autodesk tKo ra s phn chia n=) B

    cng cSp nhYng th tu)t i nh>, m mt bQn A4 b@n trong Auto+A, tQi

    nhYng i t>ng ph] hp ri sau E thB hin thc thB A4 b@n trong Auto+A.

    yiQ sM bKn cDn tKo mt ng dNng ?i mt m? cJc i t>ng = thc thB. ZQn

    >c tKo ra ?i ng dNng s cha cJc i t>ng n=) = nTu ng>i d]ng khJc c

    gCng m bQn b@n trong Auto+A m= thiTu ng dNng c_a bKn hF s ch nh[n

    thS) cJc thc thBro+m= thGi. 2Tu mun cho php nhYng ng>i n=) nh[n thS)

    cJc thc thB ri@ng nh>ng khGng thc hin bSt c lnh n=o tJc ng l@n ch|ng l|c

    E bKn s cDn ko theo phDn DT& trong ng dNng c_a m[nh. Zng cJch n=) ng>i

    d]ng cE thB nh[n thS) nhYng thc thB ri@ng = thc hin mt s thao tJc hKn chT.

    hi bQn >c l>u, Auto+A bQo to=n thGng tin thc thB ri@ng bng cJc thc thB

    gFi l= ro+. `iu n=) 9Q) ra kB cQ khi module DT&Cng mt. 4hc thB ro+

    l>u trY dY liu nhL phn c_a i t>ng ri@ng = dY ch|ng t?i tn khi n=o ng dNng

    c_a bKn qua) tr lKi l=m ic.

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    10/71

    http://arxdummies.blogspot.com/

    4rong mt nhJnh khJc, module ARX trong ng dNng s chLu trJch nhim giao

    din. 4^ E bKn n@n Vng k~ lnh, tKo hp thoKi = cJc menu ri@ng, ..

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    11/71

    http://arxdummies.blogspot.com/

    %--,ic*tion 'tructure

    Zoth %R&and DT&modules must implement an entr -oint Cunction. 4his

    %unction is responsible to per%orm messages e9change between Auto+A and )our

    application. or those who are %amiliar with old + language it is the substitute o%

    main&' %unction.

    4his entr) point %unction has a signature as %ollow*

    e_tern `7` Ac5_44App5et7odeacrxEntryPoint(Ac5_44App6s-7ode$s-, oid&

    pt);

    A simple implementation o% this %unction is*

    e_tern `7` Ac5_44App5et7ode

    acrxEntryPoint(Ac5_44App6s-7odemsg, oid& pt)

    switc#(msg)

    case Ac5_44"nitApp6s-4

    rea;

    case Ac5_44+nloadApp6s-4

    rea;

    default4

    rea;

    b

    return Ac5_445et9;

    b

    4his %unction is automaticall) implemented b) the (i;ard as )ou will see later. 4he

    %irst parameter &msg' is the message sent %rom Auto+A to )our application

    telling )ou what is happening. 8ou ma) receie a new drawing message, a init

    application message among man) others. 4hese messages are er) important to

    )our application and to allow )ou to react to each desired eent to monitor. 4he

    second parameter &-Bt' is a data package that can be use%ul in some situations

    that I would aoid to discuss now &remember, our course is %or ummies'. 4his

    %unction must return * v*,ue to %uto.%Dusing %--Ret.odewhich can

    be BRet"(&common alue' or een BRet0rrorwhich will %orce Auto+A to

    unload )our application.

    .Ou trWc Jng dng

    +Q module ARX lxn ZX u thi h=nh mt h2m entr -oint. H=m n=) chLu trJch

    nhim thc hin thGng ip qua lKi giYa Auto+A = ng dNng c_a. -?i nhYng ai

    quen ?i ngGn ngY + c, nE tha) thT cho h=m main&'.

    H=m entr) point n=) >c Vng k~ nh> sau*

    e_tern `7` Ac5_44App5et7odeacrxEntryPoint(Ac5_44App6s-7ode$s-, oid&pt);

    $t thi h=nh Wn giQn c_a h=m n=) l=*

    e_tern `7` Ac5_44App5et7ode

    acrxEntryPoint(Ac5_44App6s-7odemsg, oid& pt)

    switc#(msg)

    case Ac5_44"nitApp6s-4

    rea;

    case Ac5_44+nloadApp6s-4rea;

    default4

    rea;

    b

    return Ac5_445et9;

    b

    H=m n=) t ng thi h=nh bi (i;ard m= bKn s biTt sau. 4ham s Du ti@n &msg'

    l= thGng ip gMi t^ Auto+A t?i ng dNng = cho biTt iu g[ ang din ra. ZKn cE

    thB nhn >c thGng ip new drawing, ha) init application trong rSt nhiu cJc

    thGng ip khJc. +Jc thGng ip n=) rSt quan trFng ?i ng dNng c_a bKn = chophp bKn phQn ng lKi ?i mi s kin mong mun t?i m=n h[nh. 4ham s tiTp Tn

    l= &-tB' l= gEi dY liu cE thB hYu dNng trong mt =i tr>ng hp m= tGi ch>a mun

    thQo lun ) &h) nh?, khEa hFc c_a ch|ng ta l= cho nhYng ng>i m?i bCt Du'.

    H=m n=) -hPi trP vX gi4 tr ti %uto.%DsM dNng %--Ret.odecJi m= cE thB

    BRet"(&giJ trL chung' hoc thm chU BRet0rrorg) ra ic thoJt khi ng dNng

    c_a bKn.

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    12/71

    http://arxdummies.blogspot.com/

    4he most releant point here is to remember that this %unction is er) importantand is where )our application will begin to e9ecute.

    Registering .omm*nds

    Probabl) )our application will implement seeral commands. 8ou can register )ourcommands %rom the *cr+0ntroint&' %unction when receiingthe BInit%--9sgmessage that represents the eent %ired b) Auto+A when itloads )our application &this can be done b) seeral wa)s that we will discuss later'.

    Once this message is receied, )ou can call the appropriate methods to registereach desired command.

    Registered commands must hae a Grou- /*me, a G,o#*, /*me, aLoc*, /*me,some %lags, a void Cunction -ointerand, optionall), some other parameters.Zasicall) the registered command will %ire the %unction )ou speci%ied. 4his %unctionmust be a oid %unction without an) parameters. (hen the user inside Auto+Acall )our command, Auto+A seek its command stack, %ind )our command and %ire)our %unction. 4hat:s itc thGngip, bKn cE thB gFi ph>Wng thc thUch hp B Vng k~ mi lnh mong mun.

    `Vng k~ lnh phQi cE mt tn nhNm >Grou- /*meA, mt tn to2n cu >G,o#*,

    /*meA, mt tn Loc*, /*meA, =i loKi c, mt h=m con tr >void

    Cunction -ointerA=, mt =i tham s t]) chFn khJc. -ic Vng k~ lnh s khai

    ha h=m m= bKn ch r. H=m n=) bCt buc khGng >c cE mt tham s n=o.

    hi ng>i sM dNng Auto+A gFi lnh, Auto+A s t[m kiTm trong kho lnh, t[m

    lnh = khi ng h=m c_a bKn. -) Etn nhNmA* +ho php bKn nhEm cJc lnh chung lKi B Wn

    giQn khi unload = quQn l~ ch|ng0

    G,o#*, /*me >tn to2n ccA* 4@n lnh khGng dLch. ZKn n@n sM dNng t@n

    tiTng Anh B cE thB sM dNng >c ?i hDu hTt cJc ngGn ngY0

    Loc*, /*me >tn Wng Ki din cho t@n >c

    dLch0

    S,*gs >c4c ,oi cA* +E thB h}a trn =i loKi kiBu. Hai loKi c quan trFng

    nhSt l= A+RX+$4RA2fPAR324 = A+RX+$$OA. +h|ng thiTt lph=nh i lnh c_a bKn sao cho cE thB G h[nh &ging nh> oom' hoc mt

    ph>Wng thc &ging nh> lnh chUnh'0

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    13/71

    http://arxdummies.blogspot.com/

    void Cunction -ointer* Here )ou pass the name o% the oid %unction )ou

    would like to link with the command. 4his %unction will be %ired b) Auto+A

    when the command is inoked.

    Once )ou register )our commands )ou need obiousl) to unregisterwhen leaing

    Auto+A or when )our application is unloaded. 4his can be easil) done

    unregistering all commands b) the Grou- /*me. (hen )ou reciee

    the BUn,o*d%--9sgmessage is time to remoe )our commands.

    Running our *--,ic*tion

    fupposing )ou alread) compiled )our application success%ull) it is time to load it

    inside Auto+A and test )our commands. $) pre%erable method to load unload

    ObjectARX applications is through the %L"%Dcommand. It opens a er) hand)

    dialog that allows )ou to browse %or the application and load it. It comes also with

    a ftartup fuite brie%case that allows )ou to automaticall) load a list o% applications

    when Auto+A starts.

    Once )our application is loaded, just %ire )our commands and enjo)t qua t@n t@n c_a

    h=m m= bKn mun li@n kTt ?i lnh. H=m n=) s >c kUch hoKt bi Auto+A

    khi lnh >c Jnh thc.

    $t khi Vng k~ lnh, r r=ng l= bKn cng cDn khai tr^ lnh khi ri khi

    Auto+A hoc khi ng dNng >c unload. -ic n=) cE thB thc hin mt cJch d

    d=ng ?i Grou- /*me >tn nhNmA. hi nhn >c thGng ip BUn,o*d%--9sg

    l= l|c r b cJc lnh c_a m[nh.

    .h c4c Jng dng

    yiQ sM rng bKn bi@n dLch ng dNng th=nh cGng, Tn l|c tQi nE =o trong

    Auto+A = thM nghim. Ph>Wng thc >a thUch c_a tGi B load unload ng dNng

    ObjectARX l= thGng qua lnh %L"%D. 2E m ra mt hp thoKi rSt hYu dNng cho

    php bKn du)t qua cJc ng dNng = tQi nE. 2E c}n bao gm cQ cp t=i liu khi

    ng &ftartup fuite brie%case' cho php bKn tQi t ng mt danh sJch cJc ng

    dNng khi Auto+A khi ng.

    $t khi ng dNng >c tQi, h) khai ha lnh = tn h>ngc Vng trong =o

    web site chia s %ile cp tr>?c E. 4Gi mun bKn tQi nE = d=nh ch| ~ t?i

    oKn code m= ch|ng ta thQo lun T2i ]. HiBu rng tGi sW mt lnh

    ?i mt h=m, = b@n trong h=m n=) quJ tr[nh tKo mt >ng line >c thc hin.

    4iTn thng phUa tr>?c, thM mt lDn< Zi@n dLch code = m %ile ARX kTt quQ b@n

    trong Auto+A.

    Z=i tiTp theo tGi s tr[nh b=) cJch 9) dng ng dNng t^ Kch 9uSt phJt

    ?i %R&6i7*rd.

    4iTp tNc theo di nh?i c]ng'. Hp thoKi sau s 9uSt hin.+hFn ro$ects= sau E l= Q.bb Directories. 4rong 'ho! directories Cor,chFn Inc,ude Ci,es. Z@n d>?i s 9uSt hin mt danh sJch cJc th> mNc i km m=-isual ftudio sM dNng tr>?c E = s th@m =o >ng dxn ObjectARX incnWicha cJc %ile .H. 2hSn =o biBu t>ng th> mNc = click =o n|t elip = t[m >ngdxn inc&trong tr>ng hp c_a tGi, nE >c t tKi .)"#$ect%R& ]^^`)inc'.

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    17/71

    http://arxdummies.blogspot.com/

    Donft c,icB "(. 2ow we need to add the librar) %iles director).'e,ect Li#r*rCi,eson the 'ho! directories Cor%ield. Repeat the aboe procedure to add apath but this time )ou will add the ,i#path &in m) case, .)"#$ect%R&]^^`),i#'. +lick "(to %inish.

    2ow we need to con%igure our project. 4his will require some project settingschange and some code t)ping. irst, we will change the project settings. Rightc,icB the -ro$ect n*meinside folution 39plorer and se,ect ro-erties. 4he%ollowing dialog will appear. felect, on the .onCigur*tion%ield, %,,.onCigur*tions. 4his will allow us to change both De#ugand Re,e*sesettingsat the same time.

    On the .onCigur*tion ro-ertiesnode, select ..bband .ode Gener*tion.

    4he right portion o% this dialog will displa) a list with seeral properties. felectthe Runtime Li#r*rentr) and chance its alue to 9u,tithre*ded DLL. 4his is arequirement to make our compatible with Auto+A enironment.

    Zng nhOn "(. Z) gi ta cDn phQi th@m th> mNc %ile th> in. chjn Li#r*rCi,esb@n trong tr>ng 'ho! directories Cor. p lKi th_ tNc tr@n B th@m >ng

    dxn nh>ng lDn n=) l= >ng dxn th> in ,i#&?i tr>ng hp c_atGi, .)"#$ect%R& ]^^`),i#'. +lick "(B kTt th|c.

    Z) gi ta cDn phQi Lnh h[nh cho d Jn. -ic n=) s }i hi tha) \i = c=i t dJn ?i mt =i d}ng m. `Du ti@n, ta s tha) \i c=i t c_a d Jn. .,icB chut-hPi v2o tn d? 4n -ro$ect n*meb@n trong folution 39plorer = chjnro-erties. Hp thoKi sau 9uSt hin. +hFn .onCigur*tion, %,, .onCigur*tions.

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    18/71

    http://arxdummies.blogspot.com/

    -ic E cho php tha) \i c=i t cQ De#ug= Re,e*sec]ng mt l|c.

    Z@n trong .onCigur*tion ro-erties, chFn ..bb= .ode Gener*tion. PhDnb@n phQi c_a hp thoKi s hiBn thL danh sJch c_a mt =i thuc tUnh. +hFnmNc Runtime Li#r*r= tha) \i giJ trL sang 9u,tithre*ded DLL. `iu n=) l=cDn thiTt B l=m t>Wng thUch ?i mGi tr>ng Auto+A.

    2ow, select the LinBernode and Gener*,. On the "ut-ut Si,eentr) change thee9tension name Crom DLL to %R&. 2ote that -isual ftudio use seeral macros&those names with a at beginning' to allow eas) and %le9ible path con%iguration.

    ftill inside LinBernode, select In-ut. Here we will add those libraries ourapplication will use. 4his will depend on what %eatures )ou are using inside )ourObjectARX application. In this case, we will add just the basic two librariescalled r+*-i8,i#and *cd#kl8,i#.

    felect the %ddition*, De-endenciesentr) and click on ellipsis button. 4)pe thetwo preiousl) mentioned %iles. 4hese libraries are located at ,i#%older. Rememberthat on preious classes I hae talked about the %eatures each librar) has built in.

    +lick "(to close Project Properties dialog. 2ow we still need to do some codet)ping. 4he %irst step is to edit the D0S Ci,ewhich is placed at 'ource Si,es%oldero% )our project at 'o,ution 0+-,orer.Dou#,e c,icB the D0S Ci,eand it will appearat the right portion o% -isual ftudio window. (e will need to add the %ollowinglines, under the 0&"R3'section o% this %ile*

    Z) gi h) chFn nhJnh LinBer= Gener*,. 4rong mNc "ut-ut Si,etha) \i t@nm rng t DLL s*ng %R&. 2h? rVng -isual ftudio sM dNng =i macro &nhYng cJit@n bCt Du bng ' cho php Lnh h[nh >ng dxn mt cJch linh hoKt = Wn giQn.

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    19/71

    http://arxdummies.blogspot.com/

    -xn b@n trong nhJnh LinBer, chFn In-ut. ) ta s th@m =o cJc loKi th> incho ng dNng. +Ji E phN thuc =o loKi c tUnh n=o >c sM dNng b@n trong ngdNng ObjectARX. 4rong tr>ng hp n=), ta ch th@m =o ! th> in cW bQnl= r+*-i8,i#= *cd#kl8,i#.

    a chFn mNc %ddition*, De-endencies= nhSn =o n|t elip. 2hp ! %ile cpb@n tr@n =o. +Jc th> in n=) >c t trong th> mNc ,i#. 2h? lKi trong b=i hFctr>?c tGi nEi cJc c tUnh b@n trong mi th> in.

    2hSn "(B Eng hp thoKi Project Properties. Z) gi ch|ng ta xn cDn tKo =ioKn m. Z>?c Du ti@n l= chnh sMa Ci,eD0S t trong th> mNc 'ource Si,esc_ad Jn >'o,ution 0+-,orerA. /h4 ?i phDn 0&"R3'c_a %ile*

    *cr+0ntroint RIQ%30*cr+Get%-iQersion RIQ%30

    Pa) attention to the name between quotes in %ront o% LITR%RY section inside this%ile. 4his name must be the same name )ou hae entered on the output %ile. Inother words, i% )our project generates a %T.D8*r+%ile )ou need to hae LITR%RY%T.Dinside the 3 %ile.

    4he ne9t step is to change our 'td%C+8h%ile which is the ke) compilation %ile. (ewill need to in%orm -isual ftudio to use Release ersion o% $+ libraries when ourproject is being compiled using theD0TUGdirectie.

    4o do that, open the 'td%C+8h%ile which is located at e*der Si,es%olderinside 'o,ution 0+-,orer. Ze%ore the include line, insert the %ollowing code*

    if defined(_DEBUG) defined(_FULLDEBUG_)

    define_DEBUG_WAS_DEFINED

    undef_DEBUG

    pra-$a $essa-e (` 7o$pilin- 67 #eader files in release $ode.`)

    endif

    2ow, scroll to the end o% this %ile and add the %ollowing lines to manage the

    3Zzy s)mbol back and to include basic .H %iles our application will need*ifdef_DEBUG_WAS_DEFINED

    define_DEBUG

    undef_DEBUG_WAS_DEFINED

    endif

    // 9ectA5g "ncludes

    include `r_re-sc.#`

    include `acutads.#`

    *cr+0ntroint RIQ%30*cr+Get%-iQersion RIQ%30

    htt // d i bl t /

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    20/71

    http://arxdummies.blogspot.com/

    H) ch| ~ mt ch|t =o cJi t@n giYa nhYng li ch| thUch tr>?c phDn LITR%RYc_a %ile. 4@n phQi ging ?i t@n m= bKn nhp trong %ile Du ra. $t U dN, nTu t@nd Jn l= %T.D8*r+th[ cDn phQi cE LITR%RY %T.Db@n trong %ile 3.

    Z>?c kT tiTp l= tha) \i %ile 'td%C+8h l= ch[a khEa B bi@n soKn. +h|ng ta cDnphQi t[m hiBu thGng tin -isual ftudio B sM dNng phi@n bQn th> in $+ khi dJn >c bi@n dLch sM dNng ch thL D0TUG.

    `B l=m iu E, m %ile 'td%C+8htrong th> mNc e*der Si,es trong 'o,ution

    0+-,orer. 4r>?c d}ng include, th@m =o oKn m sau*if defined(_DEBUG) defined(_FULLDEBUG_)

    define_DEBUG_WAS_DEFINED

    undef_DEBUG

    pra-$a $essa-e (` 7o$pilin- 67 #eader files in release $ode.`)

    endif

    Z) gi h) ko 9ung cui %ile = th@m nhYng d}ng sau B quQn l~ biBu t>ng

    3Zzy B bao gm cJc %ile .H cW bQn m= ng dNng c_a ta sM dNng*ifdef_DEBUG_WAS_DEFINED

    define_DEBUG

    undef_DEBUG_WAS_DEFINED

    endif

    // 9ectA5g "ncludes

    include `r_re-sc.#`

    include `acutads.#`

    4he last step is to add our *cr+0ntrointmethod which is our application start

    point. Open the .%ile o% )our application which has the same name that )ou

    hae set to )our project plus the .e9tension. It is placed inside 'ource

    Si,es%older. Open i% and scroll down to the end. Add the %ollowing l ines*

    // 9ectA5g :N*5hP9"N*

    e_tern `7` Ac5_44App5et7ode acrxEntryPoint(Ac5_44App6s-7ode $s-, oid&

    app"d)

    switc#($s-)

    caseAcRx::kInitAppMsg4

    acr_+nlocApplication(app"d);

    acr_5e-isterApp6D"Aware(app"d);

    acutPrintf(8*( n6ini$u$ 9ectA5g application loaded`));

    rea;

    caseAcRx::kUnoa!AppMsg4

    acutPrintf(8*( n6ini$u$ 9ectA5g application unloaded`));

    rea;

    b

    returnAcRx::kR"t#$;

    b

    2ow we are read) to build our application. Open Tui,dmenu and select Tui,d

    'o,ution&or S_ke)'. -isual ftudio will compile and link and build )our project. I%

    )ou hae %ollowed all aboe steps care%ull) it will generate the application without

    an) error.

    ftart Auto+A and run %L"%Dcommand which will show the %ollowing dialog.

    Zrowse to )our project and )ou will %ind the application inside the ebug %older

    which is the de%ault compilation t)pe. felect it and c,icB Lo*d #utton. A message

    will appear at the bottom o% this dialog telling )ou that )our ARX was success%ull)

    loaded or not?c cui c]ng l= th@m ph>Wng thc *cr+0ntroint iBm bCt Du c_a ng

    dNng. $ %ile .trong ng dNng m= tr]ng t@n bKn t cho ng dNng cE uGi m

    rng .. 2E nm trong th> mNc 'ource Si,es. $ nE ra = ko 9ung d>?i c]ng.

    http://arxdummies blogspot com/

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    21/71

    http://arxdummies.blogspot.com/

    4h@m nhYng d}ng sau )*

    // 9ectA5g :N*5hP9"N*

    e_tern `7` Ac5_44App5et7ode acrxEntryPoint(Ac5_44App6s-7ode $s-, oid&

    app"d)

    switc#($s-)

    caseAcRx::kInitAppMsg4

    acr_+nlocApplication(app"d);

    acr_5e-isterApp6D"Aware(app"d);

    acutPrintf(8*(`n6ini$u$ 9ectA5g application loaded`));

    rea;

    caseAcRx::kUnoa!AppMsg4

    acutPrintf(8*(`n6ini$u$ 9ectA5g application unloaded`));

    rea;

    b

    returnAcRx::kR"t#$;

    b

    Z) gi ta sn s=ng B 9) dng ng dNng. $ menu Tui,da% la chFn Tui,d

    'o,ution&nhSn S_'. -isual ftudio s bi@n dLch, li@n kTt = 9) dng d Jn. 2Tu

    bKn l=m theo tSt cQ cJc b>?c tr@n mt cJch cn thn th[ ng dNng tKo ra ko gp

    li.

    hi ng Auto+A = chK) lnh %L"%D, hp thoKi sau hin ra. u)t t?i d

    Jn bKn s t[m thS) ng dNng b@n trong th> mNc ebug l= nWi bi@n dLch mc Lnh.

    +hFn nE = nhOn nWt Lo*d. $t thGng ip s 9uSt hin phUa d>?i trong hp

    thoKi nEi rVng ng dNng ARX >c tQi th=nh cGng hoc khGngc nhJnh th> mNc Qisu*, .bb

    ro$ectscE t@n l= %utodesB. a chFn nhJnh n=) = ri biBu

    t>ng "#$ect%R&DT&"9S ro$ects 9uSt hin phUa b@n phQi nh> sau*

    `in t@n /*me= Lnh r L trU c_a d Jn. /hOn "(B tiTp tNc. hp thoKi sau s9uSt hin*

    http://arxdummies.blogspot.com/

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    24/71

    p // g p /

    4his dialog presents the steps to setup )our new project. 4he %irst page,called "vervie!, shows some in%ormation and gie )ou the opportunit) to in%orm)our RD'&Registered Deve,o-er 'm#o,'. 4his label will be used to pre%i9an)thing that )our code could implement and could con%lict with other thirdpart)applications. 4o allow this pre%i9 to be unique, Autodesk proides &through %D/su#scri-tions' a wa) to register )our pre%i9 and in%orm other A2 members.3en )ou are note an A2 member )ou should create )our own Rf. zse )ourinitials, )our name %irst chars or an) other name )ou %ind clear and use%ul.

    4he ne9t step is to choose )our desired Application 4)pe. As I hae mentionedbe%ore, %R&6i7*rdsuggests the %R& DT&t)pes which are basicall) theseparation o% Inter%aces and +ustom +lasses. $ore details about the maindi%%erences between ARX and ZX can be %ound at ObjectARX documentation. 4histime we will choose the ObjectARX option as %ollows*

    Hp thoKi n=) thB hin t^ng b>?c c=i t cho d Jn. 4rang Du ti@n, gFi l="vervie!, thB hin mt =i thGng tin = cho bKn cW hi la chFn RD'&Ti@ut=ng ?c tiTp theo l= la chFn kiBu ng dNng. 2h> nEi t^ tr>?c, %R&6i7*rdgi ~kiBu %R& DT&l= nhYng kiBu cW s B phn chia giao din = cJc l?p t]) chnh.+hi tiTt s khJc nhau giYa ARX = ZX Fc trong t=i liu ObjectARX. yi ) tas la chFn t]) chnh ObjectARX nh> sau*

    http://arxdummies.blogspot.com/

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    25/71

    4he ne9t step is about %ddition*, 'D( 'u--ortwhich allows )ou to e9tend basicObjectARX %eatures to an speci%ic Autodesk ertical. 4here are two options*

    "9S 'u--ort* 4his is the f e9tension %or %utodesB %rchitectur*,

    DesBto-&aka %D3' which contains speci%ic %eatures that could be used i% )ou

    plan to deelop an ObjectARX application to run inside A40

    9% %I 'u--ort* 4his is the f e9tension %or %utodesB 9%which

    contains e9tra %eatures to be used i% )ou plan to deelop a $AP ObjectARX

    application.

    In our case, we will deelop an ObjectARX application targeting plain &or anilla'

    Auto+A so leae both blank.

    4he ne9t step is to speci%) 9S. 'u--ort. As I mentioned be%ore we will use 9S.

    0+tension DLLproject t)pe. 4his dialog also o%%ers the option to enable %uto.%D

    9S. 0+tension 'u--ortwhich will allow )ou to use speci%ic Auto+A controls like

    ine4)pe combo bo9es, +olor combo bo9es, ockable dialogs, etc. 4his is prett)

    hand) once those controls are not so simple to implement %rom scratch. felect39tension and enabled Auto+A $+ fupport*

    Z>?c tiTp theo l= h tr c_a %ddition*, 'D(cho php bKn m rng c tUnh c_aObjectARX t?i mt phi@n bQn Autodesk. +E hai la chFn*

    "9S 'u--ort* `) l= m rng f cho %utodesB %rchitectur*,

    DesBto-&iTt tCt %D3' cE ch>a cJc c tUnh c bit cE thB >c sM dNng

    nTu bKn d Lnh phJt triBn ng dNng ObjectARX cE thB chK) b@n trong A40

    9% %I 'u--ort* `) l= m rng c_a %utodesB 9%cha cJc c tUnh

    b\ sung nTu bKn Lnh phJt triBn mt ng dNng $AP ObjectARX.

    4rong tr>ng hp n=), ta s phJt triBn ng dNng ObjectARX thuDn nhSt [ ) h)

    B trng cQ !.

    Z>?c tiTp theo l= 9Jc Lnh 9S. 'u--ort. 2h> nEi ta s sM dNng kiBu d Jn

    9S. 0+tension DLL. Hp thoKi n=) cng 9uSt la chFn %uto.%D 9S.

    0+tension 'u--ortcho php bKn sM dNng chUnh cJc iBu khiBn Auto+A nh> hp

    ine4)pe, +olor, hp thoKi ockable, .. `iu E tht s hYu Uch [ khGng h Wn

    giQn B thi h=nh ch|ng t^ hai b=n ta) trCng. a chFn m rng = chFn

    Auto+A $+ fupport*

    http://arxdummies.blogspot.com/

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    26/71

    4he last step is dedicated to ."9related stu%%. ObjectARX supports +O$

    implementations on both 'erverand .,ientsides. As +O$ programming is er)

    comple9 and is be)ond this course scope so I wil l not coer it.

    eae the options on the /ot * ."9 'erverand /one. +lick Sinish to proceed.

    2ow )ou can open the project %iles and see what the ARX(i;ard has done %or )ou.

    4here are a lot o% di %%erences between the project we hae created on preious

    class and the present project because ARX(i;ard use di%%erent implementations

    using hand) classes. (e will coer these %eatures seeral times with our upcoming

    samples on the ne9t classes.

    .om-i,e *nd Tui,dthe project and tr) to load the resulting ObjectARX application

    inside Auto+A. 8ou probabl) will be able to success%ull) load i t.

    Z>?c cui l= d=nh cho mQng ."9. ObjectARX h tr thi h=nh +O$ tr@n cQ phUa

    'erver= .,ient. 2gGn ngY +O$ rSt phc tKp = nm ngo=i phKm i khEa hFc [

    thT tGi s khGng cp Tn.

    a chFn /ot * ."9 'erver= /one. 2hSn SinishB thc hin.

    Z) gi ta cE thB m %ile d Jn = nh[n >c nhYng g[ ARX(i;ard l=m cho

    bKn. +E rSt nhiu s khJc nhau giYa d Jn ch|ng ta tKo ra trong b=i tr>?c ?i d

    Jn hin tKi bi ARX(i;ard. +h|ng ta s ng Tn nhYng tUnh nVng n=) =i lDn

    trong nhYng U dN trong cJc b=i tiTp theo.

    Tin dch v2 +V d?ngd Jn = load ng dNng ObjectARX =o trong Auto+A.

    ZKn ho=n to=n cE thB tQi th=nh cGng.

    http://arxdummies.blogspot.com/

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    27/71

    Class ( - Ob)et *i+e,le

    2ow )ou are able to create a minimum "#$ect%R&project we will continue the

    course with some additional concepts.

    As I hae mentioned be%ore, Auto+A:s database is well organi;ed to allow sim-,e

    *nd direct m*ni-u,*tiono% its objects. yenerall) we hae two basic

    t)pes* .ont*inersand "#$ects.

    .ont*inersare special objects that proide a simple and e%%icient mechanism to

    store, edit and persist objects or collections. 4he) are optimi;ed to allow quick

    access with minimum oerhead. 3ach t)pe o% object has an appropriate container

    where )ou should alwa)s store )our object. 4here are seeral containers inside

    Auto+A:s database but some o% the most common

    are* L*er3*#,e,Linet-e3*#,eand T,ocB3*#,e. 3ach container class has

    standard access methods and most o% them also o%%er a companion class to iterate

    through its items. 3er) time )ou create an object and would like to store it inside

    Auto+A:s database )ou need to %ollow its container protocol to store and persist is

    as well.

    In other hand, "#$ects&including entities' are the most basic t)pes and represent

    each element inside Auto+A. 4he) are implemented through speci%ic classes with

    standard and speci%ic methods. fome o% them could be deried inside )our

    application to allow customi7*tion.

    3er) database resident object has an e9clusie identi%ication called "#$ectId. 4his

    identi%ication is the n*me o% each object inside database and it is used to

    re%erence, open and manipulate objects.

    4his could be a diCCicu,t conce-t%or those who are %luent in standard +

    language because inside ObjectARX )ou don:t delete a pointer to a database

    resident object. (hat 8es, this is a little bit strange but Auto+A has seeral

    reasons to do that including per%ormance, memor) management and other

    aspects.

    'oa ho! c*n I m*ni-u,*te o#$ects

    Bi ( .n# /i ca !i t"ng

    Z) gi ta cE thB tKo ra d Jn "#$ect%R&ti thiBu, ch|ng ta s tiTp tNc khEa

    hFc ?i nhYng khJi nim b\ sung.

    2h> nhCc Tn t^ tr>?c, cW s dY liu &+f' c_a Auto+A >c t\ chc tt B

    cE thB thao tJc Wn giQn = chUnh 9Jc cJc i t>ng. +h|ng ta cE chung ! kiBu cW

    bQn* .ont*iners >(ho*ng chJ*Aa% "#$ects >ZFi t=ngA.

    .ont*inersl= nhYng i t>ng c bit cung cSp mt cW chT Wn giQn = hiu quQ

    B l>u giY, chnh sMa = c}n nYa tr@n cJc i t>ng ha) cJc s>u tp. 2E >c ti

    >u hEa B cho php tru) cp nhanh ?i mt l>ng ti thiBu phU. $i kiBu i t>ng

    lKi cE mt khoang cha thUch hp l= nWi bKn luGn luGn l>u trY i t>ng c_a m[nh.

    +f c_a Auto+A cE =i khoang cha mt trong s ch|ng l= L*er3*#,e,

    Linet-e3*#,e= T,ocB3*#,e. $i i t>ng khoang cha cE phuong thc tru)

    cp chun = hDu hTt ch|ng 9uSt mt l?p quen thuc B lp lKi ?i mi th=nh

    phDn. $i lDn bKn tKo ra mt i t>ng = mun l>u trY trong +f c_a Auto+A,

    ban cDn phQi tun theo cGng thc sau B l>u trY ha) l=m bSt c ic g[ mt cJch

    |ng nhSt.

    $t khJc,

  • 7/23/2019 Objectarx by Lemanhhung

    28/71

    on:t panic. 8ou just need to keep in mind some basic but essenti*, ru,es*

    {' atabase resident objects shou,d never #e de,etedeen )ou hae erased

    themA. 4his

    %unction will open eer) object deried %rom %cD#"#$ect class and will proide

    )ou a .bb -ointer to access the object properties and methods. One o% this

    %unction signatures is the %ollowing*

    inline Acad44:rrortatusac!'#p"n#'("ct(AcD9ect&

    p9,AcD9ect"did, AcD449pen6ode$ode, ool open:rased);

    p#'( 9utput pointer to t#e opened oecti! "nput t#e oect "D of t#e oect to openmo!" "nput $ode to open oect

    op"nEras"!"nput oolean indicatin- w#et#er its 9 to open an erasedoect

    4his %unction receies an empt) pointer to %cD#"#$ect b) re%erence that will be

    %illed out b) Auto+A i% there is an object with the proided input ariable id.

    urther )ou need to proide )our action intention on the object which can open the

    object i% it is on erased status. Remember we hae talked that erased objects

    remain inside Auto+A database until the ne9t sae operation.

    Bi 0 u#n l$ !i t"ng

    Gii thiu

    4rong b=i tr>?c ch|ng ta nEi chu)n }ng i c_a i t>ng. 4rong b=i n=)

    ta s i 9a hWn =o cJch quQn l~ i t>ng c_a Auto+A. 2h> cp t^ tr>?c,

    mFi i t>ng u cE m nhn dKng gFi l= "#$ectId. `E l= ch[a khEa B t[m >c

    con tr c_a nE = tiTn h=nh thao tJc Fc = ghi.

    Ph>Wng thc tru) cp chun >c tKo bi thao tJc "0/ &Fc, iTt hoc ghi ch|',

    =i thao tJc = ph>Wng thc .L"'0. 2go=i ra cE nhiu hiu quQ hWn thGng qua

    giao tiTp. +W chT n=) rSt hiu quQ = an to=n. H) nEi cQ hai ph>Wng thc.

    i@u vX -hng thJc "0/ .L"'0

    `) l= ph>Wng thc >c sM dNng th>ng 9u)@n nh>ng mt khJc lKi thiTu an to=n

    [ bKn cE thB qu@n ic Eng i t>ng lKi = sau E g) ra s tru) cp 9m phKm

    hoc thm chU l= C*t*, errorscE thB l=m Auto+A ng^ng hoKt ng.

    H=m chung = chun nhSt B m mt i t>ng >c gFi l= *cd#"-en"#$ect>A.H=m n=) s m mFi i t>ng cE >c t^ l?p %cD#"#$ect = s cung cSp cho bKn

    mtcon trH .bb B tru) cp t?i thuc tUnh = ph>Wng thc c_a i t>ng. $t

    thB hin c_a h=m n=) nh> sau *

    inline Acad44:rrortatusac!'#p"n#'("ct(AcD9ect&

    p9,AcD9ect"did, AcD449pen6ode$ode, ool open:rased);

    p#'( 7on trJ C=u ra C $H Cmi tKLn-i! ng nTu nE bL 9Ea. 2h?

    rng ch|ng ta nEi rng i t>ng bL 9Ea xn tn tKi trong +f c_a Auto+A

    Tn tn quJ tr[nh l>u &sae' tiTp theo.

    http://arxdummies.blogspot.com/

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    31/71

    4he o-ening intention is ver im-ort*ntbecause it will limit or not what )ou

    can do with the object. I% )ou open an object %or R3A )ou will not be able to call

    methods that modi%) the object:s state. In other hand, i% )ou open the object %or

    (RI43 )ou will be able to both modi%) and read object data. Ah, so is better to

    alwa)s open the object %or (RI43

    deCinite, /"3

    (hen )ou open an object %or (RI43 Auto+A %ires seeral pre and postprocedures on it that causes some -erCorm*nce overhe*d. I% )our routine opens

    seeral objects and )ou use the (RI43 %lag )ou will certainl) loose per%ormance.

    4he same object can be open %or R0%D up to ]l times without close but it is not

    recommended. 8ou should alwa)s close the object as soon as possible. I% an object

    is opened %or 6RI30 )ou can:t open it a second time %or (RI43. Zasicall), )ou

    need to %ollow the %ollowing rules*

    Opening objects in different modes

    Object opened for: kForRead kForWrite kForNotify

    openedForRead eAtMaxReaders eWasOpenForRead (Succeeds)

    openedForWrite eWasOpenForWrite eWasOpenForWrite (Succeeds)

    openedForNotify eWasOpenForNotify eWasOpenForNotify eWasOpenForNotify

    wasNotifying (Succeeds) eWasNotifying eWasNotifying

    Undo eWasOpenForUndo eWasOpenForUndo (Succeeds)

    4he best per%ormance approach is to alwa)s open the object %orR0%D, anal);e i%

    )ou will modi%) it and onl) a%ter this anal)sis, upgrade its open operation

    to 6RI30 using the u-gr*de"-en>Amethod. It will switch the object:s state %rom

    R3A to (RI43. 4o get back to R3A use the do!ngr*de"-en>A method. 4hese

    methods are er) use%ul. A simple operation to use these methods would be*

    oid c)ang"*oor(AcD9ect"did)

    AcD:ntit& p:nt ' N+!!;

    if (acd9pen9ect(p:nt, id, AcD44or5ead) '' Acad44e9)

    if (p:nt2color"nde_() ' 3)

    p:nt2up-rade9pen();

    $Nc Uch m l= G c]ng quan trFng [ nE s gi?i hKn hoc khGng cJi g[ bKn cE thB

    l=m ?i i t>ng. 2Tu bKn m i t>ng ch B `Fc bKn s khGng thB gFi ph>Wng

    thc B chnh sMa th=nh phDn c_a i t>ng. $t khJc nTu m i t>ng B yhi

    bKn cE thB ^a chnh sMa ^a Fc dY liu c_a nE. Ah, -) th[ tt hWn hTt l= luGn

    m i t>ng B yhi sao

    r r2ng ,2 (h:ng

    hi m i t>ng B yhi, Auto+A kUch hoKt =i th_ tNc tr>?c = th_ tNc thGng bJocE thB g) quJ tQi trong quJ tr[nh. 2Tu I% )our routine opens seeral objects and

    )ou use the (RI43 %lag )ou will certainl) loose per%ormance.

    4he same object can be open %or R0%D up to ]l times without close but it is not

    recommended. 8ou should alwa)s close the object as soon as possible. I% an object

    is opened %or 6RI30 )ou can:t open it a second time %or (RI43. Zasicall), )ou

    need to %ollow the %ollowing rules*

    M cc i tng !"i cc# t#$c k#c n#a%

    &i tng c m ': kForRead kForWrite kForNotify

    openedForRead eAtMaxReaders eWasOpenForRead (Thnh c!ng)

    openedForWrite eWasOpenForWrite eWasOpenForWrite (Thnh c!ng)

    openedForNotify eWasOpenForNotify eWasOpenForNotify eWasOpenForNotify

    wasNotifying (Thnh c!ng) eWasNotifying eWasNotifying

    Undo eWasOpenForUndo eWasOpenForUndo (Thnh c!ng)

    +Jch tt nhSt l= luGn m i t>ng chT R0%D, phn tUch nTu bKn s sMa nE

    = ch sau khi phn tUch, nng cSp quJ tr[nh m B 6RI30 bng ph>Wng

    thc u-gr*de"-en>A. 4rKng thJi c_a i t>ng >c chu)Bn t^ R3A sang

    (RI43. `B tr lKi R3A gFi ph>Wng thc do!ngr*de"-en>A. +Jc ph>Wng thc

    n=) l= G c]ng hYu Uch. +Jch Wn giQn B sM dNng cJc ph>Wng thc n=) nh> sau*

    oid c)ang"*oor(AcD9ect"did)

    AcD:ntit& p:nt ' N+!!;

    if (acd9pen9ect(p:nt, id, AcD44or5ead) '' Acad44e9)

    if (p:nt2color"nde_() ' 3)

    p:nt2up-rade9pen();

    http://arxdummies.blogspot.com/

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    32/71

    http://arxdummies.blogspot.com/

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    33/71

    p:nt2set7olor"nde_(3);

    b

    else

    acutPrintf(8*(`n:ntit alread #as color'3`));

    b

    p:nt2close();

    b

    b

    Using 3r*ns*ction method

    4ransactions are a #etter *nd much more eCCicientmethod tomanage objects. 4he) can be nested and this allows )ou toper%orm,ong o-er*tionswithout the limitation o% R3A and (RI43states. Zasicall) )ou need to open a transaction, per%orm )our desiredmodi%ications, and at the end, per%orm an end or abort transactionoperation.

    4ransactions are prett) good to use when )our application uses dialogbo9es that change objects. At )our dialog opening )ou start a newtransaction and, depending on user click on O or +A2+3 button, )oucall end or abort transaction methods.

    6hen ou *#ort * tr*ns*ction the !ho,e cont*ined modiCic*tion*re c*nce,,ed. In %act, modi%ications are reall) applied onl) when )ouend a transaction. Another great %eature is that )ou can open an object%or (RI43 seeral times as )ou can open %or R3A at the same time.

    You donft need to c,ose o#$ects o-ened through * tr*ns*ction.4he end or abort method will close eer) object opened and willper%orm modi%ications as necessar). It is not recommended to mi9standard "0/ .L"'0 approach with 3R%/'%.3I"/' due somedesign limitations. 8ou could read more details about this inside fdocumentation. 2ow, let:s the see the same operation we did aboeusing transactions*

    p:nt2set7olor"nde_(3);

    b

    else

    acutPrintf(8*(`n:ntit alread #as color'3`));

    b

    p:nt2close();

    b

    b

    ' dng -hng thJc gi*o ti1-

    yiao tiTp l= ph>Wng thc tt = t ra hiu quQ hWn B quQn l~ it>ng. 2E cE thB tha) thT = [ thT cho php bKn tiTn h=nh mt quJtr[nh d=i m= khGng cDn tha) \i trKng thJi R3A = (RI43. $t cJchcW bQn, bKn cDn m mt giao tiTp, tiTn h=nh cJch t]) chnh mongmun = cui c]ng, tiTn h=nh kTt th|c hot h_) b quJ tr[nh giao tiTp.

    yiao tiTp tht s tu)t i B sM dNng trong ng dNng cE sM dNng hp

    thoKi B tha) \i i t>ng. hi m hp thoKi bKn bCt Du mt giaotiTp = t]) thuc =o ng>i d]ng nhSn chFn O ha) +A2+3,bKn gFikTt th|c hoc h_) b ph>Wng thc giao tiTp.

    (hi h5 #H mt gi*o ti1-a to2n # th* ng B(RI43 =i lDn khi bKn m nE B R3A c]ng mt l|c.

    Tn Bh:ng #t #uc -hPi ng >c m =tiTn h=nh tha) \i nTu cDn. hGng khu)Tn cJo h}a trn quJtr[nh "0/ .L"'0 chun ?i 3R%/'%.3I"/' trong mt =i gi?ihKn. ZKn cE thB Fc chi tiTt hWn b@n trong t=i liu f. Z) gi h)nh[n quJ tr[nh t>Wng t tr@n sM dNng ph>Wng thc giao tiTp*

    http://arxdummies.blogspot.com/

    id ) * ( 9 d id)

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    34/71

    oid c)ang"*oor(AcD9ect"did)

    AcD:ntit& p:nt ' N+!!;

    acd*ransaction6ana-er2start+ransaction();

    if (acd*ransaction6ana-er2g"t#'("ct((AcD9ect&)p:nt,

    id,AcD44or5ead) '' Acad44e9)

    if (p:nt2color"nde_() ' 3)

    p:nt2up-rade9pen();

    p:nt2set7olor"nde_(3);

    b

    else

    acutPrintf(8*(`n:ntit alread #as color'3`));

    b

    b

    acd*ransaction6ana-er2"n!+ransaction();

    b

    4his time )ou open the object using the get"#$ect>Amethod which is

    much like *cd#"-en"#$ect>Abut Y"U D"/f3 /00D 3" .L"'0theobject. 4he whole process is ended at end3r*ns*ction>Amethod call.At that time all operations are applied in one operation.

    oid c)ang"*oor(AcD9ect"did)

    AcD:ntit& p:nt ' N+!!;

    acd*ransaction6ana-er2start+ransaction();

    if (acd*ransaction6ana-er

    2g"t#'("ct((AcD9ect&)p:nt,id,AcD44or5ead) '' Acad44e9)

    if (p:nt2color"nde_() ' 3)

    p:nt2up-rade9pen();

    p:nt2set7olor"nde_(3);

    b

    else

    acutPrintf(8*(`n:ntit alread #as color'3`));

    b

    b

    acd*ransaction6ana-er2"n!+ransaction();

    b

    Dn n=) bKn sM dNng ph>Wng thc get"#$ect>AcE phDn ging

    ?i *cd#"-en"#$ect>Anh>ng #n Bh:ng cn -hPi A>c gFi t?i. Dn n=), to=n b quJ tr[nh >c gEi gFn bng mt th_ tNcdu) nhSt.

    http://arxdummies.blogspot.com/

    Class - ntities ine weight

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    35/71

    Class - ntities

    Introduction

    3ntities are objects that has a gr*-hic*, re-resent*tion. 4he) could

    be sim-,eor com-,e+depending on how man) %eatures and %unctionalities the)

    implement. 3ntities are stored into T,ocB3*#,eRecordcontainer objects. 3ach o%

    these containers will keep its entities until the) are erased or atabase is

    destro)ed. As an) other database resident object, each entit) can be accessedthrough its unique "#$ectId. zsing its ObjectId we can then acquire its pointer

    &%or Re*d, 6riteor /otiCas we saw on preious class' and then per%orm desired

    operations.

    fome special entities contains also another objects to simpli %) implementation and

    management. A good e9ample o% this approach is %cD#do,,inewhich has a

    collection o% %cD#do,,ineQerte+ objects that represents each o% its erte9es.

    0ntit ro-erties

    Auto+A entities has seeral properties and some o% them arecommonto all kind

    o% entit). 4hese properties are stored into entit):s base class called %cD#0ntit.

    4his class, also deried %rom%cD#"#$ectimplements seeral common

    Cunction*,itiesthat will be used b) eer) deried class and related implemented

    entit).

    I% we create a circle &%cD#.irc,e', %or e9ample, it will contain some properties

    that came %rom %cD#0ntit. 4hese properties are*

    +olor

    inet)pe

    inet)pe scale

    -isibilit)

    a)er

    ine weight

    Plot st)le name

    Bi T"%c th

    Gii thiu

    4hc thB l= cJc i t>ng cE th@ hin hnh hjc. +h|ng cE thB Wn giQn ha) phc

    tKp da =o s l>ng c tUnh = chc nVng ch|ng Qm nhim. 4hc thB >c l>ugiY trong i t>ng khoang T,ocB3*#,eRecord. $i mt loKi khoang s giY thc

    thB cho t?i khi ch|ng bL 9Ea hoc +f bL h_). ying nh> cJc i t>ng l>u tr|

    +f, mi thc thB >c tru) cp thGng qua mt "#$ectIdWn nhSt. fM dNng

    ObjectId ta cE thB thu nhn >c con tr c_a nE &cho thao tJc Re*d, 6ritehoc

    /otiC nh> ta biTt b=i tr>?c' = ri tiTn h=nh cJc quJ tr[nh mong mun.

    $t =i thc thB c bit lKi bao gm cJc i t>ng khJc B thi h=nh = quQn l~

    mt cJch Wn giQn. -U dN tt c_a Sn n=) l= %cD#do,,inecE cha cJc i

    t>ng %cD#do,,ineQerte+thB hin bng cJc nh c_a PO8I23.

    3huc tnh c5* th?c th@

    $i thc thB c_a Auto+A cha =i thuc tUnh = mt trong s ch|ng l= chung ?i

    mFi thc thB. 2hYng thuc tUnh n=) >c l>u trY b@n trong l?p cW bQn c_a thc thB

    gFi l= %cD#0ntit. ?p n=) nhn >c t^ %cD#"#$ectmang =i chc nVng

    chung m= s >c sM dNng bi cJc l?p mong mun = thc thB thc thi li@n quan.

    -U dN nTu ta tKo mt >ng tr}n &%cD#.irc,e', nE s mang =i thuc tUnh Tn

    t^ %cD#0ntit. +h|ng bao gm*

    $=u sCc

    iBu >ng

    4 l kiBu >ng

    4Unh hin thL

    http://arxdummies.blogspot.com/

    ?p 4his class has wonder%ul utilit) %unctions that will reduce )our work a lot< Among

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    36/71

    ?p

    ` m c_a nt

    4@n kiBu in

    4hese properties has speci%ic access methods that will allow )ou to read or modi%)

    them accessing the %cD#0ntitbase class. fo, i% we get our %cD#.irc,eentit)

    and would like to change its color we just need to open it %or 6rite, access the

    proper method and then c,ose the circle.

    I% we need to build an application that onl) access these properties we reall) don:t

    need to know what kind o% entit) we are opening. In this situation we just need to

    open our entit), get its pointer as an Acb3ntit) pointer and access the desired

    method.

    0ntit 3r*nsCorm*tions

    3ach Auto+A entit) is placed into a D s-*ce. 8ou alread) know that we

    can move, rot*te, sc*,e, *,ignand man) other modi%ications oer an enti t).Auto+A threats most o% these operations using geometric *,ge#r* using

    m*tri+es. Remember that we hae talked about ObjectARX classes and, speciall)

    in this case, about %cGepre%i9ed classes. 4he Acye classes aregeometric

    c,*sseswhich will allow )ou to per%orm simple and comple9 geometric operations

    inside Auto+A.

    fo let:s suppose )ou need to per%orm a rotation oer seeral entities

    &circ,es, -o,,ines, ,ines, etc.' and need to do this with minimum e%%ort and basic

    geometric knowledge. 2o big deal< (e just need to build a tr*nsCorm*tion

    m*tri+and call the appropriate method called tr*nsCormT>Aimplementedb) %cD#0ntitclass. 8es, eer) entit) could be potentiall) trans%ormedAis the responsible to do this job %or

    )ou.

    4he most common signature o% this method receies the *rgument entitpointer

    &the entit) )ou would like to test with )ours', the intersection t-e, an*rr* oC

    D -ointsto be %illed out b) this %unctions with intersection points %ound and,

    optionall) the yf marker o% both entities which represents the subentit) inde9.

    4he intersection t)pe must be one o% the %ollowing o-er*nds*

    B"nToth"-er*nds* neither entit) is e9tended0

    B0+tend3his* e9tend this entit)0

    B0+tend%rg* e9tend argument entit)0

    B0+tendToth* e9tend both entities.

    I% these two entities intercept each other &obiousl) depending on which t)pe o%

    intersection )ou speci%)' the -*ssed *rr* !i,, receive the intersection -oints.

    4his %unction is er) use%ul and uses the core geometric engine o% Auto+A which

    make it %ast and reliable.

    Our ne9t class will be a demo e9ample and I would gie )ou a couple o% da)s

    to accomplish it and then I wi ll post m) solution to it. fta) tunedWng thc thc thB

    tr*nsCormT>A thGng qua ma trn b@n trong0

    set3o3r*n,*tion* ZKn chu)Bn tJc vectorD&%cGeQectord' Ki din cho

    php biTn \i m= bKn mun tiTn h=nh. fau E thc hin c]ng mt quJ tr[nh

    nh> tr@n0

    set3o9irroring* H=m n=) nhn tham s gm mt Wng lKi c_a bKn s cDn Jnh giJ cJc iBm

    giao cCt c_a cJc thc thB. Ph>Wng thc intersect6ith>As chLu trJch nhim Qm

    nhn cGng ic E cho bKn.

    ~ s chung nhSt c_a ph>Wng thc n=) nhn con tr

  • 7/23/2019 Objectarx by Lemanhhung

    38/71

    2Tu hai thc thB chn lxn nhau &da tr@n kiBu giao m= bKn 9Jc Lnh' mPng trP

    vX s nh**n$ c ch mNc = tru) nhp =o i t>ng c_a nE. Auto+A cE

    =i ZQng biBu t>ng B l>u giY la)ers, linet)pes, te9t st)les = nhYng tp i

    http://arxdummies.blogspot.com/

    t>ng khJc. -[ nhYng khoang ch>a n=) l=m ic ging nh> nhau, cE mt l?p cW s AcD'R"gApp+a'"It"rator

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    39/71

    chung cho mi bQng biBu t>ng, cJc bQn ghi c_a nE = biTn lp ph] hp.

    +) phn mNc bQng biBu t>ng nh> sau*

    %cD#'m#o,3*#,e

    AcD'A'stract,i"&+a'"

    AcD',i"&port+a'"

    AcD',i"&+a'"

    AcD'Bock+a'"

    AcD'DimSty"+a'"

    AcD'Lay"r+a'"

    AcD'Lin"typ"+a'"

    AcD'R"gApp+a'"

    AcD'+"xtSty"+a'"

    AcD'U*S+a'"

    %cD#'m#o,3*#,eRecord

    AcD'A'stract,i"&+a'"R"cor!

    AcD',i"&port+a'"R"cor!

    AcD',i"&+a'"R"cor!

    AcD'Bock+a'"R"cor!

    AcD'DimSty"+a'"R"cor!

    AcD'Lay"r+a'"R"cor!

    AcD'Lin"typ"+a'"R"cor!

    AcD'R"gApp+a'"

    AcD'+"xtSty"+a'"

    AcD'U*S+a'"

    %cD#'m#o,3*#,eIter*tor

    AcD'A'stract,i"&+a'"It"rator

    AcD',i"&port+a'"It"rator

    AcD',i"&+a'"It"rator

    AcD'Bock+a'"It"rator

    AcD'DimSty"+a'"It"rator

    AcD'Lay"r+a'"It"rator

    AcD'Lin"typ"+a'"It"rator

    AcD'+"xtSty"+a'"It"rator

    AcD'U*S+a'"It"rator

    fo, to cre*te * ,*er, %or instance, )ou will need to*

    Open current atabase0

    Open Acba)er4able &%or write'0

    +reate an Acba)er4ableRecord &using new operator'0

    +on%igure the Acba)er4ableRecord0

    Add it to Acba)er4able which is its proper container0

    AcD'Bock+a'"

    AcD'DimSty"+a'"

    AcD'Lay"r+a'"

    AcD'Lin"typ"+a'"

    AcD'R"gApp+a'"

    AcD'+"xtSty"+a'"

    AcD'U*S+a'"

    %cD#'m#o,3*#,eRecord

    AcD'A'stract,i"&+a'"R"cor!

    AcD',i"&port+a'"R"cor!

    AcD',i"&+a'"R"cor!

    AcD'Bock+a'"R"cor!

    AcD'DimSty"+a'"R"cor!

    AcD'Lay"r+a'"R"cor!

    AcD'Lin"typ"+a'"R"cor!

    AcD'R"gApp+a'"

    AcD'+"xtSty"+a'"

    AcD'U*S+a'"

    %cD#'m#o,3*#,eIter*tor

    AcD'A'stract,i"&+a'"It"rator

    AcD',i"&port+a'"It"rator

    AcD',i"&+a'"It"rator

    http://arxdummies.blogspot.com/

    AcD'Bock+a'"It"rator

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    40/71

    AcD'DimSty"+a'"It"rator

    AcD'Lay"r+a'"It"rator

    AcD'Lin"typ"+a'"It"rator

    AcD'R"gApp+a'"It"rator

    AcD'+"xtSty"+a'"It"rator

    AcD'U*S+a'"It"rator

    -[ thT, B to mt ,*er, nh> U dN, bKn s cDn*

    $ +f hin thi0

    $ Acba)er4able &B ghi'0

    4Ko m?i Acba)er4ableRecord &sM dNng toJn tM m?i'0

    `Lnh h[nh cho Acba)er4ableRecord0

    4h@m nE =o Acba)er4able chUnh l= khoang cha thUch hp0

    +lose the record0

    +lose the container.

    oid create!aer()

    AcD!aer*ale &p!aer*l ' N+!!;

    acdostApplicationerices()2worin-Dataase()

    2-et$ol*ale(p!aer*l, AcD44orWrite);

    if (p!aer*l2#as(8*(M%LA%ER)))

    AcD!aer*ale5ecord &p!aer*l5cd ' n"& AcD!aer*ale5ecord;

    p!aer*l5cd2setNa$e(8*(M%LA%ER));

    Ac7$7olor color;

    color.set7olor"nde_(1); // red

    p!aer*l5cd2set7olor(color);

    p!aer*l2add(p!aer*l5cd);

    p!aer*l5cd2cos"./;

    b else acutPrintf(`n!aer alread e_ists`);

    p!aer*l2cos"./;

    b

    4o ,ist *,, e+isting ,*ers*

    Open current atabase0

    Open Acba)er4able &%or read'0

    +reate an Acba)er4ableIterator0

    Per%orm a loop through container entries0

    yet the ke) name %or each entr)0

    +lose the container.

    oid iterate!aers()

    AcD!aer*ale& p!aer*l ' N+!!;

    `Eng bQn ghi lKi0

    `Eng khoang cha.

    oid create!aer()

    AcD!aer*ale &p!aer*l ' N+!!;

    acdostApplicationerices()2worin-Dataase()

    2-et$ol*ale(p!aer*l, AcD44orWrite);

    if (p!aer*l2#as(8*(M%LA%ER)))

    AcD!aer*ale5ecord &p!aer*l5cd ' n"& AcD!aer*ale5ecord;

    p!aer*l5cd2setNa$e(8*(M%LA%ER));

    Ac7$7olor color;

    color.set7olor"nde_(1); // red

    http://arxdummies.blogspot.com/

    p!aer*l5cd2set7olor(color); b

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    41/71

    p!aer*l2add(p!aer*l5cd);

    p!aer*l5cd2cos"./;

    b else acutPrintf(`n!aer alread e_ists`);

    p!aer*l2cos"./;

    b

    `B,E- d*nh s4ch c4c ,- hin cN*

    $ +f hin tKi0

    $ Acba)er4able &B Fc'0

    4Ko ra Acba)er4ableIterator0

    4iTn h=nh lp qua cJc i t>ng c_a khoang cha0

    S) t@n khEa cho mi i t>ng0

    +lose the container.

    oid iterate!aers()

    AcD!aer*ale& p!aer*l ' N+!!;

    acdostApplicationerices()2worin-Dataase()

    2-et$ol*ale(p!aer*l, AcD44or5ead);

    AcD!aer*ale"terator& p!aer"terator;

    p!aer*l2new"terator(p!aer"terator);

    AcD!aer*ale5ecord& p!aer*l5cd;

    *7A5& p!Na$e;

    for (; p!aer"terator2!on"./; p!aer"terator2st"p./)

    p!aer"terator2-et5ecord(p!aer*l5cd, AcD44or5ead);

    p!aer*l5cd2-etNa$e(p!Na$e);

    p!aer*l5cd2cos"./;

    acutPrintf(8*(`n!aer na$e4 s`),p!Na$e);

    acutDeltrin-(p!Na$e);

    !""t" pLay"rIt"rator;

    p!aer*l2cos"./;

    b

    Diction*ries

    4his t)pe o% container is designed to store generic %cD#"#$ect derived c,*ss

    o#$ects. 4his container is er) use%ul because we can also store our customobjects inside it. 4he dictionar) structure is much like a tree structure where we

    hae nodes and entries. Inside the same node, entries can not repeat its name

    because the) need to be unique inside the same leel. 4hese are the so called (e

    entriesand each e) entr) will map to an %cD#"#$ect -ointerwhich can be

    retrieed directl) or through an interator &%cD#Diction*rIter*tor'.

    4o store an object we need to create an entr) using the set%t>Amethod passing

    also the object pointer which we alread) hae instantiated with the new operator.

    A%ter add this object we need to c,ose>A it. Acbictionar) container will return

    the gien %cD#"#$ectId %or each entr).

    4his container is also used b) some Auto+A %eatures like grou-s and mu,ti,ine

    st,es. (e will coer more about ictionaries on the +ustom Objects chapter.

    acdostApplicationerices()2worin-Dataase()

    2-et$ol*ale(p!aer*l, AcD44or5ead);

    AcD!aer*ale"terator& p!aer"terator;

    p!aer*l2new"terator(p!aer"terator);

    AcD!aer*ale5ecord& p!aer*l5cd;

    *7A5& p!Na$e;for (; p!aer"terator2!on"./; p!aer"terator2st"p./)

    p!aer"terator2-et5ecord(p!aer*l5cd, AcD44or5ead);

    p!aer*l5cd2-etNa$e(p!Na$e);

    p!aer*l5cd2cos"./;

    acutPrintf(8*( n!aer na$e4 s`),p!Na$e);

    acutDeltrin-(p!Na$e);

    http://arxdummies.blogspot.com/

    b

    ! t L It t

    )ou will request user to select entities indiiduall) and sometimes )ou will select

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    42/71

    !""t" pLay"rIt"rator;

    p!aer*l2cos"./;

    b

    3 c thiTt kT B l>u giY chung i t>ng l?p mong mun

    %cD#"#$ect. hoang n=) rSt hYu Uch [ ch|ng ta cng cE thB l>u giY cJc i

    t>ng ri@ng b@n trong nE. +Su tr|c c_a t^ iBn ging nh> mt cSu tr|c c) l= nWicE cJc nhJnh = cJc mNc. Z@n trong c]ng mt nhJn, cJc mNc khGng thB tr]ng t@n

    [ ch|ng cDn cE t@n du) nhSt trong c]ng mt cSp bc. $E >c gFi l= khEa mNc =

    mi khEa mNc s dxn Tn mt con tr %cD#"#$ectcE thB khGi phNc chUnh 9Jc

    hoc thGng qua biTn lp &%cD#Diction*rIter*tor'.

    `B l>u giY mt i t>ng ch|ng ta cDn tKo mt mNc sM dNng ph>Wng thc set%t>A

    thGng qua con tr i t>ng >c khi tKo ?i mt toJn tM m?i. fau khi th@m

    i t>ng n=), ta cDn phQi Eng nE bng c,ose>A. hoang Acbictionar) s trQ

    %cD#"#$ectId cho mi mNc.

    hoang cha n=) cng >c sM dNng bng cJc c tUnh Auto+A nh> cJc nhEm,

    kiBu nhiu d}ng. +h|ng ta s t[m hiBu nhiu hWn t^ iBn ch>Wng cJc i

    t>ng t]) chnh.

    Class 7 - 8eletion 8ets

    Hello,

    On this class we will coer the %irst wa)s we can interact with user to allow our

    application to get in%ormation %rom dr*!ing screen8ou probabl) will need to use

    this method inside )our application.

    Introduction

    4his is one o% the most important wa)s to interact with user because it will allow

    )ou to get in%ormation %rom drawing screen through selected entities. fome times

    them using a %ilter.

    A selection set is a grou- oC entities !hich *re current, se,ected b) an user

    or b) an application. 4he most important concept inoled when selecting entities

    %rom screen is that Auto+A will return their names through a t)pe

    called *ds}n*me. 4his t)pe contains the entit) name &which is alid onl) on the

    current session' and it can be conerted to ObjectId using

    the*cd#Get"#$ectId>Aglobal %unction*

    Acad44:rrortatusac!'G"t#'("ctI!(AcD9ect"d o"d,

    constads8na$eoNa$e);

    4his %unction receies the *ds}n*meand conert it to an%cD#"#$ectId. $ost o%

    selection set %unctions will still use the adsname as parameters and on theses

    cases )ou don:t need to conert it. 4he *ds}n*me c*n store sever*, entities or

    $ust one. 4his will depend on how )ou or the user has per%ormed the selection.

    4he selection is made using a %unction called *ced''Get>Awhich will appl) aselection or prompt the user to do that. 4he %unction signature is*

    int ac"!SSG"t (const A7A5 &str, const oid &pt1, const oid &pt%,

    const struct resuf &ent$as, ads8na$ess);

    o! to use

    It receies a selection option, two points, a mask and returns the resulting

    selection set. A%ter use the selection set it needs to be released and this is done

    through the *ced''Sree>A %unction 4he selection option will instruct Auto+A

    inter%ace to do one o% the %ollowing methods*

    S""ction *o!" D"scription

    N+!!in-lepoint selection (if pt1 is specified)or user selection (if pt1 is also N+!!)

    Non-eo$etric (all, last, preious)

    http://arxdummies.blogspot.com/

    4 Pro$pts supplied

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    43/71

    . +ser pic

    4 9t#er callacs

    A All

    o_

    7 7rossin-

    7P 7rossin- Pol-on

    4D Duplicates 9

    4: :ert#in- in aperture

    ence

    G Groups

    " "$plied

    4 eword callacs

    ! !ast

    6 6ultiple

    P Preious

    4 orce sin-le oect selection onl

    W Window

    WP Window Pol-on

    g :_tended searc# (searc# w#ole dataase)

    4his wa) we can per%orm the selection b) seeral wa)s. fome e9amples are

    presented below*ads8pointpt1, pt%;

    ads8na$e ssna$e;

    pt1gv ' pt1hv ' pt1v ' 0.0;

    pt%gv ' pt%hv ' x.0; pt%v ' 0.0;

    // Get t#e current P"7"5* or as user for a selection

    ac"!SSG"t(N+!!, N+!!, N+!!, N+!!, ssna$e);

    // Get t#e current P"7"5* set

    ac"!SSG"t(8*(0I0/, N+!!, N+!!, N+!!, ssna$e);

    // 5epeat t#e preious selection set

    ac"!SSG"t(8*(0P0/, N+!!, N+!!, N+!!, ssna$e);

    // elects t#e last created entit

    ac"!SSG"t(8*(0L0/, N+!!, N+!!, N+!!, ssna$e);

    // elects entit passin- t#rou-# point (x,x)

    ac"!SSG"t(N+!!, pt%, N+!!, N+!!, ssna$e);

    // elects entities inside t#e window fro$ point (0,0) to (x,x)

    ac"!SSG"t(8*(0W0/, pt1, pt%, N+!!, ssna$e);

    Using 'e,ection Ci,ters

    ilters are a power%ul wa) to speed up selection sets and aoid runtime operationsto eri%) entities. 8ou can use single %ilters or composed %ilters. 3ach %ilter is

    speci%ied through a structure called resbu%. A res#uC is * ,inBed ,istwhich store

    seeral t)pes o% in%ormation and ma) contains seeral items. 4o use a %ilter we

    need to construct it and pass it as a parameters o% *ced''Get>Amethod. 4he

    selection is per%ormed but each selected entit) will need to respect the %ilter. 4here

    http://arxdummies.blogspot.com/

    are a lot o% %ilters we can create and the f documentation coer all o% them. 4he

    t d l t d b l // l t All 7i l

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    44/71

    most used e9amples are presented below*struct resuf e1, e%;

    *7A5 suf110v, suf%10v;

    ads8na$essna$e1, ssna$e%;

    "'12r"styp" 3 45// :ntit na$e filter

    8tcscp(suf1, 8*(`7"57!:`));

    e1.resal.rstrin- ' suf1;

    e1.rne_t ' N+!!;

    // 5etriee all circles

    ac"!SSG"t(8*(060), N+!!, N+!!, e1, ssna$e1);

    "'72r"styp" 3 85// !aer na$e filter

    8tcscp(suf%, 8*(`0`));

    e%.resal.rstrin- ' suf%;

    e%.rne_t ' N+!!;

    // 5etriee all entities on laer 0

    ac"!SSG"t(8*(060), N+!!, N+!!, e%, ssna$e%);

    9odiCing entities through * se,ection set

    4o modi%) entities inside a selection set we need to walk through selection items,get each one, conert the *ds}n*meto an"#$ectId, open the entit) %or write,

    modi%) it and then close it. 4his operation can also be done using a transaction

    which is, in long operations, much better.

    4o show )ou how to walk through a selection set I will present a short code to

    select all +IR+3 entities inside the drawing and then change its color to red. 4he

    operation is prett) simple and is done this wa)*

    // 7onstruct t#e filter

    struct resuf e1;*7A5 suf110v;

    e1.restpe ' 0; // :ntit na$e

    8tcscp(suf1, 8*(0*IR*LE0));

    e1.resal.rstrin- ' suf1;

    e1.rne_t ' N+!!;

    // elect All 7ircles

    ads8na$ess;

    if (ac"!SSG"t(8*(060), N+!!, N+!!, e1, ss) ' R+N#RM)

    ac9tR"R'(e1);

    return;

    b

    // ree t#e resufac9tR"R'(e1);

    // Get t#e len-t# (#ow $an entities were selected)

    lon- len-t# ' 0;

    if ((ac"!SSL"ngt)( ss, len-t# ) ' R+N#RM) (len-t# '' 0))

    ac"!SSFr""( ss );

    return;

    b

    ads8na$eent;

    AcD9ect"d id ' AcD9ect"d44Null;

    // Wal t#rou-# t#e selection set and open eac# entit

    for (lon- i ' 0; i y len-t#; izz)

    if (ac"!SSNam"(ss,i,ent) ' R+N#RM) continue;

    if (ac!'G"t#'("ctI!(id,ent) ' Acad44e9) continue;

    AcD:ntit& p:nt ' N+!!;

    if (ac!'#p"nAcD'Entity(p:nt,id,AcD44orWrite) ' Acad44e9)

    continue;

    // 7#an-e color

    p:nt2s"t*oorIn!"x(1);

    p:nt2cos"();

    b

    // ree selection

    ac"!SSFr""( ss );

    I hae used some new %unctions &like *cd#"-en%cD#0ntit' that are also part o%

    http://arxdummies.blogspot.com/

    ObjectARX f. Pa) attention to the memor) releases regarding to selection set

    and resbu% t)pes 2ote that I hae used also a %unction called *ced''Length&' to

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    45/71

    and resbu% t)pes. 2ote that I hae used also a %unction called *ced''Length&' to

    get the length o% selection set.

    4he *ced''/*me&' %unction get an at the passed inde9. I% we hae more than

    one entit) selected this loop will get eer) single entit) into this selection set.

    fee )ou ne9t class.

    http://arxdummies.blogspot.com/

    Class 9 - :nteratin# wit" AutoCAD a' $oing the last created entit) based on &",","'*

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    46/71

    Hello,

    On the last class I hae presented how to per%orm se,ection sets. 4his class I will

    show how can )ou interact with Auto+A usingg,o#*, Cunctionsand acquiring

    in%ormation such as num#ers,coordin*tes, sstem v*ri*#,esand much more.

    InvoBing .omm*nds

    ObjectARX proide us two global %unctions that allows us to invoBe registered

    comm*nds. 4his %unctionalit) is er) hand) and will help users to per%orm quick

    operations that don:t require comple9 procedures. 3en this method is quite simple

    )ou should aoid using it in comple9 and huge operations. 4his method ma) also

    create problems when dealing with eents handling.

    4he two proided %unctions are *ced.md>A and *ced.omm*nd>A. 4he %irst one

    inokes the command through a passed in resbu% list which will in%orm all

    command parameters. 4he second %unction will receie a ariable number o%

    parameters which will reproduce the wa) )ou %ire the command %rom the prompt

    inter%ace. Zelow are these %unctions signature*int ac"!*m!(const struct resuf & rp);

    int ac"!*omman!(int rtpe, ... unna$ed);

    4o build the resbu% list when using aced+md&' there is a utilit) %unction

    called *cutTui,dList>Awhich constructs this ,inBed ,isteasil). 8ou just need to

    pass paired alues with codes that describe the t)pes and end the list with a "

    or R3/"/0 alue. Another good practice is to clear the command prompt,

    calling*ced.omm*nd>R3/"/0A, a%ter issued the command. on:t %orget to Creememorused, when using resbu% pointers, through the*cutRe,R#>Autilit)

    %unction to aoid memor) leaks. 4here are seeral wa)s to use theses %unctions

    and I will show some o% them below*

    *ced.md>A

    ads8pointpt;

    pt0v ' pt1v ' pt%v ' 0.0;

    struct resuf&6;

    6 ' ac9tB9i!List(R+S+R,8*(`869{:`),R+S+R,8*(`8!A*`),R+S+R,8*(``),

    R+P#IN+,pt,R+S+R,PAUSE,4);

    ac"!*m!(6);

    ac"!*omman!(R+N#NE);

    ac9tR"R'(6);

    b' +alling a redraw natie command*struct resuf &c$dlist;

    c$dlist ' ac9tB9i!List(R+S+R, 8*(`85:D5AW`), 4);

    ac"!*m!(c$dlist);

    ac"!*omman!(R+N#NE);

    ac9tR"R'(c$dlist);

    *ced.omm*nd>A

    a' +alling a OO$ command and pausing %or user input*

    ac"!*omman!(R+S+R, 8*(`oo$`), R+S+R, PAUSE, R+N#NE);

    b' +reating both a +ircle and a ine entities*ac"!*omman!(R+S+R, 8*( circle ), R+S+R, 8*( 10,10`),R+S+R, PAUSE,

    R+S+R, 8*(`line`), R+S+R, 8*(`10,10`), R+S+R, 8*( %0,%0 ),

    R+S+R, 8*(``), 4);

    'stem Q*ri*#,es

    8our application will probabl) need to access Auto+A sstem v*ri*#,esthat can

    be read or write. ObjectARX proide two %unctions to deal with these ariables

    using the resbu% structure to access andor modi%) alues. 4he %unction are

    called *cedGetQ*r>Aand *ced'etQ*r>Aand below are their signatures*int ac"!G"t,ar(const A7A5 & s$,struct resuf & result);

    http://arxdummies.blogspot.com/

    int ac"!S"t,ar(const A7A5 & s$,const struct resuf & al);

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    47/71

    4he %irst parameter is the ariable name the second the resbu% pointer to set get

    in%ormation. 4he %ollowing e9ample show how to change the SILL03 radius which

    is stored through a s)stem ariable*struct resuf r, r1;

    ac"!G"t,ar(8*(`"!!:*5AD`), r);

    r1.restpe ' R+REAL;

    r1.resal.rreal ' 1.0;

    ac"!S"t,ar(8*(`"!!:*5AD`), r1);

    It is er) important that )ou speci%) the correct t)pe o% resbu% item acquired.

    In this case, the I34 radius is a real number which is R3R0%Lt)pe.

    User In-ut Sunctions

    4here are additional global %unctions to allow interaction with users ia command

    prompt inter%ace. 3ach o% these %unctions could be used alone or with other ones.

    4he %ollowing table shows what each %unction does*

    aced(et)nt Gets an inte-er alue

    aced(etRea* Gets a real alue

    aced(et+ist Gets a distance

    aced(et,ng*eGets an an-le (oriented to 0 de-rees specified t#eANGA:)

    aced(etOrient Gets an an-le (oriented to 0 de-rees at t#e ri-#t)

    aced(et-oint Gets a point

    aced(et.orner

    Gets t#e corner of a rectan-le

    aced(et/0ordGets a eword

    aced(et1tring Gets a strin-

    3ach o% these %unctions returns a int number as a resu,t codethat could be one o%

    the %ollowing*

    R2NORM +ser entered a alid alue

    R23RROR *#e function call failed

    R2.,N +ser entered :7

    R2NON3 +ser entered onl :N*:5

    R2R34 Auto7AD reected t#e reRuest as inalid

    R2/WOR+ +ser entered a eword or aritrar te_t

    Auto+A allows )ou to -revent inv*,id v*,ueswhen user respond to )our input

    %unctions. 4his %eature can be made through the*cedInitGet>A%unction which can

    receie one or a combination o% the %ollowing alues*

    R1(5NON677 Disallow null input

    R1(5NO83RO Disallow jero alues

    R1(5NON3( Disallow ne-atie alues

    R1(5NO7)M Do not c#ec drawin- li$its, een if !"67:7 is on

    R1(5+,19 +se das#ed lines w#en drawin- ruerand line or o_

    http://arxdummies.blogspot.com/

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    48/71

    R1(5+ "-nore coordinate of 3D points (acedGetDist() onl)

    R1(5O293R Allow aritrar input|w#ateer t#e user enters

    4he %ollowing e9ample shows how to acquire a alue greater than ;ero*int a-e ' 1;

    ac"!InitG"t(RSG_N#NULL RSG_N#ER# RSG_N#NEG, N+!!);

    ac"!G"tInt(8*(`ow old are ou `), a-e);

    http://arxdummies.blogspot.com/

    Class 1; -

  • 7/23/2019 Objectarx by Lemanhhung

    49/71

    4his class is not %ull) related to Auto+A and ObjectARX but it coers an oeriew

    o% 9S. librar). 4his librar) will allow )ou to create rich inter%aces %or )our

    ObjectARX applications easil) and with pro%essional st)le.

    Introduction

    9S. &0icrosoft 1oundation Classes' is a power%ul librar) made to allowwindows programmers to easil) create rich inter%aces %ollowing the windows

    standard inter%ace.

    4he $+ class tree is huge and obiousl) it is not the objectie o% this class to

    make )ou an $+ wi;ard. I will present here the main concepts inoled when

    using $+ inside Auto+A and how to take adantage o% its power.

    I% )ou would like to use $+ inside )our ObjectARX application )ou will need to link

    it with 9S. ,i#r*rieswhich can be done d)namicall) or staticall). +urrentl)

    ObjectARX onl) support d)namic linked $+ applications because some o%

    Auto+A libraries were d)namic linked with $+ and )ou can:t mi9 static and

    d)namic linked libraries. 4o make )our application d)namic linked with $+ )ou

    need to select 9S. 0+tension DLLoption when creating )our application.

    Resource 9*n*gement

    One o% the most important concepts when dealing with 9S. ,i#r*riesis that the)

    are based on resources. Resources are rich in%ormation such as bitmaps, icons,

    string tables, dialog la)outs, etc. 3ach has its own resource package that could

    be used onl) b) itsel% or shared with other s &Resource onl) s %or e9ample'.

    4he problem is that )our ObjectARX application is running into Auto+A host

    application which has its own resources. 4o sole this problem )ou should s!itch

    the resource conte+tto )our , use them, and then switch back to Auto+A.

    4his can be done manuall) but there is a couple o% classes to help )ou to easil) do

    that.

    resource and the de%ault resources. 4o make )our application take adantage o%

    this class )ou will need to create an instance o% this class inside each

    module D,,9*in>A%unction. 4his can be done using the %ollowing*

    A*_IMPLEMEN+_E6+ENSI#N_M#DULE(t#eAr_D!!);

    "N*AN7: 8#dll"nstance ' N+!!;

    e_tern `7` int AP":N*5h

    DMain("N*AN7: #"nstance, DW95D dw5eason, !P{9"D lp5esered)

    // 5e$oe t#is if ou use lp5esered

    +N5::5:N7:D8PA5A6:*:5(lp5esered);

    if (dw5eason '' DLL_PR#*ESS_A++A*;)

    t#eAr_D!!.Attac)Instanc"(#"nstance);

    #dll"nstance ' #"nstance;

    b

    else if (dw5eason '' DLL_PR#*ESS_DE+A*;)

    t#eAr_D!!.D"tac)Instanc"();

    b

    return 1; // o

    b

    4he second class, called .%c9odu,eResource"verride is a hand) class that

    per%orms the s!itch %rom Auto+A:s resource to )our application:s resource when

    http://arxdummies.blogspot.com/

    it is instantiated and then, when it is destro)ed, switch back to Auto+A. 4o use it,

    just declare an object o% it be%ore using )our own resources. (hen it goes out o%

    4ake a look inside ObjectARX documentation to see a complete list o% those

    classes.

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    50/71

    scope it will be destro)ed and its destructor will switch back. fo, this is the wa) to

    go*

    *AcMo!9"R"so9rc"#

  • 7/23/2019 Objectarx by Lemanhhung

    51/71

    Introduction

    In m) personal opinion, the greatest %eature o% "#$ect%R& is the capabilit) to

    deelop )our own o#$ects *nd entities. 4his power%ul %eature will allow )ou to

    create com-,e+ *--,ic*tionsand proide )our users a unique e9perience using

    )our so%tware.

    4his %eature is possible since ObjectARX beginning &o%%iciall) at %uto.%D Rk'.

    fince Autodesk proided this %eature, its own deelopers thought that the) could

    deelop their seles vertic*, so,utions%or the most interesting market areas. At

    that time, products l ike $AP, $+A and A4 start to show up.

    4oda) there are seeral ertical products based on Auto+A made b) Autodesk

    and much more deeloped b) thirdpart) companies.

    o! is this -ossi#,e

    ObjectARX takes %ull adantage o% .bb ,*ngu*ge

    Ce*tureslikeinherit*nce, -o,mor-hism and overriding among man) others.

    4his allows Autodesk to publish part o% Auto+A source code using a f like

    package with librar) and header %iles.

    Ze)ond this point, ObjectARX e9ports some classes allowing )ou to derie %rom

    them and im-,ement our o!n #eh*viortaking adantage o% all read)touse

    methods and oerriding those ones )ou need.

    4his wa), when )our custom class is de%ined and implemented )our*--,ic*tion

    !i,, #e com-i,ed *nd ,inBed !ith %uto.%D n*tive ,i#r*ries *nd he*ders andwill be possible to load )our module &' at runtime to use )our own objects

    inside Auto+A< yreat hum

    6hen to use *nd !hen not to use custom o#$ects

    solution like &D*t* or &Records. 4his will totall) depend on how much comple9

    )our application is and how much comple9 will be the wa) users will interact with

    )our product.

    8ou need to #e sure !hen to use or not custom c,*sses inside ObjectARX.

    Personall) I per%orm some questions to m)sel% that will help me to decide*

    $) product:s elements are sim-,e or com-,e+

    $) elements are onl) comple9 in terms o% nongr*-hic*, d*t*or the) will

    require com-,e+ gr*-hic*, re-resent*tion

    o I need to -rotect m e,ementfs d*t*when the drawing is out o% m)

    compan)

    (ill m) elements present a com-,e+ inter*ction !ith userser) di%%erent

    %rom Auto+A natie entities

    o I need to sh*re common inCorm*tionamong m) elements

    4hese questions will reall) help )ou to decide or not to user custom classes.

    o! to use * custom o#$ects

    4he %irst step is to choose our #*se c,*ss. 4his will depend on what t)pe o%

    custom object are )ou willing to implement. Zasicall) )ou need to choose i% it !i,,

    re-resent *n entit or * d*t* o#$ect . I% it will be an entit) )ou will need to

    derie it %rom %cD#0ntit or other o% its deried classes. In other hand, i% it will

    not hae graphical appearance, )ou will derie it %rom %cD#"#$ect. 4here are

    some ObjectARX classes that does not allow )ou to derie %rom. 4ake a look at

    ObjectARX documentation %or a complete list.

    It is er) important to )ou clearl) understand these di%%erences between

    Acb3ntit) and AcbObject. Remem#er th*t ever %cD#0ntit iC *,so *n

    %cD#"#$ect #ut /"3 %LL %cD#"#$ect is *n %cD#0ntit. 4his is

    because %cD#0ntit is derived Crom %cD#"#$ect.

    http://arxdummies.blogspot.com/

    I reall) would like )ou to walk through the ObjectARX class hierarch) to locate

    )oursel% in that tree and see clearl) what are we talking about. 4here is a (y 4o implement these %unctions, )ou will need to use one o% the %ollowing 9%.R"'*

    http://arxdummies.blogspot.com/http://arxdummies.blogspot.com/
  • 7/23/2019 Objectarx by Lemanhhung

    52/71

    %ile, called c,*ssm*-8d!g, inside )our ObjectARX f %older called )c,*ssm*-.

    Runtime IdentiCic*tion

    Auto+A requires that eer) custom class has its own runtime t)pe identi%ication.

    4his will be used b) Auto+A and b) )our own ap