Presentation on theme: "Advanced deepclone API in AutoCAD®"— Presentation transcript:
1 Advanced deepclone API in AutoCAD® Cyrille FauvelAutodesk Developer NetworkADN Sparks Manager
2 Class Objective You learn We do not discuss and assume knowledge of AutoCAD deepClone API and cloning techniquesBenchmarks, performance and implementation considerationsAspects of controlling cloning operations in AutoCADWe do not discuss and assume knowledge ofHow to program in .NET or ObjectARXThe basics of the AutoCAD .Net or ObjectARX APIAutoCAD product usageThis is a class for programmers who already have some familiarity with both the .NET Framework, the AutoCAD .NET API and ObjectARX.We will be looking at using the AutoCAD deepClone API to work programmatically with objects.
3 About the Presenter Cyrille Fauvel Autodesk Developer Network Cyrille is a member of the M&E workgroup of the Autodesk Developer Network (ADN) team, providing developer support, training, and conference presentations on AutoCAD, RealDWG, Inventor, Maya, 3ds Max, FBX API.He joined Autodesk in 1994 as an AutoCAD developer based in Switzerland and California, USA. Later moved to the Developer Support group, and Consulting division.Cyrille graduated in Mechanics and Electronics in France, worked as a teacher and C++ developer for a 3rd party developer on AutoCAD. He is fluent in six programming languages, tries to learn Japanese which turns out to be more difficult than learning English, has two kids, plays the guitar and piano, likes reading, love sailing on oceans, sports, and especially hand-ball.I have been working with AutoCAD APIs for over twenty years. A key part of my job is to support communication between external plug-in developers and our engineering to help the later create the APIs that the former need to write really cool add-in applications. I learned programming by myself, because when I was young and bought my first computer, I was short of money to buy games. So I had to wrote them myself ;) Now it is like an hobby, can’t get rid of it,
4 Autodesk Developer Network Access to almost all Autodesk software and SDK’sIncludes early access to beta softwareMembers-only website with thousands of technical articlesUnlimited technical supportProduct direction through conferencesMarketing benefitsExposure on autodesk.comPromotional opportunitiesOne to three free API training classesBased on user levelSome of you may be unfamiliar with ADN. The Autodesk Developer Network is a program providing professional support to programmers writing add-in applications for Autodesk software. If you think the program benefits listed here would be useful to you, then visit this URL and read more about it. You don’t have to be a commercial software developer to join ADN.
5 Agenda 1 2 3 4 5 Overview Basics API A concrete example Cloning! What is it? Why should I care?2BasicsShallow Clone, deep Clone & wblock CloneWho is using cloning?3APICloning and ID TranslationsObjectARX or .Net?4A concrete exampleModify the default AutoCAD behavior5Additional informationInspect, spy, learning more
6 Overview Cloning! What is it? Why should I care?
7 CloningCloning in biology is the process of producing similar populations of genetically identical individuals that occurs in nature when organisms such as bacteria, insects or plants reproduce asexually. Cloning in biotechnology refers to processes used to create copies of DNA fragments (molecular cloning), cells (cell cloning), or organisms. The term also refers to the production of multiple copies of a product such as digital media or software.The term clone is derived from κλῶνος, the Greek word for "trunk, branch", referring to the process whereby a new plant can be created from a twig. In horticulture, the spelling clon was used until the twentieth century; the final e came into use to indicate the vowel is a "long o" instead of a "short o". Since the term entered the popular lexicon in a more general context, the spelling clone has been used exclusively.
8 Cloning (disambiguation) Cloning is the process of making an identical copy of something.Cloning may also refer to:Cloning (programming), the copying of a programming objectDisk cloning, the copying of the contents of a computer hard disk to a storage medium or filePhone cloning, the transfer of identity between one mobile telephone and anotherReduplication, aka "cloning", in linguistics refers to a process by which the root or stem of a word is repeatedMolecular cloning, the process of identifying and isolating a specific gene
9 Cloning Clone is not Copy For this presentation Clone = make a new instance of an object which has the same property’ values of the original objectCopy = copy the value of an object property
10 First user is AutoCAD AutoCAD uses deepClone and/or wblock Copy, Mirror, Array operationsWblock operationsInsert operationsExplode operationCopy & PasteEntity drag operationReference editing…Any other plug-ins which want to control cloning operations to:Prevent clonesMake sure objects required for a clone will be presentMaintain the integrity of a user defined structure across AutoCAD commands
11 Basics Shallow Clone, Deep Clone & Wblock Clone Who is using cloning?
12 Cloning methods Shallow Cloning Deep Cloning Wblock Cloning Copy of a singleton ObjectARX C++ objectAcRxObject::clone()RTTI and C++ object copycopyFrom() to copy propertiesDeep Cloningclones an object and its hard/soft ownership referencesbut do not clone hard/soft pointer referenced objectshowever, copies the pointer reference valuesWblock Cloningclones an object and its hard owner and hard pointer referencesbut ignores any soft referencesand reset non cloned references to null
13 First user is AutoCAD AutoCAD uses deepClone and/or wblock Copy operationsdeepCloneWblock operationswblockInsert operationsdeepClone (insert)Copy & PasteWblock & deepClone (insert)Entity drag operation…
14 'Ownership' and 'Pointer References' 4 typesCombination of [ Hard or Soft ] and [ Ownership or Pointer ]HardReference required for the object to survive in a databaseSoftReference not required (can be ignored depending of the context)OwnershipParent – Child relation shipPointerCooperative object the object is referencing for its definition
15 References ObjectARX .Net No custom objects in .Net AcDbHardOwnershipIdAcDbSoftOwnershipIdAcDbHardPointerIdAcDbSoftPointerId.NetObjectIdNo custom objects in .NetUse overrules insteadCloning reference logic follows reference found in the filing protocoldwgInFields() / dwgOutFields()
17 Entity ownership Entity Sub Entity Sub Entity Sub Entity Sub Entity Hard OwnerSoft OwnerHard PointerSoft Pointer
18 Can we get things more complicated? Entities are objects Entity or BTRExt. Dict.Sub EntityObject’Sub EntityObject’Ext. Dict.Sub EntityObject’Sub Entity or EntityObject’DictionaryObjectDictionaryExt. Dict.Ext. Dict.Ext. Dict.ObjectObjectObjectObjectDictionaryDictionaryDictionaryObjectObjectObjectDictionaryDictionaryDictionaryHard OwnerObjectObjectObjectObjectObjectObjectSoft OwnerObjectObjectObjectObjectObjectObjectHard PointerSoft Pointer
20 Extension dictionaryUsing extension dictionary can simplify a lot cloning operations, because:The object hard ‘owns’ it extension dictionary versus having to reference an object in the NODdeepClone will find & clone itWblock will find & clone it as wellThe extension dictionary hard ‘owns’ its elementsdeepClone will clone its elementsWblock will clone them as wellSounds a good solution to avoid to think about cloning. Well consider the following:Each DWG object is about ~300b footprintAn object with an extension dictionary and an 1 object in it is ~ 1kMake a DWG 3 times bigger with no useful data in yet
21 Cloning phases Default cloning phase Application cloning phase AutoCAD clones objects by following the ID referencesApplication cloning phaseAutoCAD may give control to a plug-in to do additional cloning and will follow the ID references as requiredID translation phaseAutoCAD translate clone IDs to new ID & handles for object in ‘Flux’
22 In FluxClones in ‘Flux’ mode, means object being cloned, versus created and mapped to an original objectRequires ID translationYou cannot intervene during this ID translation process processUse the AcRxEventReactor class for monitoring activities and steps
23 Primary objectIf the key object is part of the primary set of objects clonedAn object can tell if it's being cloned by referencing or notThat's what the isPrimary flag is all about
25 AcDbObject::deepClone() AcDbObject::wblockClone() Never use AcDbObject::deepClone() or AcDbObject::wblockClone() directlyYou are missing the contextBut you can call them in custom object implementation or reactorsInstead useWithin the same databaseAcDbDatabase::deepCloneObjects()Across databasesAcDbDatabase::wblockCloneObjects()AcDbDatabase::wblock()AcDbDatabase::insert()
26 API Cloning and ID Translations ObjectARX or .Net?
29 RefEdit RefEdit uses the wblock() mechanism CheckoutCheckinOnly modified objects will be clones in checkinSee the AcApLongTransactionReactor classvoid beginCheckOut(AcDbLongTransaction&, AcDbObjectIdArray&);void endCheckOut(AcDbLongTransaction&);void beginCheckIn(AcDbLongTransaction&);void endCheckIn(AcDbLongTransaction&);void abortLongTransaction(AcDbLongTransaction&);Acad::ErrorStatus veto();
30 Custom objects ObjectARX Only API Sealed in ARX now AcDbObject Autodesk.AutoCAD.DatabaseServices.DBObject.Net implements these method, but you cannot override themYou can call them in a cloning context/operationAPI Sealed in ARX nowAcad::ErrorStatus deepClone(AcDbObject*, AcDbObject*&, AcDbIdMapping&, Adesk::Boolean) const;Acad::ErrorStatus wblockClone(AcRxObject*, AcDbObject*&, AcDbIdMapping&, Adesk::Boolean) const;Use the subXXX() version insteadAcad::ErrorStatus subDeepClone(AcDbObject*, AcDbObject*&, AcDbIdMapping&, Adesk::Boolean) const;Acad::ErrorStatus subWblockClone(AcRxObject*, AcDbObject*&, AcDbIdMapping&, Adesk::Boolean) const;
31 Overrule API Overrules registered on per class basis Can ‘modify’ PEX protocolSee ‘CP230-1V - .Net Overrule API’ for detailsCan ‘modify’Draw aspect,Grips,Avoid the need of a custom object
32 Available overrules PropertiesOverrule DrawableOverrule OsnapOverrule TransformOverruleGripOverruleSubentityOverruleHighlightOverruleGeometryOverruleObjectOverrule
34 A concrete example Modify the default AutoCAD behavior
35 ARXCloning sample CLONE1 command CLONE2 command CLONE3 command Performs a shallow clone of a non-database resident object.CLONE2 commandPerforms a shallow clone of a database resident object into the same databaseCLONE3 commandPerforms a shallow clone of a database resident object to another DWG databaseVery basic code one simple object such as a line or circle.
36 OPLine project OPLine1 OPLine2 OPLine3 Custom entity derived from AcDbPolylineAnd a companion custom object derived from AcDdBObject stored in the NODOPLine2Try to replicate the above structure without custom object but using reactors insteadOPLine3Same but using the new overrule API
37 Bonus The deepClone Inspector tool Monitors deepClone activity in AutoCADRecord object status and cloning stepsShows primary and secondary clonesDisplays a diagram of the structures (original and clones)Displays differences between the original and target databases
38 Additional information Inspect, spy, learning more
39 Learning more CP230-1V - .Net Overrule API CP240-2V AutoCAD .NET: Practical Examples of Customizing AutoCAD Entity BehaviorStephen Preston – Autodesk, Inc.
40 Learning more AutoCAD API Online Help, Developer's Guide and SDK SamplesAutoCAD Developer Center Free DevTV for .NET APIWebcasts and Trainings on Programming and News > AutoCAD APIThrough the Interface
41 Materials Handout Presentation Sample code and models AU10_CP220-3C_ARX_Cloning_2011_API.docxPresentationAU10_CP220-3C_ARX_Cloning_2011_API.pptxSample code and modelsAU10_CP220-3C_ARX_Cloning_2011_API.zip
Your consent to our cookies if you continue to use this website.