620 likes | 1.02k Views
AutoCAD MEP .NET API. Steve Milligan API Engineer, Autodesk steve.milligan@autodesk.com. Why the use the .NET Framework?.
E N D
AutoCAD MEP .NET API Steve Milligan API Engineer, Autodesk steve.milligan@autodesk.com
Why the use the .NET Framework? • Since the introduction of AutoLISP, users of AutoCAD have been able to customize the AutoCAD platform to perform tasks never envisioned by the founders of the product. As AutoCAD has continued to grow as an application and a framework, new development technologies have been introduced to speed and enhance the customization. AutoLISP and VBA are easy to use and available out of the box. They hide much of the complexity of managing the memory and objects from the user, allowing the user to concentrate more on the solution to a problem and less about the code. ObjectARX, on the other hand, is much harder to use and is not included with the product. One needs to be fluent in C++, memory management and understand the underlying C++ structure of the application to customize with ObjectARX. Of course, these development environments have pros and cons. With the introduction of the AutoCAD .NET API, a whole new door was opened to the customization of AutoCAD. • The .NET API allows developers to have the ease of use of VBA and LISP with the coverage and speed of ObjectARX. Want to design a dialog with a list control and a tree control to show the contents of a dictionary in AutoCAD? No problem! This would have been very complicated in AutoLISP, VBA and even ObjectARX. While not a trivial task in .NET, it is certainly obtainable in a couple of hours. How can this be? While there are some of use that might remember programming DCL (yikes!) and we have all created our fare share of forms in VBA, and maybe even some have ventured into MFC, these are all much more complicated than using the Windows Forms.
Why the use the .NET Framework? • Because the AutoCAD MEP .NET API is built for the Microsoft .NET Framework you can take advantage of using the framework to garbage collect memory, use templated container classes, use Windows Form classes, use Xml classes, support multiple side by side versions, create installation applications, access databases and file systems, or take advantage of the multitude of other classes that are part of the .NET Framework. • While it may seems like just another technology to learn, I can assure you that your productivity and AutoCAD enhancement will improve using the .NET API. Some of you may be new to .NET and object oriented programming, so please dive in and enjoy the ride. Others may be object oriented gurus and are looking to hone your skills. The great thing about the .NET framework is gives you the opportunity to use the library to your skill level.
Class Poll How many people have programmed AutoCAD using .NET How many people have programmed AutoCAD MEP using .NET
AutoCAD MEP API Review MEP API Overview OMF Directly utilize .NET assemblies Wraps a lot of MEP 3rd party .NET apps MEP MEP .NET ObjectARX ACA .NET ACA MEP ActiveX via COM Interop AutoCAD .NET AutoCAD ACA ActiveX AutoCAD ActiveX MEP 3rd party VB/VBA apps API’S
Assembly References The following is a list of references used by AutoCAD MEP: AutoCAD Managed Modules acmgd.dl * acdbmgd.dll * ACA Managed Modules AecArchMgd.dll AecBaseMgd.dll * AecPropDataMgd.dll AecStructureMgd.dll MEP Managed Modules AecbBldSrvMgd.dll AecbElecBaseMgd.dll AecbHvacBaseMgd.dll AecbPartBaseMgd.dll AecbPipeBaseMgd.dll AecbPlumbingBaseMgd.dll * Required reference
MEP .NET API Managed Dlls Assembly DLLs Provided with MEP product Folder: <MEP 2008>\Aecb*Mgd.dll Files: AecbBldSrvMgd.dll AecbElecBaseMgd.dll AecbHvacBaseMgd.dll AecbPartBaseMgd.dll AecbPipeBaseMgd.dll AecbPlumbingBaseMgd.dll
MEP .NET API Documentation A CHM file Provided with MEP product <MEP 2008>\Help\absmgd.chm Contents: Aedb*Mgd .NET API Reference AecBaseMgd .NET API Reference AecBaseUtilsMgd .NET API Reference AecArchMgd .NET API Reference AecPropDataMgd .NET API Reference AecProjectBaseMgd .NET API Reference AecStructureMgd .NET API Reference
MEP .NET API AutoCAD MEP Part Catalog
MEP Part Catalog APC + XML = AutoCAD MEP Part Catalog APC File The APC file contains all of the parts in the catalog. XML File Contains all the data needed to create a parametric part Drawing Recipe Contains the path to the drawing Image Url Contains the image path
APC File <Part name="Round Duct" id="B7B201F3-FE40-404C-B5BC-0FB413D25FF8“> <Desc>Round Duct US Imperial</Desc> <Images> <Image> <URL xlink:title="Round Duct US Imperial" xlink:href="Bmp\Aecb_Round_Duct.bmp" xlink:show="embed" xlink:actuate="onLoad"/> </Image> </Images> <TableRef> <URL xlink:href="Round\Ducts\Round Duct.xml"/> </TableRef> <Extrinsics> <Extrinsic name="AecbPartSearchAttribList"> <AecbPartSearchAttribList domain="Duct_Component" part_type="Duct" content_type="3" part_subtype="Rigid" port_shapes_1="Round" port_shapes_2="Round" connection_types_1="Undefined_Connection_Type;Banded;Flange;Slip_Joint;Vanstone" connection_types_2="Undefined_Connection_Type;Banded;Flange;Slip_Joint;Vanstone" autolayout="True" placeholder="False" eccentricity="False" hidepart="False"/> </Extrinsic> </Extrinsics> </Part>
XML File A sample XML file: Round Duct Straight Cross.xml
MEP Part Catalog The part catalog is the heart of the MEP parametric platform. To use the Part Catalog, we need to add a reference to: AecbPartBaseMgd.dll This assembly has all the methods needed to query, create and modify MEP parametric parts.
AecbPartBaseMgd Classes • DataPartLookup • Contains general information about parts: • Name • Domain • GUID • Path • DataPartLookupCollection • List container of DataPartLookup objects. • DataPartList • Contains a collection of DataPartLookup items obtained from the CatalogManager or PartManager GetPartList method.
AecbPartBaseMgd Classes Cont’d • DataField • The Datafield class represents the container object for the data. The datafield can hold the following types: • Boolean • Double • Integer • ObjectId • String • Use the properties ValueDouble, ValueString, etc to get or set the properties. Autodesk Building Solutions
AecbPartBaseMgd Classes Cont’d • DataQuery • Represent the query object for accessing the underlying xml files. This is where you can specify how granular you want your results. DataQuery query = new DataQuery(); query.PartGuid = "B7B201F3-FE40-404C-B5BC-0FB413D25FF8"; query.AddSizeParameter(Context.ConnectionSizeDiameter, 1, 12.0); DataExpandedTable exTable = PartManager.GetPartTable(query, maxRecords); Autodesk Building Solutions
AecbPartBaseMgd Classes Cont’d • DataExpandedTable • The expanded table represents the results of the query. It will contain 0 to N records based on the specifics of the DataQuery. You may limit the number of items returned by providing a max search in the call: • PartManager.GetPartTable(query, maxRecords); • DataRecord • Represent a row of data made up of Datafields
AecbPartBaseMgd Classes Cont’d • The DataRawTable is the in memory representation of the XML part file. This class gives you several useful methods to retrieve data about the parts. • FindConstListByContext • Get the list of sizes supported • FindConstListByContextAndIndex • Get the list of sizes supported by index • Basic Table • Get the basic table • Const Set • Get the list of the constant values Autodesk Building Solutions
PartManager • The PartManager class is responsible for all data associated with all parts. Through the PartManager you are able to add, query and modify the parts. • CreatePartEntityViaStyle • CreatePartViaQueryParameters • CreatePartViaRecord • GetEngineeringData • GetPartData • GetPartsList • GetPartTable • ModifyPartViaQueryParameters • ModifyPartViaRecord Autodesk Building Solutions
PartManager – New Methods 2008 • The following methods are new to PartManager and all take a Member object. (Similar to methods of the AecbPartData VBA interface) • GetPartCatalogGuid • GetPartDescription • GetPartDomain • GetPartGuid • GetPartName • GetPartSizeName • GetPartSubType • GetPartType • IsPartPlaceholder • New Data Methods – Use with Caution • SetPartData - This function can cause data corruption! • SetEngineeringData Autodesk Building Solutions
CatalogManager • The CatalogManager class represents the in-memory representation of the APC and XML files. This class gives complete access to the Part Catalog, including adding new parts to the catalog. • AddCatalogPartEntry • GetChapters • DomainLists • FullCatalogPath • ConnectionTypes • PartTypes • Shapes • GetRawTable • GetExpandedTable Autodesk Building Solutions
CatalogManager Sample: AddToCatalog Sample: AddCustomData
Samples • CatalogExplorer • This sample demonstrates using the DataPartLookup, DataPartsList and DataRawTable, and the CatalogManager classes Autodesk Building Solutions
MEP .NET API AutoCAD MEP Object Model
Member Based Classes Member MutliViewPartBase Fitting Segment Schematic MultiSegment SchematicPipe
Segment Based Classes Segment CableTray Pipe Conduit Duct
MultiSegment Based Classes MultiSegment DuctFlex DuctCusomFitting PipeFlex PipeCustomFitting Wire
Fitting Based Classes Fitting DuctFitting CableTrayFitting PipeFitting ConduitFitting
MultiViewPartBase Based Classes MultiViewPartBase MultiViewPart Device SchematicSymbol Panel SchematicPipeFitting
SystemDefinition Based Classes SystemDefinition DuctSystemDefinition PlumbingSystemDefinition PipeSystemDefinition ElectricalSystemDefinition SchematicSystemDefinition
MEP .NET API Part Creation
Part Creation • Workflow: • Create a new part, call SetToStandard, SetDatabaseDefaults • Create and populate part query • Get the ExpandedTable from the catalog • Apply those results to create the part with PartManager • Set geometry, system, style and layer information • Add the part to the database and update the transaction
Sample Code • Create a fitting: • Round Duct Straight Cross - US Imperial • GUID: D5BF1BC5-A058-445F-82BB-C522F7A689D5 • Size: 10.0 x 10.0 x 20.0 x 30.0 Modify Duct Increase duct size * 2
MEP .NET API Application and Database Settings
MEP .NET API – App & DB Settings Two classes: BuildingPreferences BuildingDBVariables
MEP .NET API – App & DB Settings BuildingPreferences: Correspond to the settings in the Options dialog: ExtendDuctTakeOffCenterline DisplayMultiShapeFittingCenterline DisplayFlexDuctCenterline DisplayOvalDuctCenterline DisplayRectangularDuctCenterline DisplayRoundDuctCenterline
MEP .NET API – App & DB Settings BuildingPreferences: Almost all properties and methods are static. So we don’t have to create an instance.
MEP .NET API – App & DB Settings BuildingDBVariables: corresponds to the preferences of each MEP system (e.g. HVAC) Duct Layout Preferences: EnableDuctLining DuctLiningThickness EnableDuctInsulation DuctInsulationThickness UseDefaultDuctLabelStyle1 DefaultDuctLabelStyle1 LayoutDuctLabelStyle1 NumNodesDuctLabelStyle1 DistanceDuctLabelStyle1 UseDefaultDuctLabelStyle2 DefaultDuctLabelStyle2 LayoutDuctLabelStyle2 NumNodesDuctLabelStyle2 DistanceDuctLabelStyle2
MEP .NET API – App & DB Settings BuildingDBVariables: Its properties and methods are per instance. The class has a static method: BuildingDBVariables.GetInstance() Sample code: ObjectId oid = BuildingDBVariables.GetInstance(db, false); BuildingDBVariables mepDbVars = null; using (Transaction trans = transMgr.StartTransaction()) { using (mepDbVars = (BuildingDBVariables)trans.GetObject(oid, OpenMode.ForRead)) { } }
MEP .NET API – App & DB Settings API names may not be consistent with UI labels: For example: BuildingPreferences ::SetInterferenceDetection() -> Collision Detection BuildingPreferences.SetUseHaloedLinesGapOnContours -> Crossing Objects Display related BuildingPreferences.SetUseHaloedLinesFor2LineMvParts -> Crossing Objects Display related BuildingPreferences.SetHaloedLineGap -> Crossing Objects Display related BuildingPreferences.SetUseHaloedLinesCacheOrFileInDwg -> Crossing Objects Display related SystemDefinition ::Family -> Group Name SystemDefinition ::Abbreviation -> LabelName
MEP .NET API – Systems Defintions DictionaryXXXXSystemDefinition An AutoCAD dictionary actually (derived from Dictionary) Properties and methods are per instance Create an instance for a DB: DictionaryDuctSystemDefinition ddsd = new DictionaryDuctSystemDefinition(db); All definitions are returned in the collection: ddsd.Records We can loop through the collection to get each definition: XXXXSystemDefinition A Dict Record actually (derived from DictionaryRecord)
Creating a System Definition Create a system definition Start a transaction Get the DictionarySystemDefinition instance for the DB Create a new SystemDefinition Set its properties Call AddNewRecord on the dictionary Call AddNewlyCreatedDbObject on the transaction Commit the transaction
MEP .NET API – App & DB Settings Sample Code: Set MEP Tooltips Class name: true Object Name: false System: true Elevation: false Set MEP collision options Collision Detection Collision Color List out Duct Layout Preferences
MEP .NET API Part Connection
Connectors • Class name: • ConnectionComponentMember • Method: • Member.ConnectionComponentMembers • Direct accessible information: • name, gender, location, domain, connection type, flow type, Curve/Point connector, system type, etc. • Indirect accessible information: • connected objects through Member.GetObjectsAtConnectionComponent • Direction through GetLayoutNodeDirectionAtPoint • Dimension (width/height or diameter) through Profile • Style through styleId
Connectors • Retrieve connector dimension: • ProfileId property refers to a Profile Definition ProfileDefinition pd = (ProfileDefinition)transMgr.GetObject(connection.ProfileId, OpenMode.ForRead, false); if (pd != null) { shape = pd.ProfileShape; height = pd.NominalHeight; width = pd.NominalWidth; }
Connectors • Sample Code • ShowConnectedParts